25const char*
names[
NUM_EVENTS] = {
"READ_CALLS",
"READ_BYTES",
"READ_USEC",
"WRITE_CALLS",
"WRITE_BYTES",
"WRITE_USEC"};
28static const char*
files[
NUM_INFILES] = {
"/etc/passwd",
"/etc/group",
"/etc/protocols",
"/etc/nsswitch.conf"};
31 unsigned long tid = (
unsigned long)pthread_self();
32 if (!
TESTS_QUIET) printf(
"\nThread %#lx: will read %s and write it to /dev/null\n", tid,(
const char*) arg);
41 fprintf(
stderr,
"Error creating event set\n");
48 fprintf(
stderr,
"Error getting code for %s\n",
names[e]);
53 fprintf(
stderr,
"Error adding %s to event set\n",
names[e]);
60 fprintf(
stderr,
"Error in PAPI_start\n");
68 int fdin =
open((
const char*)arg, O_RDONLY);
69 if (fdin < 0) perror(
"Could not open file for reading: \n");
74 int fdout =
open(
"/dev/null", O_WRONLY);
75 if (fdout < 0) perror(
"Could not open /dev/null for writing: \n");
76 while ((bytes =
read(fdin,
buf, 1024)) > 0) {
83 fprintf(
stderr,
"Error in PAPI_stop\n");
88 printf(
"Thread %#lx: %s: %lld\n", tid,
names[e],
values[e]);
93int main(
int argc,
char** argv) {
104 fprintf(
stderr,
"PAPI_library_init version mismatch\n");
109 pthread_attr_init(&attr);
111 fprintf(
stderr,
"PAPI_thread_init returned an error\n");
114#ifdef PTHREAD_CREATE_UNDETACHED
115 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED);
117#ifdef PTHREAD_SCOPE_SYSTEM
118 retval = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
120 fprintf(
stderr,
"This system does not support kernel scheduled pthreads.\n");
130 for (
i=0;
i<(numthrds-1);
i++) {
132 if (
rc != 0) perror(
"Error creating thread using pthread_create()");
135 pthread_attr_destroy(&attr);
137 for (
i=0;
i<(numthrds-1);
i++)
138 pthread_join(callThd[
i], NULL);
int open(const char *pathname, int flags, mode_t mode)
ssize_t write(int fd, const void *buf, size_t count)
ssize_t read(int fd, void *buf, size_t count)
static const char * files[NUM_INFILES]
const char * names[NUM_EVENTS]
void * ThreadIO(void *arg)
add PAPI preset or native hardware event to an event set
Create a new empty PAPI 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.
Initialize thread support in the PAPI library.
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
static long long values[NUM_EVENTS]
Return codes and api definitions.
unsigned long int pthread_t
int tests_quiet(int argc, char **argv)
void PAPI_NORETURN test_pass(const char *filename)