PAPI 7.1.0.0
Loading...
Searching...
No Matches
zero_attach.c File Reference
Include dependency graph for zero_attach.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

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 47 of file zero_attach.c.

48{
49 int status, retval, num_tests = 1, tmp;
50 int EventSet1 = PAPI_NULL;
51 int PAPI_event, mask1;
52 int num_events1;
53 long long **values;
54 long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
55 char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_2MAX_STR_LEN];
56 const PAPI_component_info_t *cmpinfo;
57 pid_t pid;
58
59 /* Set TESTS_QUIET variable */
60 tests_quiet( argc, argv );
61
62 /* Initialize the PAPI library */
64 if ( retval != PAPI_VER_CURRENT ) {
65 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
66 }
67
68 if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL ) {
69 test_fail( __FILE__, __LINE__, "PAPI_get_component_info", 0 );
70 }
71
72 if ( cmpinfo->attach == 0 ) {
73 test_skip( __FILE__, __LINE__,
74 "Platform does not support attaching", 0 );
75 }
76
77 pid = fork( );
78 if ( pid < 0 ) {
79 test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS );
80 }
81 if ( pid == 0 ) {
82 exit( wait_for_attach_and_loop( ) );
83 }
84
85 /* add PAPI_TOT_CYC and one of the events in
86 PAPI_FP_INS, PAPI_FP_OPS or PAPI_TOT_INS,
87 depending on the availability of the event
88 on the platform */
90
91 if ( cmpinfo->attach_must_ptrace ) {
92 if ( ptrace( PTRACE_ATTACH, pid, NULL, NULL ) == -1 ) {
93 perror( "ptrace(PTRACE_ATTACH)" );
94 return 1;
95 }
96 if ( waitpid( pid, &status, 0 ) == -1 ) {
97 perror( "waitpid()" );
98 exit( 1 );
99 }
100 if ( WIFSTOPPED( status ) == 0 )
101 test_fail( __FILE__, __LINE__,
102 "Child process didnt return true to WIFSTOPPED", 0 );
103 }
104
105 retval = PAPI_attach( EventSet1, ( unsigned long ) pid );
106 if ( retval != PAPI_OK )
107 test_fail( __FILE__, __LINE__, "PAPI_attach", retval );
108
110 if ( retval != PAPI_OK )
111 test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
112 sprintf( add_event_str, "PAPI_add_event[%s]", event_name );
113
114 /* num_events1 is greater than num_events2 so don't worry. */
115
117
120 elapsed_virt_us = PAPI_get_virt_usec( );
121 elapsed_virt_cyc = PAPI_get_virt_cyc( );
122
123 /* Wait for the SIGSTOP. */
124 if ( cmpinfo->attach_must_ptrace ) {
125 if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
126 perror( "ptrace(PTRACE_CONT)" );
127 return 1;
128 }
129 if ( waitpid( pid, &status, 0 ) == -1 ) {
130 perror( "waitpid()" );
131 exit( 1 );
132 }
133 if ( WIFSTOPPED( status ) == 0 ) {
134 test_fail( __FILE__, __LINE__,
135 "Child process didn't return true to WIFSTOPPED", 0 );
136 }
137 if ( WSTOPSIG( status ) != SIGSTOP ) {
138 test_fail( __FILE__, __LINE__,
139 "Child process didn't stop on SIGSTOP", 0 );
140 }
141 }
142
144 if ( retval != PAPI_OK ) {
145 test_fail( __FILE__, __LINE__, "PAPI_start", retval );
146 }
147
148 /* Wait for the SIGSTOP. */
149 if ( cmpinfo->attach_must_ptrace ) {
150 if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
151 perror( "ptrace(PTRACE_CONT)" );
152 return 1;
153 }
154 if ( waitpid( pid, &status, 0 ) == -1 ) {
155 perror( "waitpid()" );
156 exit( 1 );
157 }
158 if ( WIFSTOPPED( status ) == 0 ) {
159 test_fail( __FILE__, __LINE__,
160 "Child process didn't return true to WIFSTOPPED", 0 );
161 }
162 if ( WSTOPSIG( status ) != SIGSTOP ) {
163 test_fail( __FILE__, __LINE__,
164 "Child process didn't stop on SIGSTOP", 0 );
165 }
166 }
167
168 elapsed_virt_us = PAPI_get_virt_usec( ) - elapsed_virt_us;
169 elapsed_virt_cyc = PAPI_get_virt_cyc( ) - elapsed_virt_cyc;
172
174 if ( retval != PAPI_OK ) {
175 test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
176 }
177
179
180 if ( cmpinfo->attach_must_ptrace ) {
181 if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
182 perror( "ptrace(PTRACE_CONT)" );
183 return 1;
184 }
185 }
186
187 if ( waitpid( pid, &status, 0 ) == -1 ) {
188 perror( "waitpid()" );
189 exit( 1 );
190 }
191 if ( WIFEXITED( status ) == 0 ) {
192 test_fail( __FILE__, __LINE__,
193 "Child process didn't return true to WIFEXITED", 0 );
194 }
195
196 if (!TESTS_QUIET) {
197 printf( "Test case: 3rd party attach start, stop.\n" );
198 printf( "-----------------------------------------------\n" );
199 tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
200 printf( "Default domain is: %d (%s)\n", 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( "-------------------------------------------------------------------------\n" );
207
208 printf( "Test type : \t 1\n" );
209
210 sprintf( add_event_str, "%-12s : \t", event_name );
211 printf( TAB1, add_event_str, values[0][1] );
212 printf( TAB1, "PAPI_TOT_CYC : \t", values[0][0] );
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( "-------------------------------------------------------------------------\n" );
219
220 printf( "Verification: none\n" );
221 }
222
223 test_pass( __FILE__ );
224
225 return 0;
226}
double tmp
Attach PAPI event set to the specified thread id.
Convert a numeric hardware event code to a name.
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
#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 wait_for_attach_and_loop(void)
Definition: zero_attach.c:38
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 ( void  )

Definition at line 38 of file zero_attach.c.

39{
40 kill( getpid( ), SIGSTOP );
42 kill( getpid( ), SIGSTOP );
43 return 0;
44}
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:
Here is the caller graph for this function: