22#include <sys/ptrace.h>
32#define _LINUX_SOURCE_COMPAT
35#if defined(__FreeBSD__)
36# define PTRACE_ATTACH PT_ATTACH
37# define PTRACE_CONT PT_CONTINUE
43 kill( getpid( ), SIGSTOP );
45 kill( getpid( ), SIGSTOP );
50main(
int argc,
char **argv )
73 test_fail( __FILE__, __LINE__,
"PAPI_get_component_info", 0 );
77 if ( cmpinfo->
attach == 0 ) {
79 "Platform does not support attaching",0 );
101 if ( ptrace( PTRACE_ATTACH,
pid, NULL, NULL ) == -1 ) {
102 perror(
"ptrace(PTRACE_ATTACH)" );
105 if ( waitpid(
pid, &status, 0 ) == -1 ) {
106 perror(
"waitpid()" );
109 if ( WIFSTOPPED( status ) == 0 ) {
111 "Child process didnt return true to WIFSTOPPED", 0 );
121 sprintf( add_event_str,
"PAPI_add_event[%s]",
event_name );
135 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
136 perror(
"ptrace(PTRACE_CONT)" );
139 if ( waitpid(
pid, &status, 0 ) == -1 ) {
140 perror(
"waitpid()" );
143 if ( WIFSTOPPED( status ) == 0 ) {
145 "Child process didn't return true to WIFSTOPPED", 0 );
147 if ( WSTOPSIG( status ) != SIGSTOP ) {
149 "Child process didn't stop on SIGSTOP", 0 );
165 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
166 perror(
"ptrace(PTRACE_ATTACH)" );
169 if ( waitpid(
pid, &status, 0 ) == -1 ) {
170 perror(
"waitpid()" );
173 if ( WIFSTOPPED( status ) == 0 ) {
175 "Child process didn't return true to WIFSTOPPED", 0 );
177 if ( WSTOPSIG( status ) != SIGSTOP ) {
179 "Child process didn't stop on SIGSTOP", 0 );
190 printf(
"Warning: PAPI_stop returned error %d, probably ok.\n",
196 printf(
"Warning: PAPI_stop returned error %d, probably ok.\n",
204 if ( ptrace( PTRACE_CONT,
pid, NULL, NULL ) == -1 ) {
205 perror(
"ptrace(PTRACE_CONT)" );
210 if ( waitpid(
pid, &status, 0 ) == -1 ) {
211 perror(
"waitpid()" );
214 if ( WIFEXITED( status ) == 0 ) {
216 "Child process didn't return true to WIFEXITED", 0 );
224 printf(
"Test case: multiple 3rd party attach start, stop.\n" );
225 printf(
"-----------------------------------------------\n" );
229 printf(
"Default granularity is: %d (%s)\n",
tmp,
231 printf(
"Using %d iterations of c += a*b\n",
NUM_FLOPS );
232 printf(
"-------------------------------------------------------------------------\n" );
234 sprintf( add_event_str,
"(PID self) %-12s : \t",
237 sprintf( add_event_str,
"(PID self) PAPI_TOT_CYC : \t" );
239 sprintf( add_event_str,
"(PID %jd) %-12s : \t", ( intmax_t )
pid,
242 sprintf( add_event_str,
"(PID %jd) PAPI_TOT_CYC : \t",
247 printf(
TAB1,
"Virt usec : \t", elapsed_virt_us );
248 printf(
TAB1,
"Virt cycles : \t", elapsed_virt_cyc );
250 printf(
"-------------------------------------------------------------------------\n" );
252 printf(
"Verification: none\n" );
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