xref: /aosp_15_r20/external/cronet/base/tracing/trace_time.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2020 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 #include "base/tracing/trace_time.h"
6 
7 #include "base/trace_event/trace_event.h"
8 #include "build/build_config.h"
9 #include "third_party/perfetto/include/perfetto/base/time.h"
10 
11 namespace base {
12 namespace tracing {
13 
TraceBootTicksNow()14 int64_t TraceBootTicksNow() {
15   // On Windows and Mac, TRACE_TIME_TICKS_NOW() behaves like boottime already.
16 #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
17     BUILDFLAG(IS_FUCHSIA)
18   struct timespec ts;
19   int res = clock_gettime(CLOCK_BOOTTIME, &ts);
20   if (res != -1)
21     return static_cast<int64_t>(perfetto::base::FromPosixTimespec(ts).count());
22 #endif
23   return TRACE_TIME_TICKS_NOW().since_origin().InNanoseconds();
24 }
25 
26 }  // namespace tracing
27 }  // namespace base