File: papi_component_avail.c

package info (click to toggle)
papi 5.7.0+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,856 kB
  • sloc: ansic: 93,265; fortran: 3,338; xml: 2,460; makefile: 815; sh: 290
file content (172 lines) | stat: -rw-r--r-- 4,572 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/** file papi_component_avail.c
  *	@page papi_component_avail
  * @brief papi_component_avail utility.
  *	@section  NAME
  *		papi_component_avail - provides detailed information on the PAPI components available on the system.
  *
  *	@section Synopsis
  *
  *	@section Description
  *		papi_component_avail is a PAPI utility program that reports information 
  *		about the components papi was built with.
  *
  *	@section Options
  *      <ul>
  *		<li>-h help message
  *		<li>-d provide detailed information about each component.
  *      </ul>
  *
  *	@section Bugs
  *		There are no known bugs in this utility.
  *		If you find a bug, it should be reported to the
  *		PAPI Mailing List at <ptools-perfapi@icl.utk.edu>.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "papi.h"

#include "print_header.h"

#define EVT_LINE 80

typedef struct command_flags
{
	int help;
	int details;
	int named;
	char *name;
} command_flags_t;

static void
print_help( char **argv )
{
	printf( "This is the PAPI component avail program.\n" );
	printf( "It provides availability of installed PAPI components.\n" );
	printf( "Usage: %s [options]\n", argv[0] );
	printf( "Options:\n\n" );
	printf( "  --help, -h    print this help message\n" );
	printf( "  -d            print detailed information on each component\n" );
}

static void
parse_args( int argc, char **argv, command_flags_t * f )
{
	int i;

	/* Look for all currently defined commands */
	memset( f, 0, sizeof ( command_flags_t ) );
	for ( i = 1; i < argc; i++ ) {
		if ( !strcmp( argv[i], "-d" ) ) {
			f->details = 1;
		} else if ( !strcmp( argv[i], "-h" ) || !strcmp( argv[i], "--help" ) )
			f->help = 1;
		else
			printf( "%s is not supported\n", argv[i] );
	}

	/* if help requested, print and bail */
	if ( f->help ) {
		print_help( argv );
		exit( 1 );
	}

}

int
main( int argc, char **argv )
{
	int i;
	int retval;
	const PAPI_hw_info_t *hwinfo = NULL;
	const PAPI_component_info_t* cmpinfo;
	command_flags_t flags;
	int numcmp, cid;

	/* Initialize before parsing the input arguments */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
		fprintf(stderr,"Error!  PAPI_library_init\n");
		return retval;
	}

	parse_args( argc, argv, &flags );

	retval = PAPI_set_debug( PAPI_VERB_ECONT );
	if ( retval != PAPI_OK ) {
		fprintf(stderr,"Error!  PAPI_set_debug\n");
		return retval;
	}

	retval = papi_print_header( "Available components and "
					"hardware information.\n", &hwinfo );
	if ( retval != PAPI_OK ) {
		fprintf(stderr,"Error! PAPI_get_ahrdware_info\n");
		return 2;
	}

	/* Compiled-in Components */
	numcmp = PAPI_num_components(  );

	printf("Compiled-in components:\n");
	for ( cid = 0; cid < numcmp; cid++ ) {
	  cmpinfo = PAPI_get_component_info( cid );

	  printf( "Name:   %-23s %s\n", cmpinfo->name ,cmpinfo->description);

	  if (cmpinfo->disabled) {
	    printf("   \\-> Disabled: %s\n",cmpinfo->disabled_reason);
	  }

	  if ( flags.details ) {
		printf( "        %-23s Version:\t\t\t%s\n", " ", cmpinfo->version );
		printf( "        %-23s Number of native events:\t%d\n", " ", cmpinfo->num_native_events);
		printf( "        %-23s Number of preset events:\t%d\n", " ", cmpinfo->num_preset_events);
		printf("\n");
	  }
	}

	printf("\nActive components:\n");
	numcmp = PAPI_num_components(  );

	for ( cid = 0; cid < numcmp; cid++ ) {
	  cmpinfo = PAPI_get_component_info( cid );
	  if (cmpinfo->disabled) continue;

	  printf( "Name:   %-23s %s\n", cmpinfo->name ,cmpinfo->description);
	  printf( "        %-23s Native: %d, Preset: %d, Counters: %d\n",
		  " ", cmpinfo->num_native_events, cmpinfo->num_preset_events, cmpinfo->num_cntrs);
	  printf( "        %-23s PMUs supported: ", " ");
	  int line_len = 49;
	  for (i=0 ; i<PAPI_PMU_MAX ; i++) {
		  if (cmpinfo->pmu_names[i] == NULL) continue;

		  if (line_len + strlen(cmpinfo->pmu_names[i]) > 130) {
			  printf("\n        %-23s                  ", " ");
			  line_len = 49;
		  } else {
			  line_len += strlen(cmpinfo->pmu_names[i]);
		  }
		  // if it is not the first entry on a line, separate the names
		  if ((i != 0) && (line_len > 50)) {
			  printf(", ");
		  }
		  printf("%s", cmpinfo->pmu_names[i]);
	  }
	  printf("\n\n");

	  if ( flags.details ) {
		printf( "        %-23s Version:\t\t\t%s\n", " ", cmpinfo->version );
		printf( "        %-23s Fast counter read:\t\t%d\n", " ", cmpinfo->fast_counter_read);
		printf("\n");
	  }
	}


	printf
	  ( "\n--------------------------------------------------------------------------------\n" );

	return 0;
}