host_micpower_plot.c File Reference

Include dependency graph for host_micpower_plot.c:

Go to the source code of this file.

Defines

#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

Define 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.

00025 {
00026 
00027     int retval,cid,host_micpower_cid=-1,numcmp;
00028     int EventSet = PAPI_NULL;
00029     long long values[MAX_EVENTS];
00030     int i,code,enum_retval;
00031     const PAPI_component_info_t *cmpinfo = NULL;
00032     long long start_time,before_time,after_time;
00033     double elapsed_time,total_time;
00034     double energy = 0.0;
00035     char event_name[BUFSIZ];
00036 
00037     /* PAPI Initialization */
00038      retval = PAPI_library_init( PAPI_VER_CURRENT );
00039      if ( retval != PAPI_VER_CURRENT ) {
00040         fprintf(stderr,"PAPI_library_init failed\n");
00041     exit(1);
00042      }
00043 
00044      numcmp = PAPI_num_components();
00045 
00046      for(cid=0; cid<numcmp; cid++) {
00047 
00048     if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
00049        fprintf(stderr,"PAPI_get_component_info failed\n");
00050        exit(1);
00051     }
00052 
00053     if (strstr(cmpinfo->name,"host_micpower")) {
00054        host_micpower_cid=cid;
00055        printf("Found host_micpower component at cid %d\n", host_micpower_cid);
00056 
00057            if (cmpinfo->disabled) {
00058          fprintf(stderr,"No host_micpower events found: %s\n",
00059              cmpinfo->disabled_reason);
00060          exit(1);
00061            }
00062        break;
00063     }
00064      }
00065 
00066      /* Component not found */
00067      if (cid==numcmp) {
00068         fprintf(stderr,"No host_micpower component found\n");
00069         exit(1);
00070      }
00071 
00072      /* Find Events */
00073      code = PAPI_NATIVE_MASK;
00074 
00075      enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
00076 
00077      while ( enum_retval == PAPI_OK ) {
00078 
00079        retval = PAPI_event_code_to_name( code, event_name );
00080        if ( retval != PAPI_OK ) {
00081       printf("Error translating %#x\n",code);
00082       exit(1);
00083        }
00084 
00085        printf("Found: %s\n",event_name);
00086        strncpy(events[num_events],event_name,BUFSIZ);
00087        sprintf(filenames[num_events],"results.%s",event_name);
00088        num_events++;
00089        
00090        if (num_events==MAX_EVENTS) {
00091       printf("Too many events! %d\n",num_events);
00092       exit(1);
00093        }
00094 
00095        enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
00096 
00097      }
00098 
00099      if (num_events==0) {
00100         printf("Error!  No host_micpower events found!\n");
00101     exit(1);
00102      }
00103 
00104      /* Open output files */
00105      for(i=0;i<num_events;i++) {
00106         fff[i]=fopen(filenames[i],"w");
00107     if (fff[i]==NULL) {
00108        fprintf(stderr,"Could not open %s\n",filenames[i]);
00109        exit(1);
00110     }
00111      }
00112                    
00113 
00114      /* Create EventSet */
00115      retval = PAPI_create_eventset( &EventSet );
00116      if (retval != PAPI_OK) {
00117         fprintf(stderr,"Error creating eventset!\n");
00118      }
00119 
00120      for(i=0;i<num_events;i++) {
00121     
00122         retval = PAPI_add_named_event( EventSet, events[i] );
00123         if (retval != PAPI_OK) {
00124        fprintf(stderr,"Error adding event %s\n",events[i]);
00125     }
00126      }
00127 
00128   
00129 
00130      start_time=PAPI_get_real_nsec();
00131 
00132      while(1) {
00133 
00134         /* Start Counting */
00135         before_time=PAPI_get_real_nsec();
00136         retval = PAPI_start( EventSet);
00137         if (retval != PAPI_OK) {
00138            fprintf(stderr,"PAPI_start() failed\n");
00139        exit(1);
00140         }
00141 
00142 
00143         usleep(100000);
00144 
00145         /* Stop Counting */
00146         after_time=PAPI_get_real_nsec();
00147         retval = PAPI_stop( EventSet, values);
00148         if (retval != PAPI_OK) {
00149            fprintf(stderr, "PAPI_start() failed\n");
00150         }
00151 
00152         total_time=((double)(after_time-start_time))/1.0e9;
00153         elapsed_time=((double)(after_time-before_time))/1.0e9;
00154 
00155         for(i=0;i<num_events;i++) {
00156         if( (strstr(events[i],"vccp") != NULL) || 
00157             (strstr(events[i],"vddg") != NULL) || 
00158             (strstr(events[i],"vddq") != NULL) ) {
00159 
00160            fprintf(fff[i],"%.4f %.1f (* Average Voltage (Volt) for %s *)\n",
00161                total_time,
00162                ((double)values[i]/1.0e6),
00163                events[i]);
00164         } else {
00165             if( strstr(events[i],"tot0") != NULL ){
00166             energy += elapsed_time*((double)values[i]/1.0e6);
00167             fprintf(fff[i],"%.4f %.1f %.1f (* Average Power (Watt) and Energy consumption (kWs) for %s *)\n",
00168                 total_time,
00169                 ((double)values[i]/1.0e6),
00170                 energy/1.0e3,
00171                 events[i]);
00172             } else {
00173                 fprintf(fff[i],"%.4f %.1f (* Average Power (Watt) for %s *)\n",
00174                         total_time,
00175                         ((double)values[i]/1.0e6),
00176                         events[i]);
00177             }
00178         }
00179         fflush(fff[i]);
00180         }
00181      }
00182 
00183      return 0;
00184 }

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.


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1