]>
git.proxmox.com Git - ceph.git/blob - ceph/src/dmclock/sim/src/sim_recs.h
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.
7 * Author: J. Eric Ivancich <ivancich@redhat.com>
9 * This is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License version
11 * 2.1, as published by the Free Software Foundation. See file
34 using ClientId
= uint
;
35 using ServerId
= uint
;
39 namespace qos_simulation
{
41 using Cost
= uint32_t;
43 inline void debugger() {
48 void time_stats(std::mutex
& mtx
,
50 std::function
<void()> code
) {
51 auto t1
= std::chrono::steady_clock::now();
53 auto t2
= std::chrono::steady_clock::now();
54 auto duration
= t2
- t1
;
55 auto cast_duration
= std::chrono::duration_cast
<T
>(duration
);
56 std::lock_guard
<std::mutex
> lock(mtx
);
57 time_accumulate
+= cast_duration
;
60 // unfortunately it's hard for the compiler to infer the types,
61 // and therefore when called the template params might have to be
63 template<typename T
, typename R
>
64 R
time_stats_w_return(std::mutex
& mtx
,
66 std::function
<R()> code
) {
67 auto t1
= std::chrono::steady_clock::now();
69 auto t2
= std::chrono::steady_clock::now();
70 auto duration
= t2
- t1
;
71 auto cast_duration
= std::chrono::duration_cast
<T
>(duration
);
72 std::lock_guard
<std::mutex
> lock(mtx
);
73 time_accumulate
+= cast_duration
;
78 void count_stats(std::mutex
& mtx
,
80 std::lock_guard
<std::mutex
> lock(mtx
);
85 ServerId server
; // allows debugging
89 TestRequest(ServerId _server
,
99 TestRequest(const TestRequest
& r
) :
100 TestRequest(r
.server
, r
.epoch
, r
.op
)
104 }; // struct TestRequest
107 struct TestResponse
{
110 explicit TestResponse(uint32_t _epoch
) :
116 TestResponse(const TestResponse
& r
) :
122 friend std::ostream
& operator<<(std::ostream
& out
, const TestResponse
& resp
) {
124 out
<< "epoch:" << resp
.epoch
;
128 }; // class TestResponse
130 }; // namespace qos_simulation
131 }; // namespace crimson