PAPI 7.1.0.0
Loading...
Searching...
No Matches
appio_values_by_code.c File Reference
Include dependency graph for appio_values_by_code.c:

Go to the source code of this file.

Macros

#define MAX_EVENTS   48
 Prints the value of every appio event (by code)
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ MAX_EVENTS

#define MAX_EVENTS   48
Author
Tushar Mohan (adapted from code in linux-net) test case for the appio component

Definition at line 23 of file appio_values_by_code.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 25 of file appio_values_by_code.c.

26{
27 int retval,cid,numcmp;
28 int EventSet = PAPI_NULL;
29 int code;
31 int event_codes[MAX_EVENTS];
32 long long event_values[MAX_EVENTS];
33 int total_events=0; /* events added so far */
34 int r;
35 const PAPI_component_info_t *cmpinfo = NULL;
36
37 /* Set TESTS_QUIET variable */
38 tests_quiet( argc, argv );
39
40 /* PAPI Initialization */
42 if ( retval != PAPI_VER_CURRENT ) {
43 test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
44 }
45
46 if (!TESTS_QUIET) {
47 printf("Trying all appio events\n");
48 }
49
50 numcmp = PAPI_num_components();
51
52 for(cid=0; cid<numcmp; cid++) {
53
54 if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
55 test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n",-1);
56 }
57
58 if (!TESTS_QUIET) {
59 printf("Component %d - %d events - %s\n", cid,
60 cmpinfo->num_native_events, cmpinfo->name);
61 }
62
63 if ( strstr(cmpinfo->name, "appio") == NULL) {
64 continue;
65 }
66
67 code = PAPI_NATIVE_MASK;
68
69 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
70 /* Create and populate the EventSet */
72
74 if (retval != PAPI_OK) {
75 test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
76 }
77
78 while ( r == PAPI_OK ) {
79
80 retval = PAPI_event_code_to_name( code, event_names[total_events] );
81 if ( retval != PAPI_OK ) {
82 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
83 }
84
85 if (!TESTS_QUIET) {
86 printf("Added event %s (code=%#x)\n", event_names[total_events], code);
87 }
88 event_codes[total_events++] = code;
89 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
90 }
91
92 }
93
94 int fdin,fdout;
95 const char* infile = "/etc/group";
96 printf("This program will read %s and write it to /dev/null\n", infile);
97 int bytes = 0;
98 char buf[1024];
99
100 retval = PAPI_add_events( EventSet, event_codes, total_events);
101 if (retval != PAPI_OK) {
102 test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
103 }
104
106 if (retval != PAPI_OK) {
107 test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
108 }
109
110 fdin=open(infile, O_RDONLY);
111 if (fdin < 0) perror("Could not open file for reading: \n");
112 fdout = open("/dev/null", O_WRONLY);
113 if (fdout < 0) perror("Could not open /dev/null for writing: \n");
114
115 while ((bytes = read(fdin, buf, 1024)) > 0) {
116 write(fdout, buf, bytes);
117 }
118
119 retval = PAPI_stop( EventSet, event_values );
120 if (retval != PAPI_OK) {
121 test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
122 }
123 close(fdin);
124 close(fdout);
125
126 int i;
127 if (!TESTS_QUIET) {
128 for ( i=0; i<total_events; i++ ) {
129 printf("%#x %-24s = %lld\n",
130 event_codes[i], event_names[i], event_values[i]);
131 }
132 }
133
135 if (retval != PAPI_OK) {
136 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
137 }
138
140 if (retval != PAPI_OK) {
141 test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
142 }
143
144 if (total_events==0) {
145 test_skip(__FILE__,__LINE__,"No appio events found", 0);
146 }
147
148 test_pass( __FILE__ );
149
151 if (retval != PAPI_OK) {
152 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
153 }
154
156 if (retval != PAPI_OK) {
157 test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
158 }
159 return 0;
160}
static const char * event_names[2]
Definition: Gamum.c:27
int i
int open(const char *pathname, int flags, mode_t mode)
Definition: appio.c:188
int close(int fd)
Definition: appio.c:179
ssize_t write(int fd, const void *buf, size_t count)
Definition: appio.c:302
ssize_t read(int fd, void *buf, size_t count)
Definition: appio.c:229
#define MAX_EVENTS
Prints the value of every appio event (by code)
add multiple PAPI presets or native hardware events to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Convert a numeric hardware event code to a name.
get information about a specific software component
initialize the PAPI library.
Get the number of components available on the system.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
static int EventSet
Definition: init_fini.c:8
int TESTS_QUIET
Definition: test_utils.c:18
#define PAPI_NATIVE_MASK
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
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
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
int retval
Definition: zero_fork.c:53
Here is the call graph for this function: