summaryrefslogtreecommitdiffstats
path: root/src/test/osd/TestOpStat.h
blob: 2c680558ff12fe4fdabb1dff8621f3bf62ebe634 (plain)
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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
#include "common/ceph_mutex.h"
#include "common/Cond.h"
#include "include/rados/librados.hpp"

#ifndef TESTOPSTAT_H
#define TESTOPSTAT_H

class TestOp;

class TestOpStat {
public:
  mutable ceph::mutex stat_lock = ceph::make_mutex("TestOpStat lock");

  TestOpStat() = default;
    
  static uint64_t gettime()
  {
    timeval t;
    gettimeofday(&t,0);
    return (1000000*t.tv_sec) + t.tv_usec;
  }

  class TypeStatus {
  public:
    std::map<TestOp*,uint64_t> inflight;
    std::multiset<uint64_t> latencies;
    void begin(TestOp *in)
    {
      ceph_assert(!inflight.count(in));
      inflight[in] = gettime();
    }

    void end(TestOp *in)
    {
      ceph_assert(inflight.count(in));
      uint64_t curtime = gettime();
      latencies.insert(curtime - inflight[in]);
      inflight.erase(in);
    }

    void export_latencies(std::map<double,uint64_t> &in) const;
  };
  std::map<std::string,TypeStatus> stats;

  void begin(TestOp *in);
  void end(TestOp *in);
  friend std::ostream & operator<<(std::ostream &, const TestOpStat &);
};

std::ostream & operator<<(std::ostream &out, const TestOpStat &rhs);

#endif