mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-14 11:48:28 -04:00
31 lines
611 B
C#
31 lines
611 B
C#
namespace SpacetimeDB;
|
|
|
|
using System.Text;
|
|
using SpacetimeDB.Internal;
|
|
|
|
public sealed class LogStopwatch : IDisposable
|
|
{
|
|
private readonly FFI.ConsoleTimerId StopwatchId;
|
|
private bool WasStopped;
|
|
|
|
public LogStopwatch(string name)
|
|
{
|
|
var name_bytes = Encoding.UTF8.GetBytes(name);
|
|
StopwatchId = FFI.console_timer_start(name_bytes, (uint)name_bytes.Length);
|
|
}
|
|
|
|
void IDisposable.Dispose()
|
|
{
|
|
if (!WasStopped)
|
|
{
|
|
End();
|
|
}
|
|
}
|
|
|
|
public void End()
|
|
{
|
|
FFI.console_timer_end(StopwatchId);
|
|
WasStopped = true;
|
|
}
|
|
}
|