perfaware/part2: Add disable switch for profiler
This commit is contained in:
parent
bc2da4df4c
commit
5817060a8b
@ -322,9 +322,15 @@ pushd %part2_build_dir%
|
|||||||
cl %part2_dir%\haversine_generator.c /W4 /WX /Z7 /nologo /Fe:haversine_generator_debug || exit /b 1
|
cl %part2_dir%\haversine_generator.c /W4 /WX /Z7 /nologo /Fe:haversine_generator_debug || exit /b 1
|
||||||
cl %part2_dir%\haversine_generator.c /W4 /WX /Z7 /nologo /O2 /Fe:haversine_generator_release || exit /b 1
|
cl %part2_dir%\haversine_generator.c /W4 /WX /Z7 /nologo /O2 /Fe:haversine_generator_release || exit /b 1
|
||||||
|
|
||||||
|
cl %part2_dir%\haversine_generator.c /DHAV_PROFILER /W4 /WX /Z7 /nologo /Fe:haversine_generator_profiled_debug || exit /b 1
|
||||||
|
cl %part2_dir%\haversine_generator.c /DHAV_PROFILER /W4 /WX /Z7 /nologo /O2 /Fe:haversine_generator_profiled_release || exit /b 1
|
||||||
|
|
||||||
cl %part2_dir%\haversine.c /W4 /WX /Z7 /nologo /Fe:haversine_debug || exit /b 1
|
cl %part2_dir%\haversine.c /W4 /WX /Z7 /nologo /Fe:haversine_debug || exit /b 1
|
||||||
cl %part2_dir%\haversine.c /W4 /WX /Z7 /nologo /O2 /Fe:haversine_release || exit /b 1
|
cl %part2_dir%\haversine.c /W4 /WX /Z7 /nologo /O2 /Fe:haversine_release || exit /b 1
|
||||||
|
|
||||||
|
cl %part2_dir%\haversine.c /DHAV_PROFILER /W4 /WX /Z7 /nologo /Fe:haversine_profiled_debug || exit /b 1
|
||||||
|
cl %part2_dir%\haversine.c /DHAV_PROFILER /W4 /WX /Z7 /nologo /O2 /Fe:haversine_profiled_release || exit /b 1
|
||||||
|
|
||||||
cl %part2_dir%\listing_0071_os_timer_main.cpp /W4 /WX /Z7 /O2 /nologo /Fe:listing_0071_os_timer_main_release || exit /b 1
|
cl %part2_dir%\listing_0071_os_timer_main.cpp /W4 /WX /Z7 /O2 /nologo /Fe:listing_0071_os_timer_main_release || exit /b 1
|
||||||
cl %part2_dir%\listing_0072_cpu_timer_main.cpp /W4 /WX /Z7 /O2 /nologo /Fe:listing_0072_cpu_timer_main_release || exit /b 1
|
cl %part2_dir%\listing_0072_cpu_timer_main.cpp /W4 /WX /Z7 /O2 /nologo /Fe:listing_0072_cpu_timer_main_release || exit /b 1
|
||||||
cl %part2_dir%\listing_0073_cpu_timer_guessfreq_main.cpp /W4 /WX /Z7 /O2 /nologo /Fe:listing_0073_cpu_timer_guessfreq_release || exit /b 1
|
cl %part2_dir%\listing_0073_cpu_timer_guessfreq_main.cpp /W4 /WX /Z7 /O2 /nologo /Fe:listing_0073_cpu_timer_guessfreq_release || exit /b 1
|
||||||
|
@ -17,14 +17,6 @@ typedef struct ProfilerAnchor {
|
|||||||
u64 hits;
|
u64 hits;
|
||||||
} ProfilerAnchor;
|
} ProfilerAnchor;
|
||||||
|
|
||||||
typedef struct ProfilerZone {
|
|
||||||
u64 parent_index;
|
|
||||||
uint32_t index;
|
|
||||||
HAV_Str8 label;
|
|
||||||
u64 elapsed_tsc_inclusive;
|
|
||||||
u64 tsc;
|
|
||||||
} ProfilerZone;
|
|
||||||
|
|
||||||
typedef struct Profiler {
|
typedef struct Profiler {
|
||||||
ProfilerAnchor anchors[4096];
|
ProfilerAnchor anchors[4096];
|
||||||
u64 begin_tsc;
|
u64 begin_tsc;
|
||||||
@ -34,33 +26,6 @@ typedef struct Profiler {
|
|||||||
|
|
||||||
static Profiler g_profiler;
|
static Profiler g_profiler;
|
||||||
|
|
||||||
#define Profiler_BeginZone(label) Profiler_BeginZone_(HAV_STR8(label), __COUNTER__ + 1)
|
|
||||||
static ProfilerZone Profiler_BeginZone_(HAV_Str8 label, uint32_t index)
|
|
||||||
{
|
|
||||||
ProfilerZone result = {0};
|
|
||||||
result.index = index;
|
|
||||||
result.label = label;
|
|
||||||
result.tsc = ReadCPUTimer();
|
|
||||||
result.elapsed_tsc_inclusive = g_profiler.anchors[index].elapsed_tsc_inclusive;
|
|
||||||
result.parent_index = g_profiler.parent_index;
|
|
||||||
g_profiler.parent_index = index;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Profiler_EndZone(ProfilerZone zone)
|
|
||||||
{
|
|
||||||
u64 elapsed_tsc = ReadCPUTimer() - zone.tsc;
|
|
||||||
ProfilerAnchor* anchor = g_profiler.anchors + zone.index;
|
|
||||||
ProfilerAnchor* parent = g_profiler.anchors + zone.parent_index;
|
|
||||||
|
|
||||||
anchor->elapsed_tsc_exclusive += elapsed_tsc;
|
|
||||||
anchor->elapsed_tsc_inclusive = zone.elapsed_tsc_inclusive + elapsed_tsc;
|
|
||||||
anchor->label = zone.label;
|
|
||||||
anchor->hits++;
|
|
||||||
parent->elapsed_tsc_exclusive -= elapsed_tsc;
|
|
||||||
g_profiler.parent_index = zone.parent_index;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Profiler_Dump()
|
static void Profiler_Dump()
|
||||||
{
|
{
|
||||||
u64 total_elapsed_tsc = g_profiler.end_tsc - g_profiler.begin_tsc;
|
u64 total_elapsed_tsc = g_profiler.end_tsc - g_profiler.begin_tsc;
|
||||||
@ -83,6 +48,50 @@ static void Profiler_Dump()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct ProfilerZone {
|
||||||
|
u64 parent_index;
|
||||||
|
uint32_t index;
|
||||||
|
HAV_Str8 label;
|
||||||
|
u64 elapsed_tsc_inclusive;
|
||||||
|
u64 tsc;
|
||||||
|
} ProfilerZone;
|
||||||
|
|
||||||
|
#define Profiler_BeginZone(label) Profiler_BeginZone_(HAV_STR8(label), __COUNTER__ + 1)
|
||||||
|
|
||||||
|
static ProfilerZone Profiler_BeginZone_(HAV_Str8 label, uint32_t index)
|
||||||
|
{
|
||||||
|
ProfilerZone result = {0};
|
||||||
|
#if defined(HAV_PROFILER)
|
||||||
|
result.index = index;
|
||||||
|
result.label = label;
|
||||||
|
result.tsc = ReadCPUTimer();
|
||||||
|
result.elapsed_tsc_inclusive = g_profiler.anchors[index].elapsed_tsc_inclusive;
|
||||||
|
result.parent_index = g_profiler.parent_index;
|
||||||
|
g_profiler.parent_index = index;
|
||||||
|
#else
|
||||||
|
(void)label; (void)index;
|
||||||
|
#endif
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Profiler_EndZone(ProfilerZone zone)
|
||||||
|
{
|
||||||
|
#if defined(HAV_PROFILER)
|
||||||
|
u64 elapsed_tsc = ReadCPUTimer() - zone.tsc;
|
||||||
|
ProfilerAnchor* anchor = g_profiler.anchors + zone.index;
|
||||||
|
ProfilerAnchor* parent = g_profiler.anchors + zone.parent_index;
|
||||||
|
|
||||||
|
anchor->elapsed_tsc_exclusive += elapsed_tsc;
|
||||||
|
anchor->elapsed_tsc_inclusive = zone.elapsed_tsc_inclusive + elapsed_tsc;
|
||||||
|
anchor->label = zone.label;
|
||||||
|
anchor->hits++;
|
||||||
|
parent->elapsed_tsc_exclusive -= elapsed_tsc;
|
||||||
|
g_profiler.parent_index = zone.parent_index;
|
||||||
|
#else
|
||||||
|
(void)zone;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct Str8FindResult {
|
typedef struct Str8FindResult {
|
||||||
bool found;
|
bool found;
|
||||||
HAV_Str8 match;
|
HAV_Str8 match;
|
||||||
|
Loading…
Reference in New Issue
Block a user