68 #include <include/hpctoolkit-config.h> 69 #ifdef ENABLE_CLOCK_REALTIME 70 #include <sys/syscall.h> 125 #define IDLE_METRIC_NAME "idleness (usec)" 127 #define WALLCLOCK_EVENT_NAME "WALLCLOCK" 128 #define WALLCLOCK_METRIC_NAME "WALLCLOCK (usec)" 130 #define ITIMER_EVENT_NAME "ITIMER" 131 #define ITIMER_METRIC_NAME "ITIMER (usec)" 132 #define ITIMER_SIGNAL SIGPROF 133 #define ITIMER_TYPE ITIMER_PROF 135 #define REALTIME_EVENT_NAME "REALTIME" 136 #define REALTIME_METRIC_NAME "REALTIME (usec)" 137 #define REALTIME_SIGNAL (SIGRTMIN + 3) 139 #define REALTIME_CLOCK_TYPE CLOCK_REALTIME 140 #define REALTIME_NOTIFY_METHOD SIGEV_THREAD_ID 142 #define CPUTIME_EVENT_NAME "CPUTIME" 143 #define CPUTIME_METRIC_NAME "CPUTIME (usec)" 144 #define CPUTIME_CLOCK_TYPE CLOCK_THREAD_CPUTIME_ID 148 #ifndef sigev_notify_thread_id 149 #define sigev_notify_thread_id _sigev_un._tid 152 #if !defined(HOST_SYSTEM_IBM_BLUEGENE) 153 #define USE_ELAPSED_TIME_FOR_WALLCLOCK 156 #ifdef USE_ELAPSED_TIME_FOR_WALLCLOCK 157 #define sample_period 1 159 #define sample_period period 162 #define DEFAULT_PERIOD 5000L 232 #ifdef ENABLE_CLOCK_REALTIME 238 td->
sigev.sigev_notify_thread_id = syscall(SYS_gettid);
241 #ifdef ENABLE_CLOCK_CPUTIME 261 #ifdef ENABLE_CLOCK_REALTIME 263 ret = timer_delete(td->
timerid);
285 if (mytimer ==
NULL)
return -1;
287 return timer_settime(mytimer, 0, spec,
NULL);
293 #ifdef ENABLE_CLOCK_REALTIME 305 #ifdef ENABLE_CLOCK_REALTIME 334 TMSG(ITIMER_CTL,
"Thread data unavailable ==> sampling suspended");
341 TMSG(ITIMER_HANDLER,
"starting %s: value = (%d,%d), interval = (%d,%d)",
364 TMSG(ITIMER_CTL,
"setitimer failed to start!!");
365 EMSG(
"setitimer failed (%d): %s", errno, strerror(errno));
370 #ifdef USE_ELAPSED_TIME_FOR_WALLCLOCK 374 EMSG(
"time_getTimeReal (clock_gettime) failed!");
391 TMSG(ITIMER_CTL,
"init");
399 TMSG(ITIMER_CTL,
"thread init");
405 TMSG(ITIMER_CTL,
"thread init action");
432 TMSG(ITIMER_CTL,
"thread fini action");
486 TMSG(ITIMER_CTL,
"process event list, lush_metrics = %d", lush_metrics);
492 TMSG(ITIMER_CTL,
"checking event spec = %s",event);
495 #ifdef HOST_SYSTEM_IBM_BLUEGENE 501 #ifdef ENABLE_CLOCK_CPUTIME 507 EEMSG(
"Event %s (%s) is not available on this system.",
515 #ifdef ENABLE_CLOCK_REALTIME 527 #ifdef ENABLE_CLOCK_CPUTIME 555 TMSG(OPTIONS,
"wallclock period set to %ld",
period);
558 int seconds =
period / 1000000;
559 int microseconds =
period % 1000000;
561 TMSG(ITIMER_CTL,
"init %s sample_period = %ld, seconds = %d, usec = %d",
577 #ifdef HOST_SYSTEM_IBM_BLUEGENE 599 if (lush_metrics == 1) {
611 EEMSG(
"Can't use multiple timer events in the same run.");
629 printf(
"===========================================================================\n");
630 printf(
"Available Timer events\n");
631 printf(
"===========================================================================\n");
632 printf(
"Name\t\tDescription\n");
633 printf(
"---------------------------------------------------------------------------\n");
634 printf(
"%s\tReal clock time used by the thread in microseconds.\n" 635 "\t\tBased on the CLOCK_REALTIME timer with the SIGEV_THREAD_ID\n" 636 "\t\textension. Includes time blocked in the kernel, but may\n" 637 "\t\tnot be available on all systems (eg, Blue Gene) and may\n" 638 "\t\tbreak some syscalls that are sensitive to EINTR.\n",
640 #ifndef ENABLE_CLOCK_REALTIME 641 printf(
"\t\tNot available on this system.\n");
644 printf(
"%s \tCPU clock time used by the thread in microseconds. Based\n" 645 "\t\ton the CLOCK_THREAD_CPUTIME_ID timer with the SIGEV_THREAD_ID\n" 646 "\t\textension. May not be available on all systems (eg, Blue Gene).\n",
648 #ifndef ENABLE_CLOCK_CPUTIME 649 printf(
"\t\tNot available on this system.\n");
652 printf(
"%s \tCPU clock time used by the thread in microseconds. Same\n" 653 "\t\tas %s except on Blue Gene, where it is implemented\n" 654 "\t\tby ITIMER_PROF.\n",
657 printf(
"Note: do not use multiple timer events in the same run.\n");
666 #define ss_name itimer 667 #define ss_cls SS_HARDWARE 668 #define ss_sort_order 20 682 static bool metrics_finalized =
false;
687 TMSG(ITIMER_HANDLER,
"thread sampling suppressed");
697 EMSG(
"Received itimer signal, but thread not initialized");
714 if (!metrics_finalized) {
716 metrics_finalized =
true;
719 TMSG(ITIMER_HANDLER,
"Itimer sample event");
721 uint64_t metric_incr = 1;
723 #if defined (USE_ELAPSED_TIME_FOR_WALLCLOCK) 724 uint64_t cur_time_us = 0;
727 EMSG(
"time_getTimeReal (clock_gettime) failed!");
730 metric_incr = cur_time_us -
TD_GET(last_time_us);
741 TMSG(ITIMER_HANDLER,
"No itimer restart, due to disabled sampling");
static int hpcrun_create_real_timer(thread_data_t *td)
static struct itimerspec itspec_stop
static int itimer_signal_handler(int sig, siginfo_t *siginfo, void *context)
#define REALTIME_METRIC_NAME
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)
#define CPUTIME_METRIC_NAME
#define HPCTOOLKIT_APPLICATION_ERRNO_RESTORE()
static char * the_metric_name
#define metric_property_time
void blame_shift_source_register(bs_type bst)
void hpcrun_ssfail_unknown(char *event)
static bool hpcrun_is_sampling_disabled(void)
static void hpcrun_restart_timer(sample_source_t *self, int safe)
#define WALLCLOCK_EVENT_NAME
#define ITIMER_EVENT_NAME
static sigset_t timer_mask
bool(* hpcrun_td_avail)(void)
#define WALLCLOCK_METRIC_NAME
void hpcrun_itimer_wallclock_ok(bool flag)
void blame_shift_apply(int metric_id, cct_node_t *node, int metric_incr)
void hpcrun_stats_num_samples_blocked_async_inc(void)
static int the_signal_num
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)
static int hpcrun_delete_real_timer(thread_data_t *td)
#define CPUTIME_EVENT_NAME
static struct itimerspec itspec_start
static int hpcrun_stop_timer(thread_data_t *td)
char * start_tok(char *lst)
void hpcrun_ssfail_start(char *source)
static struct itimerval itval_stop
#define REALTIME_NOTIFY_METHOD
bool hpcrun_ev_is(const char *candidate, const char *event_name)
static int time_getTimeReal(uint64_t *time)
static int hpcrun_start_timer(thread_data_t *td)
static char * the_event_name
int hpcrun_extract_ev_thresh(const char *in, int evlen, char *ev, long *th, long def)
static __thread bool wallclock_ok
static int hpcrun_safe_enter_async(void *pc)
#define CPUTIME_CLOCK_TYPE
int hpcrun_event2metric(sample_source_t *ss, int event_idx)
#define METHOD_CALL(obj, meth,...)
#define ITIMER_METRIC_NAME
static struct itimerval itval_start
#define REALTIME_CLOCK_TYPE
int hpcrun_new_metric(void)
#define REALTIME_EVENT_NAME
__thread bool hpcrun_thread_suppress_sample
#define HPCTOOLKIT_APPLICATION_ERRNO_SAVE()
void hpcrun_finalize_metrics()
void monitor_real_abort(void)
void hpcrun_pre_allocate_metrics(size_t num)
void * hpcrun_context_pc(void *context)
lush_agent_pool_t * lush_agents
static void METHOD_FN(init)
static int hpcrun_settime(thread_data_t *td, struct itimerspec *spec)
thread_data_t *(* hpcrun_get_thread_data)(void)
void hpcrun_ssfail_conflict(char *source, char *event)