]> git.proxmox.com Git - ceph.git/blob - ceph/src/test/osd/TestOpStat.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / test / osd / TestOpStat.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 #include "common/Mutex.h"
3 #include "common/Cond.h"
4 #include "include/rados/librados.hpp"
5
6 #ifndef TESTOPSTAT_H
7 #define TESTOPSTAT_H
8
9 class TestOp;
10
11 class TestOpStat {
12 public:
13 mutable Mutex stat_lock;
14
15 TestOpStat() : stat_lock("TestOpStat lock") {}
16
17 static uint64_t gettime()
18 {
19 timeval t;
20 gettimeofday(&t,0);
21 return (1000000*t.tv_sec) + t.tv_usec;
22 }
23
24 class TypeStatus {
25 public:
26 map<TestOp*,uint64_t> inflight;
27 multiset<uint64_t> latencies;
28 void begin(TestOp *in)
29 {
30 assert(!inflight.count(in));
31 inflight[in] = gettime();
32 }
33
34 void end(TestOp *in)
35 {
36 assert(inflight.count(in));
37 uint64_t curtime = gettime();
38 latencies.insert(curtime - inflight[in]);
39 inflight.erase(in);
40 }
41
42 void export_latencies(map<double,uint64_t> &in) const;
43 };
44 map<string,TypeStatus> stats;
45
46 void begin(TestOp *in);
47 void end(TestOp *in);
48 friend std::ostream & operator<<(std::ostream &, const TestOpStat &);
49 };
50
51 std::ostream & operator<<(std::ostream &out, const TestOpStat &rhs);
52
53 #endif