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

Go to the source code of this file.

Macros

#define MAX_EVENTS   128
 

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 MAX_EVENTS   128
Author
Vince Weaver

Definition at line 12 of file rapl_plot.c.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 21 of file rapl_plot.c.

22 {
23 
24  int retval,cid,rapl_cid=-1,numcmp;
25  int EventSet = PAPI_NULL;
26  long long values[MAX_EVENTS];
27  int i,code,enum_retval;
28  const PAPI_component_info_t *cmpinfo = NULL;
30  double elapsed_time,total_time;
31  char event_name[BUFSIZ];
32 
33  /* PAPI Initialization */
35  if ( retval != PAPI_VER_CURRENT ) {
36  fprintf(stderr,"PAPI_library_init failed\n");
37  exit(1);
38  }
39 
40  numcmp = PAPI_num_components();
41 
42  for(cid=0; cid<numcmp; cid++) {
43 
44  if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
45  fprintf(stderr,"PAPI_get_component_info failed\n");
46  exit(1);
47  }
48 
49  if (strstr(cmpinfo->name,"rapl")) {
50  rapl_cid=cid;
51  printf("Found rapl component at cid %d\n", rapl_cid);
52 
53  if (cmpinfo->disabled) {
54  fprintf(stderr,"No rapl events found: %s\n",
55  cmpinfo->disabled_reason);
56  exit(1);
57  }
58  break;
59  }
60  }
61 
62  /* Component not found */
63  if (cid==numcmp) {
64  fprintf(stderr,"No rapl component found\n");
65  exit(1);
66  }
67 
68  /* Find Events */
69  code = PAPI_NATIVE_MASK;
70 
71  enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
72 
73  while ( enum_retval == PAPI_OK ) {
74 
75  retval = PAPI_event_code_to_name( code, event_name );
76  if ( retval != PAPI_OK ) {
77  printf("Error translating %#x\n",code);
78  exit(1);
79  }
80 
81  printf("Found: %s\n",event_name);
82  strncpy(events[num_events],event_name,BUFSIZ);
83  sprintf(filenames[num_events],"results.%s",event_name);
84  num_events++;
85 
86  if (num_events==MAX_EVENTS) {
87  printf("Too many events! %d\n",num_events);
88  exit(1);
89  }
90 
91  enum_retval = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
92 
93  }
94 
95  if (num_events==0) {
96  printf("Error! No RAPL events found!\n");
97  exit(1);
98  }
99 
100  /* Open output files */
101  for(i=0;i<num_events;i++) {
102  fff[i]=fopen(filenames[i],"w");
103  if (fff[i]==NULL) {
104  fprintf(stderr,"Could not open %s\n",filenames[i]);
105  exit(1);
106  }
107  }
108 
109 
110  /* Create EventSet */
111  retval = PAPI_create_eventset( &EventSet );
112  if (retval != PAPI_OK) {
113  fprintf(stderr,"Error creating eventset!\n");
114  }
115 
116  for(i=0;i<num_events;i++) {
117 
118  retval = PAPI_add_named_event( EventSet, events[i] );
119  if (retval != PAPI_OK) {
120  fprintf(stderr,"Error adding event %s\n",events[i]);
121  }
122  }
123 
124 
125 
126  start_time=PAPI_get_real_nsec();
127 
128  while(1) {
129 
130  /* Start Counting */
131  before_time=PAPI_get_real_nsec();
132  retval = PAPI_start( EventSet);
133  if (retval != PAPI_OK) {
134  fprintf(stderr,"PAPI_start() failed\n");
135  exit(1);
136  }
137 
138 
139  usleep(100000);
140 
141  /* Stop Counting */
142  after_time=PAPI_get_real_nsec();
143  retval = PAPI_stop( EventSet, values);
144  if (retval != PAPI_OK) {
145  fprintf(stderr, "PAPI_start() failed\n");
146  }
147 
148  total_time=((double)(after_time-start_time))/1.0e9;
149  elapsed_time=((double)(after_time-before_time))/1.0e9;
150 
151  for(i=0;i<num_events;i++) {
152 
153  fprintf(fff[i],"%.4f %.1f (* Average Power for %s *)\n",
154  total_time,
155  ((double)values[i]/1.0e9)/elapsed_time,
156  events[i]);
157  fflush(fff[i]);
158  }
159  }
160 
161  return 0;
162 }
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
#define MAX_EVENTS
Definition: rapl_plot.c:12
int EventSet
long long after_time
long long PAPI_get_real_nsec(void)
Definition: papi.c:6111
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 14 of file rapl_plot.c.

FILE* fff[MAX_EVENTS]

Definition at line 17 of file rapl_plot.c.

char filenames[MAX_EVENTS][BUFSIZ]

Definition at line 15 of file rapl_plot.c.

int num_events =0
static

Definition at line 19 of file rapl_plot.c.