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

Go to the source code of this file.

Functions

static void print_help (char **argv)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 56 of file papi_command_line.c.

57{
58 int retval;
59 int num_events;
60 long long *values;
61 char *success;
63 int EventSet = PAPI_NULL;
64 int i, j, event, data_type = PAPI_DATATYPE_INT64;
65 int u_format = 0;
66 int hex_format = 0;
67
68 printf( "\nThis utility lets you add events from the command line "
69 "interface to see if they work.\n\n" );
70
72 if (retval != PAPI_VER_CURRENT ) {
73 fprintf(stderr,"Error! PAPI_library_init\n");
74 exit(retval );
75 }
76
78 if (retval != PAPI_OK ) {
79 fprintf(stderr,"Error! PAPI_create_eventset\n");
80 exit(retval );
81 }
82
83 values =
84 ( long long * ) malloc( sizeof ( long long ) * ( size_t ) argc );
85 success = ( char * ) malloc( ( size_t ) argc );
86
87 if ( success == NULL || values == NULL ) {
88 fprintf(stderr,"Error allocating memory!\n");
89 exit(1);
90 }
91
92 for ( num_events = 0, i = 1; i < argc; i++ ) {
93 if ( !strcmp( argv[i], "-h" ) ) {
94 print_help( argv );
95 exit( 1 );
96 } else if ( !strcmp( argv[i], "-u" ) ) {
97 u_format = 1;
98 } else if ( !strcmp( argv[i], "-x" ) ) {
99 hex_format = 1;
100 } else {
101 if ( ( retval = PAPI_add_named_event( EventSet, argv[i] ) ) != PAPI_OK ) {
102 printf( "Failed adding: %s\nbecause: %s\n", argv[i],
104 } else {
105 success[num_events++] = i;
106 printf( "Successfully added: %s\n", argv[i] );
107 }
108 }
109 }
110
111 /* Automatically pass if no events, for run_tests.sh */
112 if ( num_events == 0 ) {
113 free(values);
114 free(success);
115 printf("No events specified!\n");
116 printf("Try running something like: %s PAPI_TOT_CYC\n\n",
117 argv[0]);
118 return 0;
119 }
120
121
122 printf( "\n" );
123
124 do_flops( 1 );
125 do_flush( );
126
128 if (retval != PAPI_OK ) {
129 free(values);
130 free(success);
131 fprintf(stderr,"Error! PAPI_start\n");
132 exit( retval );
133 }
134
137
139 if (retval != PAPI_OK ) {
140 free(values);
141 free(success);
142 fprintf(stderr,"Error! PAPI_stop\n");
143 exit( retval );
144 }
145
146 for ( j = 0; j < num_events; j++ ) {
147 i = success[j];
148 if (! (u_format || hex_format) ) {
149 retval = PAPI_event_name_to_code( argv[i], &event );
150 if (retval == PAPI_OK) {
151 retval = PAPI_get_event_info(event, &info);
152 if (retval == PAPI_OK) data_type = info.data_type;
154 }
155 switch (data_type) {
157 printf( "%s : \t%llu(u)", argv[i], (unsigned long long)values[j] );
158 break;
160 printf( "%s : \t%0.3f", argv[i], *((double *)(&values[j])) );
161 break;
163 printf( "%s : \t%#llX", argv[i], values[j] );
164 break;
166 default:
167 printf( "%s : \t%lld", argv[i], values[j] );
168 break;
169 }
170 if (retval == PAPI_OK) printf( " %s", info.units );
171 printf( "\n" );
172 }
173 if (u_format) printf( "%s : \t%llu(u)\n", argv[i], (unsigned long long)values[j] );
174 if (hex_format) printf( "%s : \t%#llX\n", argv[i], values[j] );
175 }
176
177 printf( "\n----------------------------------\n" );
178
179 free(values);
180 free(success);
181 return 0;
182
183}
int i
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
Convert a name to a numeric hardware event code.
Get the event's name and description info.
initialize the PAPI library.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
Returns a string describing the PAPI error code.
void do_flush(void)
Definition: do_loops.c:172
void do_misses(int n, int bytes)
Definition: do_loops.c:120
#define L1_MISS_BUFFER_SIZE_INTS
Definition: do_loops.h:11
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_DATATYPE_FP64
Definition: f90papi.h:171
#define PAPI_DATATYPE_UINT64
Definition: f90papi.h:278
#define PAPI_DATATYPE_BIT64
Definition: f90papi.h:189
#define PAPI_DATATYPE_INT64
Definition: f90papi.h:227
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
void do_flops(int n)
Definition: multiplex.c:23
static void print_help(void)
Definition: papi_cost.c:85
long unsigned int size_t
FILE * stderr
int data_type[MAX_EVENTS]
Definition: powercap_plot.c:16
#define NUM_FLOPS
Definition: sdsc-mpx.c:24
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ print_help()

static void print_help ( char **  argv)
static

Definition at line 40 of file papi_command_line.c.

41{
42 printf( "Usage: %s [options] [EVENTNAMEs]\n", argv[0] );
43 printf( "Options:\n\n" );
44 printf( "General command options:\n" );
45 printf( "\t-u Display output values as unsigned integers\n" );
46 printf( "\t-x Display output values as hexadecimal\n" );
47 printf( "\t-h Print this help message\n" );
48 printf( "\tEVENTNAMEs Specify one or more preset or native events\n" );
49 printf( "\n" );
50 printf( "This utility performs work while measuring the specified events.\n" );
51 printf( "It can be useful for sanity checks on given events and sets of events.\n" );
52}