@@ -91,6 +91,7 @@ PATENT RIGHTS GRANT:
91
91
92
92
#include < db.h>
93
93
94
+ #include < math.h>
94
95
#include < stdio.h>
95
96
#include < string.h>
96
97
@@ -308,6 +309,26 @@ static vector<string> canonicalize_trace_from(FILE *file) {
308
309
return canonicalized_trace;
309
310
}
310
311
312
+ struct streaming_variance_calculator {
313
+ int64_t n_samples;
314
+ int64_t mean;
315
+ int64_t variance;
316
+
317
+ // math credit: AoCP, Donald Knuth, '62
318
+ void add_sample (int64_t x) {
319
+ n_samples++;
320
+ if (n_samples == 1 ) {
321
+ mean = x;
322
+ variance = 0 ;
323
+ } else {
324
+ int64_t old_mean = mean;
325
+ mean = old_mean + ((x - old_mean) / n_samples);
326
+ variance = (((n_samples - 1 ) * variance) +
327
+ ((x - old_mean) * (x - mean))) / n_samples;
328
+ }
329
+ }
330
+ };
331
+
311
332
struct canonical_trace_stats {
312
333
uint64_t n_lines_replayed;
313
334
@@ -318,6 +339,9 @@ struct canonical_trace_stats {
318
339
uint64_t n_free;
319
340
uint64_t n_destroy;
320
341
342
+ struct streaming_variance_calculator alloc_hot_bytes;
343
+ struct streaming_variance_calculator alloc_cold_bytes;
344
+
321
345
canonical_trace_stats () {
322
346
memset (this , 0 , sizeof (*this ));
323
347
}
@@ -389,6 +413,7 @@ static void replay_canonicalized_trace(const vector<string> &canonicalized_trace
389
413
ba->alloc_block (size, heat, &offset);
390
414
seq_num_to_offset[asn] = offset;
391
415
heat ? stats->n_alloc_hot ++ : stats->n_alloc_cold ++;
416
+ heat ? stats->alloc_hot_bytes .add_sample (size) : stats->alloc_cold_bytes .add_sample (size);
392
417
} else if (fn == " ba_trace_free_asn" ) {
393
418
// replay a `free' on a block whose offset is the result of an alloc with an asn
394
419
const uint64_t asn = parse_uint64 (&ptr, line_num);
@@ -559,13 +584,18 @@ int main(void) {
559
584
printf (" \n " );
560
585
printf (" Overall trace stats:\n " );
561
586
printf (" \n " );
562
- printf (" n_lines_played: %9" PRIu64 " \n " , stats.n_lines_replayed );
563
- printf (" n_create: %9" PRIu64 " \n " , stats.n_create );
564
- printf (" n_create_from_blockpairs: %9" PRIu64 " \n " , stats.n_create_from_blockpairs );
565
- printf (" n_alloc_hot: %9" PRIu64 " \n " , stats.n_alloc_hot );
566
- printf (" n_alloc_cold: %9" PRIu64 " \n " , stats.n_alloc_cold );
567
- printf (" n_free: %9" PRIu64 " \n " , stats.n_free );
568
- printf (" n_destroy: %9" PRIu64 " \n " , stats.n_destroy );
587
+ printf (" n_lines_played: %15" PRIu64 " \n " , stats.n_lines_replayed );
588
+ printf (" n_create: %15" PRIu64 " \n " , stats.n_create );
589
+ printf (" n_create_from_blockpairs: %15" PRIu64 " \n " , stats.n_create_from_blockpairs );
590
+ printf (" n_alloc_hot: %15" PRIu64 " \n " , stats.n_alloc_hot );
591
+ printf (" n_alloc_cold: %15" PRIu64 " \n " , stats.n_alloc_cold );
592
+ printf (" n_free: %15" PRIu64 " \n " , stats.n_free );
593
+ printf (" n_destroy: %15" PRIu64 " \n " , stats.n_destroy );
594
+ printf (" \n " );
595
+ printf (" avg_alloc_hot: %15" PRIu64 " \n " , stats.alloc_hot_bytes .mean );
596
+ printf (" stddev_alloc_hot: %15" PRIu64 " \n " , (uint64_t ) sqrt (stats.alloc_hot_bytes .variance ));
597
+ printf (" avg_alloc_cold: %15" PRIu64 " \n " , stats.alloc_cold_bytes .mean );
598
+ printf (" stddev_alloc_cold: %15" PRIu64 " \n " , (uint64_t ) sqrt (stats.alloc_cold_bytes .variance ));
569
599
printf (" \n " );
570
600
571
601
return 0 ;
0 commit comments