Add data throughput calculation

This commit is contained in:
2023-09-03 00:26:30 +01:00
parent 19c02b4e99
commit e461de30c0
6 changed files with 45 additions and 29 deletions

View File

@@ -62,7 +62,7 @@ u64 get_cpu_freq(u64 milliseconds) {
}
void profile_start(u64 count) {
profiler.cpu_freq = get_cpu_freq(500);
profiler.cpu_freq = get_cpu_freq(1000);
profiler.start = read_cpu_timer();
profiler.max_title_length = 0;
profiler.size = count;
@@ -89,16 +89,21 @@ void profile_end() {
// clang-format on
if (profiler.cpu_freq) {
printf("Total: %*.*f seconds (CPU frequency: %llu hz/sec)\n\n",
printf("Total: %*.*f seconds, %zu (CPU frequency: %llu hz/sec)\n\n",
time_char_count, time_precision, (f64)total / profiler.cpu_freq,
(unsigned long long)profiler.cpu_freq);
total, (unsigned long long)profiler.cpu_freq);
}
#ifdef FULL_PROFILING
f64 byte_to_mb = 1.0 / (1024.0 * 1024.0);
f64 mb_to_gb = 1.0 / 1024.0;
u16 duration_char_count = 22;
u16 hits_char_count = 10;
u16 percentage_precision = 8;
u16 percentage_char_count = 12;
u16 throughput_precision = 24;
u16 throughput_char_count = 32;
profiler_sample_t *sample = NULL;
@@ -122,6 +127,18 @@ void profile_end() {
100.0);
}
if (sample->byte_count > 0) {
f64 data_read = (f64)(sample->byte_count) * byte_to_mb;
f64 sample_time_in_seconds =
(f64)(sample->exclusive_time + sample->children_time) /
profiler.cpu_freq;
printf(", Byte count: %*.*f MB, Throughput: %*.*f GB/s",
throughput_char_count, throughput_precision, data_read,
throughput_char_count, throughput_precision,
data_read * mb_to_gb / sample_time_in_seconds);
}
printf(")\n");
}
#endif // FULL_PROFILING
@@ -143,6 +160,7 @@ void sample_start(u64 id, const char *title) {
sample->exclusive_time = 0;
sample->children_time = 0;
sample->hit_count = 0;
sample->byte_count = 0;
sample->parent = NULL;
u64 length = strlen(sample->title);
@@ -175,7 +193,7 @@ void sample_start(u64 id, const char *title) {
profiler.active = sample;
}
void sample_end(u64 id) {
void sample_end(u64 id, u64 byte_count) {
if (id >= MAX_PROFILE_SAMPLES) {
return;
}
@@ -185,6 +203,7 @@ void sample_end(u64 id) {
u64 duration = read_cpu_timer() - sample->start;
sample->exclusive_time += duration;
sample->byte_count += byte_count;
u64 now = read_cpu_timer();