blob: 86221ee3bb583a548deb82d14515ae95711916de [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2020 The Chromium Authors
Eric Seckler9e0365a2020-01-29 15:11:592// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Sami Kyostila15d10792021-04-13 16:45:115#include "base/tracing/trace_time.h"
Eric Seckler9e0365a2020-01-29 15:11:596
Eric Seckler9e0365a2020-01-29 15:11:597#include "base/trace_event/trace_event.h"
8#include "build/build_config.h"
9#include "third_party/perfetto/include/perfetto/base/time.h"
10
Peter Kasting811504a72025-01-09 03:18:5011namespace base::tracing {
Eric Seckler9e0365a2020-01-29 15:11:5912
13int64_t TraceBootTicksNow() {
14 // On Windows and Mac, TRACE_TIME_TICKS_NOW() behaves like boottime already.
Xiaohan Wangea6313d2022-01-15 19:51:1115#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \
16 BUILDFLAG(IS_FUCHSIA)
Eric Seckler9e0365a2020-01-29 15:11:5917 struct timespec ts;
18 int res = clock_gettime(CLOCK_BOOTTIME, &ts);
Peter Kasting134ef9af2024-12-28 02:30:0919 if (res != -1) {
Eric Seckler9e0365a2020-01-29 15:11:5920 return static_cast<int64_t>(perfetto::base::FromPosixTimespec(ts).count());
Peter Kasting134ef9af2024-12-28 02:30:0921 }
Eric Seckler9e0365a2020-01-29 15:11:5922#endif
23 return TRACE_TIME_TICKS_NOW().since_origin().InNanoseconds();
24}
25
Peter Kasting811504a72025-01-09 03:18:5026} // namespace base::tracing