PAPI  5.7.0.0
child_overflow.c File Reference
Include dependency graph for child_overflow.c:

Go to the source code of this file.

Macros

#define MAX_EVENTS   3
 

Functions

static void my_handler (int EventSet, void *pc, long long ovec, void *context)
 
static void print_rate (const char *str)
 
static void run (const char *str, int len)
 
int main (int argc, char **argv)
 

Variables

static int Event [MAX_EVENTS]
 
static int Threshold [MAX_EVENTS]
 
static struct timeval start last
 
static long count
 
static long total
 

Macro Definition Documentation

◆ MAX_EVENTS

#define MAX_EVENTS   3

Definition at line 18 of file child_overflow.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 95 of file child_overflow.c.

96 {
97  int quiet,retval;
98  int ev, EventSet = PAPI_NULL;
99  int num_events;
100  const char *name = "unknown";
101 
102  /* Used to be able to set this via command line */
103  num_events=1;
104 
105  /* Set TESTS_QUIET variable */
106  quiet=tests_quiet( argc, argv );
107 
108  do_cycles( 1 );
109 
110  /* zero out the count fields */
111  gettimeofday( &start, NULL );
112  last = start;
113  count = 0;
114  total = 0;
115 
116  /* Initialize PAPI */
118  if (retval!=PAPI_VER_CURRENT) {
119  test_fail( name, __LINE__, "PAPI_library_init failed", 1 );
120  }
121 
122  name = argv[0];
123  if (!quiet) {
124  printf( "[%d] %s, num_events = %d\n", getpid(),
125  name, num_events );
126  }
127 
128  /* Set up eventset */
129  if ( PAPI_create_eventset( &EventSet ) != PAPI_OK ) {
130  test_fail( name, __LINE__, "PAPI_create_eventset failed", 1 );
131  }
132 
133  /* Add events */
134  for ( ev = 0; ev < num_events; ev++ ) {
135  if ( PAPI_add_event( EventSet, Event[ev] ) != PAPI_OK ) {
136  if (!quiet) printf("Trouble adding event.\n");
137  test_skip( name, __LINE__, "PAPI_add_event failed", 1 );
138  }
139  }
140 
141  /* Set up overflow handler */
142  for ( ev = 0; ev < num_events; ev++ ) {
143  if ( PAPI_overflow( EventSet, Event[ev],
144  Threshold[ev], 0, my_handler )
145  != PAPI_OK ) {
146  test_fail( name, __LINE__, "PAPI_overflow failed", 1 );
147  }
148  }
149 
150  /* Start the eventset */
151  if ( PAPI_start( EventSet ) != PAPI_OK ) {
152  test_fail( name, __LINE__, "PAPI_start failed", 1 );
153  }
154 
155  /* Generate some workload */
156  run( name, 3 );
157 
158  if (!quiet) {
159  printf("[%d] %s, %s\n", getpid(), name, "stop");
160  }
161 
162  /* Stop measuring */
163  if ( PAPI_stop( EventSet, NULL ) != PAPI_OK ) {
164  test_fail( name, __LINE__, "PAPI_stop failed", 1 );
165  }
166 
167  if (!quiet) {
168  printf("[%d] %s, %s\n", getpid(), name, "end");
169  }
170 
171  test_pass(__FILE__);
172 
173  return 0;
174 }
#define PAPI_OK
Definition: fpapi.h:105
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
static const char * name
Definition: fork_overflow.c:31
void test_pass(const char *filename)
Definition: test_utils.c:432
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
static void run(const char *str, int len)
static int num_events
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int EventSet
int PAPI_overflow(int EventSet, int EventCode, int threshold, int flags, PAPI_overflow_handler_t handler)
Definition: papi.c:4788
int retval
Definition: zero_fork.c:53
static struct timeval start
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:561
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
static void my_handler(int EventSet, void *pc, long long ovec, void *context)
#define PAPI_NULL
Definition: fpapi.h:13
static int Event[MAX_EVENTS]
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
static void do_cycles(int program_time)
Definition: fork_overflow.c:95
int gettimeofday(void *ptr1, void *ptr2)
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
static long total
static int Threshold[MAX_EVENTS]
int PAPI_start(int EventSet)
Definition: papi.c:2096
static struct timeval start last
static long count
Here is the call graph for this function:

◆ my_handler()

static void my_handler ( int  EventSet,
void *  pc,
long long  ovec,
void *  context 
)
static

Definition at line 36 of file child_overflow.c.

37 {
38  ( void ) EventSet;
39  ( void ) pc;
40  ( void ) ovec;
41  ( void ) context;
42 
43  count++;
44  total++;
45 }
int EventSet
static long total
static long count
Here is the caller graph for this function:

◆ print_rate()

static void print_rate ( const char *  str)
static

Definition at line 52 of file child_overflow.c.

53 {
54  static int last_count = -1;
55  struct timeval now;
56  double st_secs, last_secs;
57 
58  gettimeofday( &now, NULL );
59  st_secs = ( double ) ( now.tv_sec - start.tv_sec )
60  + ( ( double ) ( now.tv_usec - start.tv_usec ) ) / 1000000.0;
61  last_secs = ( double ) ( now.tv_sec - last.tv_sec )
62  + ( ( double ) ( now.tv_usec - last.tv_usec ) ) / 1000000.0;
63  if ( last_secs <= 0.001 )
64  last_secs = 0.001;
65 
66  if (!TESTS_QUIET) {
67  printf( "[%d] %s, time = %.3f, total = %ld, last = %ld, rate = %.1f/sec\n",
68  getpid( ), str, st_secs, total, count,
69  ( ( double ) count ) / last_secs );
70  }
71 
72  if ( last_count != -1 ) {
73  if ( count < .1 * last_count ) {
74  test_fail( __FILE__, __LINE__, "Interrupt rate changed!", 1 );
75  exit( 1 );
76  }
77  }
78  last_count = ( int ) count;
79  count = 0;
80  last = now;
81 }
static struct timeval start
__time_t tv_sec
__suseconds_t tv_usec
int gettimeofday(void *ptr1, void *ptr2)
int TESTS_QUIET
Definition: test_utils.c:18
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
static long total
void exit()
static struct timeval start last
static long count
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( const char *  str,
int  len 
)
static

Definition at line 84 of file child_overflow.c.

85 {
86  int n;
87 
88  for ( n = 1; n <= len; n++ ) {
89  do_cycles( 1 );
90  print_rate( str );
91  }
92 }
static void print_rate(const char *str)
static void do_cycles(int program_time)
Definition: fork_overflow.c:95
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ count

long count
static

Definition at line 33 of file child_overflow.c.

◆ Event

int Event[MAX_EVENTS]
static
Initial value:
= {
}
#define PAPI_FAD_INS
Definition: fpapi.h:234
#define PAPI_TOT_CYC
Definition: fpapi.h:195
#define PAPI_FP_INS
Definition: fpapi.h:188

Definition at line 20 of file child_overflow.c.

◆ last

struct timeval start last
static

Definition at line 32 of file child_overflow.c.

◆ Threshold

int Threshold[MAX_EVENTS]
static
Initial value:
= {
8000000,
4000000,
4000000,
}

Definition at line 26 of file child_overflow.c.

◆ total

long total
static

Definition at line 33 of file child_overflow.c.