1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
extern crate ndarray;
use self::ndarray::{OwnedArray, Ix};
use std::f64;

// initialize matrix object
pub type Mat<A> = OwnedArray<A, (Ix, Ix)>;

// Profiler enum. We have two profilers: CacheGrind and CallGrind.
pub enum Profiler {
    // CachGrind holds the parsed objects of
    // `valgrind --tool=cachegrind -cachegrind-out-file=cachegrind.out
    // && cg_annotate cachegrind.out`
    CacheGrind {
        ir: f64,
        i1mr: f64,
        ilmr: f64,
        dr: f64,
        d1mr: f64,
        dlmr: f64,
        dw: f64,
        d1mw: f64,
        dlmw: f64,
        data: Mat<f64>,
        functs: Vec<String>,
    },

    // Call holds the parsed objects of
    // `valgrind --tool=callgrind --callgrind-out-file=callgrind.out
    // && callgrind_annotate callgrind.out`
    CallGrind {
        total_instructions: f64,
        instructions: Vec<f64>,
        functs: Vec<String>,
    },
}


// Initialize the Profilers
impl Profiler {
    // Initialize CacheGrind

    pub fn new_cachegrind() -> Profiler {
        Profiler::CacheGrind {
            // total instructions
            ir: f64::NAN,
            // total instruction-cache read misses
            i1mr: f64::NAN,
            // total LL-cache read misses
            ilmr: f64::NAN,
            // total reads
            dr: f64::NAN,
            // total data-cache read misses
            d1mr: f64::NAN,
            // total LL-cache read misses
            dlmr: f64::NAN,
            // total data-cache writes
            dw: f64::NAN,
            // total data-cache write-misses
            d1mw: f64::NAN,
            // total LL cache write misses
            dlmw: f64::NAN,
            // profiler data
            data: OwnedArray::zeros((2, 2)),
            // profiled functions in binary
            functs: Vec::new(),
        }
    }
    // Initialize CallGrind
    pub fn new_callgrind() -> Profiler {
        Profiler::CallGrind {
            // total instruction calls
            total_instructions: f64::NAN,
            // instruction data
            instructions: Vec::new(),
            // profiled functions in binary
            functs: Vec::new(),
        }
    }
}