-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
progress_point.h
184 lines (146 loc) · 4.87 KB
/
progress_point.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* Copyright (c) 2015, Charlie Curtsinger and Emery Berger,
* University of Massachusetts Amherst
* This file is part of the Coz project. See LICENSE.md file at the top-level
* directory of this distribution and at http://github.com/plasma-umass/coz.
*/
#if !defined(CAUSAL_RUNTIME_PROGRESS_POINT_H)
#define CAUSAL_RUNTIME_PROGRESS_POINT_H
#include <memory>
#include <string>
#include "coz.h"
#include "inspect.h"
#include "perf.h"
#include "util.h"
#include "ccutil/log.h"
/// Enum wrapper around defines for progress point types
enum class progress_point_type {
throughput = COZ_COUNTER_TYPE_THROUGHPUT,
begin = COZ_COUNTER_TYPE_BEGIN,
end = COZ_COUNTER_TYPE_END
};
/**
* A progress point to measure throughput
*/
class throughput_point {
public:
class saved;
/// Create a throughput progress point with a given name
throughput_point(const std::string& name) : _name(name), _counter() {}
/// Save the state of this progress point
saved* save() const {
return new saved(this);
}
/// Add one to the number of visits to this progress point
void visit(size_t visits=1) {
__atomic_add_fetch(&_counter.count, visits, __ATOMIC_RELAXED);
}
/// Get the number of visits to this progress point
size_t get_count() const {
return __atomic_load_n(&_counter.count, __ATOMIC_RELAXED);
}
/// Get a pointer to the counter struct (used by source progress points)
coz_counter_t* get_counter_struct() {
return &_counter;
}
/// Get the name of this progress point
const std::string& get_name() const {
return _name;
}
class saved {
public:
saved() {}
/// Save the state of a throughput point
saved(const throughput_point* origin) : _origin(origin), _start_count(origin->get_count()) {}
/// Log the change in this progress point since it was saved
void log(std::ostream& os) const {
os << "throughput-point\t"
<< "name=" << _origin->get_name() << "\t"
<< "delta=" << get_delta() << "\n";
}
size_t get_delta() const {
return _origin->get_count() - _start_count;
}
protected:
const throughput_point* _origin;
size_t _start_count;
};
private:
const std::string _name;
coz_counter_t _counter;
};
/**
* A progress point to measure latency with two counters
*/
class latency_point {
public:
class saved;
/// Create a latency progress point with a given name
latency_point(const std::string& name) : _name(name), _begin_counter(), _end_counter() {}
/// Save the state of this progress point
saved* save() const {
return new saved(this);
}
/// Add one visit to the begin progress point
void visit_begin(size_t visits=1) {
__atomic_add_fetch(&_begin_counter.count, visits, __ATOMIC_RELAXED);
}
/// Add one visit to the end progress point
void visit_end(size_t visits=1) {
__atomic_add_fetch(&_end_counter.count, visits, __ATOMIC_RELAXED);
}
/// Get the number of visits to the begin progress point
size_t get_begin_count() const {
return __atomic_load_n(&_begin_counter.count, __ATOMIC_RELAXED);
}
/// Get the number of visits to the end progress point
size_t get_end_count() const {
return __atomic_load_n(&_end_counter.count, __ATOMIC_RELAXED);
}
/// Get a pointer to the begin point's counter struct (used by source progress points)
coz_counter_t* get_begin_counter_struct() {
return &_begin_counter;
}
/// Get a pointer to the end point's counter struct (used by source progress points)
coz_counter_t* get_end_counter_struct() {
return &_end_counter;
}
/// Get the name of this progress point
const std::string& get_name() const {
return _name;
}
class saved {
public:
saved() {}
/// Save the state of a throughput point
saved(const latency_point* origin) : _origin(origin),
_begin_start_count(origin->get_begin_count()),
_end_start_count(origin->get_end_count()) {}
/// Log the change in this progress point since it was saved
virtual void log(std::ostream& os) const {
os << "latency-point\t"
<< "name=" << _origin->get_name() << "\t"
<< "arrivals=" << get_begin_delta() << "\t"
<< "departures=" << get_end_delta() << "\t"
<< "difference=" << get_difference() << "\n";
}
virtual size_t get_begin_delta() const {
return _origin->get_begin_count() - _begin_start_count;
}
virtual size_t get_end_delta() const {
return _origin->get_end_count() - _end_start_count;
}
virtual size_t get_difference() const {
return _origin->get_begin_count() - _origin->get_end_count();
}
protected:
const latency_point* _origin;
size_t _begin_start_count;
size_t _end_start_count;
};
private:
const std::string _name;
coz_counter_t _begin_counter;
coz_counter_t _end_counter;
};
#endif