PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
host_micpower_plot.c File Reference
Include dependency graph for host_micpower_plot.c:

Go to the source code of this file.

Macros

#define MAX_DEVICES   (32)
 
#define EVENTS_PER_DEVICE   10
 
#define MAX_EVENTS   (MAX_DEVICES*EVENTS_PER_DEVICE)
 

Functions

int main (int argc, char **argv)
 

Variables

char events [MAX_EVENTS][BUFSIZ]
 
char filenames [MAX_EVENTS][BUFSIZ]
 
FILE * fff [MAX_EVENTS]
 
static int num_events =0
 

Macro Definition Documentation

#define EVENTS_PER_DEVICE   10

Definition at line 13 of file host_micpower_plot.c.

#define MAX_DEVICES   (32)
Author
Vince Weaver, Heike McCraw

Definition at line 12 of file host_micpower_plot.c.

#define MAX_EVENTS   (MAX_DEVICES*EVENTS_PER_DEVICE)

Definition at line 15 of file host_micpower_plot.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 24 of file host_micpower_plot.c.

25 {
26 
27  int retval,cid,host_micpower_cid=-1,numcmp;
28  int EventSet = PAPI_NULL;
29  long long values[MAX_EVENTS];
30  int i,code,enum_retval;
31  const PAPI_component_info_t *cmpinfo = NULL;
33  double elapsed_time,total_time;
34  double energy = 0.0;
35  char event_name[BUFSIZ];
36 
37  /* PAPI Initialization */
39  if ( retval != PAPI_VER_CURRENT ) {
40  fprintf(stderr,"PAPI_library_init failed\n");
41  exit(1);
42  }
43 
44  numcmp = PAPI_num_components();
45 
46  for(cid=0; cid<numcmp; cid++) {
47 
48  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
49  fprintf(stderr,"PAPI_get_component_info failed\n");
50  exit(1);
51  }
52 
53  if (strstr(cmpinfo->name,"host_micpower")) {
54  host_micpower_cid=cid;
55  printf("Found host_micpower component at cid %d\n", host_micpower_cid);
56 
57  if (cmpinfo->disabled) {
58  fprintf(stderr,"No host_micpower events found: %s\n",
59  cmpinfo->disabled_reason);
60  exit(1);
61  }
62  break;
63  }
64  }
65 
66  /* Component not found */
67  if (cid==numcmp) {
68  fprintf(stderr,"No host_micpower component found\n");
69  exit(1);
70  }
71 
72  /* Find Events */
73  code = PAPI_NATIVE_MASK;
74 
75  enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
76 
77  while ( enum_retval == PAPI_OK ) {
78 
79  retval = PAPI_event_code_to_name( code, event_name );
80  if ( retval != PAPI_OK ) {
81  printf("Error translating %#x\n",code);
82  exit(1);
83  }
84 
85  printf("Found: %s\n",event_name);
86  strncpy(events[num_events],event_name,BUFSIZ);
87  sprintf(filenames[num_events],"results.%s",event_name);
88  num_events++;
89 
90  if (num_events==MAX_EVENTS) {
91  printf("Too many events! %d\n",num_events);
92  exit(1);
93  }
94 
95  enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
96 
97  }
98 
99  if (num_events==0) {
100  printf("Error! No host_micpower events found!\n");
101  exit(1);
102  }
103 
104  /* Open output files */
105  for(i=0;i<num_events;i++) {
106  fff[i]=fopen(filenames[i],"w");
107  if (fff[i]==NULL) {
108  fprintf(stderr,"Could not open %s\n",filenames[i]);
109  exit(1);
110  }
111  }
112 
113 
114  /* Create EventSet */
115  retval = PAPI_create_eventset( &EventSet );
116  if (retval != PAPI_OK) {
117  fprintf(stderr,"Error creating eventset!\n");
118  }
119 
120  for(i=0;i<num_events;i++) {
121 
122  retval = PAPI_add_named_event( EventSet, events[i] );
123  if (retval != PAPI_OK) {
124  fprintf(stderr,"Error adding event %s\n",events[i]);
125  }
126  }
127 
128 
129 
130  start_time=PAPI_get_real_nsec();
131 
132  while(1) {
133 
134  /* Start Counting */
135  before_time=PAPI_get_real_nsec();
136  retval = PAPI_start( EventSet);
137  if (retval != PAPI_OK) {
138  fprintf(stderr,"PAPI_start() failed\n");
139  exit(1);
140  }
141 
142 
143  usleep(100000);
144 
145  /* Stop Counting */
146  after_time=PAPI_get_real_nsec();
147  retval = PAPI_stop( EventSet, values);
148  if (retval != PAPI_OK) {
149  fprintf(stderr, "PAPI_start() failed\n");
150  }
151 
152  total_time=((double)(after_time-start_time))/1.0e9;
153  elapsed_time=((double)(after_time-before_time))/1.0e9;
154 
155  for(i=0;i<num_events;i++) {
156  if( (strstr(events[i],"vccp") != NULL) ||
157  (strstr(events[i],"vddg") != NULL) ||
158  (strstr(events[i],"vddq") != NULL) ) {
159 
160  fprintf(fff[i],"%.4f %.1f (* Average Voltage (Volt) for %s *)\n",
161  total_time,
162  ((double)values[i]/1.0e6),
163  events[i]);
164  } else {
165  if( strstr(events[i],"tot0") != NULL ){
166  energy += elapsed_time*((double)values[i]/1.0e6);
167  fprintf(fff[i],"%.4f %.1f %.1f (* Average Power (Watt) and Energy consumption (kWs) for %s *)\n",
168  total_time,
169  ((double)values[i]/1.0e6),
170  energy/1.0e3,
171  events[i]);
172  } else {
173  fprintf(fff[i],"%.4f %.1f (* Average Power (Watt) for %s *)\n",
174  total_time,
175  ((double)values[i]/1.0e6),
176  events[i]);
177  }
178  }
179  fflush(fff[i]);
180  }
181  }
182 
183  return 0;
184 }
char event_name[2][PAPI_MAX_STR_LEN]
Definition: data_range.c:23
char name[PAPI_MAX_STR_LEN]
Definition: papi.h:625
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int PAPI_stop(int EventSet, long long *values)
Definition: papi.c:2232
#define PAPI_NATIVE_MASK
const PAPI_component_info_t * PAPI_get_component_info(int cidx)
Definition: papi.c:805
char filenames[MAX_EVENTS][BUFSIZ]
#define PAPI_NULL
Definition: fpapi.h:13
int PAPI_add_named_event(int EventSet, char *EventName)
Definition: papi.c:1816
static int num_events
int PAPI_num_components(void)
Definition: papi.c:4285
return PAPI_OK
Definition: linux-nvml.c:458
fflush(stdout)
#define printf
Definition: papi_test.h:125
static double
Definition: fileop.c:1281
FILE * fff[MAX_EVENTS]
long long start_time
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:632
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
char events[MAX_EVENTS][BUFSIZ]
long long before_time
int PAPI_enum_cmp_event(int *EventCode, int modifier, int cidx)
Definition: papi.c:1311
int PAPI_create_eventset(int *EventSet)
Definition: papi.c:1406
int PAPI_event_code_to_name(int EventCode, char *out)
Definition: papi.c:924
int EventSet
long long after_time
long long PAPI_get_real_nsec(void)
Definition: papi.c:6111
#define MAX_EVENTS
int PAPI_start(int EventSet)
Definition: papi.c:2026
double elapsed_time
static long long values[NUM_EVENTS]
Definition: init_fini.c:10
ssize_t retval
Definition: libasync.c:338
void exit()
double total_time
Definition: iozone.c:1268

Here is the call graph for this function:

Variable Documentation

char events[MAX_EVENTS][BUFSIZ]

Definition at line 17 of file host_micpower_plot.c.

FILE* fff[MAX_EVENTS]

Definition at line 20 of file host_micpower_plot.c.

char filenames[MAX_EVENTS][BUFSIZ]

Definition at line 18 of file host_micpower_plot.c.

int num_events =0
static

Definition at line 22 of file host_micpower_plot.c.