static int papi_setup_auto_af(void) { if (auto_enable_afid >= 0) __pmAFunregister(auto_enable_afid); auto_enable_afid = -1; if (auto_enable_time) { struct timeval t; t.tv_sec = (time_t) auto_enable_time; t.tv_usec = 0; auto_enable_afid = __pmAFregister(&t, NULL, auto_enable_expiry_cb); return auto_enable_afid < 0 ? auto_enable_afid : 0; } return 0; }
int newvolume(int vol_switch_type) { FILE *newfp; int nextvol = logctl.l_curvol + 1; time_t now; static char *vol_sw_strs[] = { "SIGHUP", "pmlc request", "sample counter", "sample byte size", "sample time", "max data volume size" }; vol_samples_counter = 0; vol_bytes += ftell(logctl.l_mfp); if (exit_bytes != -1) { if (vol_bytes >= exit_bytes) run_done(0, "Byte limit reached"); } /* * If we are not part of a callback but instead a * volume switch from "pmlc" or a "SIGHUP" then * get rid of pending volume switch in event queue * as it will now be wrong, and schedule a new * volume switch event. */ if (vol_switch_afid >= 0 && vol_switch_type != VOL_SW_TIME) { __pmAFunregister(vol_switch_afid); vol_switch_afid = __pmAFregister(&vol_switch_time, NULL, vol_switch_callback); } if ((newfp = __pmLogNewFile(archBase, nextvol)) != NULL) { if (logctl.l_state == PM_LOG_STATE_NEW) { /* * nothing has been logged as yet, force out the label records */ __pmtimevalNow(&last_stamp); logctl.l_label.ill_start.tv_sec = (__int32_t)last_stamp.tv_sec; logctl.l_label.ill_start.tv_usec = (__int32_t)last_stamp.tv_usec; logctl.l_label.ill_vol = PM_LOG_VOL_TI; __pmLogWriteLabel(logctl.l_tifp, &logctl.l_label); logctl.l_label.ill_vol = PM_LOG_VOL_META; __pmLogWriteLabel(logctl.l_mdfp, &logctl.l_label); logctl.l_label.ill_vol = 0; __pmLogWriteLabel(logctl.l_mfp, &logctl.l_label); logctl.l_state = PM_LOG_STATE_INIT; } #if 0 if (last_stamp.tv_sec != 0) { __pmTimeval tmp; tmp.tv_sec = (__int32_t)last_stamp.tv_sec; tmp.tv_usec = (__int32_t)last_stamp.tv_usec; __pmLogPutIndex(&logctl, &tmp); } #endif fclose(logctl.l_mfp); logctl.l_mfp = newfp; logctl.l_label.ill_vol = logctl.l_curvol = nextvol; __pmLogWriteLabel(logctl.l_mfp, &logctl.l_label); time(&now); fprintf(stderr, "New log volume %d, via %s at %s", nextvol, vol_sw_strs[vol_switch_type], ctime(&now)); return nextvol; } else return -oserror(); }
void onevent(int afid, void *data) { struct timeval now; static int delay = -3; int evnum; double elapsed; struct timeval sec = { 0, 0 }; gettimeofday(&now, NULL); if (pmDebug & DBG_TRACE_AF) { fprintf(stderr, "onevent(%d, " PRINTF_P_PFX "%p) called: ", afid, data); printstamp(&now); fputc('\n', stderr); } elapsed = now.tv_sec - start.tv_sec + (double)(now.tv_usec - start.tv_usec) / 1000000.0; if (afid == reg[2]) printf("event %d callback\n", afid); else { if (afid == reg[0]) evnum = (int)(elapsed / 2.5); else evnum = (int)(elapsed / 1.5); /* evnum not reliable for small elapsed intervals */ if (evnum >= 3) printf("event %d callback #%d\n", afid, evnum); else printf("event %d callback #?\n", afid); } if (delay > 6) { /* only report the unexpected */ if (__pmAFunregister(reg[0]) < 0) printf("unregister %d failed\n", reg[0]); if (__pmAFunregister(reg[1]) == 0) printf("unregister %d success\n", reg[1]); if (__pmAFunregister(reg[2]) == 0) printf("unregister %d success\n", reg[2]); if (__pmAFunregister(reg[3]) < 0) printf("unregister %d failed\n", reg[0]); exit(0); } if (delay > 0) { /* * was sginap(delay * CLK_TCK) ... usleep() for * delay*CLK_TCK*10^6/CLK_TCK microseconds so "delay" sec */ sec.tv_sec = delay; __pmtimevalSleep(sec); } delay++; if (pmDebug & DBG_TRACE_AF) { gettimeofday(&now, NULL); fprintf(stderr, "onevent done: "); printstamp(&now); fputc('\n', stderr); } fflush(stderr); fflush(stdout); }