24{
25
26 int retval,cid,rapl_cid=-1,numcmp;
29 int i,code,enum_retval;
33 double elapsed_time,total_time;
35
36
39 fprintf(
stderr,
"PAPI_library_init failed\n");
40 exit(1);
41 }
42
44
45 for(cid=0; cid<numcmp; cid++) {
46
48 fprintf(
stderr,
"PAPI_get_component_info failed\n");
49 exit(1);
50 }
51
52 if (strstr(cmpinfo->
name,
"rapl")) {
53 rapl_cid=cid;
54 printf("Found rapl component at cid %d\n", rapl_cid);
55
57 fprintf(
stderr,
"No rapl events found: %s\n",
59 exit(1);
60 }
61 break;
62 }
63 }
64
65
66 if (cid==numcmp) {
67 fprintf(
stderr,
"No rapl component found\n");
68 exit(1);
69 }
70
71
73
75
76 while ( enum_retval ==
PAPI_OK ) {
77
80 printf("Error translating %#x\n",code);
81 exit(1);
82 }
83
87
88
89
92 printf("Error getting event info for %#x\n",code);
93 exit(1);
94 }
95
97
99
101
103
106 exit(1);
107 }
108
110
111 }
112
113
114
116 printf("Error! No RAPL events found!\n");
117 exit(1);
118 }
119
120
125 exit(1);
126 }
127 }
128
129
130
133 fprintf(
stderr,
"Error creating eventset!\n");
134 }
135
137
141 }
142 }
143
144
145
147
148 while(1) {
149
150
154 fprintf(
stderr,
"PAPI_start() failed\n");
155 exit(1);
156 }
157
158
159 usleep(100000);
160
161
165 fprintf(
stderr,
"PAPI_start() failed\n");
166 }
167
168 total_time=((double)(
after_time-start_time))/1.0e9;
170
172
173
174 if (!strstr(
events[
i],
"ENERGY")) {
175
176
178
179 union {
180 long long ll;
183
185
186
187 fprintf(
fff[
i],
"%.4f %.3f (* %s in (%s) *)\n",
188 total_time,
191
192 }
193
195
196 fprintf(
fff[
i],
"%.4f %lld (* %s *)\n",
197 total_time,
200
201 }
202 }
203
204
205 else if (strstr(
events[
i],
"ENERGY_CNT")) {
206
207 fprintf(
fff[
i],
"%.4f %lld (* %s *)\n",
208 total_time,
211
212 }
213
214
215 else {
216 fprintf(
fff[
i],
"%.4f %.3f %s %.3f %s (* Average Power for %s *)\n",
217 total_time,
218 ((
double)
values[
i]/1.0e9),
"J",
219 ((
double)
values[
i]/1.0e9)/elapsed_time,
"W",
221 };
222
224 }
225 }
226
227 return 0;
228}
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI 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.
Get real time counter value in nanoseconds.
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.
char event_name[2][PAPI_MAX_STR_LEN]
#define PAPI_DATATYPE_FP64
#define PAPI_DATATYPE_UINT64
static long long values[NUM_EVENTS]
static long long after_time
static long long before_time
char events[MAX_EVENTS][BUFSIZ]
int data_type[MAX_EVENTS]
char filenames[MAX_EVENTS][BUFSIZ]
char units[MAX_EVENTS][BUFSIZ]
char name[PAPI_MAX_STR_LEN]
char disabled_reason[PAPI_HUGE_STR_LEN]
char units[PAPI_MIN_STR_LEN]