Files
sbox-public/game/addons/tools/Code/Diagnostics/AllocationsDock.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

69 lines
1.3 KiB
C#

namespace Editor;
[Dock( "Editor", "Allocations", "timer" )]
public class Allocations : Widget
{
Sandbox.Diagnostics.Allocations.Scope scope;
Layout Header;
Layout Body;
Button StopStart;
public Allocations( Widget parent ) : base( parent )
{
MinimumSize = 200;
scope = new Sandbox.Diagnostics.Allocations.Scope();
Layout = Layout.Column();
Header = Layout.AddRow();
Header.Spacing = 2;
Header.Margin = 4;
Body = Layout.AddColumn( 1 );
Body.AddStretchCell();
StopStart = Header.Add( new Button( "Start", this ) { Clicked = () => Start() } );
Header.Add( new Button( "Clear", this ) { Clicked = () => scope.Clear() } );
}
public override void OnDestroyed()
{
base.OnDestroyed();
scope?.Stop();
scope = null;
}
public void Start()
{
scope.Start();
StopStart.Text = "Stop";
StopStart.Clicked = Stop;
}
void Stop()
{
scope.Stop();
StopStart.Text = "Start";
StopStart.Clicked = Start;
}
protected override void OnPaint()
{
base.OnPaint();
const int lineHeight = 16;
var y = Body.OuterRect.Top + 8;
foreach ( var line in scope.Entries.OrderByDescending( x => x.Count ).Take( 64 ) )
{
Paint.DrawText( new Rect( 0, y, Width, lineHeight ), $"{line.Count}: {line.Name}", TextFlag.LeftBottom );
y += lineHeight;
}
Update();
}
}