-
Notifications
You must be signed in to change notification settings - Fork 2
/
profiler.h
117 lines (91 loc) · 2.85 KB
/
profiler.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// profiler.h
// Copyright (c) 2014 Jinglei Ren <jinglei@ren.systems>
#ifndef SEXAIN_PROFILER_H_
#define SEXAIN_PROFILER_H_
#include <cstdint>
#include <cassert>
class Profiler {
public:
Profiler(int block_bits, int page_bits);
Profiler(const Profiler& p);
void AddTableOp(int num = 1);
void AddBufferOp(int num = 1);
void AddLatency(int lat);
void AddBlockMoveIntra(int num = 1);
void AddBlockMoveInter(int num = 1);
void AddPageMoveIntra(int num = 1);
void AddPageMoveInter(int num = 1);
uint64_t SumLatency();
uint64_t SumBusUtil(bool exc_intra = false);
uint64_t num_table_ops() const { return num_table_ops_; }
uint64_t num_buffer_ops() const { return num_buffer_ops_; }
uint64_t bytes_intra_channel() const { return bytes_intra_channel_; }
uint64_t bytes_inter_channel() const { return bytes_inter_channel_; }
void set_ignore_latency();
void clear_ignore_latency();
void set_op_latency(int64_t lat) { op_latency_ = lat; }
static Profiler Null;
static Profiler Overlap;
private:
const int block_bits_;
const int page_bits_;
uint64_t num_table_ops_;
uint64_t num_buffer_ops_;
uint64_t latency_;
uint64_t bytes_intra_channel_;
uint64_t bytes_inter_channel_;
int64_t op_latency_;
bool ignore_latency_;
};
inline Profiler::Profiler(int block_bits, int page_bits) :
block_bits_(block_bits), page_bits_(page_bits),
num_table_ops_(0), num_buffer_ops_(0), latency_(0),
bytes_intra_channel_(0), bytes_inter_channel_(0) {
op_latency_ = -1;
ignore_latency_ = false;
}
inline Profiler::Profiler(const Profiler& p) :
Profiler(p.block_bits_, p.page_bits_) {
op_latency_ = p.op_latency_;
}
inline void Profiler::set_ignore_latency() {
assert(!ignore_latency_);
ignore_latency_ = true;
}
inline void Profiler::clear_ignore_latency() {
assert(ignore_latency_);
ignore_latency_ = false;
}
inline void Profiler::AddTableOp(int num) {
if (ignore_latency_) return;
num_table_ops_ += num;
}
inline void Profiler::AddBufferOp(int num) {
if (ignore_latency_) return;
num_buffer_ops_ += num;
}
inline void Profiler::AddLatency(int lat) {
assert(lat > 0 && !ignore_latency_);
latency_ += lat;
}
inline void Profiler::AddBlockMoveIntra(int num) {
bytes_intra_channel_ += num << block_bits_;
}
inline void Profiler::AddBlockMoveInter(int num) {
bytes_inter_channel_ += num << block_bits_;
}
inline void Profiler::AddPageMoveIntra(int num) {
bytes_intra_channel_ += num << page_bits_;
}
inline void Profiler::AddPageMoveInter(int num) {
bytes_inter_channel_ += num << page_bits_;
}
inline uint64_t Profiler::SumLatency() {
assert(op_latency_ >= 0);
assert(!ignore_latency_);
return latency_ + op_latency_ * (num_table_ops_ + num_buffer_ops_);
}
inline uint64_t Profiler::SumBusUtil(bool exc_intra) {
return (exc_intra ? 0 : bytes_intra_channel_) + bytes_inter_channel_;
}
#endif // SEXAIN_PROFILER_H_