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

Go to the source code of this file.

Functions

int wait_for_attach_and_loop (int num)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 50 of file multiattach2.c.

51{
52 int status, retval, num_tests = 2, tmp;
54 int PAPI_event, PAPI_event2, mask1, mask2;
55 int num_events1, num_events2;
56 long long **values;
57 long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
58 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_2MAX_STR_LEN];
59 const PAPI_component_info_t *cmpinfo;
60 pid_t pid;
61
62 /* Set TESTS_QUIET variable */
63 tests_quiet( argc, argv );
64
65 /* init the library */
67 if ( retval != PAPI_VER_CURRENT ) {
68 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
69 }
70
71 /* get component info */
72 if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL ) {
73 test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 0 );
74 }
75
76 /* see if we support attach */
77 if ( cmpinfo->attach == 0 ) {
78 test_skip( __FILE__, __LINE__,
79 "Platform does not support attaching",0 );
80 }
81
82 /* fork! */
83 pid = fork( );
84 if ( pid < 0 ) {
85 test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS );
86 }
87
88 /* if child, wait_for_attach_and_loop */
89 if ( pid == 0 ) {
90 exit( wait_for_attach_and_loop( 2 ) );
91 }
92
93 /* add PAPI_TOT_CYC and one of the events in
94 PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
95 depending on the availability of the event
96 on the platform */
98 EventSet2 = add_two_events( &num_events2, &PAPI_event2, &mask2 );
99
100 if ( cmpinfo->attach_must_ptrace ) {
101 if ( ptrace( PTRACE_ATTACH, pid, NULL, NULL ) == -1 ) {
102 perror( "ptrace(PTRACE_ATTACH)" );
103 return 1;
104 }
105 if ( waitpid( pid, &status, 0 ) == -1 ) {
106 perror( "waitpid()" );
107 exit( 1 );
108 }
109 if ( WIFSTOPPED( status ) == 0 ) {
110 test_fail( __FILE__, __LINE__,
111 "Child process didnt return true to WIFSTOPPED", 0 );
112 }
113 }
114
115 retval = PAPI_attach( EventSet2, ( unsigned long ) pid );
116 if ( retval != PAPI_OK ) {
117 test_fail( __FILE__, __LINE__, "PAPI_attach", retval );
118 }
119
120 strcpy(event_name,"PAPI_TOT_INS");
121 sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
122
123 /* num_events1 is greater than num_events2 so don't worry. */
124
126
127 /* get before values */
130 elapsed_virt_us = PAPI_get_virt_usec( );
131 elapsed_virt_cyc = PAPI_get_virt_cyc( );
132
133 /* Wait for the SIGSTOP. */
134 if ( cmpinfo->attach_must_ptrace ) {
135 if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
136 perror( "ptrace(PTRACE_CONT)" );
137 return 1;
138 }
139 if ( waitpid( pid, &status, 0 ) == -1 ) {
140 perror( "waitpid()" );
141 exit( 1 );
142 }
143 if ( WIFSTOPPED( status ) == 0 ) {
144 test_fail( __FILE__, __LINE__,
145 "Child process didn't return true to WIFSTOPPED", 0 );
146 }
147 if ( WSTOPSIG( status ) != SIGSTOP ) {
148 test_fail( __FILE__, __LINE__,
149 "Child process didn't stop on SIGSTOP", 0 );
150 }
151 }
152
154 if ( retval != PAPI_OK ) {
155 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
156 }
157
159 if ( retval != PAPI_OK ) {
160 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
161 }
162
163 /* Wait for the SIGSTOP. */
164 if ( cmpinfo->attach_must_ptrace ) {
165 if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
166 perror( "ptrace(PTRACE_ATTACH)" );
167 return 1;
168 }
169 if ( waitpid( pid, &status, 0 ) == -1 ) {
170 perror( "waitpid()" );
171 exit( 1 );
172 }
173 if ( WIFSTOPPED( status ) == 0 ) {
174 test_fail( __FILE__, __LINE__,
175 "Child process didn't return true to WIFSTOPPED", 0 );
176 }
177 if ( WSTOPSIG( status ) != SIGSTOP ) {
178 test_fail( __FILE__, __LINE__,
179 "Child process didn't stop on SIGSTOP", 0 );
180 }
181 }
182
183 elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
184 elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
187
189 if ( retval != PAPI_OK ) {
190 printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
191 retval );
192 }
193
195 if ( retval != PAPI_OK ) {
196 printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
197 retval );
198 }
199
201 remove_test_events( &EventSet2, mask2 );
202
203 if ( cmpinfo->attach_must_ptrace ) {
204 if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
205 perror( "ptrace(PTRACE_CONT)" );
206 return 1;
207 }
208 }
209
210 if ( waitpid( pid, &status, 0 ) == -1 ) {
211 perror( "waitpid()" );
212 exit( 1 );
213 }
214 if ( WIFEXITED( status ) == 0 ) {
215 test_fail( __FILE__, __LINE__,
216 "Child process didn't return true to WIFEXITED", 0 );
217 }
218
219 /* This code isn't necessary as we know the child has exited,
220 it *may* return an error if the component so chooses.
221 You should use read() instead. */
222
223 if (!TESTS_QUIET) {
224 printf( "Test case: multiple 3rd party attach start, stop.\n" );
225 printf( "-----------------------------------------------\n" );
226 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
227 printf( "Default domain is: %d (%s)\n", tmp, stringify_all_domains( tmp ) );
228 tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
229 printf( "Default granularity is: %d (%s)\n", tmp,
231 printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
232 printf( "-------------------------------------------------------------------------\n" );
233
234 sprintf( add_event_str, "(PID self) %-12s : \t",
235 event_name );
236 printf( TAB1, add_event_str, values[0][1] );
237 sprintf( add_event_str, "(PID self) PAPI_TOT_CYC : \t" );
238 printf( TAB1, add_event_str, values[0][0] );
239 sprintf( add_event_str, "(PID %jd) %-12s : \t", ( intmax_t ) pid,
240 event_name );
241 printf( TAB1, add_event_str, values[1][1] );
242 sprintf( add_event_str, "(PID %jd) PAPI_TOT_CYC : \t",
243 ( intmax_t ) pid );
244 printf( TAB1, add_event_str, values[1][0] );
245 printf( TAB1, "Real usec : \t", elapsed_us );
246 printf( TAB1, "Real cycles : \t", elapsed_cyc );
247 printf( TAB1, "Virt usec : \t", elapsed_virt_us );
248 printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc );
249
250 printf( "-------------------------------------------------------------------------\n" );
251
252 printf( "Verification: none\n" );
253
254 }
255
256 test_pass( __FILE__ );
257
258 return 0;
259}
double tmp
static int wait_for_attach_and_loop(void)
Definition: attach2.c:41
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.
int PAPI_event[2]
Definition: data_range.c:30
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_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_2MAX_STR_LEN
Definition: f90papi.h:180
#define PAPI_DEFDOM
Definition: f90papi.h:188
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
int TESTS_QUIET
Definition: test_utils.c:18
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
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:640
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int EventSet2
Definition: rapl_overflow.c:17
#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
int EventSet1
Definition: zero_fork.c:47
int num_events1
Definition: zero_fork.c:49
int mask1
Definition: zero_fork.c:48
long long elapsed_cyc
Definition: zero_fork.c:50
long long elapsed_us
Definition: zero_fork.c:50
int num_tests
Definition: zero_fork.c:53
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ wait_for_attach_and_loop()

int wait_for_attach_and_loop ( int  num)

Definition at line 41 of file multiattach2.c.

42{
43 kill( getpid( ), SIGSTOP );
44 do_flops( NUM_FLOPS * num );
45 kill( getpid( ), SIGSTOP );
46 return 0;
47}
void do_flops(int n)
Definition: multiplex.c:23
int kill(__pid_t __pid, int __sig) __attribute__((__nothrow__
Here is the call graph for this function: