PAPI 7.1.0.0
Loading...
Searching...
No Matches
appio_values_by_name.c
Go to the documentation of this file.
1/****************************/
2/* THIS IS OPEN SOURCE CODE */
3/****************************/
4
15#include <stdio.h>
16#include <stdlib.h>
17#include <errno.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <fcntl.h>
21#include <unistd.h>
22
23#include "papi.h"
24#include "papi_test.h"
25
26
27#define NUM_EVENTS 11
28
29int main (int argc, char **argv)
30{
31 int i, retval;
32 int EventSet = PAPI_NULL;
33 char *event_name[NUM_EVENTS] = {
34 "READ_BYTES",
35 "READ_CALLS",
36 "READ_USEC",
37 "READ_EOF",
38 "READ_SHORT",
39 "READ_ERR",
40 "WRITE_BYTES",
41 "WRITE_CALLS",
42 "WRITE_USEC",
43 "WRITE_ERR",
44 "WRITE_SHORT"
45 };
46 int event_code[NUM_EVENTS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0};
47 long long event_value[NUM_EVENTS];
48 int total_events=0;
49
50 /* Set TESTS_QUIET variable */
51 tests_quiet( argc, argv );
52
53 /* PAPI Initialization */
55 if ( retval != PAPI_VER_CURRENT ) {
56 test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
57 }
58
59 if (!TESTS_QUIET) {
60 printf("Appio events by name\n");
61 }
62
63 /* Map names to codes */
64 for ( i=0; i<NUM_EVENTS; i++ ) {
65 retval = PAPI_event_name_to_code( event_name[i], &event_code[i]);
66 if ( retval != PAPI_OK ) {
67 test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
68 }
69
70 total_events++;
71 }
72
73 int fdin,fdout;
74 const char* infile = "/etc/group";
75 if (!TESTS_QUIET) printf("This program will read %s and write it to /dev/null\n", infile);
76 int bytes = 0;
77 char buf[1024];
78
79 /* Create and populate the EventSet */
81
83 if (retval != PAPI_OK) {
84 test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
85 }
86
88 if (retval != PAPI_OK) {
89 test_fail(__FILE__, __LINE__, "PAPI_add_events()", retval);
90 }
91
93 if (retval != PAPI_OK) {
94 test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
95 }
96
97 fdin=open(infile, O_RDONLY);
98 if (fdin < 0) perror("Could not open file for reading: \n");
99 fdout=open("/dev/null", O_WRONLY);
100 if (fdout < 0) perror("Could not open /dev/null for writing: \n");
101
102 while ((bytes = read(fdin, buf, 1024)) > 0) {
103 write(fdout, buf, bytes);
104 }
105 close(fdin);
106 close(fdout);
107
108 retval = PAPI_stop( EventSet, event_value );
109 if (retval != PAPI_OK) {
110 test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
111 }
112
113 if (!TESTS_QUIET) {
114 for ( i=0; i<NUM_EVENTS; i++ ) {
115 printf("%#x %-24s = %lld\n",
116 event_code[i], event_name[i], event_value[i]);
117 }
118 }
119
121 if (retval != PAPI_OK) {
122 test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset()", retval);
123 }
124
126 if (retval != PAPI_OK) {
127 test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset()", retval);
128 }
129
130 if (total_events==0) {
131 test_skip(__FILE__,__LINE__,"No appio events found", 0);
132 }
133
134 test_pass( __FILE__ );
135
136 return 0;
137}
138
139// vim:set ai ts=4 sw=4 sts=4 et:
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 NUM_EVENTS
Prints the values of several (but not all) appio events specified by names.
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.
Convert a name to a numeric hardware event code.
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
static int EventSet
Definition: init_fini.c:8
int TESTS_QUIET
Definition: test_utils.c:18
Return codes and api definitions.
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
int main()
Definition: pernode.c:20
int retval
Definition: zero_fork.c:53