Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / osd / TestOpStat.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
2 #include "include/interval_set.h"
3 #include "include/buffer.h"
4 #include <list>
5 #include <map>
6 #include <set>
7 #include "RadosModel.h"
8 #include "TestOpStat.h"
9
10 void TestOpStat::begin(TestOp *in) {
11   stat_lock.Lock();
12   stats[in->getType()].begin(in);
13   stat_lock.Unlock();
14 }
15
16 void TestOpStat::end(TestOp *in) {
17   stat_lock.Lock();
18   stats[in->getType()].end(in);
19   stat_lock.Unlock();
20 }
21
22 void TestOpStat::TypeStatus::export_latencies(map<double,uint64_t> &in) const
23 {
24   map<double,uint64_t>::iterator i = in.begin();
25   multiset<uint64_t>::iterator j = latencies.begin();
26   int count = 0;
27   while (j != latencies.end() && i != in.end()) {
28     count++;
29     if ((((double)count)/((double)latencies.size())) * 100 >= i->first) {
30       i->second = *j;
31       ++i;
32     }
33     ++j;
34   }
35 }
36   
37 std::ostream & operator<<(std::ostream &out, const TestOpStat &rhs)
38 {
39   rhs.stat_lock.Lock();
40   for (auto i = rhs.stats.begin();
41        i != rhs.stats.end();
42        ++i) {
43     map<double,uint64_t> latency;
44     latency[10] = 0;
45     latency[50] = 0;
46     latency[90] = 0;
47     latency[99] = 0;
48     i->second.export_latencies(latency);
49     
50     out << i->first << " latency: " << std::endl;
51     for (map<double,uint64_t>::iterator j = latency.begin();
52          j != latency.end();
53          ++j) {
54       if (j->second == 0) break;
55       out << "\t" << j->first << "th percentile: " 
56           << j->second / 1000 << "ms" << std::endl;
57     }
58   }
59   rhs.stat_lock.Unlock();
60   return out;
61 }