-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetailed_stat_collector.h
96 lines (84 loc) · 2.13 KB
/
detailed_stat_collector.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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
#ifndef DETAILEDSTATCOLLECTERH
#define DETAILEDSTATCOLLECTERH
#include "stat_collector.h"
#include "common/Formatter.h"
#include <boost/scoped_ptr.hpp>
#include "common/Mutex.h"
#include "common/Cond.h"
#include "include/utime.h"
#include <list>
#include <map>
#include <boost/tuple/tuple.hpp>
#include <ostream>
class DetailedStatCollector : public StatCollector {
public:
class AdditionalPrinting {
public:
virtual void operator()(std::ostream *) = 0;
virtual ~AdditionalPrinting() {}
};
private:
struct Op {
string type;
utime_t start;
double latency;
uint64_t size;
uint64_t seq;
Op(
string type,
utime_t start,
double latency,
uint64_t size,
uint64_t seq)
: type(type), start(start), latency(latency),
size(size), seq(seq) {}
void dump(ostream *out, Formatter *f);
};
class Aggregator {
uint64_t recent_size;
uint64_t total_size;
double recent_latency;
double total_latency;
utime_t last;
utime_t first;
uint64_t recent_ops;
uint64_t total_ops;
bool started;
public:
Aggregator();
void add(const Op &op);
void dump(Formatter *f);
};
const double bin_size;
boost::scoped_ptr<Formatter> f;
ostream *out;
ostream *summary_out;
boost::scoped_ptr<AdditionalPrinting> details;
utime_t last_dump;
Mutex lock;
Cond cond;
map<string, Aggregator> aggregators;
map<uint64_t, pair<uint64_t, utime_t> > not_applied;
map<uint64_t, pair<uint64_t, utime_t> > not_committed;
map<uint64_t, pair<uint64_t, utime_t> > not_read;
uint64_t cur_seq;
void dump(
const string &type,
boost::tuple<utime_t, utime_t, uint64_t, uint64_t> stuff);
public:
DetailedStatCollector(
double bin_size,
Formatter *formatter,
ostream *out,
ostream *summary_out,
AdditionalPrinting *details = 0
);
uint64_t next_seq();
void start_write(uint64_t seq, uint64_t size);
void start_read(uint64_t seq, uint64_t size);
void write_applied(uint64_t seq);
void write_committed(uint64_t seq);
void read_complete(uint64_t seq);
};
#endif