Files
2024-09-27 14:35:27 +00:00

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;
}
}