PAPI 7.1.0.0
Loading...
Searching...
No Matches
ppc/tests/powercap_basic.c File Reference
Include dependency graph for ppc/tests/powercap_basic.c:

Go to the source code of this file.

Macros

#define MAX_powercap_EVENTS   64
 Tests basic functionality of powercap component.
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ MAX_powercap_EVENTS

#define MAX_powercap_EVENTS   64
Author
PAPI team UTK/ICL Test case for powercap component

Definition at line 16 of file ppc/tests/powercap_basic.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 19 of file ppc/tests/powercap_basic.c.

20{
21 (void) argv;
22 (void) argc;
23 int retval,cid,powercap_cid=-1,numcmp;
24 int EventSet = PAPI_NULL;
25 long long *values;
26 int num_events=0;
27 int code;
29 char event_descrs[MAX_powercap_EVENTS][PAPI_HUGE_STR_LEN];
32 int r,i, quiet = 1, passed = 0;
33
34 const PAPI_component_info_t *cmpinfo = NULL;
35 PAPI_event_info_t evinfo;
36
37 if (2 == argc) quiet = atoi(argv[1]);
38
39 /* PAPI Initialization */
41 if ( retval != PAPI_VER_CURRENT )
42 fprintf( stderr, "PAPI_library_init failed\n" );
43
44 if (!quiet) fprintf( stdout, "Trying all powercap_ppc events\n" );
45
46 numcmp = PAPI_num_components();
47
48 for( cid=0; cid<numcmp; cid++ ) {
49
50 if ( ( cmpinfo = PAPI_get_component_info( cid ) ) == NULL )
51 fprintf(stderr, "PAPI_get_component_info failed\n");
52
53 if ( strstr( cmpinfo->name,"powercap_ppc" ) ) {
54 powercap_cid=cid;
55 if ( !quiet ) fprintf( stdout, "Found powercap_ppc component at cid %d\n",powercap_cid );
56 if ( cmpinfo->disabled ) {
57 if ( !quiet ) {
58 fprintf(stderr, "powercap_ppc component disabled: %s\n",
59 cmpinfo->disabled_reason);
60 }
61 fprintf(stderr, "powercap_ppc component disabled\n");
62 }
63 break;
64 }
65 }
66
67 /* Component not found */
68 if ( cid==numcmp )
69 fprintf(stderr, "No powercap_ppc component found\n" );
70
71 /* Skip if component has no counters */
72 if ( cmpinfo->num_cntrs==0 )
73 fprintf(stderr, "No counters in the powercap_ppc component\n" );
74
75 /* Create EventSet */
77 if ( retval != PAPI_OK )
78 fprintf(stderr, "PAPI_create_eventset()\n");
79
80 /* Add all events */
81 code = PAPI_NATIVE_MASK;
82 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, powercap_cid );
83 while ( r == PAPI_OK ) {
85 if ( retval != PAPI_OK )
86 fprintf(stdout, "Error from PAPI_event_code_to_name\n");
87
88 retval = PAPI_get_event_info( code,&evinfo );
89 if ( retval != PAPI_OK )
90 fprintf(stderr, "Error getting event info\n");
91
92 strncpy( event_descrs[num_events],evinfo.long_descr,sizeof( event_descrs[0] ) );
93 strncpy( units[num_events],evinfo.units,sizeof( units[0] ) );
95
97
98 if ( retval != PAPI_OK )
99 break; /* We've hit an event limit */
100 num_events++;
101
102 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, powercap_cid );
103 }
104
105 passed = 1;
107
108 values = calloc( num_events,sizeof( long long ) );
109 if (!values) { fprintf(stderr, "No enough memory for allocation of values array.\n"); return -1; }
110
112 for (i = 0; i < num_events; ++i) {
113 if (!quiet && strstr( event_names[i], "POWER") && data_type[i] == PAPI_DATATYPE_INT64)
114 fprintf( stdout, "%-45s%-20s > %lldW\n",
115 event_names[i], event_descrs[i], values[i]);
116 if (1 > values[0] || values[0] > values[1] || values[1] > 10000)
117 passed = 0;
118 if (values[0] > values[2] || values[2] > values[1])
119 passed = 0;
120 }
121
123
124 if (passed && PAPI_OK == retval)
125 fprintf(stdout, "TEST PASSED\n");
126 else
127 fprintf(stdout, "TESTS FAILED\n");
128
129 /* Done, clean up */
131 if ( retval != PAPI_OK )
132 fprintf(stderr, "PAPI_cleanup_eventset()\n");
133
135 if ( retval != PAPI_OK )
136 fprintf(stderr, "PAPI_destroy_eventset()\n");
137
138 return 0;
139}
static const char * event_names[2]
Definition: Gamum.c:27
int i
add PAPI preset or native hardware event to an event set
Empty and destroy an EventSet.
Create a new empty PAPI EventSet.
Empty and destroy an EventSet.
Enumerate PAPI preset or native events for a given component.
Convert a numeric hardware event code to a name.
get information about a specific software component
Get the event's name and description info.
initialize the PAPI library.
Get the number of components available on the system.
Read hardware counters from an event set.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_MIN_STR_LEN
Definition: f90papi.h:208
#define PAPI_NULL
Definition: f90papi.h:78
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_DATATYPE_INT64
Definition: f90papi.h:227
#define PAPI_HUGE_STR_LEN
Definition: f90papi.h:120
static int EventSet
Definition: init_fini.c:8
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
static int num_events
#define PAPI_NATIVE_MASK
FILE * stdout
FILE * stderr
int data_type[MAX_EVENTS]
Definition: powercap_plot.c:16
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
#define MAX_powercap_EVENTS
Tests basic functionality of powercap component.
int quiet
Definition: rapl_overflow.c:19
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
int retval
Definition: zero_fork.c:53