Update the profiler to allow for different level of profiling
This commit is contained in:
		@@ -7,6 +7,7 @@
 | 
			
		||||
 | 
			
		||||
#include <x86intrin.h>
 | 
			
		||||
 | 
			
		||||
#if defined(BASIC_PROFILING) || defined(FULL_PROFILING)
 | 
			
		||||
typedef struct {
 | 
			
		||||
  profiler_sample_t samples[MAX_PROFILE_SAMPLES];
 | 
			
		||||
  u64 cpu_freq;
 | 
			
		||||
@@ -82,10 +83,6 @@ void profile_end() {
 | 
			
		||||
 | 
			
		||||
  u16 time_precision = 16;
 | 
			
		||||
  u16 time_char_count = 20;
 | 
			
		||||
  u16 duration_char_count = 22;
 | 
			
		||||
  u16 hits_char_count = 10;
 | 
			
		||||
  u16 percentage_precision = 8;
 | 
			
		||||
  u16 percentage_char_count = 12;
 | 
			
		||||
 | 
			
		||||
  // clang-format off
 | 
			
		||||
  printf("\n==============================PROFILING==============================\n");
 | 
			
		||||
@@ -97,6 +94,12 @@ void profile_end() {
 | 
			
		||||
           (unsigned long long)profiler.cpu_freq);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
#ifdef FULL_PROFILING
 | 
			
		||||
  u16 duration_char_count = 22;
 | 
			
		||||
  u16 hits_char_count = 10;
 | 
			
		||||
  u16 percentage_precision = 8;
 | 
			
		||||
  u16 percentage_char_count = 12;
 | 
			
		||||
 | 
			
		||||
  profiler_sample_t *sample = NULL;
 | 
			
		||||
 | 
			
		||||
  for (u64 i = 0; i < profiler.size; ++i) {
 | 
			
		||||
@@ -121,8 +124,11 @@ void profile_end() {
 | 
			
		||||
 | 
			
		||||
    printf(")\n");
 | 
			
		||||
  }
 | 
			
		||||
#endif // FULL_PROFILING
 | 
			
		||||
}
 | 
			
		||||
#endif // BASIC_PROFILING || FULL_PROFILING
 | 
			
		||||
 | 
			
		||||
#ifdef FULL_PROFILING
 | 
			
		||||
void sample_start(u64 id, const char *title) {
 | 
			
		||||
  if (id >= MAX_PROFILE_SAMPLES) {
 | 
			
		||||
    return;
 | 
			
		||||
@@ -188,15 +194,16 @@ void sample_end(u64 id) {
 | 
			
		||||
  profiler_sample_t *parent = sample->parent;
 | 
			
		||||
 | 
			
		||||
  if (parent) {
 | 
			
		||||
    sample->parent->start = now;
 | 
			
		||||
 | 
			
		||||
    // Add sample duration to all parents. This handles deep call stacks
 | 
			
		||||
    while (parent) {
 | 
			
		||||
      parent->children_time += duration;
 | 
			
		||||
 | 
			
		||||
      parent = parent->parent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sample->parent->start = now;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  profiler.active = sample->parent;
 | 
			
		||||
}
 | 
			
		||||
#endif // FULL_PROFILING
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user