PAPI  5.3.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

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

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 49 of file attach3.c.

50 {
51  int status, retval, num_tests = 1, tmp;
52  int EventSet1 = PAPI_NULL;
53  long long **values;
54  long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
56  const PAPI_hw_info_t *hw_info;
57  const PAPI_component_info_t *cmpinfo;
58  pid_t pid;
59 
60  /* Fork before doing anything with the PMU */
61 
62  setbuf(stdout,NULL);
63  pid = fork( );
64  if ( pid < 0 )
65  test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS );
66  if ( pid == 0 )
68 
69  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
70 
71 
72  /* Master only process below here */
73 
75  if ( retval != PAPI_VER_CURRENT )
76  test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval );
77 
78  if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL )
79  test_fail_exit( __FILE__, __LINE__, "PAPI_get_component_info", 0 );
80 
81  if ( cmpinfo->attach == 0 )
82  test_skip( __FILE__, __LINE__, "Platform does not support attaching",
83  0 );
84 
85  hw_info = PAPI_get_hardware_info( );
86  if ( hw_info == NULL )
87  test_fail_exit( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );
88 
89  /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
90  PAPI_TOT_INS, depending on the availability of the event on the
91  platform */
92  retval = PAPI_create_eventset(&EventSet1);
93  if ( retval != PAPI_OK )
94  test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval );
95 
96  /* Force addition of component */
97 
98  retval = PAPI_assign_eventset_component( EventSet1, 0 );
99  if ( retval != PAPI_OK )
100  test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
101  retval );
102 
103  /* The following call causes this test to fail for perf_events */
104 
105  retval = PAPI_attach( EventSet1, ( unsigned long ) pid );
106  if ( retval != PAPI_OK )
107  test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval );
108 
109  sprintf(event_name,"PAPI_TOT_CYC");
110 
111  retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC);
112  if ( retval != PAPI_OK )
113  test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
114  retval = PAPI_add_event(EventSet1, PAPI_FP_INS);
115  if ( retval == PAPI_ENOEVNT ) {
116  test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval);
117  } else if ( retval != PAPI_OK ) {
118  test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
119  }
120 
121  values = allocate_test_space( 1, 2);
122 
123  elapsed_us = PAPI_get_real_usec( );
124 
125  elapsed_cyc = PAPI_get_real_cyc( );
126 
127  elapsed_virt_us = PAPI_get_virt_usec( );
128 
129  elapsed_virt_cyc = PAPI_get_virt_cyc( );
130 
131  printf("must_ptrace is %d\n",cmpinfo->attach_must_ptrace);
132  pid_t child = wait( &status );
133  printf( "Debugger exited wait() with %d\n",child );
134  if (WIFSTOPPED( status ))
135  {
136  printf( "Child has stopped due to signal %d (%s)\n",
137  WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
138  }
139  if (WIFSIGNALED( status ))
140  {
141  printf( "Child %ld received signal %d (%s)\n",
142  (long)child,
143  WTERMSIG(status) , strsignal(WTERMSIG( status )) );
144  }
145  printf("After %d\n",retval);
146 
147  retval = PAPI_start( EventSet1 );
148  if ( retval != PAPI_OK )
149  test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );
150 
151  printf("Continuing\n");
152  if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
153  perror( "ptrace(PTRACE_CONT)" );
154  return 1;
155  }
156 
157 
158  do {
159  child = wait( &status );
160  printf( "Debugger exited wait() with %d\n", child);
161  if (WIFSTOPPED( status ))
162  {
163  printf( "Child has stopped due to signal %d (%s)\n",
164  WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
165  }
166  if (WIFSIGNALED( status ))
167  {
168  printf( "Child %ld received signal %d (%s)\n",
169  (long)child,
170  WTERMSIG(status) , strsignal(WTERMSIG( status )) );
171  }
172  } while (!WIFEXITED( status ));
173 
174  printf("Child exited with value %d\n",WEXITSTATUS(status));
175  if (WEXITSTATUS(status) != 0)
176  test_fail_exit( __FILE__, __LINE__, "Exit status of child to attach to", PAPI_EMISC);
177 
178  retval = PAPI_stop( EventSet1, values[0] );
179  if ( retval != PAPI_OK )
180  test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );
181 
182  elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
183 
184  elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
185 
186  elapsed_us = PAPI_get_real_usec( ) - elapsed_us;
187 
188  elapsed_cyc = PAPI_get_real_cyc( ) - elapsed_cyc;
189 
190  retval = PAPI_cleanup_eventset(EventSet1);
191  if (retval != PAPI_OK)
192  test_fail_exit( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );
193 
194  retval = PAPI_destroy_eventset(&EventSet1);
195  if (retval != PAPI_OK)
196  test_fail_exit( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );
197 
198  printf( "Test case: 3rd party attach start, stop.\n" );
199  printf( "-----------------------------------------------\n" );
200  tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
201  printf( "Default domain is: %d (%s)\n", tmp, stringify_all_domains( tmp ) );
202  tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
203  printf( "Default granularity is: %d (%s)\n", tmp,
205  printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
206  printf
207  ( "-------------------------------------------------------------------------\n" );
208 
209  printf( "Test type : \t 1\n" );
210 
211  printf( TAB1, "PAPI_TOT_CYC : \t", ( values[0] )[0] );
212  printf( TAB1, "PAPI_FP_INS : \t", ( values[0] )[1] );
213  printf( TAB1, "Real usec : \t", elapsed_us );
214  printf( TAB1, "Real cycles : \t", elapsed_cyc );
215  printf( TAB1, "Virt usec : \t", elapsed_virt_us );
216  printf( TAB1, "Virt cycles : \t", elapsed_virt_cyc );
217 
218  printf
219  ( "-------------------------------------------------------------------------\n" );
220 
221  printf( "Verification: none\n" );
222 
223  test_pass( __FILE__, values, num_tests );
224  exit( 1 );
225 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2225
#define NUM_FLOPS
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:803
#define PAPI_EMISC
Definition: fpapi.h:119
int PAPI_add_event(int EventSet, int EventCode)
Definition: papi.c:1597
Hardware info structure.
Definition: papi.h:775
long long PAPI_get_virt_usec(void)
Definition: papi.c:6233
#define PAPI_NULL
Definition: fpapi.h:13
unsigned int attach
Definition: papi.h:657
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
char * stringify_granularity(int granularity)
Definition: test_utils.c:429
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
long long PAPI_get_virt_cyc(void)
Definition: papi.c:6161
#define PAPI_ENOEVNT
Definition: fpapi.h:112
#define TAB1
Definition: papi_test.h:112
return PAPI_OK
Definition: linux-nvml.c:458
tests_quiet(argc, argv)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
#define PAPI_TOT_CYC
Definition: fpapi.h:194
char * stringify_all_domains(int domains)
Definition: test_utils.c:369
unsigned int attach_must_ptrace
Definition: papi.h:658
static int pid
int PAPI_get_opt(int option, PAPI_option_t *ptr)
Definition: papi.c:4030
long long elapsed_cyc
Definition: zero_fork.c:43
int wait_for_attach_and_loop(void)
Definition: attach2.c:31
int wait()
#define PAPI_DEFDOM
Definition: fpapi.h:49
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
#define PAPI_DEFGRN
Definition: fpapi.h:51
#define PAPI_FP_INS
Definition: fpapi.h:187
int PAPI_cleanup_eventset(int EventSet)
Definition: papi.c:2795
int PAPI_assign_eventset_component(int EventSet, int cidx)
Definition: papi.c:1460
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1399
#define PAPI_ESYS
Definition: fpapi.h:108
int num_tests
Definition: zero_fork.c:46
long long PAPI_get_real_usec(void)
Definition: papi.c:6125
long long status
Definition: iozone.c:1335
int PAPI_destroy_eventset(int *EventSet)
Definition: papi.c:1937
int PAPI_attach(int EventSet, unsigned long tid)
Definition: papi.c:3100
long long PAPI_get_real_cyc(void)
Definition: papi.c:6078
int PAPI_start(int EventSet)
Definition: papi.c:2019
void test_fail_exit(char *file, int line, char *call, int retval)
Definition: test_utils.c:567
const PAPI_hw_info_t * PAPI_get_hardware_info(void)
Definition: papi.c:6046
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:43
long long ** allocate_test_space(int num_tests, int num_events)
Definition: test_utils.c:107
static const PAPI_hw_info_t * hw_info
Definition: byte_profile.c:23
void exit()
int EventSet1
Definition: zero_fork.c:40

Here is the call graph for this function:

int wait_for_attach_and_loop ( void  )

Definition at line 31 of file attach3.c.

32 {
33  char *path;
34  char newpath[PATH_MAX];
35  path = getenv("PATH");
36 
37  sprintf(newpath, "PATH=./:%s", (path)?path:'\0' );
38  putenv(newpath);
39 
40  if (ptrace(PTRACE_TRACEME, 0, 0, 0) == 0) {
41  execlp("attach_target","attach_target","100000000",NULL);
42  perror("execl(attach_target) failed");
43  }
44  perror("PTRACE_TRACEME");
45  return ( 1 );
46 }
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: