Skip to content

Commit 0238bba

Browse files
sven5ssven5s
sven5s
authored and
sven5s
committed
with x86_energy_sync_plugin.cpp compatible C version of the plugin
1 parent 846213f commit 0238bba

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

x86_energy_plugin.c

+26-23
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@
8686
__minfo.exponent = 0;
8787
#endif
8888

89-
#define PLUGIN_PREFIX "METRIC_X86_ENERGY_PLUGIN_"
89+
#define PLUGIN_NAME "X86_ENERGY_PLUGIN"
90+
91+
#define PLUGIN_PREFIX "METRIC_" PLUGIN_NAME "_"
9092

9193
#ifdef BACKEND_SCOREP
9294
#include <scorep/SCOREP_MetricPlugins.h>
@@ -172,7 +174,7 @@ static size_t parse_buffer_size(const char *s)
172174
size = strtoll(s, &tmp, 10);
173175

174176
if (size == 0) {
175-
fprintf(stderr, "X86_ENERGY_PLUGIN: Failed to parse buffer size ('%s'), "\
177+
fprintf(stderr, PLUGIN_NAME ": Failed to parse buffer size ('%s'), "\
176178
"using default %zu\n", s, DEFAULT_BUF_SIZE);
177179
return DEFAULT_BUF_SIZE;
178180
}
@@ -204,7 +206,7 @@ static int init_devices(void)
204206
/* init x86_energy */
205207
source = get_available_sources();
206208
if(source == NULL) {
207-
fprintf(stderr,"X86_ENERGY_PLUGIN: Could not detect a suitable cpu "\
209+
fprintf(stderr, PLUGIN_NAME ": Could not detect a suitable cpu "\
208210
"(errno = %i: %s)\n", errno, strerror(errno));
209211
return -1;
210212
}
@@ -215,7 +217,7 @@ static int init_devices(void)
215217
int ret;
216218
if ((ret = source->init_device(i)) != 0)
217219
{
218-
fprintf(stderr, "X86_ENERGY_PLUGIN: Failed to initialize device "\
220+
fprintf(stderr, PLUGIN_NAME ": Failed to initialize device "\
219221
"%i of %i: %i (%s)!\n", i, nr_packages, ret, strerror(errno));
220222
return -1;
221223
}
@@ -248,7 +250,7 @@ void strupr(char * name, char * buffer)
248250
int i;
249251

250252
if (strlen(name) >= BUFFERSIZE)
251-
fprintf(stderr, "X86_ENERGY_PLUGIN: %s is too long for the buffer. "\
253+
fprintf(stderr, PLUGIN_NAME ": %s is too long for the buffer. "\
252254
"Please increase char buffer size to get correct sensor names.\n");
253255

254256
for(i = 0; i <= strlen(name) && i < BUFFERSIZE - 1; i++)
@@ -265,15 +267,15 @@ static int32_t init(void) {
265267

266268
printf("init()\n");
267269

268-
env = getenv(ENV_PREFIX PLUGIN_PREFIX "INTERVAL_US");
270+
env = getenv(ENV_PREFIX PLUGIN_PREFIX "READING_TIME");
269271
if (env == NULL) {
270272
interval_us = 100000;
271273
}
272274
else {
273275
interval_us = atoi(env);
274276
if (interval_us == 0) {
275-
fprintf(stderr, "X86_ENERGY_PLUGIN: Could not parse "\
276-
"%sINTERVAL_US, using 100 ms\n", ENV_PREFIX PLUGIN_PREFIX);
277+
fprintf(stderr, PLUGIN_NAME ": Could not parse "\
278+
"%sREADING_TIME, using 100 ms\n", ENV_PREFIX PLUGIN_PREFIX);
277279
interval_us = 100000;
278280
}
279281
}
@@ -288,7 +290,7 @@ static int32_t init(void) {
288290
buf_size = parse_buffer_size(env);
289291
if (buf_size < 1024)
290292
{
291-
fprintf(stderr, "X86_ENERGY_PLUGIN: Given buffer size (%zu) "\
293+
fprintf(stderr, PLUGIN_NAME ": Given buffer size (%zu) "\
292294
"too small, falling back to default (%zu)\n", buf_size, \
293295
DEFAULT_BUF_SIZE);
294296
buf_size = DEFAULT_BUF_SIZE;
@@ -308,7 +310,7 @@ static int32_t init(void) {
308310
offset = atof(env);
309311
if (offset < 0)
310312
{
311-
fprintf(stderr, "X86_ENERGY_PLUGIN: Power offset can't be negative "\
313+
fprintf(stderr, PLUGIN_NAME ": Power offset can't be negative "\
312314
"setting value to zero\n");
313315
offset = 0;
314316
}
@@ -338,7 +340,7 @@ static metric_properties_t * get_event_info(char * event_name) {
338340
metric_properties_t * return_values;
339341
return_values = malloc(numberOfMetrics * sizeof(metric_properties_t));
340342
if (return_values == NULL) {
341-
fprintf(stderr, "X86_ENERGY_PLUGIN: Unable to allocate space for "\
343+
fprintf(stderr, PLUGIN_NAME ": Unable to allocate space for "\
342344
"counter information\n");
343345
return NULL;
344346
}
@@ -388,7 +390,7 @@ static metric_properties_t * get_event_info(char * event_name) {
388390
metric_properties_t * return_values;
389391
return_values = malloc(numberOfMetrics * sizeof(metric_properties_t));
390392
if (return_values == NULL) {
391-
fprintf(stderr, "X86_ENERGY_PLUGIN: Unable to allocate space for "\
393+
fprintf(stderr, PLUGIN_NAME ": Unable to allocate space for "\
392394
"counter information\n");
393395
return NULL;
394396
}
@@ -445,7 +447,7 @@ static metric_properties_t * get_event_info(char * event_name) {
445447
metric_properties_t * return_values;
446448
return_values = malloc((nr_packages + 2) * sizeof(metric_properties_t));
447449
if (return_values == NULL) {
448-
fprintf(stderr, "X86_ENERGY_PLUGIN: Unable to allocate space "\
450+
fprintf(stderr, PLUGIN_NAME ": Unable to allocate space "\
449451
"for counter information\n");
450452
return NULL;
451453
}
@@ -509,7 +511,7 @@ static metric_properties_t * get_event_info(char * event_name) {
509511
}
510512
}
511513

512-
fprintf(stderr, "X86_ENERGY_PLUGIN: Unknown Event %s\n", event_name);
514+
fprintf(stderr, PLUGIN_NAME ": Unknown Event %s\n", event_name);
513515
return NULL;
514516
}
515517

@@ -532,11 +534,11 @@ static void * thread_report(void * ignore) {
532534
if (wtime == NULL)
533535
return NULL;
534536
if (sample_count >= num_entries) {
535-
fprintf(stderr, "X86_ENERGY_PLUGIN: buffer size of %zu is to small.\n",
537+
fprintf(stderr, PLUGIN_NAME ": buffer size of %zu is to small.\n",
536538
buf_size);
537-
fprintf(stderr, "X86_ENERGY_PLUGIN: Increase the buffer size with the "\
539+
fprintf(stderr, PLUGIN_NAME ": Increase the buffer size with the "\
538540
"environment variable %sSIZE\n",ENV_PREFIX PLUGIN_PREFIX);
539-
fprintf(stderr, "X86_ENERGY_PLUGIN: Stopping sample thread\n");
541+
fprintf(stderr, PLUGIN_NAME ": Stopping sample thread\n");
540542
return NULL;
541543
}
542544

@@ -605,20 +607,20 @@ static int32_t add_counter(char * event_name) {
605607
}
606608

607609
if(!is_thread_created && !synchronous) {
608-
fprintf(stderr, "X86_ENERGY_PLUGIN: using buffer with %zu entries per "\
610+
fprintf(stderr, PLUGIN_NAME ": using buffer with %zu entries per "\
609611
"feature\n", num_entries);
610612
/* allocate space for time values */
611613
timestamps = malloc(num_entries * sizeof(struct timestamp_scorep_gettime));
612614
if (timestamps == NULL)
613615
{
614-
fprintf(stderr, "X86_ENERGY_PLUGIN: Failed to allocate memory for "\
616+
fprintf(stderr, PLUGIN_NAME ": Failed to allocate memory for "\
615617
"timestamps (%zu B)\n", num_entries *
616618
sizeof(struct timestamp_scorep_gettime));
617619
return -1;
618620
}
619621
if (pthread_create(&thread, NULL, &thread_report, NULL) != 0)
620622
{
621-
fprintf(stderr, "X86_ENERGY_PLUGIN: Failed to create measurement "\
623+
fprintf(stderr, PLUGIN_NAME ": Failed to create measurement "\
622624
"thread!\n");
623625
return -1;
624626
}
@@ -637,7 +639,7 @@ static int32_t add_counter(char * event_name) {
637639
event_list[i].reg_values = malloc(num_entries * sizeof(union value));
638640
if (event_list[i].reg_values == NULL)
639641
{
640-
fprintf(stderr, "X86_ENERGY_PLUGIN: Failed to allocate "\
642+
fprintf(stderr, PLUGIN_NAME ": Failed to allocate "\
641643
"memory for reg_values (%zu B)\n",
642644
num_entries * sizeof(union value));
643645
return -1;
@@ -769,7 +771,7 @@ static uint64_t get_all_values(int32_t id, timevalue_t **result)
769771
/* add the offset for the BLADE */
770772
if (blade == 1 && sumtype == ENERGY)
771773
{
772-
/* convertation to J is needed for rapl */
774+
/* converting to J is needed for rapl */
773775
sum.dbl += offset/1000.0 * (timestamps[i].millisecs - \
774776
timestamps[0].millisecs)/1000.0;
775777
}
@@ -804,8 +806,9 @@ static uint64_t get_all_values(int32_t id, timevalue_t **result)
804806
return sample_count;
805807
}
806808

809+
// Plugin name
807810
#ifdef BACKEND_SCOREP
808-
SCOREP_METRIC_PLUGIN_ENTRY( x86energy_plugin )
811+
SCOREP_METRIC_PLUGIN_ENTRY( x86_energy_plugin )
809812
#endif
810813
#ifdef BACKEND_VTRACE
811814
vt_plugin_cntr_info get_info()

0 commit comments

Comments
 (0)