public async Task StartTracing( CancellationToken cancellationToken, TimeSpan?secsOrDefault = null, ProfilingType?profilingTypeOrDefault = null) { if (IsTracing) { throw new Exception("already running"); } await TaskUtils.MoveToThreadPool(cancellationToken); try { IsTracing = true; await DotTrace.EnsurePrerequisiteAsync(cancellationToken); var interval = secsOrDefault ?? _config.TraceSecs.Seconds(); var profilingType = profilingTypeOrDefault ?? _config.ProfilingType; var dirPath = _config.SaveDirPath; if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); Log.Info($"Created directory: \"{dirPath}\""); } var config = new DotTrace.Config().SaveToDir(dirPath); if (profilingType == ProfilingType.Sampling) { config = config.UseTimelineProfilingType(); Log.Info("Making a timeline; this can be laggy for the server!"); } DotTrace.Attach(config); try { Log.Info($"Tracing (type: {profilingType}, {interval.TotalSeconds:0} seconds)..."); DotTrace.StartCollectingData(); await Task.Delay(interval, cancellationToken); DotTrace.SaveData(); Log.Info("Finished tracing!"); } finally { DotTrace.Detach(); } } finally { IsTracing = false; } }
public static async void TraceMe(bool start = true) { #if !LIB if (start) { await DotTrace.EnsurePrerequisiteAsync(); Directory.CreateDirectory("C:\\Temp\\Snapshot"); var config = new DotTrace.Config(); config.SaveToDir("C:\\Temp\\Snapshot"); DotTrace.Attach(config); DotTrace.StartCollectingData(); } else { DotTrace.StopCollectingData(); DotTrace.SaveData(); } #endif }
public static void Main() { String packageDir = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName, "packages"); String snapshotDir = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "Snapshots"); #if TESTPERFORMANCE DotTrace.EnsurePrerequisite(downloadTo: packageDir); DotTrace.Config config = new DotTrace.Config(); Directory.CreateDirectory(Path.Combine(snapshotDir, "Performance", Version)); config.SaveToDir(Path.Combine(snapshotDir, "Performance", Version)); DotTrace.Attach(config); for (int index = 1; index <= 100; index++) { Console.WriteLine("Running Test Border Generation no. {0}", index); SpeedCounter counter = SpeedCounter.GetCounter("ProvinceBordersConstructor"); DotTrace.StartCollectingData(); counter.Start(); TestBordersGeneration(); counter.Stop(); DotTrace.StopCollectingData(); Console.WriteLine("Test no. {0} finished in {1} seconds", index, (double)SpeedCounter.GetCounter("ProvinceBordersConstructor").mLast / 1000); } DotTrace.SaveData(); DotTrace.Detach(); Console.WriteLine("Average test speed {0}", (double)SpeedCounter.GetCounter("ProvinceBordersConstructor").mAverage / 1000); Console.WriteLine("Total test time {0}", (double)SpeedCounter.GetCounter("ProvinceBordersConstructor").mSum / 1000); Console.ReadKey(); #elif TESTMEMORY DotMemory.EnsurePrerequisite(downloadTo: packageDir); DotMemory.Config config = new DotMemory.Config(); Directory.CreateDirectory(Path.Combine(snapshotDir, "Memory", Version)); config.SaveToDir(Path.Combine(snapshotDir, "Memory", Version)); DotMemory.Attach(config); DotMemory.GetSnapshot("Setup finished"); TestBordersGeneration(); DotMemory.GetSnapshot("Border Generation Finished"); DotMemory.Detach(); #endif }