Files
speckle-sharp-connectors/Sdk/Speckle.Performance/JetbrainsProfiler.cs
T
Adam Hathcock 9d5faa92e8 feat: Perf testing helpers for Jetbrains (#635)
* add perf project

* formatting

* add perf project to local
2025-03-06 11:04:14 +00:00

49 lines
1.1 KiB
C#

using JetBrains.Profiler.SelfApi;
namespace Speckle.Performance;
public static class JetbrainsProfiler
{
private sealed class CpuClass : IDisposable
{
public CpuClass(string snapshotPath)
{
DotTrace.Init();
var config2 = new DotTrace.Config();
config2.SaveToDir(snapshotPath);
DotTrace.Attach(config2);
DotTrace.StartCollectingData();
}
public void Dispose()
{
DotTrace.StopCollectingData();
DotTrace.SaveData();
DotTrace.Detach();
}
}
private sealed class MemoryClass : IDisposable
{
public MemoryClass(string snapshotPath)
{
DotMemory.Init();
var config = new DotMemory.Config();
config.OpenDotMemory();
config.SaveToDir(snapshotPath);
DotMemory.Attach(config);
DotMemory.GetSnapshot("Before");
}
public void Dispose()
{
DotMemory.GetSnapshot("After");
DotMemory.Detach();
}
}
public static IDisposable Cpu(string snapshotPath) => new CpuClass(snapshotPath);
public static IDisposable Memory(string snapshotPath) => new MemoryClass(snapshotPath);
}