103 #define OVERFLOW_MODE 0 104 #define WEIGHT_METRIC 0 105 #define DEFAULT_THRESHOLD 2000000L 122 static void papi_event_handler(
int event_set,
void *pc,
long long ovec,
void *context);
158 if (strncasecmp(str,
"papi:", 5) == 0) {
161 while (str[0] ==
':') {
172 PAPI_set_debug(0x3ff);
178 monitor_disable_new_threads();
179 int ret = PAPI_library_init(PAPI_VER_CURRENT);
180 monitor_enable_new_threads();
181 TMSG(PAPI,
"PAPI_library_init = %d", ret);
182 TMSG(PAPI,
"PAPI_VER_CURRENT = %d", PAPI_VER_CURRENT);
189 }
else if (ret != PAPI_VER_CURRENT) {
201 ret = PAPI_set_domain(PAPI_DOM_ALL);
202 if (ret != PAPI_OK) {
203 EMSG(
"warning: PAPI_set_domain(PAPI_DOM_ALL) failed: %d", ret);
213 TMSG(PAPI,
"thread init");
216 int retval = PAPI_thread_init(pthread_self);
217 if (retval != PAPI_OK) {
218 EEMSG(
"PAPI_thread_init NOT ok, retval = %d", retval);
221 TMSG(PAPI,
"thread init OK");
227 TMSG(PAPI,
"register thread");
230 int retval = PAPI_register_thread();
231 if (retval != PAPI_OK) {
232 EEMSG(
"PAPI_register_thread NOT ok, retval = %d", retval);
235 TMSG(PAPI,
"register thread ok");
253 if (my_state ==
START) {
257 TMSG(PAPI,
"starting PAPI w event set %d",eventSet);
258 int ret = PAPI_start(eventSet);
259 if (ret == PAPI_EISRUN) {
261 EMSG(
"PAPI returned EISRUN, but state was not START");
263 else if (ret != PAPI_OK) {
264 EMSG(
"PAPI_start failed with %s (%d)", PAPI_strerror(ret), ret);
270 if (ret != PAPI_OK) {
271 EMSG(
"PAPI_read failed with %s (%d)", PAPI_strerror(ret), ret);
281 TMSG(PAPI,
"unregister thread");
284 int retval = PAPI_unregister_thread();
285 char msg[] =
"!!NOT PAPI_OK!! (code = -9999999)\n";
286 snprintf(msg,
sizeof(msg)-1,
"!!NOT PAPI_OK!! (code = %d)", retval);
287 TMSG(PAPI,
"unregister thread returns %s", retval == PAPI_OK?
"PAPI_OK" : msg);
299 int nevents =
self->evl.nevents;
302 if (my_state ==
STOP) {
303 TMSG(PAPI,
"--stop called on an already stopped event set %d",eventSet);
307 if (my_state !=
START) {
308 TMSG(PAPI,
"*WARNING* Stop called on event set that has not been started");
312 TMSG(PAPI,
"stop w event set = %d",eventSet);
313 long_long *values = (long_long *) alloca(
sizeof(long_long) * (nevents+2));
314 int ret = PAPI_stop(eventSet, values);
316 EMSG(
"Failed to stop papi f eventset %d. Return code = %d ==> %s",
317 eventSet,ret,PAPI_strerror(ret));
326 TMSG(PAPI,
"shutdown");
342 TMSG(PAPI,
"supports event");
345 if (self->state ==
UNINIT){
354 return PAPI_event_name_to_code(evtmp, &ec) == PAPI_OK;
360 TMSG(PAPI,
"process event list");
365 int num_lush_metrics = 0;
375 TMSG(PAPI,
"checking event spec = %s",event);
377 AMSG(
"WARNING: %s using default threshold %ld, " 380 ret = PAPI_event_name_to_code(name, &evcode);
381 if (ret != PAPI_OK) {
382 EMSG(
"unexpected failure in PAPI process_event_list(): " 383 "PAPI_event_name_to_code() returned %s (%d)",
384 PAPI_strerror(ret), ret);
387 if (PAPI_query_event(evcode) != PAPI_OK) {
392 if (lush_metrics == 1 && strncmp(event,
"PAPI_TOT_CYC", 12) == 0) {
396 TMSG(PAPI,
"got event code = %x, thresh = %ld", evcode, thresh);
399 int nevents = (
self->evl).nevents;
400 TMSG(PAPI,
"nevents = %d", nevents);
406 for (i = 0; i < nevents; i++) {
407 char buffer[PAPI_MAX_STR_LEN + 10];
411 PAPI_event_code_to_name(self->evl.events[i].event, buffer);
412 TMSG(PAPI,
"metric for event %d = %s", i, buffer);
414 if (strcmp(buffer,
"PAPI_TOT_CYC") == 0) {
423 || self->evl.events[i].thresh == 0)
425 TMSG(PAPI,
"using proxy sampling for event %s", buffer);
426 strcat(buffer,
" (proxy)");
427 self->evl.events[i].thresh = 1;
437 self->evl.events[i].thresh, prop);
440 if (num_lush_metrics > 0 && strcmp(buffer,
"PAPI_TOT_CYC") == 0) {
442 assert(num_lush_metrics == 1 && (i == (nevents - 1)));
449 self->evl.events[i].thresh, prop);
465 TMSG(PAPI,
"gen event set");
471 hpcrun_abort(
"Failure to allocate space for PAPI sample source");
482 eventSet = PAPI_NULL;
483 ret = PAPI_create_eventset(&eventSet);
484 TMSG(PAPI,
"PAPI_create_eventset = %d, eventSet = %d", ret, eventSet);
485 if (ret != PAPI_OK) {
486 hpcrun_abort(
"Failure: PAPI_create_eventset.Return code = %d ==> %s",
487 ret, PAPI_strerror(ret));
490 int nevents = (
self->evl).nevents;
491 for (i = 0; i < nevents; i++) {
492 int evcode =
self->evl.events[i].event;
493 ret = PAPI_add_event(eventSet, evcode);
494 TMSG(PAPI,
"PAPI_add_event(eventSet=%d, event_code=%x)", eventSet, evcode);
495 if (ret != PAPI_OK) {
496 EMSG(
"failure in PAPI gen_event_set(): PAPI_add_event() returned: %s (%d)",
497 PAPI_strerror(ret), ret);
502 for (i = 0; i < nevents; i++) {
503 int evcode =
self->evl.events[i].event;
504 long thresh =
self->evl.events[i].thresh;
507 TMSG(PAPI,
"PAPI_overflow(eventSet=%d, evcode=%x, thresh=%d)",
508 eventSet, evcode, thresh);
511 TMSG(PAPI,
"PAPI_overflow = %d", ret);
512 if (ret != PAPI_OK) {
513 EMSG(
"failure in PAPI gen_event_set(): PAPI_overflow() returned: %s (%d)",
514 PAPI_strerror(ret), ret);
525 PAPI_event_info_t info;
526 char name[200], *prof;
527 int ev, ret, num_total, num_prof;
529 printf(
"===========================================================================\n");
530 printf(
"Available PAPI preset events\n");
531 printf(
"===========================================================================\n");
532 printf(
"Name\t Profilable\tDescription\n");
533 printf(
"---------------------------------------------------------------------------\n");
536 printf(
"PAPI is not available. Probably, the kernel doesn't support PAPI,\n" 537 "or else maybe HPCToolkit is out of sync with PAPI.\n\n");
543 ev = PAPI_PRESET_MASK;
545 #ifdef PAPI_ENUM_FIRST 546 ret = PAPI_enum_event(&ev, PAPI_ENUM_FIRST);
548 while (ret == PAPI_OK) {
549 if (PAPI_query_event(ev) == PAPI_OK
550 && PAPI_get_event_info(ev, &info) == PAPI_OK
553 PAPI_event_code_to_name(ev, name);
561 printf(
"%-10s\t%s\t%s\n", name, prof, info.long_descr);
563 ret = PAPI_enum_event(&ev, PAPI_ENUM_EVENTS);
565 printf(
"Total PAPI events: %d, able to profile: %d\n",
566 num_total, num_prof);
569 printf(
"===========================================================================\n");
570 printf(
"Available native events\n");
571 printf(
"===========================================================================\n");
572 printf(
"Name\t\t\t\tDescription\n");
573 printf(
"---------------------------------------------------------------------------\n");
576 ev = PAPI_NATIVE_MASK;
578 #ifdef PAPI_ENUM_FIRST 579 ret = PAPI_enum_event(&ev, PAPI_ENUM_FIRST);
581 while (ret == PAPI_OK) {
582 if (PAPI_query_event(ev) == PAPI_OK) {
583 PAPI_event_code_to_name(ev, name);
584 PAPI_get_event_info(ev, &info);
586 printf(
"%-30s\t%s\n", name, info.long_descr);
588 ret = PAPI_enum_event(&ev, PAPI_ENUM_EVENTS);
590 printf(
"Total native events: %d\n", num_total);
599 #define ss_cls SS_HARDWARE 600 #define ss_sort_order 70 626 PAPI_event_info_t info;
630 if (PAPI_get_event_info(ev_code, &info) != PAPI_OK
631 || info.derived ==
NULL) {
635 || strlen(info.derived) == 0
636 || strcmp(info.derived,
"NOT_DERIVED") == 0
637 || strcmp(info.derived,
"DERIVED_CMPD") == 0) {
648 PAPI_event_code_to_name(ev_code, name);
649 if (PAPI_query_event(ev_code) != PAPI_OK) {
655 if (papi_ret == PAPI_ECNFLCT) {
669 int nevents =
self->evl.nevents;
683 TMSG(PAPI_SAMPLE,
"papi event happened, ovec = %ld",ovec);
686 ret = PAPI_read(event_set, values);
687 if (ret != PAPI_OK) {
688 EMSG(
"PAPI_read failed with %s (%d)", PAPI_strerror(ret), ret);
692 ret = PAPI_get_overflow_event_index(event_set, ovec, my_events, &my_event_count);
693 if (ret != PAPI_OK) {
694 hpcrun_abort(
"Failed inside papi_event_handler at get_overflow_event_index." 695 "Return code = %d ==> %s", ret, PAPI_strerror(ret));
698 for (i = 0; i < my_event_count; i++) {
704 TMSG(PAPI_SAMPLE,
"sampling call path for metric_id = %d", metric_id);
720 for (i = 0; i < nevents; i++) {
729 if (ret != PAPI_OK) {
730 EMSG(
"PAPI_read failed with %s (%d)", PAPI_strerror(ret), ret);
static int derived[MAX_EVENTS]
static void hpcrun_safe_exit(void)
sample_val_t hpcrun_sample_callpath(void *context, int metricId, hpcrun_metricVal_t metricIncr, int skipInner, int isSync, sampling_info_t *data)
void hpcrun_ssfail_derived(char *source, char *event)
long long prev_values[MAX_EVENTS]
void blame_shift_source_register(bs_type bst)
void hpcrun_save_papi_error(int error)
void hpcrun_ssfail_all_derived(char *source)
#define hpcrun_abort(...)
static const char * strip_papi_prefix(const char *str)
void blame_shift_apply(int metric_id, cct_node_t *node, int metric_incr)
void hpcrun_stats_num_samples_blocked_async_inc(void)
static void METHOD_FN(init)
static int event_is_derived(int ev_code)
metric_desc_t * hpcrun_set_metric_info_and_period(int metric_id, const char *name, MetricFlags_ValFmt_t valFmt, size_t period, metric_desc_properties_t prop)
void hpcrun_ssfail_unsupported(char *source, char *event)
#define metric_property_cycles
char * start_tok(char *lst)
static void papi_event_handler(int event_set, void *pc, long long ovec, void *context)
void hpcrun_ssfail_start(char *source)
void * hpcrun_malloc(size_t size)
__thread bool hpcrun_thread_suppress_sample
int hpcrun_extract_ev_thresh(const char *in, int evlen, char *ev, long *th, long def)
static int hpcrun_safe_enter_async(void *pc)
int hpcrun_event2metric(sample_source_t *ss, int event_idx)
#define METHOD_CALL(obj, meth,...)
int hpcrun_new_metric(void)
#define HPCRUN_PAPI_ERROR_VERSION
static void event_fatal_error(int ev_code, int papi_ret)
void monitor_real_abort(void)
#define DEFAULT_THRESHOLD
void hpcrun_pre_allocate_metrics(size_t num)
lush_agent_pool_t * lush_agents
void hpcrun_disable_papi_cuda(void)
#define HPCRUN_PAPI_ERROR_UNAVAIL
thread_data_t *(* hpcrun_get_thread_data)(void)
#define metric_property_none
void hpcrun_ssfail_conflict(char *source, char *event)