forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTelemetry.h
More file actions
65 lines (54 loc) · 1.68 KB
/
Telemetry.h
File metadata and controls
65 lines (54 loc) · 1.68 KB
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
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <chrono>
namespace facebook {
namespace react {
/*
* Represents a monotonic clock suitable for measuring intervals.
*/
using TelemetryClock = std::chrono::steady_clock;
/*
* Represents a point in time satisfied the requirements of TelemetryClock.
*/
using TelemetryTimePoint = TelemetryClock::time_point;
/*
* Represents a time interval satisfied the requirements of TelemetryClock.
*/
using TelemetryDuration = std::chrono::nanoseconds;
/*
* Represents a time point which never happens.
*/
static TelemetryTimePoint const kTelemetryUndefinedTimePoint =
TelemetryTimePoint::max();
/*
* Returns a time point representing the current point in time.
*/
static inline TelemetryTimePoint telemetryTimePointNow() {
return TelemetryClock::now();
}
/*
* Returns a number of milliseconds that passed from some epoch starting time
* point to a given time point. The epoch starting time point is not specified
* but stays the same for an application run.
*/
static inline int64_t telemetryTimePointToMilliseconds(
TelemetryTimePoint timePoint) {
return std::chrono::duration_cast<std::chrono::milliseconds>(
timePoint - TelemetryTimePoint{})
.count();
}
/*
* Returns a number of milliseconds that represents the given duration object.
*/
static inline int64_t telemetryDurationToMilliseconds(
TelemetryDuration duration) {
return std::chrono::duration_cast<std::chrono::milliseconds>(duration)
.count();
}
} // namespace react
} // namespace facebook