Skip to content

v1.0.0

Latest
Compare
Choose a tag to compare
@Myriad-Dreamin Myriad-Dreamin released this 08 Feb 05:56
· 2 commits to main since this release

Use tsc on x86 Linux / Linux Kernel / Windows.

Install

The library is header only. You can also link PerfRdtsc as a cmake interface library.

add_subdirectory(vendor/rdtsc)

API Usage

#include <perfApi/rdtsc.h>

int runApp() {
  int64_t cpu_cycle = perfApiRdtsc(); // or precisely perfApiRdCycle()
  int64_t cpu_cycle = perfApiRdCycle();

  int64_t nanosecond = perfApiTsc2ns(cpu_cycle); // offline translation
  int64_t nanosecond = perfApiRdns();    // sampled by tsc instruction
  int64_t nanosecond = perfApiRdsysns(); // sampled by kernel syscall

  return 0;
}

int main() { perfApiTscInit(0); return runApp(); }