OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
PerformanceCounter.h
Go to the documentation of this file.
1/*
2* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3*
4* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5* and international copyright treaties.
6*
7* Access to and use of the software is governed by the terms of the applicable OnixS Software
8* Services Agreement (the Agreement) and Customer end user license agreements granting
9* a non-assignable, non-transferable and non-exclusive license to use the software
10* for it's own data processing purposes under the terms defined in the Agreement.
11*
12* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13* of this source code or associated reference material to any other location for further reproduction
14* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15*
16* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17* the terms of the Agreement is a violation of copyright law.
18*/
19#pragma once
20
21#include <iosfwd>
22
23#ifdef _WIN32
24#include <Windows.h>
25#else
26#include <time.h>
27#endif
28
31{
32public:
33#ifdef _WIN32
34 typedef LARGE_INTEGER Count;
35#else
36 typedef timespec Count;
37#endif
38
39 static void setToUndefinedValue(Count * value);
40
41 static bool isUndefinedValue(const Count & value);
42
44 static Count current();
45
46 ONIXS_ICEBOE_FORCEINLINE ONIXS_ICEBOE_HOTPATH
47 static void current(PerformanceCounter::Count * result) noexcept
48 {
49#ifdef _WIN32
50 ::QueryPerformanceCounter(result);
51#else
52 ::clock_gettime(CLOCK_MONOTONIC, result);
53#endif
54 }
55
56 typedef long long Span;
57
58 static Span nsSpan(const PerformanceCounter::Count & stop, const PerformanceCounter::Count & start);
59
60 static Span usSpan(const PerformanceCounter::Count & stop, const PerformanceCounter::Count & start);
61
63
65
66private:
67#ifdef _WIN32
68 typedef LARGE_INTEGER Frequency;
69 static const Frequency frequency_;
70#endif
71};
72
73std::ostream & operator<< (std::ostream & os, const PerformanceCounter::Count & value);
74
76{
77#ifdef _WIN32
78 return (left.LowPart == right.LowPart && left.HighPart == right.HighPart);
79#else
80 return (left.tv_nsec == right.tv_nsec && left.tv_sec == right.tv_sec);
81#endif
82}
83
85{
86 return !(left == right);
87}
88
89inline
91 const PerformanceCounter::Count & stop, const PerformanceCounter::Count & start)
92{
93#ifdef _WIN32
94 return static_cast<PerformanceCounter::Span>((stop.QuadPart - start.QuadPart) * 1000000000.0 / frequency_.QuadPart);
95#else
96 return static_cast<PerformanceCounter::Span>((stop.tv_sec - start.tv_sec) * 1000000000 + (stop.tv_nsec - start.tv_nsec));
97#endif
98}
99
100inline
102 const PerformanceCounter::Count & stop, const PerformanceCounter::Count & start)
103{
104#ifdef _WIN32
105 return static_cast<PerformanceCounter::Span>((stop.QuadPart - start.QuadPart) * 1000000.0 / frequency_.QuadPart);
106#else
107 return static_cast<PerformanceCounter::Span>((stop.tv_sec - start.tv_sec) * 1000000 + (stop.tv_nsec - start.tv_nsec) / 1000);
108#endif
109}
110
111inline
116
117inline
122
124{
125#ifdef _WIN32
126 value->LowPart = 0;
127 value->HighPart = 0;
128#else
129 value->tv_sec = 0;
130 value->tv_nsec = 0;
131#endif
132}
133
135{
136#ifdef _WIN32
137 return (0 == value.LowPart && 0 == value.HighPart);
138#else
139 return (0 == value.tv_sec && 0 == value.tv_nsec);
140#endif
141}
142
144{
145 Count result;
146 current(&result);
147 return result;
148}
149
150inline std::ostream & operator<<(std::ostream & os, const PerformanceCounter::Count & value)
151{
152#ifdef _WIN32
153 os << value.HighPart << value.LowPart;
154#else
155 os << '[' << value.tv_sec << '.' << value.tv_nsec << ']';
156#endif
157
158 return os;
159}
#define ONIXS_ICEBOE_HOTPATH
Definition Compiler.h:157
std::ostream & operator<<(std::ostream &os, const PerformanceCounter::Count &value)
bool operator==(const PerformanceCounter::Count &left, const PerformanceCounter::Count &right)
bool operator!=(const PerformanceCounter::Count &left, const PerformanceCounter::Count &right)
High-resolution performance counter.
static void setToUndefinedValue(Count *value)
static Span nsSpan(const PerformanceCounter::Count &stop, const PerformanceCounter::Count &start)
static Span elapsedNanoseconds(const PerformanceCounter::Count &start)
static Span usSpan(const PerformanceCounter::Count &stop, const PerformanceCounter::Count &start)
ONIXS_ICEBOE_FORCEINLINE static ONIXS_ICEBOE_HOTPATH void current(PerformanceCounter::Count *result) noexcept
static Span elapsedMicroseconds(const PerformanceCounter::Count &start)
static Count current()
Retrieves the current value of the high-resolution performance counter.
static bool isUndefinedValue(const Count &value)