void startTicker(void) { #if defined(USE_TIMER_CREATE) { struct itimerspec it; it.it_value.tv_sec = TimeToSeconds(itimer_interval); it.it_value.tv_nsec = TimeToNS(itimer_interval) % 1000000000; it.it_interval = it.it_value; if (timer_settime(timer, 0, &it, NULL) != 0) { sysErrorBelch("timer_settime"); stg_exit(EXIT_FAILURE); } } #else { struct itimerval it; it.it_value.tv_sec = TimeToSeconds(itimer_interval); it.it_value.tv_usec = TimeToUS(itimer_interval) % 1000000; it.it_interval = it.it_value; if (setitimer(ITIMER_REAL, &it, NULL) != 0) { sysErrorBelch("setitimer"); stg_exit(EXIT_FAILURE); } } #endif }
void writeCCSReportJson(FILE *prof_file, CostCentreStack const *stack, ProfilerTotals totals) { fprintf(prof_file, "{\n\"program\": \"%s\",\n", prog_name); fprintf(prof_file, "\"arguments\": ["); for (int count = 0; prog_argv[count]; count++) fprintf(prof_file, "%s\"%s\"", count == 0 ? "" : ", ", prog_argv[count]); fprintf(prof_file, "],\n\"rts_arguments\": ["); for (int count = 0; rts_argv[count]; count++) fprintf(prof_file, "%s\"%s\"", count == 0 ? "" : ", ", rts_argv[count]); fprintf(prof_file, "],\n"); fprintf(prof_file, "\"end_time\": \"%s\",\n", time_str()); fprintf(prof_file, "\"initial_capabilities\": %d,\n", RtsFlags.ParFlags.nCapabilities); fprintf(prof_file, "\"total_time\": %11.2f,\n", ((double) totals.total_prof_ticks * (double) RtsFlags.MiscFlags.tickInterval) / (TIME_RESOLUTION * n_capabilities)); fprintf(prof_file, "\"total_ticks\": %lu,\n", (unsigned long) totals.total_prof_ticks); fprintf(prof_file, "\"tick_interval\": %d,\n", (int) TimeToUS(RtsFlags.MiscFlags.tickInterval)); fprintf(prof_file, "\"total_alloc\":%" FMT_Word64 ",\n", totals.total_alloc * sizeof(W_)); fprintf(prof_file, "\"cost_centres\": "); logCostCentres(prof_file); fprintf(prof_file, ",\n\"profile\": "); logCostCentreStack(prof_file, stack); fprintf(prof_file, "}\n"); }
static void *itimer_thread_func(void *_handle_tick) { TickProc handle_tick = _handle_tick; uint64_t nticks; int timerfd = -1; #if defined(USE_TIMERFD_FOR_ITIMER) && USE_TIMERFD_FOR_ITIMER struct itimerspec it; it.it_value.tv_sec = TimeToSeconds(itimer_interval); it.it_value.tv_nsec = TimeToNS(itimer_interval) % 1000000000; it.it_interval = it.it_value; timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); if (timerfd == -1) { sysErrorBelch("timerfd_create"); stg_exit(EXIT_FAILURE); } if (!TFD_CLOEXEC) { fcntl(timerfd, F_SETFD, FD_CLOEXEC); } if (timerfd_settime(timerfd, 0, &it, NULL)) { sysErrorBelch("timerfd_settime"); stg_exit(EXIT_FAILURE); } #endif while (!exited) { if (USE_TIMERFD_FOR_ITIMER) { if (read(timerfd, &nticks, sizeof(nticks)) != sizeof(nticks)) { if (errno != EINTR) { sysErrorBelch("Itimer: read(timerfd) failed"); } } } else { if (usleep(TimeToUS(itimer_interval)) != 0 && errno != EINTR) { sysErrorBelch("usleep(TimeToUS(itimer_interval) failed"); } } // first try a cheap test if (stopped) { ACQUIRE_LOCK(&mutex); // should we really stop? if (stopped) { waitCondition(&start_cond, &mutex); } RELEASE_LOCK(&mutex); } else { handle_tick(0); } } if (USE_TIMERFD_FOR_ITIMER) close(timerfd); closeMutex(&mutex); closeCondition(&start_cond); return NULL; }
static void *itimer_thread_func(void *_handle_tick) { TickProc handle_tick = _handle_tick; while (1) { usleep(TimeToUS(itimer_interval)); switch (itimer_enabled) { case 1: handle_tick(0); break; case 2: itimer_enabled = 0; } } return NULL; }
/* * For a given microsecond delay, return the target time in LowResTime. */ LowResTime getDelayTarget (HsInt us) { Time elapsed; elapsed = getProcessElapsedTime(); // If the desired target would be larger than the maximum Time, // default to the maximum Time. (#7087) if (us > TimeToUS(TIME_MAX - elapsed)) { return TimeToLowResTimeRoundDown(TIME_MAX); } else { // round up the target time, because we never want to sleep *less* // than the desired amount. return TimeToLowResTimeRoundUp(elapsed + USToTime(us)); } }
void startTicker(void) { BOOL r; r = CreateTimerQueueTimer(&timer, timer_queue, tick_callback, 0, 0, TimeToUS(tick_interval) / 1000, // ms WT_EXECUTEINTIMERTHREAD); if (r == 0) { sysErrorBelch("CreateTimerQueueTimer"); stg_exit(EXIT_FAILURE); } }