xref: /aosp_15_r20/external/cronet/base/tracing/trace_time.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2019 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 BASE_TRACING_TRACE_TIME_H_
6 #define BASE_TRACING_TRACE_TIME_H_
7 
8 #include "build/build_config.h"
9 #include "third_party/perfetto/protos/perfetto/common/builtin_clock.pbzero.h"
10 
11 namespace base {
12 namespace tracing {
13 
14 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
15     BUILDFLAG(IS_FUCHSIA)
16 // Linux, Android, and Fuchsia all use CLOCK_MONOTONIC. See crbug.com/166153
17 // about efforts to unify base::TimeTicks across all platforms.
18 constexpr perfetto::protos::pbzero::BuiltinClock kTraceClockId =
19     perfetto::protos::pbzero::BUILTIN_CLOCK_MONOTONIC;
20 #else
21 // Mac and Windows TimeTicks advance when sleeping, so are closest to BOOTTIME
22 // in behavior.
23 // TODO(eseckler): Support specifying Mac/Win platform clocks in BuiltinClock.
24 constexpr perfetto::protos::pbzero::BuiltinClock kTraceClockId =
25     perfetto::protos::pbzero::BUILTIN_CLOCK_BOOTTIME;
26 #endif
27 
28 // Returns CLOCK_BOOTTIME on systems that support it, otherwise falls back to
29 // TRACE_TIME_TICKS_NOW().
30 int64_t TraceBootTicksNow();
31 
32 }  // namespace tracing
33 }  // namespace base
34 
35 #endif  // BASE_TRACING_TRACE_TIME_H_
36