xref: /aosp_15_r20/external/cronet/components/cronet/metrics_util.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef COMPONENTS_CRONET_METRICS_UTIL_H_
6 #define COMPONENTS_CRONET_METRICS_UTIL_H_
7 
8 #include <stdint.h>
9 
10 #include "base/time/time.h"
11 
12 namespace cronet {
13 
14 namespace metrics_util {
15 
16 constexpr int64_t kNullTime = -1;
17 
18 // Converts timing metrics stored as TimeTicks into the format expected by the
19 // API layer: ms since Unix epoch, or kNullTime for null (if either |ticks| or
20 // |start_ticks| is null).
21 //
22 // By calculating time values using a base (|start_ticks|, |start_time|) pair,
23 // time values are normalized. This allows time deltas between pairs of events
24 // to be accurately computed, even if the system clock changed between those
25 // events, as long as times for both events were calculated using the same
26 // (|start_ticks|, |start_time|) pair.
27 //
28 // Args:
29 //
30 // ticks: The ticks value corresponding to the time of the event -- the returned
31 //        time corresponds to this event.
32 //
33 // start_ticks: The ticks measurement at some base time -- the ticks equivalent
34 //              of start_time. Should be smaller than ticks.
35 //
36 // start_time: Time measurement at some base time -- the time equivalent of
37 //             start_ticks. Must not be null.
38 int64_t ConvertTime(const base::TimeTicks& ticks,
39                     const base::TimeTicks& start_ticks,
40                     const base::Time& start_time);
41 
42 }  // namespace metrics_util
43 
44 }  // namespace cronet
45 
46 #endif  // COMPONENTS_CRONET_METRICS_UTIL_H_
47