Coverage Report

Created: 2026-09-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/abseil-cpp/absl/base/internal/cycleclock.cc
Line
Count
Source
1
// Copyright 2017 The Abseil Authors.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      https://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
// The implementation of CycleClock::Frequency.
16
//
17
// NOTE: only i386 and x86_64 have been well tested.
18
// PPC, sparc, alpha, and ia64 are based on
19
//    http://peter.kuscsik.com/wordpress/?p=14
20
// with modifications by m3b.  See also
21
//    https://setisvn.ssl.berkeley.edu/svn/lib/fftw-3.0.1/kernel/cycle.h
22
23
#include "absl/base/internal/cycleclock.h"
24
25
#include <atomic>
26
#include <chrono>  // NOLINT(build/c++11)
27
28
#include "absl/base/attributes.h"
29
#include "absl/base/config.h"
30
#include "absl/base/internal/unscaledcycleclock.h"
31
#include "absl/base/internal/unscaledcycleclock_config.h"
32
33
namespace absl {
34
ABSL_NAMESPACE_BEGIN
35
namespace base_internal {
36
37
#if ABSL_USE_UNSCALED_CYCLECLOCK
38
39
ABSL_CONST_INIT std::atomic<CycleClockSourceFunc>
40
    CycleClock::cycle_clock_source_{nullptr};
41
42
0
void CycleClockSource::Register(CycleClockSourceFunc source) {
43
  // Corresponds to the load(std::memory_order_acquire) in LoadCycleClockSource.
44
0
  CycleClock::cycle_clock_source_.store(source, std::memory_order_release);
45
0
}
46
47
#ifdef _WIN32
48
int64_t CycleClock::Now() {
49
  auto fn = LoadCycleClockSource();
50
  if (fn == nullptr) {
51
    return base_internal::UnscaledCycleClock::Now() >> kShift;
52
  }
53
  return fn() >> kShift;
54
}
55
#endif
56
57
#else
58
59
int64_t CycleClock::Now() {
60
  return std::chrono::duration_cast<std::chrono::nanoseconds>(
61
             std::chrono::steady_clock::now().time_since_epoch())
62
      .count();
63
}
64
65
double CycleClock::Frequency() {
66
  return 1e9;
67
}
68
69
#endif
70
71
}  // namespace base_internal
72
ABSL_NAMESPACE_END
73
}  // namespace absl