-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Mosa.Tool.Explorer.Avalonia project (#1221)
Signed-off-by: AnErrupTion <[email protected]>
- Loading branch information
1 parent
00fdf6a
commit 79b06b5
Showing
21 changed files
with
2,724 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
Source/Mosa.Tool.Explorer.Avalonia/CompilerStage/ExplorerMethodCompileTimeStage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.