-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathpmu.cpp
More file actions
29 lines (27 loc) · 841 Bytes
/
pmu.cpp
File metadata and controls
29 lines (27 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
// Created by zheng on 2020/7/29.
//
#include "pmu.h"
#include "papi_wrap.h"
#include <sys/time.h>
#include <sys/resource.h>
#include <vector>
#include <iostream>
std::vector<long long> get_rusage_data()
{
static long long values[CNT_RUSAGE_EVENTS];
static rusage raw_data;
if (getrusage(RUSAGE_SELF, &raw_data))
{
std::cerr << "Error: getrusage failed:"<<strerror(errno);
}
auto ret = std::vector<long long>{raw_data.ru_nvcsw - values[0],
raw_data.ru_nivcsw - values[1],
raw_data.ru_majflt - values[2],
raw_data.ru_minflt - values[3]};
values[0]=raw_data.ru_nvcsw;
values[1]=raw_data.ru_nivcsw;
values[2]=raw_data.ru_majflt;
values[3]=raw_data.ru_minflt;
return ret;
}