mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
- Add DiagnosticUtil to automatically filter out the "boring" stack entries. Co-authored-by: goat <16760685+goaaats@users.noreply.github.com>
32 lines
950 B
C#
32 lines
950 B
C#
using System.Diagnostics;
|
|
using System.Linq;
|
|
|
|
namespace Dalamud.Utility;
|
|
|
|
/// <summary>
|
|
/// A set of utilities for diagnostics.
|
|
/// </summary>
|
|
public static class DiagnosticUtil
|
|
{
|
|
private static readonly string[] IgnoredNamespaces = [
|
|
nameof(System),
|
|
nameof(ImGuiNET.ImGuiNative)
|
|
];
|
|
|
|
/// <summary>
|
|
/// Gets a stack trace that filters out irrelevant frames.
|
|
/// </summary>
|
|
/// <param name="source">The source stacktrace to filter.</param>
|
|
/// <returns>Returns a stack trace with "extra" frames removed.</returns>
|
|
public static StackTrace GetUsefulTrace(StackTrace source)
|
|
{
|
|
var frames = source.GetFrames().SkipWhile(
|
|
f =>
|
|
{
|
|
var frameNs = f.GetMethod()?.DeclaringType?.Namespace;
|
|
return frameNs == null || IgnoredNamespaces.Any(i => frameNs.StartsWith(i, true, null));
|
|
});
|
|
|
|
return new StackTrace(frames);
|
|
}
|
|
}
|