xref: /aosp_15_r20/external/skia/src/base/SkTime.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "src/base/SkTime.h"
9 
10 #include <chrono>
11 #include <ratio>
12 
13 #if !defined(__has_feature)
14     #define  __has_feature(x) 0
15 #endif
16 
GetNSecs()17 double SkTime::GetNSecs() {
18 #if __has_feature(memory_sanitizer)
19     // See skia:6504
20     struct timespec tp;
21     clock_gettime(CLOCK_MONOTONIC, &tp);
22     return tp.tv_sec * 1e9 + tp.tv_nsec;
23 #else
24     auto now = std::chrono::steady_clock::now();
25     std::chrono::duration<double, std::nano> ns = now.time_since_epoch();
26     return ns.count();
27 #endif
28 }
29