21#include <sys/ptrace.h>
31#define _LINUX_SOURCE_COMPAT
34#if defined(__FreeBSD__)
35# define PTRACE_ATTACH PT_ATTACH
36# define PTRACE_CONT PT_CONTINUE
44 kill( getpid( ), SIGSTOP );
46 kill( getpid( ), SIGSTOP );
51main(
int argc,
char **argv )
75 test_fail( __FILE__, __LINE__,
"PAPI_get_component_info", 0 );
78 if ( cmpinfo->
attach == 0 ) {
80 "Platform does not support attaching", 0 );
109 if ( ptrace( PTRACE_ATTACH,
pid, NULL, NULL ) == -1 ) {
110 perror(
"ptrace(PTRACE_ATTACH)" );
113 if ( waitpid(
pid, &status, 0 ) == -1 ) {
114 perror(
"waitpid()" );
117 if ( WIFSTOPPED( status ) == 0 ) {
119 "Child process didnt return true to WIFSTOPPED", 0 );
122 if ( ptrace( PTRACE_ATTACH, pid2, NULL, NULL ) == -1 ) {
123 perror(
"ptrace(PTRACE_ATTACH)" );
126 if ( waitpid( pid2, &status, 0 ) == -1 ) {
127 perror(
"waitpid()" );
130 if ( WIFSTOPPED( status ) == 0 ) {
132 "Child process didnt return true to WIFSTOPPED", 0 );
147 sprintf( add_event_str,
"PAPI_add_event[%s]",
event_name );
161 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
162 perror(
"ptrace(PTRACE_CONT)" );
165 if ( waitpid(
pid, &status, 0 ) == -1 ) {
166 perror(
"waitpid()" );
169 if ( WIFSTOPPED( status ) == 0 ) {
171 "Child process didn't return true to WIFSTOPPED", 0 );
173 if ( WSTOPSIG( status ) != SIGSTOP ) {
175 "Child process didn't stop on SIGSTOP", 0 );
178 if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
179 perror(
"ptrace(PTRACE_CONT)" );
182 if ( waitpid( pid2, &status, 0 ) == -1 ) {
183 perror(
"waitpid()" );
186 if ( WIFSTOPPED( status ) == 0 ) {
188 "Child process didn't return true to WIFSTOPPED", 0 );
190 if ( WSTOPSIG( status ) != SIGSTOP ) {
192 "Child process didn't stop on SIGSTOP", 0 );
210 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
211 perror(
"ptrace(PTRACE_ATTACH)" );
214 if ( waitpid(
pid, &status, 0 ) == -1 ) {
215 perror(
"waitpid()" );
218 if ( WIFSTOPPED( status ) == 0 ) {
220 "Child process didn't return true to WIFSTOPPED", 0 );
222 if ( WSTOPSIG( status ) != SIGSTOP ) {
224 "Child process didn't stop on SIGSTOP", 0 );
228 if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
229 perror(
"ptrace(PTRACE_ATTACH)" );
232 if ( waitpid( pid2, &status, 0 ) == -1 ) {
233 perror(
"waitpid()" );
236 if ( WIFSTOPPED( status ) == 0 ) {
238 "Child process didn't return true to WIFSTOPPED", 0 );
240 if ( WSTOPSIG( status ) != SIGSTOP ) {
242 "Child process didn't stop on SIGSTOP", 0 );
254 printf(
"Warning: PAPI_stop returned error %d, probably ok.\n",
261 printf(
"Warning: PAPI_stop returned error %d, probably ok.\n",
271 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
272 perror(
"ptrace(PTRACE_CONT)" );
275 if ( ptrace( PTRACE_CONT, pid2, NULL, NULL ) == -1 ) {
276 perror(
"ptrace(PTRACE_CONT)" );
281 if ( waitpid(
pid, &status, 0 ) == -1 ) {
282 perror(
"waitpid()" );
285 if ( WIFEXITED( status ) == 0 ) {
287 "Child process didn't return true to WIFEXITED", 0 );
290 if ( waitpid( pid2, &status, 0 ) == -1 ) {
291 perror(
"waitpid()" );
294 if ( WIFEXITED( status ) == 0 ) {
296 "Child process didn't return true to WIFEXITED", 0 );
304 printf(
"Test case: multiple 3rd party attach start, stop.\n" );
305 printf(
"-----------------------------------------------\n" );
307 printf(
"Default domain is: %d (%s)\n",
tmp,
310 printf(
"Default granularity is: %d (%s)\n",
tmp,
312 printf(
"Using %d iterations of c += a*b\n",
NUM_FLOPS );
313 printf(
"-------------------------------------------------------------------------\n" );
315 sprintf( add_event_str,
"(PID %jd) %-12s : \t", ( intmax_t )
pid,
318 sprintf( add_event_str,
"(PID %jd) PAPI_TOT_CYC : \t",
321 sprintf( add_event_str,
"(PID %jd) %-12s : \t", ( intmax_t ) pid2,
324 sprintf( add_event_str,
"(PID %jd) PAPI_TOT_CYC : \t",
329 printf(
TAB1,
"Virt usec : \t", elapsed_virt_us );
330 printf(
TAB1,
"Virt cycles : \t", elapsed_virt_cyc );
332 printf(
"-------------------------------------------------------------------------\n" );
334 printf(
"Verification: pid %d results should be %dx pid %d\n",
345 printf(
"\tFLOPS ratio %lld/%lld = %lf\n",
349 double ratio1_high,ratio1_low,ratio2_high,ratio2_low;
354 if ((ratio1 > ratio1_high ) || (ratio1 < ratio1_low)) {
355 printf(
"Ratio out of range, should be ~%lf not %lf\n",
358 "Error: Counter ratio not two", 0 );
362 printf(
"\tCycles ratio %lld/%lld = %lf\n",
369 if ((ratio2 > ratio2_high ) || (ratio2 < ratio2_low )) {
370 printf(
"Ratio out of range, should be ~%lf, not %lf\n",
373 "Known issue: Counter ratio not two", 0 );
static int wait_for_attach_and_loop(void)
Attach PAPI event set to the specified thread id.
get information about a specific software component
Get PAPI library or event set options.
get real time counter value in clock cycles Returns the total real time passed since some arbitrary s...
get real time counter value in microseconds
get virtual time counter value in clock cycles
get virtual time counter values in microseconds
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]
#define PAPI_2MAX_STR_LEN
static long long values[NUM_EVENTS]
Return codes and api definitions.
int kill(__pid_t __pid, int __sig) __attribute__((__nothrow__
int tests_quiet(int argc, char **argv)
char * stringify_all_domains(int domains)
char * stringify_granularity(int granularity)
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
long long ** allocate_test_space(int num_tests, int num_events)
void PAPI_NORETURN test_pass(const char *filename)
int add_two_events(int *num_events, int *papi_event, int *mask)
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
int remove_test_events(int *EventSet, int mask)
unsigned int attach_must_ptrace