Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Eric Seckler | 9e0365a | 2020-01-29 15:11:59 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Sami Kyostila | 15d1079 | 2021-04-13 16:45:11 | [diff] [blame] | 5 | #include "base/tracing/trace_time.h" |
Eric Seckler | 9e0365a | 2020-01-29 15:11:59 | [diff] [blame] | 6 | |
Eric Seckler | 9e0365a | 2020-01-29 15:11:59 | [diff] [blame] | 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 | |
Peter Kasting | 811504a7 | 2025-01-09 03:18:50 | [diff] [blame] | 11 | namespace base::tracing { |
Eric Seckler | 9e0365a | 2020-01-29 15:11:59 | [diff] [blame] | 12 | |
| 13 | int64_t TraceBootTicksNow() { |
| 14 | // On Windows and Mac, TRACE_TIME_TICKS_NOW() behaves like boottime already. |
Xiaohan Wang | ea6313d | 2022-01-15 19:51:11 | [diff] [blame] | 15 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) || \ |
| 16 | BUILDFLAG(IS_FUCHSIA) |
Eric Seckler | 9e0365a | 2020-01-29 15:11:59 | [diff] [blame] | 17 | struct timespec ts; |
| 18 | int res = clock_gettime(CLOCK_BOOTTIME, &ts); |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 19 | if (res != -1) { |
Eric Seckler | 9e0365a | 2020-01-29 15:11:59 | [diff] [blame] | 20 | return static_cast<int64_t>(perfetto::base::FromPosixTimespec(ts).count()); |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 21 | } |
Eric Seckler | 9e0365a | 2020-01-29 15:11:59 | [diff] [blame] | 22 | #endif |
| 23 | return TRACE_TIME_TICKS_NOW().since_origin().InNanoseconds(); |
| 24 | } |
| 25 | |
Peter Kasting | 811504a7 | 2025-01-09 03:18:50 | [diff] [blame] | 26 | } // namespace base::tracing |