Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mosa.Tool.Explorer: Port to Avalonia #1221

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions Source/Mosa.Linux.sln
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mosa.Workspace.FileSystem.D
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mosa.Workspace.GDB.Debug", "Mosa.Workspace.GDB.Debug\Mosa.Workspace.GDB.Debug.csproj", "{00512754-29C4-4AA3-8619-8C04120D7B55}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mosa.Tool.Explorer.Avalonia", "Mosa.Tool.Explorer.Avalonia\Mosa.Tool.Explorer.Avalonia.csproj", "{FBC3B0CD-D775-41C6-A735-F59118838397}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1384,6 +1386,24 @@ Global
{00512754-29C4-4AA3-8619-8C04120D7B55}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{00512754-29C4-4AA3-8619-8C04120D7B55}.Release|x86.ActiveCfg = Release|Any CPU
{00512754-29C4-4AA3-8619-8C04120D7B55}.Release|x86.Build.0 = Release|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Debug|x86.ActiveCfg = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Debug|x86.Build.0 = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Description|Any CPU.ActiveCfg = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Description|Any CPU.Build.0 = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Description|Mixed Platforms.ActiveCfg = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Description|Mixed Platforms.Build.0 = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Description|x86.ActiveCfg = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Description|x86.Build.0 = Debug|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Release|Any CPU.Build.0 = Release|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Release|x86.ActiveCfg = Release|Any CPU
{FBC3B0CD-D775-41C6-A735-F59118838397}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1457,6 +1477,7 @@ Global
{FDD348E9-AD4A-497E-98A9-FBBD47D51DE4} = {D1C4B715-9764-4430-B3D3-676B0EBCE75A}
{00512754-29C4-4AA3-8619-8C04120D7B55} = {D1C4B715-9764-4430-B3D3-676B0EBCE75A}
{A4028807-1B21-4D14-9CE3-5FD1AAD9EDD7} = {F0EFF742-92D5-4219-939A-8F6F8DAB24E5}
{FBC3B0CD-D775-41C6-A735-F59118838397} = {D032B24A-CE3A-4881-BACE-CC4FE0AFD69D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C22A5C94-6B05-4B1B-845A-A2EA7615E093}
Expand Down
9 changes: 9 additions & 0 deletions Source/Mosa.Tool.Explorer.Avalonia/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Mosa.Tool.Explorer.Avalonia.App"
RequestedThemeVariant="Default">
<Application.Styles>
<SimpleTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Simple.xaml"/>
</Application.Styles>
</Application>
28 changes: 28 additions & 0 deletions Source/Mosa.Tool.Explorer.Avalonia/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;

namespace Mosa.Tool.Explorer.Avalonia;

public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.Startup += (_, args) =>
{
var win = new MainWindow();
win.Initialize(args.Args);
desktop.MainWindow = win;
};
}

base.OnFrameworkInitializationCompleted();
}
}
118 changes: 118 additions & 0 deletions Source/Mosa.Tool.Explorer.Avalonia/CompilerData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.Diagnostics;

namespace Mosa.Tool.Explorer.Avalonia;

public class CompilerData
{
public readonly Dictionary<string, List<string>> Logs = new Dictionary<string, List<string>>();
public readonly List<string> LogSections = new List<string>();

public readonly Stopwatch Stopwatch = new Stopwatch();

public bool DirtyLog = true;
public bool DirtyLogSections = true;

public void ClearAllLogs()
{
lock (Logs)
{
Logs.Clear();
LogSections.Clear();
}

UpdateLog("Compiler", null);
}

public void UpdateLog(string section, List<string> lines, bool dirty)
{
lock (Logs)
{
if (!Logs.TryGetValue(section, out List<string> log))
{
log = new List<string>(100);
Logs.Add(section, log);
LogSections.Add(section);
DirtyLogSections = true;
}

lock (log)
{
log.AddRange(lines);
}

DirtyLog = dirty;
}
}

private void UpdateLog(string section, string line)
{
lock (Logs)
{
if (!Logs.TryGetValue(section, out List<string> log))
{
log = new List<string>(100);
Logs.Add(section, log);
LogSections.Add(section);
DirtyLogSections = true;
}

lock (log)
{
log.Add(line);
}

DirtyLog = true;
}
}

public List<string> GetLog(string section)
{
lock (Logs)
{
return Logs.GetValueOrDefault(section);
}
}

public void AddTraceEvent(CompilerEvent compilerEvent, string message, int threadID)
{
if (compilerEvent == CompilerEvent.Counter)
{
UpdateLog("Counters", message);
return;
}

var part = string.IsNullOrWhiteSpace(message) ? string.Empty : ": " + message;
var msg = $"{compilerEvent.ToText()}{part}";

var timeLog = $"{Stopwatch.Elapsed.TotalSeconds:00.00} | [{threadID}] {msg}";

if (compilerEvent == CompilerEvent.Error)
{
UpdateLog("Error", msg);
UpdateLog("Compiler", timeLog);
}
if (compilerEvent == CompilerEvent.Exception)
{
UpdateLog("Exception", msg);
UpdateLog("Compiler", timeLog);
}
else
{
UpdateLog("Compiler", timeLog);
}
}

public void SortLog(string section)
{
lock (Logs)
{
if (!Logs.TryGetValue(section, out List<string> lines))
return;

lines.Sort();
Logs[section] = lines;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;
using Mosa.Compiler.Framework.CompilerStages;

namespace Mosa.Tool.Explorer.Avalonia.CompilerStage;

/// <summary>
/// A compilation stage which generates a map file of the built binary file.
/// </summary>
/// <seealso cref="Mosa.Compiler.Framework.BaseCompilerStage" />
public sealed class ExplorerMethodCompileTimeStage : MethodCompileTimeStage
{
protected override void Finalization()
{
var methods = GetAndSortMethodData();
var log = new TraceLog(TraceType.GlobalDebug, null, null, "Compiler Time");

log.Log("Ticks\tMilliseconds\tCompiler Count\tMethod");

foreach (var data in methods)
log.Log($"{data.ElapsedTicks}{'\t'}{data.ElapsedTicks / TimeSpan.TicksPerMillisecond}{'\t'}{data.Version}{'\t'}{data.Method.FullName}");

PostTraceLog(log);
}
}
5 changes: 5 additions & 0 deletions Source/Mosa.Tool.Explorer.Avalonia/CounterEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

namespace Mosa.Tool.Explorer.Avalonia;

public record CounterEntry(string Name, int Value);