Debian Codegraph @

src/base/SkTime.cpp

raw
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 #if !defined(__has_feature)
11 #define __has_feature(x) 0
12 #endif
13
14 #if __has_feature(memory_sanitizer)
15 #include <time.h>
16 #else
17 #include <chrono>
18 #include <ratio>
19 #endif
20
21 double SkTime::GetNSecs() {
22 #if __has_feature(memory_sanitizer)
23 // See skbug.com/40037711
24 struct timespec tp;
25 clock_gettime(CLOCK_MONOTONIC, &tp);
26 return tp.tv_sec * 1e9 + tp.tv_nsec;
27 #else
28 auto now = std::chrono::steady_clock::now();
29 std::chrono::duration<double, std::nano> ns = now.time_since_epoch();
30 return ns.count();
31 #endif
32 }