mmtk/util/statistics/counter/
size_counter.rs

1use super::*;
2use std::sync::Arc;
3use std::sync::Mutex;
4
5pub struct SizeCounter {
6    units: Arc<Mutex<EventCounter>>,
7    volume: Arc<Mutex<EventCounter>>,
8}
9
10/**
11 * This file implements a simple counter of events of different sizes
12 * (eg object allocations, where total number of objects and total
13 * volume of objects would be counted).
14 *
15 * The counter is trivially composed from two event counters (one for
16 * counting the number of events, the other for counting the volume).
17 */
18impl SizeCounter {
19    pub fn new(units: Arc<Mutex<EventCounter>>, volume: Arc<Mutex<EventCounter>>) -> Self {
20        SizeCounter { units, volume }
21    }
22
23    /**
24     * Increment the event counter by provided value
25     */
26    pub fn inc(&mut self, size: u64) {
27        self.units.lock().unwrap().inc();
28        self.volume.lock().unwrap().inc_by(size);
29    }
30
31    /**
32     * Start this counter
33     */
34    pub fn start(&mut self) {
35        self.units.lock().unwrap().start();
36        self.volume.lock().unwrap().start();
37    }
38
39    /**
40     * Stop this counter
41     */
42    pub fn stop(&mut self) {
43        self.units.lock().unwrap().stop();
44        self.volume.lock().unwrap().stop();
45    }
46
47    /**
48     * Print current (mid-phase) units
49     */
50    pub fn print_current_units(&self) {
51        self.units.lock().unwrap().print_current();
52    }
53
54    /**
55     * Print (mid-phase) volume
56     */
57    pub fn print_current_volume(&self) {
58        self.volume.lock().unwrap().print_current();
59    }
60
61    /**
62     * Print units
63     */
64    pub fn print_units(&self) {
65        self.units.lock().unwrap().print_total(None);
66    }
67
68    /**
69     * Print volume
70     */
71    pub fn print_volume(&self) {
72        self.volume.lock().unwrap().print_total(None);
73    }
74}