///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // D E R E L I C T // /// // (c) 2003..2024 using System; using System.Runtime.CompilerServices; using Godot; namespace prof; public record struct Id( ulong id ); public interface Profiler { public Id Begin( string name ); public void End( Id id ); public void Text( Id id, string text ); public void Value( Id id, ulong value ); } public class Zone : IDisposable { public Zone( [CallerFilePath] string dbgPath = "", [CallerLineNumber] int dbgLine = 0, [CallerMemberName] string dbgMethod = "" ) { var file = log.whatFile( dbgPath ); _id = Util.GetProfiler().Begin( $"{file}::{dbgMethod}" ); } public void Dispose() { Util.GetProfiler().End( _id ); } public void Text( string text ) { Util.GetProfiler().Text( _id, text ); } public void Value( ulong value ) { Util.GetProfiler().Value( _id, value ); } Id _id; } static public class Util { static public Profiler GetProfiler() { //* return new ProfilerNull(); /*/ return new ProfilerTracy(); //*/ } } /* public class ProfilerTracy : Profiler { public Id Begin(string name) { var id = GD.TracyBegin( name ); return new Id( id ); } public void End(Id id) { GD.TracyEnd( id.id ); } public void Text(Id id, string text) { GD.TracyName( id.id, text ); } public void Value(Id id, ulong value) { GD.TracyValue( id.id, value ); } } /*/ public class ProfilerNull : Profiler { static Id s_Id = new Id( 0 ); public Id Begin( string name ) { return s_Id; } public void End( Id id ) { } public void Text( Id id, string text ) { } public void Value( Id id, ulong value ) { } } //*/