forked from mariadb-corporation/MaxScale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeasurements.hh
69 lines (60 loc) · 1.31 KB
/
measurements.hh
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) 2021 MariaDB Corporation Ab
* Copyright (c) 2023 MariaDB plc, Finnish Branch
*
* Use of this software is governed by the Business Source License included
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
*
* Change Date: 2025-09-12
*
* On the date above, in accordance with the Business Source License, use
* of this software will be governed by version 2 or later of the General
* Public License.
*/
#pragma once
#include <maxbase/ccdefs.hh>
#include <maxbase/worker.hh>
namespace maxbase
{
class Worker;
}
namespace maxbase
{
/**
* @brief MeasureTime is a helper class to keep as a member to
* measure time for a Worker.
*
* NOTE: The time used in MeasureTime is epoll_tick_now().
*/
class MeasureTime
{
public:
enum class Operation {NOP, READ, WRITE};
MeasureTime(mxb::Worker* pWorker)
: m_pWorker(pWorker)
{
}
void start(Operation opr)
{
m_start = m_pWorker->epoll_tick_now();
m_opr = opr;
}
void stop()
{
m_stop = m_pWorker->epoll_tick_now();
}
Duration duration()
{
return m_stop - m_start;
}
Operation opr()
{
return m_opr;
}
private:
mxb::Worker* m_pWorker;
Operation m_opr;
mxb::TimePoint m_start;
mxb::TimePoint m_stop;
};
}