PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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

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_MAX_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 ) {
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 */
97  EventSet1 = add_two_events( &num_events1, &PAPI_event, &mask1 );
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 
125  values = allocate_test_space( num_tests, num_events1 );
126 
127  /* get before values */
128  elapsed_us = PAPI_get_real_usec( );
129  elapsed_cyc = PAPI_get_real_cyc( );
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 
153  retval = PAPI_start( EventSet1 );
154  if ( retval != PAPI_OK ) {
155  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
156  }
157 
158  retval = PAPI_start( EventSet2 );
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;
185  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
186  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
187 
188  retval = PAPI_stop( EventSet1, values[0] );
189  if ( retval != PAPI_OK ) {
190  printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
191  retval );
192  }
193 
194  retval = PAPI_stop( EventSet2, values[1] );
195  if ( retval != PAPI_OK ) {
196  printf( "Warning: PAPI_stop returned error %d, probably ok.\n",
197  retval );
198  }
199 
200  remove_test_events( &EventSet1, mask1 );
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 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
int mask1
Definition: zero_fork.c:48
int PAPI_event[2]
Definition: data_range.c:30
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:796
void test_pass(const char *filename)
Definition: test_utils.c:432
long long PAPI_get_virt_usec(void)
Definition: papi.c:6372
static int wait_for_attach_and_loop(void)
Definition: attach2.c:41
unsigned int attach
Definition: papi.h:662
char * stringify_granularity(int granularity)
Definition: test_utils.c:353
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6300
#define PAPI_NULL
Definition: papi.h:292
int num_events1
Definition: zero_fork.c:49
#define TAB1
Definition: papi_test.h:88
return PAPI_OK
Definition: linux-nvml.c:497
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
int int argc
Definition: iozone.c:1609
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
unsigned int attach_must_ptrace
Definition: papi.h:663
static int pid
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4143
long long elapsed_cyc
Definition: zero_fork.c:50
#define PAPI_ESYS
Definition: papi.h:255
int add_two_events(int *num_events, int *papi_event, int *mask)
Definition: test_utils.c:615
#define PAPI_DEFGRN
Definition: papi.h:434
int EventSet2
Definition: rapl_overflow.c:16
int num_tests
Definition: zero_fork.c:53
strcpy(filename, default_filename)
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
printf("\tTry: -i 0 -i 1 \n\n")
long long status
Definition: iozone.c:1335
int TESTS_QUIET
Definition: test_utils.c:18
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
#define PAPI_DEFDOM
Definition: papi.h:432
#define PAPI_MAX_STR_LEN
Definition: papi.h:465
int PAPI_attach(int EventSet, unsigned long tid)
Definition: papi.c:3201
long long PAPI_get_real_cyc(void)
Definition: papi.c:6217
int PAPI_start(int EventSet)
Definition: papi.c:2096
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
long long tmp
Definition: iozone.c:12031
long long elapsed_us
Definition: zero_fork.c:50
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:46
#define PAPI_VER_CURRENT
Definition: papi.h:225
void exit()
int remove_test_events(int *EventSet, int mask)
Definition: test_utils.c:201
int EventSet1
Definition: zero_fork.c:47

Here is the call graph for this function:

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 }
kill(master_listen_pid, SIGKILL)
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
void int num
Definition: iozone.c:22151
void do_flops(int n)
Definition: multiplex.c:23

Here is the call graph for this function: