-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsPAPI_toc.c
34 lines (33 loc) · 1.03 KB
/
sPAPI_toc.c
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
31
32
33
34
#include <stdio.h>
#include "mex.h"
#include "papi.h"
/*
* sPAPI_toc -- read values from hardware performance monitoring counters.
*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
/* Get number of running counters */
int num_counters = 0;
mxArray *sPAPI_status = mexGetVariable("global", "sPAPI_status");
if (sPAPI_status)
{
num_counters = *((int *)mxGetData(sPAPI_status));
}
if (num_counters > 0)
{
plhs[0] = mxCreateNumericMatrix(1, num_counters, mxINT64_CLASS, mxREAL);
long long *counter_values = (long long *)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 sPAPI_register first.\n");
}
}