PAPI 7.1.0.0
Loading...
Searching...
No Matches
attach3.c File Reference
Include dependency graph for attach3.c:

Go to the source code of this file.

Functions

static int wait_for_attach_and_loop (void)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 60 of file attach3.c.

61{
62 int status, retval, tmp;
63 int EventSet1 = PAPI_NULL;
64 long long **values;
65 long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
68 const PAPI_component_info_t *cmpinfo;
69 pid_t pid;
70 int quiet;
71
72 /* Fork before doing anything with the PMU */
73
74 setbuf(stdout,NULL);
75 pid = fork( );
76 if ( pid < 0 )
77 test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS );
78 if ( pid == 0 )
79 exit( wait_for_attach_and_loop( ) );
80
81 /* Set TESTS_QUIET variable */
82 quiet=tests_quiet( argc, argv );
83
84
85 /* Master only process below here */
86
88 if ( retval != PAPI_VER_CURRENT )
89 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
90
91 if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL )
92 test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 0 );
93
94 if ( cmpinfo->attach == 0 )
95 test_skip( __FILE__, __LINE__, "Platform does not support attaching",
96 0 );
97
99 if ( hw_info == NULL )
100 test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
101
102 /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
103 PAPI_TOT_INS, depending on the availability of the event on the
104 platform */
106 if ( retval != PAPI_OK ) {
107 test_fail( __FILE__, __LINE__, "PAPI_attach", retval );
108 }
109
110 /* Force addition of component */
111
113 if ( retval != PAPI_OK )
114 test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
115 retval );
116
117 /* The following call causes this test to fail for perf_events */
118
119 retval = PAPI_attach( EventSet1, ( unsigned long ) pid );
120 if ( retval != PAPI_OK ) {
121 if (!quiet) printf("Cannot attach: %s\n",PAPI_strerror(retval));
122 test_skip( __FILE__, __LINE__, "PAPI_attach", retval );
123 }
124
125
127 if ( retval != PAPI_OK ) {
128 if (!quiet) printf("Could not add PAPI_TOT_CYC\n");
129 test_skip( __FILE__, __LINE__, "PAPI_add_event", retval );
130 }
131
132 strcpy(event_name,"PAPI_FP_INS");
134 if ( retval == PAPI_ENOEVNT ) {
135 strcpy(event_name,"PAPI_TOT_INS");
137 }
138
139 if ( retval != PAPI_OK ) {
140 test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
141 }
142
144
146
148
149 elapsed_virt_us = PAPI_get_virt_usec( );
150
151 elapsed_virt_cyc = PAPI_get_virt_cyc( );
152
153 if (!quiet) printf("must_ptrace is %d\n",cmpinfo->attach_must_ptrace);
154 pid_t child = wait( &status );
155 if (!quiet) printf( "Debugger exited wait() with %d\n",child );
156 if (WIFSTOPPED( status ))
157 {
158 if (!quiet) printf( "Child has stopped due to signal %d (%s)\n",
159 WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
160 }
161 if (WIFSIGNALED( status ))
162 {
163 if (!quiet) printf( "Child %ld received signal %d (%s)\n",
164 (long)child,
165 WTERMSIG(status) , strsignal(WTERMSIG( status )) );
166 }
167 if (!quiet) printf("After %d\n",retval);
168
170 if ( retval != PAPI_OK )
171 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
172
173 if (!quiet) printf("Continuing\n");
174#if defined(__FreeBSD__)
175 if ( ptrace( PT_CONTINUE, pid, (vptr_t) 1, 0 ) == -1 ) {
176#else
177 if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
178#endif
179 perror( "ptrace(PTRACE_CONT)" );
180 return 1;
181 }
182
183
184 do {
185 child = wait( &status );
186 if (!quiet) printf( "Debugger exited wait() with %d\n", child);
187 if (WIFSTOPPED( status ))
188 {
189 if (!quiet) printf( "Child has stopped due to signal %d (%s)\n",
190 WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
191 }
192 if (WIFSIGNALED( status ))
193 {
194 if (!quiet) printf( "Child %ld received signal %d (%s)\n",
195 (long)child,
196 WTERMSIG(status) , strsignal(WTERMSIG( status )) );
197 }
198 } while (!WIFEXITED( status ));
199
200 if (!quiet) printf("Child exited with value %d\n",WEXITSTATUS(status));
201 if (WEXITSTATUS(status) != 0) {
202 test_fail( __FILE__, __LINE__, "Exit status of child to attach to", PAPI_EMISC);
203 }
205 if ( retval != PAPI_OK )
206 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
207
208 elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
209
210 elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
211
213
215
217 if (retval != PAPI_OK)
218 test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
219
221 if (retval != PAPI_OK)
222 test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
223
224 if (!quiet) {
225 printf( "Test case: 3rd party attach start, stop.\n" );
226 printf( "-----------------------------------------------\n" );
227 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
228 printf( "Default domain is: %d (%s)\n", tmp, stringify_all_domains( tmp ) );
229 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
230 printf( "Default granularity is: %d (%s)\n", tmp,
232 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
233 printf( "-------------------------------------------------------------------------\n" );
234
235 printf( "Test type : \t 1\n" );
236
237 printf( TAB1, "PAPI_TOT_CYC : \t", ( values[0] )[0] );
238 printf( "%s : \t %12lld\n", event_name, ( values[0] )[1] );
239 printf( TAB1, "Real usec : \t", elapsed_us );
240 printf( TAB1, "Real cycles : \t", elapsed_cyc );
241 printf( TAB1, "Virt usec : \t", elapsed_virt_us );
242 printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc );
243
244 printf( "-------------------------------------------------------------------------\n" );
245
246 printf( "Verification: none\n" );
247 }
248 test_pass( __FILE__ );
249
250 return 0;
251
252}
double tmp
static int wait_for_attach_and_loop(void)
Definition: attach3.c:42
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
add PAPI preset or native hardware event to an event set
add PAPI preset or native hardware event by name to an EventSet
Assign a component index to an existing but empty EventSet.
Attach PAPI event set to the specified thread id.
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
get information about a specific software component
get information about the system hardware
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.
Returns a string describing the PAPI error code.
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_DEFGRN
Definition: f90papi.h:26
#define PAPI_TOT_CYC
Definition: f90papi.h:308
#define PAPI_ENOEVNT
Definition: f90papi.h:139
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_EMISC
Definition: f90papi.h:122
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_DEFDOM
Definition: f90papi.h:188
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
void * vptr_t
Definition: papi.h:576
FILE * stdout
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
#define TAB1
Definition: papi_test.h:98
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
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 quiet
Definition: rapl_overflow.c:19
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
static int pid
unsigned int attach
Definition: papi.h:658
unsigned int attach_must_ptrace
Definition: papi.h:659
Hardware info structure.
Definition: papi.h:774
int EventSet1
Definition: zero_fork.c:47
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ wait_for_attach_and_loop()

static int wait_for_attach_and_loop ( void  )
static

Definition at line 42 of file attach3.c.

43{
44 char *path;
45 char newpath[PATH_MAX];
46 path = getenv("PATH");
47
48 sprintf(newpath, "PATH=./:%s", (path)?path:"\0" );
49 putenv(newpath);
50
51 if (ptrace(PTRACE_TRACEME, 0, 0, 0) == 0) {
52 execlp("attach_target","attach_target","100000000",NULL);
53 perror("execl(attach_target) failed");
54 }
55 perror("PTRACE_TRACEME");
56 return ( 1 );
57}
Here is the caller graph for this function: