Skip to content

Commit e5f59d7

Browse files
committed
graph: Print summary about sample allocations and weights in stress example
1 parent 33e1978 commit e5f59d7

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

graph/examples/stress.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ fn stress<T: Template<T, Item = T>>(opt: &Opt) {
378378
let print_mod = opt.niter / opt.print_count + 1;
379379
let mut should_print = true;
380380
let mut print_header = true;
381+
let mut sample_weight: usize = 0;
382+
let mut sample_alloc: usize = 0;
381383
for key in 0..opt.niter {
382384
should_print = should_print || key % print_mod == 0;
383385
let before_mem = ALLOCATED.load(SeqCst);
@@ -407,15 +409,27 @@ fn stress<T: Template<T, Item = T>>(opt: &Opt) {
407409
};
408410
let before = ALLOCATED.load(SeqCst);
409411
let sample = cacheable.sample(size);
412+
let weight = sample.weight();
413+
let alloc = ALLOCATED.load(SeqCst) - before;
414+
sample_weight += weight;
415+
sample_alloc += alloc;
410416
if opt.samples {
411-
println!(
412-
"sample: weight {:6} alloc {:6}",
413-
sample.weight(),
414-
ALLOCATED.load(SeqCst) - before,
415-
);
417+
println!("sample: weight {:6} alloc {:6}", weight, alloc,);
416418
}
417419
cacheable.cache.insert(key, *cacheable.sample(size));
418420
}
421+
if sample_alloc == sample_weight {
422+
println!(
423+
"samples: weight {} alloc {} weight/alloc precise",
424+
sample_weight, sample_alloc
425+
);
426+
} else {
427+
let heap_factor = sample_alloc as f64 / sample_weight as f64;
428+
println!(
429+
"samples: weight {} alloc {} weight/alloc {:0.2}",
430+
sample_weight, sample_alloc, heap_factor
431+
);
432+
}
419433
}
420434

421435
/// This program constructs a template object of size `obj_size` and then

0 commit comments

Comments
 (0)