1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
5 * Copyright (C) 2016 Red Hat Inc.
27 using ClientId = uint;
28 using ServerId = uint;
32 namespace qos_simulation {
34 inline void debugger() {
39 void time_stats(std::mutex& mtx,
41 std::function<void()> code) {
42 auto t1 = std::chrono::steady_clock::now();
44 auto t2 = std::chrono::steady_clock::now();
45 auto duration = t2 - t1;
46 auto cast_duration = std::chrono::duration_cast<T>(duration);
47 std::lock_guard<std::mutex> lock(mtx);
48 time_accumulate += cast_duration;
51 // unfortunately it's hard for the compiler to infer the types,
52 // and therefore when called the template params might have to be
54 template<typename T, typename R>
55 R time_stats_w_return(std::mutex& mtx,
57 std::function<R()> code) {
58 auto t1 = std::chrono::steady_clock::now();
60 auto t2 = std::chrono::steady_clock::now();
61 auto duration = t2 - t1;
62 auto cast_duration = std::chrono::duration_cast<T>(duration);
63 std::lock_guard<std::mutex> lock(mtx);
64 time_accumulate += cast_duration;
69 void count_stats(std::mutex& mtx,
71 std::lock_guard<std::mutex> lock(mtx);
76 ServerId server; // allows debugging
80 TestRequest(ServerId _server,
90 TestRequest(const TestRequest& r) :
91 TestRequest(r.server, r.epoch, r.op)
95 }; // struct TestRequest
101 TestResponse(uint32_t _epoch) :
107 TestResponse(const TestResponse& r) :
113 friend std::ostream& operator<<(std::ostream& out, const TestResponse& resp) {
115 out << "epoch:" << resp.epoch;
119 }; // class TestResponse
121 }; // namespace qos_simulation
122 }; // namespace crimson