PAPI 7.1.0.0
Loading...
Searching...
No Matches
sensors_ppc_basic.c
Go to the documentation of this file.
1
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <unistd.h>
12
13#include "papi.h"
14
15#define MAX_sensors_ppc_EVENTS 64
16
17int main ( int argc, char **argv )
18{
19 (void) argv;
20 (void) argc;
21 int retval,cid,sensors_ppc_cid=-1,numcmp;
22 int EventSet = PAPI_NULL;
23 long long *values;
24 int num_events=0;
25 int code;
28 int r,i;
29
30 const PAPI_component_info_t *cmpinfo = NULL;
31 PAPI_event_info_t evinfo;
32
33 /* PAPI Initialization */
35 if ( retval != PAPI_VER_CURRENT )
36 fprintf(stderr, "PAPI_library_init failed %d\n",retval );
37
38 numcmp = PAPI_num_components();
39
40 for( cid=0; cid<numcmp; cid++ ) {
41 if ( ( cmpinfo = PAPI_get_component_info( cid ) ) == NULL )
42 fprintf(stderr, "PAPI_get_component_info failed cid=%d\n", cid);
43 if ( strstr( cmpinfo->name,"sensors_ppc" ) ) {
44 sensors_ppc_cid=cid;
45 break;
46 }
47 }
48
49 /* Component not found */
50 if ( cid==numcmp )
51 fprintf(stderr, "No sensors_ppc component found\n");
52
53 /* Skip if component has no counters */
54 if ( cmpinfo->num_cntrs==0 )
55 fprintf(stderr, "No counters in the sensors_ppc component\n");
56
57 /* Create EventSet */
59 if ( retval != PAPI_OK )
60 fprintf(stderr, "PAPI_create_eventset()\n");
61
62 /* Add all events */
63 code = PAPI_NATIVE_MASK;
64 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, sensors_ppc_cid );
65 while ( r == PAPI_OK ) {
67 if ( retval != PAPI_OK )
68 fprintf(stderr, "Error from PAPI_event_code_to_name, error = %d\n", retval);
69
70 retval = PAPI_get_event_info(code,&evinfo);
71 if ( retval != PAPI_OK )
72 fprintf(stderr, "Error getting event info, error = %d\n",retval);
73
74 char *evt = "sensors_ppc:::VOLTVDD:occ=0";
75 if (!strncmp(event_names[num_events], evt, strlen(evt))) {
77 strcpy(units[num_events], evinfo.units);
78 num_events++;
79 }
80
81 r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, sensors_ppc_cid );
82 }
83
84 values=calloc( num_events,sizeof( long long ) );
85 if ( values==NULL )
86 fprintf(stderr, "No memory");
87
89
91
92 for (i = 0; i < num_events; ++i)
93 fprintf(stdout, "%s > %lld %s\n", event_names[i], values[i], units[i]);
94
95 /* Done, clean up */
97 if ( retval != PAPI_OK )
98 fprintf(stderr, "PAPI_cleanup_eventset(), error=%d\n",retval );
99
101 if ( retval != PAPI_OK )
102 fprintf(stderr, "PAPI_destroy_eventset(), error=%d\n",retval );
103
104 return 0;
105}
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.
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
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
Return codes and api definitions.
FILE * stdout
FILE * stderr
int main()
Definition: pernode.c:20
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
#define MAX_sensors_ppc_EVENTS
Tests basic functionality of sensors_ppc component.
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:627
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
int retval
Definition: zero_fork.c:53