1 // Copyright 2020 The Chromium Authors. All rights reserved. 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 "services/tracing/public/cpp/perfetto/trace_time.h" 6 7 #include "base/logging.h" 8 #include "base/trace_event/trace_event.h" 9 #include "build/build_config.h" 10 #include "third_party/perfetto/include/perfetto/base/time.h" 11 12 namespace tracing { 13 TraceBootTicksNow()14int64_t TraceBootTicksNow() { 15 // On Windows and Mac, TRACE_TIME_TICKS_NOW() behaves like boottime already. 16 #if defined(OS_LINUX) || defined(OS_ANDROID) || defined(OS_FUCHSIA) 17 struct timespec ts; 18 int res = clock_gettime(CLOCK_BOOTTIME, &ts); 19 if (res != -1) 20 return static_cast<int64_t>(perfetto::base::FromPosixTimespec(ts).count()); 21 #endif 22 return TRACE_TIME_TICKS_NOW().since_origin().InNanoseconds(); 23 } 24 25 } // namespace tracing