Skip to content

Commit

Permalink
Simplified involved rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Apr 11, 2024
1 parent 75e60fe commit f6524f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 149 deletions.
74 changes: 8 additions & 66 deletions src/BUTR.CrashReport.Renderer.Html/CrashReportHtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,89 +220,31 @@ private static string GetEnhancedStacktraceHtml(CrashReportModel crashReport)

private static void AddInvolvedModules(CrashReportModel crashReport, StringBuilder sbMain)
{
foreach (var grouping in crashReport.EnhancedStacktrace.GroupBy(x => x.ExecutingMethod.ModuleId ?? "UNKNOWN"))
foreach (var involvedModule in crashReport.InvolvedLoaderPlugins.GroupBy(x => x.ModuleOrLoaderPluginId))
{
var moduleId = grouping.Key;
if (moduleId == "UNKNOWN") continue;

sbMain.Append("<li>")
.Append("Module Id: ").Append("<a href='javascript:;' onclick='scrollToElement(\"").Append(moduleId).Append("\")'>").Append(moduleId).Append("</a>").Append("<br/>");
.Append("Module Id: ").Append("<a href='javascript:;' onclick='scrollToElement(\"").Append(involvedModule.Key).Append("\")'>").Append(involvedModule.Key).Append("</a>").Append("<br/>");

foreach (var stacktrace in grouping)
foreach (var involved in involvedModule)
{
sbMain.Append("Method: ").Append(stacktrace.ExecutingMethod.MethodFullDescription.EscapeGenerics()).Append("<br/>")
.Append("Frame: ").Append(stacktrace.FrameDescription.EscapeGenerics()).Append("<br/>");

if (stacktrace.PatchMethods.Count > 0)
{
sbMain.Append("Patches:").Append("<br/>")
.Append("<ul>");
foreach (var method in stacktrace.PatchMethods)
{
var harmonyPatchType = method.AdditionalMetadata.FirstOrDefault(x => x.Key == "HarmonyPatchType");

// Ignore blank transpilers used to force the jitter to skip inlining
if (method.MethodName == "BlankTranspiler") continue;
var moduleId2 = method.ModuleId ?? "UNKNOWN";
sbMain.Append("<li>")
.AppendIf(moduleId2 == "UNKNOWN", sb => sb.Append("Module Id: ").Append(moduleId2).Append("<br/>"))
.AppendIf(moduleId2 != "UNKNOWN", sb => sb.Append("Module Id: ").Append("<b><a href='javascript:;' onclick='scrollToElement(\"").Append(moduleId2).Append("\")'>").Append(moduleId2).Append("</a></b>").Append("<br/>"))
.Append("Method: ").Append(method.MethodFullDescription.EscapeGenerics()).Append("<br/>")
.AppendIf(harmonyPatchType is not null, sb => sb.Append("Harmony Patch Type: ").Append(harmonyPatchType!.Value).Append("<br/>"))
.Append("</li>");
}
sbMain.Append("</ul>");
}

sbMain.Append("</br>");

sbMain.Append("Frame: ").Append(involved.EnhancedStacktraceFrameName.EscapeGenerics()).Append("<br/>");
sbMain.Append("</li>");
}

sbMain.Append("</li>");
}
}
private static void AddInvolvedPlugins(CrashReportModel crashReport, StringBuilder sbMain)
{
foreach (var grouping in crashReport.EnhancedStacktrace.GroupBy(x => x.ExecutingMethod.LoaderPluginId ?? "UNKNOWN"))
foreach (var involvedPlugin in crashReport.InvolvedLoaderPlugins.GroupBy(x => x.ModuleOrLoaderPluginId))
{
var pluginId = grouping.Key;
if (pluginId == "UNKNOWN") continue;

sbMain.Append("<li>")
.Append("Plugin Id: ").Append("<a href='javascript:;' onclick='scrollToElement(\"").Append(pluginId).Append("\")'>").Append(pluginId).Append("</a>").Append("<br/>");
.Append("Plugin Id: ").Append("<a href='javascript:;' onclick='scrollToElement(\"").Append(involvedPlugin.Key).Append("\")'>").Append(involvedPlugin.Key).Append("</a>").Append("<br/>");

foreach (var stacktrace in grouping)
foreach (var involved in involvedPlugin)
{
sbMain.Append("Method: ").Append(stacktrace.ExecutingMethod.MethodFullDescription.EscapeGenerics()).Append("<br/>")
.Append("Frame: ").Append(stacktrace.FrameDescription.EscapeGenerics()).Append("<br/>");

if (stacktrace.PatchMethods.Count > 0)
{
sbMain.Append("Patches:").Append("<br/>")
.Append("<ul>");
foreach (var method in stacktrace.PatchMethods)
{
var harmonyPatchType = method.AdditionalMetadata.FirstOrDefault(x => x.Key == "HarmonyPatchType");

// Ignore blank transpilers used to force the jitter to skip inlining
if (method.MethodName == "BlankTranspiler") continue;
var pluginId2 = method.LoaderPluginId ?? "UNKNOWN";
sbMain.Append("<li>")
.AppendIf(pluginId2 == "UNKNOWN", sb => sb.Append("Plugin Id: ").Append(pluginId2).Append("<br/>"))
.AppendIf(pluginId2 != "UNKNOWN", sb => sb.Append("Plugin Id: ").Append("<b><a href='javascript:;' onclick='scrollToElement(\"").Append(pluginId2).Append("\")'>").Append(pluginId2).Append("</a></b>").Append("<br/>"))
.Append("Method: ").Append(method.MethodFullDescription.EscapeGenerics()).Append("<br/>")
.AppendIf(harmonyPatchType is not null, sb => sb.Append("Harmony Patch Type: ").Append(harmonyPatchType!.Value).Append("<br/>"))
.Append("</li>");
}
sbMain.Append("</ul>");
}

sbMain.Append("</br>");

sbMain.Append("Frame: ").Append(involved.EnhancedStacktraceFrameName.EscapeGenerics()).Append("<br/>");
sbMain.Append("</li>");
}

sbMain.Append("</li>");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using BUTR.CrashReport.Models;
using BUTR.CrashReport.Renderer.ImGui.Extensions;

using HonkPerf.NET.RefLinq;

using ImGuiNET;

Expand All @@ -12,71 +9,39 @@ namespace BUTR.CrashReport.Renderer.ImGui.Renderer;

partial class ImGuiRenderer
{
private KeyValuePair<string, EnhancedStacktraceFrameModel[]>[] _enhancedStacktraceGroupedByModuleId = [];
private KeyValuePair<string, EnhancedStacktraceFrameModel[]>[] _enhancedStacktraceGroupedByLoaderPluginIdId = [];
private KeyValuePair<string, InvolvedModuleOrPluginModel[]>[] _enhancedStacktraceGroupedByModuleId = [];
private KeyValuePair<string, InvolvedModuleOrPluginModel[]>[] _enhancedStacktraceGroupedByLoaderPluginIdId = [];

private void InitializeInvolved()
{
_enhancedStacktraceGroupedByModuleId = _crashReport.EnhancedStacktrace
.GroupBy(x => x.ExecutingMethod.ModuleId ?? "UNKNOWN")
.Select(x => new KeyValuePair<string, EnhancedStacktraceFrameModel[]>(x.Key, x.ToArray()))
_enhancedStacktraceGroupedByModuleId = _crashReport.InvolvedModules
.GroupBy(x => x.ModuleOrLoaderPluginId)
.Select(x => new KeyValuePair<string, InvolvedModuleOrPluginModel[]>(x.Key, x.ToArray()))
.ToArray();

_enhancedStacktraceGroupedByLoaderPluginIdId = _crashReport.EnhancedStacktrace
.GroupBy(x => x.ExecutingMethod.LoaderPluginId ?? "UNKNOWN")
.Select(x => new KeyValuePair<string, EnhancedStacktraceFrameModel[]>(x.Key, x.ToArray()))
_enhancedStacktraceGroupedByLoaderPluginIdId = _crashReport.InvolvedLoaderPlugins
.GroupBy(x => x.ModuleOrLoaderPluginId)
.Select(x => new KeyValuePair<string, InvolvedModuleOrPluginModel[]>(x.Key, x.ToArray()))
.ToArray();
}

private void RenderInvolvedModules()
{
foreach (var kv in _enhancedStacktraceGroupedByModuleId)
{
if (kv.Key == "UNKNOWN") continue;

if (_imgui.TreeNode(kv.Key, ImGuiTreeNodeFlags.DefaultOpen))
{
_imgui.RenderId("Module Id:\0"u8, kv.Key);

for (var j = 0; j < kv.Value.Length; j++)
{
var stacktrace = kv.Value[j];
var involved = kv.Value[j];
_imgui.Bullet();
_imgui.Indent();

_imgui.TextSameLine("Method: \0"u8);
_imgui.Text(stacktrace.ExecutingMethod.MethodFullDescription);
_imgui.TextSameLine("Frame: \0"u8);
_imgui.Text(stacktrace.FrameDescription);

if (stacktrace.PatchMethods.Count > 0)
{
_imgui.Text("Patches:\0"u8);

_imgui.Bullet();
_imgui.Indent();
for (var k = 0; k < stacktrace.PatchMethods.Count; k++)
{
var method = stacktrace.PatchMethods[k];
var harmonyPatchType = method.AdditionalMetadata.ToRefLinq().Where(x => x.Key == "HarmonyPatchType").FirstOrDefault();

// Ignore blank transpilers used to force the jitter to skip inlining
if (method.MethodName == "BlankTranspiler") continue;
var moduleId2 = method.ModuleId ?? "UNKNOWN";

if (moduleId2 == "UNKNOWN") _imgui.RenderId("Module Id:\0"u8, kv.Key);
_imgui.TextSameLine("Method: \0"u8);
_imgui.Text(method.MethodFullDescription);
if (harmonyPatchType is not null)
{
_imgui.TextSameLine("Harmony Patch Type: }\0"u8);
_imgui.Text(harmonyPatchType.Value);
}
}

_imgui.Unindent();
}

_imgui.Text(involved.EnhancedStacktraceFrameName);

_imgui.Unindent();
}

Expand All @@ -89,52 +54,19 @@ private void RenderInvolvedPlugins()
{
foreach (var kv in _enhancedStacktraceGroupedByLoaderPluginIdId)
{
if (kv.Key == "UNKNOWN") continue;

if (_imgui.TreeNode(kv.Key, ImGuiTreeNodeFlags.DefaultOpen))
{
_imgui.RenderId("Plugin Id:\0"u8, kv.Key);

for (var j = 0; j < kv.Value.Length; j++)
{
var stacktrace = kv.Value[j];
var involved = kv.Value[j];
_imgui.Bullet();
_imgui.Indent();

_imgui.TextSameLine("Method: \0"u8);
_imgui.Text(stacktrace.ExecutingMethod.MethodFullDescription);
_imgui.TextSameLine("Frame: \0"u8);
_imgui.Text(stacktrace.FrameDescription);

if (stacktrace.PatchMethods.Count > 0)
{
_imgui.Text("Patches:\0"u8);

_imgui.Bullet();
_imgui.Indent();

for (var k = 0; k < stacktrace.PatchMethods.Count; k++)
{
var method = stacktrace.PatchMethods[k];
var harmonyPatchType = method.AdditionalMetadata.ToRefLinq().Where(x => x.Key == "HarmonyPatchType").FirstOrDefault();

// Ignore blank transpilers used to force the jitter to skip inlining
if (method.MethodName == "BlankTranspiler") continue;
var pluginId2 = method.LoaderPluginId ?? "UNKNOWN";

if (pluginId2 == "UNKNOWN") _imgui.RenderId("Plugin Id:\0"u8, kv.Key);
_imgui.TextSameLine("Method: \0"u8);
_imgui.Text(method.MethodFullDescription);
if (harmonyPatchType is not null)
{
_imgui.TextSameLine("Harmony Patch Type: \0"u8);
_imgui.Text(harmonyPatchType.Value);
}
}

_imgui.Unindent();
}

_imgui.Text(involved.EnhancedStacktraceFrameName);

_imgui.Unindent();
}

Expand All @@ -145,7 +77,7 @@ private void RenderInvolvedPlugins()

private void RenderInvolvedModulesAndPlugins()
{
_imgui.Text("Based on Stacktrace (From highest probability to lowest):\0"u8);
_imgui.Text("From highest probability to lowest:\0"u8);
_imgui.Indent();
RenderInvolvedModules();
RenderInvolvedPlugins();
Expand Down

0 comments on commit f6524f9

Please sign in to comment.