PAPI 7.1.0.0
Loading...
Searching...
No Matches
smoke_tests/simple.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include <unistd.h>
3#include <stdio.h>
4#include <papi.h>
5#define NUM_EVENTS 2
6
7int main( int argc, char **argv )
8{
9 int retval, i;
10 long long values[NUM_EVENTS];
11 int EventSet = PAPI_NULL;
12 int events[NUM_EVENTS];
13 char *EventName[] = { "PAPI_TOT_CYC", "PAPI_TOT_INS" };
14
16 if ( retval != PAPI_VER_CURRENT ) {
17 printf("ERROR: PAPI_library_init: %d: %s\n", retval, PAPI_strerror(retval));
18 exit(EXIT_FAILURE);
19 } else {
20 printf ( "PAPI_VERSION : %4d %6d %7d\n",
24 }
25
27 if ( retval != PAPI_OK ) {
28 printf("ERROR: PAPI_create_eventset: %d: %s\n", retval, PAPI_strerror(retval));
29 exit(EXIT_FAILURE);
30 }
31
32 for( i = 0; i < NUM_EVENTS; i++ ) {
33 retval = PAPI_event_name_to_code ( EventName[i], &events[i] );
34 if ( retval != PAPI_OK ) {
35 printf("ERROR: PAPI_event_name_to_code: %d: %s\n", retval, PAPI_strerror(retval));
36 exit(EXIT_FAILURE);
37 }
38 }
39
41 if ( retval != PAPI_OK ) {
42 printf("ERROR: PAPI_add_events: %d: %s\n", retval, PAPI_strerror(retval));
43 exit(EXIT_FAILURE);
44 }
45
47 if ( retval != PAPI_OK ) {
48 printf("ERROR: PAPI_start: %d: %s\n", retval, PAPI_strerror(retval));
49 exit(EXIT_FAILURE);
50 }
51
52 // do work
53 sleep(3);
54
56 if ( retval != PAPI_OK ) {
57 printf("ERROR: PAPI_stop: %d: %s\n", retval, PAPI_strerror(retval));
58 exit(EXIT_FAILURE);
59 }
60
61 for( i = 0; i < NUM_EVENTS; i++ ) {
62 printf( "%12lld \t\t --> %s \n", values[i],
63 EventName[i] );
64 }
65
67 return EXIT_SUCCESS;
68}
69
int i
add multiple PAPI presets or native hardware events to an event set
Create a new empty PAPI EventSet.
Convert a name to a numeric hardware event code.
initialize the PAPI library.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Returns a string describing the PAPI error code.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_VERSION
Definition: f90papi.h:193
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
char events[MAX_EVENTS][BUFSIZ]
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
Return codes and api definitions.
#define PAPI_VERSION_REVISION(x)
Definition: papi.h:221
#define PAPI_VERSION_MAJOR(x)
Definition: papi.h:219
#define PAPI_VERSION_MINOR(x)
Definition: papi.h:220
int main()
Definition: pernode.c:20
#define NUM_EVENTS
int retval
Definition: zero_fork.c:53