-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoPAPI_toc.c
More file actions
30 lines (28 loc) · 894 Bytes
/
oPAPI_toc.c
File metadata and controls
30 lines (28 loc) · 894 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
30
#include <stdio.h>
#include "mex.h"
#include "papi.h"
#include "oPAPI_status.h"
/*
* oPAPI_toc -- read values from hardware performance monitoring counters.
*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int num_counters = oPAPI_getNumRunningCounters();
if (num_counters > 0)
{
plhs[0] = mxCreateNumericMatrix(1, num_counters, mxINT64_CLASS, mxREAL);
long long *counter_values = mxGetData(plhs[0]);
int result;
if ((result = PAPI_read_counters(counter_values, num_counters)) != PAPI_OK)
{
char error[256];
sprintf(error, "Failed to read counters. "
"Error message: %s.",
PAPI_strerror(result));
}
}
else
{
mexPrintf("Counters are unregistered and not running. Execute oPAPI_register first.\n");
}
}