PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
command_line.c File Reference
Include dependency graph for 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

int main ( int  argc,
char **  argv 
)

Definition at line 51 of file command_line.c.

52 {
53  int retval;
54  int num_events;
55  long long *values;
56  char *success;
57  PAPI_event_info_t info;
58  int EventSet = PAPI_NULL;
59  int i, j, event, data_type = PAPI_DATATYPE_INT64;
60  int u_format = 0;
61  int hex_format = 0;
62 
63  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
64 
65  if ( ( retval =
67  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
68 
69  if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
70  test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
71 
72  /* Automatically pass if no events, for run_tests.sh */
73  if ((( TESTS_QUIET ) && ( argc == 2)) || ( argc == 1 )) {
74  test_pass( __FILE__, NULL, 0 );
75  }
76 
77  values =
78  ( long long * ) malloc( sizeof ( long long ) * ( size_t ) argc );
79  success = ( char * ) malloc( ( size_t ) argc );
80 
81  if ( success == NULL || values == NULL )
82  test_fail_exit( __FILE__, __LINE__, "malloc", PAPI_ESYS );
83 
84  for ( num_events = 0, i = 1; i < argc; i++ ) {
85  if ( !strcmp( argv[i], "-h" ) ) {
86  print_help( argv );
87  exit( 1 );
88  } else if ( !strcmp( argv[i], "-u" ) ) {
89  u_format = 1;
90  } else if ( !strcmp( argv[i], "-x" ) ) {
91  hex_format = 1;
92  } else {
93  if ( ( retval = PAPI_add_named_event( EventSet, argv[i] ) ) != PAPI_OK ) {
94  printf( "Failed adding: %s\nbecause: %s\n", argv[i],
95  PAPI_strerror(retval));
96  } else {
97  success[num_events++] = i;
98  printf( "Successfully added: %s\n", argv[i] );
99  }
100  }
101  }
102 
103  /* Automatically pass if no events, for run_tests.sh */
104  if ( num_events == 0 ) {
105  test_pass( __FILE__, NULL, 0 );
106  }
107 
108 
109  printf( "\n" );
110 
111  do_flops( 1 );
112  do_flush( );
113 
114  if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) {
115  test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );
116  }
117 
118  do_flops( NUM_FLOPS );
120 
121  if ( ( retval = PAPI_stop( EventSet, values ) ) != PAPI_OK )
122  test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );
123 
124  for ( j = 0; j < num_events; j++ ) {
125  i = success[j];
126  if (! (u_format || hex_format) ) {
127  retval = PAPI_event_name_to_code( argv[i], &event );
128  if (retval == PAPI_OK) {
129  retval = PAPI_get_event_info(event, &info);
130  if (retval == PAPI_OK) data_type = info.data_type;
131  else data_type = PAPI_DATATYPE_INT64;
132  }
133  switch (data_type) {
135  printf( "%s : \t%llu(u)", argv[i], (unsigned long long)values[j] );
136  break;
137  case PAPI_DATATYPE_FP64:
138  printf( "%s : \t%0.3f", argv[i], *((double *)(&values[j])) );
139  break;
140  case PAPI_DATATYPE_BIT64:
141  printf( "%s : \t%#llX", argv[i], values[j] );
142  break;
143  case PAPI_DATATYPE_INT64:
144  default:
145  printf( "%s : \t%lld", argv[i], values[j] );
146  break;
147  }
148  if (retval == PAPI_OK) printf( " %s", info.units );
149  printf( "\n" );
150  }
151  if (u_format) printf( "%s : \t%llu(u)\n", argv[i], (unsigned long long)values[j] );
152  if (hex_format) printf( "%s : \t%#llX\n", argv[i], values[j] );
153  }
154 
155  printf( "\n----------------------------------\n" );
156  printf
157  ( "Verification: Checks for valid event name.\n This utility lets you add events from the command line interface to see if they work.\n" );
158  test_pass( __FILE__, NULL, 0 );
159  exit( 1 );
160 }
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define NUM_FLOPS
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_add_named_event(int EventSet, char *EventName)
Definition: papi.c:1816
int num_events
device[deviceId] domain[domainId] event
Definition: linux-cuda.c:306
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
int PAPI_get_event_info(int EventCode, PAPI_event_info_t *info)
Definition: papi.c:844
static void print_help(char **argv)
Definition: command_line.c:35
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
void do_misses(int n, int bytes)
Definition: do_loops.c:113
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
#define PAPI_ESYS
Definition: fpapi.h:108
int PAPI_event_name_to_code(char *in, int *out)
Definition: papi.c:1008
void do_flops(int n)
Definition: multiplex.c:23
int EventSet
void do_flush(void)
Definition: do_loops.c:165
char * PAPI_strerror(int errorCode)
Definition: papi.c:4483
int PAPI_start(int EventSet)
Definition: papi.c:2026
void test_fail_exit(char *file, int line, char *call, int retval)
Definition: test_utils.c:567
long j
Definition: iozone.c:19135
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
#define L1_MISS_BUFFER_SIZE_INTS
Definition: test_utils.h:11
void exit()
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:970

Here is the call graph for this function:

static void print_help ( char **  argv)
static

Definition at line 35 of file command_line.c.

36 {
37  printf( "Usage: %s [options] [EVENTNAMEs]\n", argv[0] );
38  printf( "Options:\n\n" );
39  printf( "General command options:\n" );
40  printf( "\t-u Display output values as unsigned integers\n" );
41  printf( "\t-x Display output values as hexadecimal\n" );
42  printf( "\t-h Print this help message\n" );
43  printf( "\tEVENTNAMEs Specify one or more preset or native events\n" );
44  printf( "\n" );
45  printf( "This utility performs work while measuring the specified events.\n" );
46  printf( "It can be useful for sanity checks on given events and sets of events.\n" );
47 }
#define printf
Definition: papi_test.h:125
char ** argv
Definition: iozone.c:1610

Here is the caller graph for this function: