1*2c2f96dcSApple OSS Distributions #ifndef BENCHMARK_PERF_HELPERS_H 2*2c2f96dcSApple OSS Distributions #define BENCHMARK_PERF_HELPERS_H 3*2c2f96dcSApple OSS Distributions 4*2c2f96dcSApple OSS Distributions /* 5*2c2f96dcSApple OSS Distributions * Utility functions and constants used by perf tests. 6*2c2f96dcSApple OSS Distributions */ 7*2c2f96dcSApple OSS Distributions #include <inttypes.h> 8*2c2f96dcSApple OSS Distributions #include <time.h> 9*2c2f96dcSApple OSS Distributions #include <stdbool.h> 10*2c2f96dcSApple OSS Distributions 11*2c2f96dcSApple OSS Distributions /* 12*2c2f96dcSApple OSS Distributions * mmap an anonymous chunk of memory. 13*2c2f96dcSApple OSS Distributions */ 14*2c2f96dcSApple OSS Distributions unsigned char *mmap_buffer(size_t size); 15*2c2f96dcSApple OSS Distributions /* 16*2c2f96dcSApple OSS Distributions * Returns a - b in microseconds. 17*2c2f96dcSApple OSS Distributions * NB: a must be >= b 18*2c2f96dcSApple OSS Distributions */ 19*2c2f96dcSApple OSS Distributions uint64_t timespec_difference_us(const struct timespec* a, const struct timespec* b); 20*2c2f96dcSApple OSS Distributions /* 21*2c2f96dcSApple OSS Distributions * Print the message to stdout along with the current time. 22*2c2f96dcSApple OSS Distributions * Also flushes stdout so that the log can help detect hangs. Don't call 23*2c2f96dcSApple OSS Distributions * this function from within the measured portion of the benchmark as it will 24*2c2f96dcSApple OSS Distributions * pollute your measurement. 25*2c2f96dcSApple OSS Distributions * 26*2c2f96dcSApple OSS Distributions * NB: Will only log if verbose == true. 27*2c2f96dcSApple OSS Distributions */ 28*2c2f96dcSApple OSS Distributions void benchmark_log(bool verbose, const char *restrict fmt, ...) __attribute__((format(printf, 2, 3))); 29*2c2f96dcSApple OSS Distributions 30*2c2f96dcSApple OSS Distributions static const uint64_t kNumMicrosecondsInSecond = 1000UL * 1000; 31*2c2f96dcSApple OSS Distributions static const uint64_t kNumNanosecondsInMicrosecond = 1000UL; 32*2c2f96dcSApple OSS Distributions static const uint64_t kNumNanosecondsInSecond = kNumNanosecondsInMicrosecond * kNumMicrosecondsInSecond; 33*2c2f96dcSApple OSS Distributions /* Get a (wall-time) timestamp in nanoseconds */ 34*2c2f96dcSApple OSS Distributions #define current_timestamp_ns() (clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW)); 35*2c2f96dcSApple OSS Distributions 36*2c2f96dcSApple OSS Distributions unsigned int get_ncpu(void); 37*2c2f96dcSApple OSS Distributions 38*2c2f96dcSApple OSS Distributions #endif /* !defined(BENCHMARK_PERF_HELPERS_H) */ 39