3 #ifndef UTILS_ThreadPerf_H
4 #define UTILS_ThreadPerf_H
6 #define PERF_ERROR(n) printf(n)
17 #include <sys/syscall.h>
18 #include <sys/types.h>
19 #include <sys/ioctl.h>
24 #include <linux/perf_event.h>
31 #define __LIBPERF_MAX_COUNTERS 32
32 #define __LIBPERF_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
57 std::vector<PerfEntry> entries;
67 uint64_t readPerf(
size_t ch);
69 int startPerf(
size_t ch);
71 int stopPerf(
size_t ch);
73 bool isValidChannel(
size_t ch);
76 typedef std::shared_ptr<PerfTool> PerfToolPtr;
134 string getChValueAsString(
size_t idx);
135 uint64_t getRunTime(
void) {
137 int64_t s0, e0, s1, e1;
142 return 1000000 * (e0 - s0) + (e1 - s1);
145 vector<PerfPair> pairs;
146 struct timeval ts, te;
237 TRACE_RUNNING_TIME = -1,
238 COUNT_SW_CPU_CLOCK = 0,
239 COUNT_SW_TASK_CLOCK = 1,
240 COUNT_SW_CONTEXT_SWITCHES = 2,
241 COUNT_SW_CPU_MIGRATIONS = 3,
242 COUNT_SW_PAGE_FAULTS = 4,
243 COUNT_SW_PAGE_FAULTS_MIN = 5,
244 COUNT_SW_PAGE_FAULTS_MAJ = 6,
247 COUNT_HW_CPU_CYCLES = 7,
248 COUNT_HW_INSTRUCTIONS = 8,
249 COUNT_HW_CACHE_REFERENCES = 9,
250 COUNT_HW_CACHE_MISSES = 10,
251 COUNT_HW_BRANCH_INSTRUCTIONS = 11,
252 COUNT_HW_BRANCH_MISSES = 12,
253 COUNT_HW_BUS_CYCLES = 13,
258 COUNT_HW_CACHE_L1D_LOADS = 14,
259 COUNT_HW_CACHE_L1D_LOADS_MISSES = 15,
260 COUNT_HW_CACHE_L1D_STORES = 16,
261 COUNT_HW_CACHE_L1D_STORES_MISSES = 17,
262 COUNT_HW_CACHE_L1D_PREFETCHES = 18,
265 COUNT_HW_CACHE_L1I_LOADS = 19,
266 COUNT_HW_CACHE_L1I_LOADS_MISSES = 20,
269 COUNT_HW_CACHE_LL_LOADS = 21,
270 COUNT_HW_CACHE_LL_LOADS_MISSES = 22,
271 COUNT_HW_CACHE_LL_STORES = 23,
272 COUNT_HW_CACHE_LL_STORES_MISSES = 24,
275 COUNT_HW_CACHE_DTLB_LOADS = 25,
276 COUNT_HW_CACHE_DTLB_LOADS_MISSES = 26,
277 COUNT_HW_CACHE_DTLB_STORES = 27,
278 COUNT_HW_CACHE_DTLB_STORES_MISSES = 28,
281 COUNT_HW_CACHE_ITLB_LOADS = 29,
282 COUNT_HW_CACHE_ITLB_LOADS_MISSES = 30,
285 COUNT_HW_CACHE_BPU_LOADS = 31,
286 COUNT_HW_CACHE_BPU_LOADS_MISSES = 32,
Definition: ThreadPerf.h:40
Combine PerfTool together with tags.
Definition: ThreadPerf.h:82
The all-in-on perf class for thread.
Definition: ThreadPerf.h:132
void start()
start all registered perf
ThreadPerf(int cpu, vector< PerfPair > customPair)
To start perf this thread at specific cpu, with customized perf events.
ThreadPerf(int cpu)
To start perf this thread at specific cpu, with default perf events.
uint64_t record
Definition: ThreadPerf.h:89
int ref
Definition: ThreadPerf.h:85
std::string name
Definition: ThreadPerf.h:87
perfTrace
The valid idx for perf.
Definition: ThreadPerf.h:235
PerfPair(int _ref, string _name)
The construction function.
Definition: ThreadPerf.h:95
uint64_t getResultById(int idx)
Get the perf result by event id.
void end()
end all registered perf
string resultStringCsv(void)
get the result string for csv file a result sheet
string resultStringPrintf(void)
get the result string for print a result sheet
uint64_t getResultByName(string name)
Get the perf result by event tag string.
string headStringCsv(void)
get the head string for csv file of a result sheet
string headStringPrintf(void)
get the head string for print a result sheet
Definition: DatasetTool.h:10