TracyWrapper 0.11.1
See the version list below for details.
dotnet add package TracyWrapper --version 0.11.1
NuGet\Install-Package TracyWrapper -Version 0.11.1
<PackageReference Include="TracyWrapper" Version="0.11.1" />
<PackageVersion Include="TracyWrapper" Version="0.11.1" />
<PackageReference Include="TracyWrapper" />
paket add TracyWrapper --version 0.11.1
#r "nuget: TracyWrapper, 0.11.1"
#:package TracyWrapper@0.11.1
#addin nuget:?package=TracyWrapper&version=0.11.1
#tool nuget:?package=TracyWrapper&version=0.11.1
Tracy Profiler Wrapper for C#
This repository contains a C# wrapper for the Tracy Profiler. It provides simple helper functions to easily profile a C# application.
The wrapper uses Tracy-CSharp bindings to interface with Tracy.
Installation
Get Tracy Profiler
This wrapper only supports Tracy v0.11.1. Download here.
From source
- Clone this repository via URL: https://github.com/AugsEU/TracyWrapper.git
- Add the .csproj to your solution.
Usage
1. Call the heartbeat function
The TracyWrapper.Profiler.HeartBeat(); function needs to be called exactly once per frame.
E.g.
// Called once per frame.
protected override void Update(GameTime gameTime)
{
TracyWrapper.Profiler.HeartBeat();
/* Game logic goes here */
}
2. Push and pop zones.
Push a zone to begin profiling a section of code. Pop the zone when the section is over. We can provide a name and a color so we can then identify this block when viewing in the profiler.
E.g.
public void PollInputs(TimeSpan timeStamp)
{
TracyWrapper.Profiler.PushProfileZone("Inputs", System.Drawing.Color.AliceBlue);
/* Input polling logic. */
TracyWrapper.Profiler.PopProfileZone();
}
Make sure you don't forget to pop the profile zone of the profiler will crash.
3. Profile a block using the ProfileScope class
Push a zone to begin profiling a section of code. Pop the zone when the section is over. This can be more convinient but is less accurate, due to the overhead of allocating TracyWrapper.ProfileScope.
E.g.
public void PollInputs(TimeSpan timeStamp)
{
using (new TracyWrapper.ProfileScope("Inputs", System.Drawing.Color.AliceBlue))
{
/* Input polling logic. This part is measured.*/
}
/* This code is not measured. */
}
Profiling accuracy
The Tracy profiler running natively on C++ is extremely accurate. Propertedly it is nanosecond accurate.
Using Tracy through this C# wrapper is much less accurate, due to the fact we must allocate strings to begin a profiling block, and then interface with the C++ code through bindings.
From my measurements, profiling via "PushProfileZone" and "PopProfileZone" directly is more accurate than using the TracyWrapper.ProfileScope class. From my crude measurements:
PushProfileZone/PopProfileZone : ~150ns accuracy
TracyWrapper.ProfileScope : ~310ns accuracy
Any operation that takes less than 1μs = 1000 ns should not be profiled.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Tracy-CSharp (>= 0.11.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.