PAPI 7.1.0.0
Loading...
Searching...
No Matches
Recorder_Driver.c
Go to the documentation of this file.
1#include <stdio.h>
2#include <stdint.h>
3#include <stdlib.h>
4#include <string.h>
5#include "papi.h"
6#include "papi_test.h"
7
8void recorder_init_(void);
9void recorder_do_work_(void);
10void setup_PAPI(int *event_set);
11
12long long int expectation[10] = {20674LL, 50122LL, 112964LL, 32904LL, 101565LL, 56993LL, 58388LL, 122543LL, 62312LL, 52433LL};
13
14int main(int argc, char **argv){
15 int i, j, ret, event_set = PAPI_NULL;
16 int discrepancies = 0;
17 int be_verbose = 0;
18 long long counter_values[2];
19
20 if( (argc > 1) && !strcmp(argv[1], "-verbose") )
21 be_verbose = 1;
22
24
25 setup_PAPI(&event_set);
26
27 // --- Start PAPI
28 if((ret=PAPI_start(event_set)) != PAPI_OK){
29 test_fail( __FILE__, __LINE__, "PAPI_start", ret );
30 }
31
32 for(i=0; i<10; i++){
33
35
36 // --- read the event counters
37 if((ret=PAPI_read(event_set, counter_values)) != PAPI_OK){
38 test_fail( __FILE__, __LINE__, "PAPI_read", ret );
39 }
40
41 long long *ptr = (long long *)counter_values[1];
42
43 if( be_verbose ){
44 printf("The number of recordings is: %lld (ptr is: %p)\n",counter_values[0],(void *)counter_values[1]);
45 for(j=0; j<counter_values[0]; j++){
46 printf("%lld ",*(ptr+j));
47 }
48 printf("\n");
49 }
50
51 free(ptr);
52 }
53
54 // --- Stop PAPI
55 if((ret=PAPI_stop(event_set, counter_values)) != PAPI_OK){
56 test_fail( __FILE__, __LINE__, "PAPI_stop", ret );
57 }
58
59 if( counter_values[0] != 10 ){
60 discrepancies++;
61 }
62 long long *ptr = (long long *)counter_values[1];
63 for(j=0; j<10; j++){
64 if( *(ptr+j) != expectation[j] ){
65 discrepancies++;
66 }
67 }
68 free(ptr);
69
70 if( !discrepancies )
71 test_pass(__FILE__);
72 else
73 test_fail( __FILE__, __LINE__, "SDE values in recorder are wrong!", 0 );
74
75 // The following "return" is dead code, because both test_pass() and test_fail() call exit(),
76 // however, we need it to prevent compiler warnings.
77 return 0;
78}
79
80
81void setup_PAPI(int *event_set){
82 int ret;
83
85 test_fail( __FILE__, __LINE__, "PAPI_library_init", ret );
86 }
87
88 if((ret=PAPI_create_eventset(event_set)) != PAPI_OK){
89 test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret );
90 }
91
92 if((ret=PAPI_add_named_event(*event_set, "sde:::Lib_With_Recorder::simple_recording:CNT")) != PAPI_OK){
93 test_fail( __FILE__, __LINE__, "PAPI_add_named_event", ret );
94 }
95
96 if((ret=PAPI_add_named_event(*event_set, "sde:::Lib_With_Recorder::simple_recording")) != PAPI_OK){
97 test_fail( __FILE__, __LINE__, "PAPI_add_named_event", ret );
98 }
99
100 return;
101}
102
int be_verbose
int i
void setup_PAPI(int *event_set)
void recorder_init_(void)
long long int expectation[10]
void recorder_do_work_(void)
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Read hardware counters from an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
Return codes and api definitions.
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
int main()
Definition: pernode.c:20