Add support for reading TRACY_SAMPLING_HZ from an env variable.

This commit is contained in:
Bartosz Taudul 2024-07-30 18:42:05 +02:00
parent ffb98a9724
commit fb18a81d79
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -16,16 +16,25 @@
namespace tracy namespace tracy
{ {
static constexpr int GetSamplingFrequency() static int GetSamplingFrequency()
{ {
int samplingHz = TRACY_SAMPLING_HZ;
auto env = GetEnvVar( "TRACY_SAMPLING_HZ" );
if( env )
{
int val = atoi( env );
if( val > 0 ) samplingHz = val;
}
#if defined _WIN32 #if defined _WIN32
return TRACY_SAMPLING_HZ > 8000 ? 8000 : ( TRACY_SAMPLING_HZ < 1 ? 1 : TRACY_SAMPLING_HZ ); return samplingHz > 8000 ? 8000 : ( samplingHz < 1 ? 1 : samplingHz );
#else #else
return TRACY_SAMPLING_HZ > 1000000 ? 1000000 : ( TRACY_SAMPLING_HZ < 1 ? 1 : TRACY_SAMPLING_HZ ); return samplingHz > 1000000 ? 1000000 : ( samplingHz < 1 ? 1 : samplingHz );
#endif #endif
} }
static constexpr int GetSamplingPeriod() static int GetSamplingPeriod()
{ {
return 1000000000 / GetSamplingFrequency(); return 1000000000 / GetSamplingFrequency();
} }