// Copyright 2021 Google Inc. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef BENCHMARK_PERF_COUNTERS_H #define BENCHMARK_PERF_COUNTERS_H #include <array> #include <cstdint> #include <cstring> #include <memory> #include <vector> #include "benchmark/benchmark.h" #include "check.h" #include "log.h" #include "mutex.h" #ifndef BENCHMARK_OS_WINDOWS #include <unistd.h> #endif #if defined(_MSC_VER) #pragma warning(push) // C4251: <symbol> needs to have dll-interface to be used by clients of class #pragma warning(disable : 4251) #endif namespace benchmark { namespace internal { // Typically, we can only read a small number of counters. There is also a // padding preceding counter values, when reading multiple counters with one // syscall (which is desirable). PerfCounterValues abstracts these details. // The implementation ensures the storage is inlined, and allows 0-based // indexing into the counter values. // The object is used in conjunction with a PerfCounters object, by passing it // to Snapshot(). The Read() method relocates individual reads, discarding // the initial padding from each group leader in the values buffer such that // all user accesses through the [] operator are correct. class BENCHMARK_EXPORT PerfCounterValues { … }; // Collect PMU counters. The object, once constructed, is ready to be used by // calling read(). PMU counter collection is enabled from the time create() is // called, to obtain the object, until the object's destructor is called. class BENCHMARK_EXPORT PerfCounters final { … }; // Typical usage of the above primitives. class BENCHMARK_EXPORT PerfCountersMeasurement final { … }; } // namespace internal } // namespace benchmark #if defined(_MSC_VER) #pragma warning(pop) #endif #endif // BENCHMARK_PERF_COUNTERS_H