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

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;
67  const PAPI_hw_info_t *hw_info;
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 )
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 
98  hw_info = PAPI_get_hardware_info( );
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 */
105  retval = PAPI_create_eventset(&EventSet1);
106  if ( retval != PAPI_OK )
107  test_fail( __FILE__, __LINE__, "PAPI_attach", retval );
108 
109  /* Force addition of component */
110 
111  retval = PAPI_assign_eventset_component( EventSet1, 0 );
112  if ( retval != PAPI_OK )
113  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
114  retval );
115 
116  /* The following call causes this test to fail for perf_events */
117 
118  retval = PAPI_attach( EventSet1, ( unsigned long ) pid );
119  if ( retval != PAPI_OK )
120  test_fail( __FILE__, __LINE__, "PAPI_attach", retval );
121 
122 
123 
124  retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC);
125  if ( retval != PAPI_OK ) {
126  if (!quiet) printf("Could not add PAPI_TOT_CYC\n");
127  test_skip( __FILE__, __LINE__, "PAPI_add_event", retval );
128  }
129 
130  strcpy(event_name,"PAPI_FP_INS");
131  retval = PAPI_add_named_event(EventSet1, event_name);
132  if ( retval == PAPI_ENOEVNT ) {
133  strcpy(event_name,"PAPI_TOT_INS");
134  retval = PAPI_add_named_event(EventSet1, event_name);
135  }
136 
137  if ( retval != PAPI_OK ) {
138  test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
139  }
140 
141  values = allocate_test_space( 1, 2);
142 
143  elapsed_us = PAPI_get_real_usec( );
144 
145  elapsed_cyc = PAPI_get_real_cyc( );
146 
147  elapsed_virt_us = PAPI_get_virt_usec( );
148 
149  elapsed_virt_cyc = PAPI_get_virt_cyc( );
150 
151  if (!quiet) printf("must_ptrace is %d\n",cmpinfo->attach_must_ptrace);
152  pid_t child = wait( &status );
153  if (!quiet) printf( "Debugger exited wait() with %d\n",child );
154  if (WIFSTOPPED( status ))
155  {
156  if (!quiet) printf( "Child has stopped due to signal %d (%s)\n",
157  WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
158  }
159  if (WIFSIGNALED( status ))
160  {
161  if (!quiet) printf( "Child %ld received signal %d (%s)\n",
162  (long)child,
163  WTERMSIG(status) , strsignal(WTERMSIG( status )) );
164  }
165  if (!quiet) printf("After %d\n",retval);
166 
167  retval = PAPI_start( EventSet1 );
168  if ( retval != PAPI_OK )
169  test_fail( __FILE__, __LINE__, "PAPI_start", retval );
170 
171  if (!quiet) printf("Continuing\n");
172 #if defined(__FreeBSD__)
173  if ( ptrace( PT_CONTINUE, pid, (caddr_t) 1, 0 ) == -1 ) {
174 #else
175  if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
176 #endif
177  perror( "ptrace(PTRACE_CONT)" );
178  return 1;
179  }
180 
181 
182  do {
183  child = wait( &status );
184  if (!quiet) printf( "Debugger exited wait() with %d\n", child);
185  if (WIFSTOPPED( status ))
186  {
187  if (!quiet) printf( "Child has stopped due to signal %d (%s)\n",
188  WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
189  }
190  if (WIFSIGNALED( status ))
191  {
192  if (!quiet) printf( "Child %ld received signal %d (%s)\n",
193  (long)child,
194  WTERMSIG(status) , strsignal(WTERMSIG( status )) );
195  }
196  } while (!WIFEXITED( status ));
197 
198  if (!quiet) printf("Child exited with value %d\n",WEXITSTATUS(status));
199  if (WEXITSTATUS(status) != 0) {
200  test_fail( __FILE__, __LINE__, "Exit status of child to attach to", PAPI_EMISC);
201  }
202  retval = PAPI_stop( EventSet1, values[0] );
203  if ( retval != PAPI_OK )
204  test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
205 
206  elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
207 
208  elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
209 
210  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
211 
212  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
213 
214  retval = PAPI_cleanup_eventset(EventSet1);
215  if (retval != PAPI_OK)
216  test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
217 
218  retval = PAPI_destroy_eventset(&EventSet1);
219  if (retval != PAPI_OK)
220  test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
221 
222  if (!quiet) {
223  printf( "Test case: 3rd party attach start, stop.\n" );
224  printf( "-----------------------------------------------\n" );
225  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
226  printf( "Default domain is: %d (%s)\n", tmp, stringify_all_domains( tmp ) );
227  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
228  printf( "Default granularity is: %d (%s)\n", tmp,
229  stringify_granularity( tmp ) );
230  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
231  printf( "-------------------------------------------------------------------------\n" );
232 
233  printf( "Test type : \t 1\n" );
234 
235  printf( TAB1, "PAPI_TOT_CYC : \t", ( values[0] )[0] );
236  printf( "%s : \t %12lld\n", event_name, ( values[0] )[1] );
237  printf( TAB1, "Real usec : \t", elapsed_us );
238  printf( TAB1, "Real cycles : \t", elapsed_cyc );
239  printf( TAB1, "Virt usec : \t", elapsed_virt_us );
240  printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc );
241 
242  printf( "-------------------------------------------------------------------------\n" );
243 
244  printf( "Verification: none\n" );
245  }
246  test_pass( __FILE__ );
247 
248  return 0;
249 
250 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:29
#define PAPI_ENOEVNT
Definition: papi.h:260
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2314
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
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1663
Hardware info structure.
Definition: papi.h:780
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
#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
int PAPI_add_named_event(int EventSet, const char *EventName)
Definition: papi.c:1876
char ** argv
Definition: iozone.c:1610
#define PAPI_EMISC
Definition: papi.h:267
int PAPI_library_init(int version)
Definition: papi.c:500
char * stringify_all_domains(int domains)
Definition: test_utils.c:293
int quiet
Definition: rapl_overflow.c:18
#define PAPI_TOT_CYC
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
int wait()
#define PAPI_ESYS
Definition: papi.h:255
#define PAPI_DEFGRN
Definition: papi.h:434
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2890
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1526
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1464
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(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
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:2014
#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
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6185
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
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:28
void exit()
int EventSet1
Definition: zero_fork.c:47

Here is the call graph for this function:

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 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
char * getenv()
#define PATH_MAX
Definition: fileop.c:68

Here is the call graph for this function: