#include "instrumentation.h" #include #include #include #include #include #include #define POLL_SECS 0 #define POLL_USECS 1e5 static int event_set = PAPI_NULL; struct timeval sysv_t0; struct timeval sysv_wallclock; struct timeval wallclock; static inline double walltime(struct timeval * t) { return ((double)t->tv_sec) + 1e-6 * ((double)t->tv_usec); } static inline double energy(long long e) { return ((double)e)*1e-9; } void alrm_handler(int s) { long long values[6]; if (PAPI_stop(event_set, values) != PAPI_OK) error(true, true, "Error PAPI_stop.\n"); double interval = walltime(&sysv_wallclock); gettimeofday(&sysv_wallclock, NULL); interval = walltime(&sysv_wallclock) - interval; wallclock.tv_sec += POLL_SECS; wallclock.tv_usec += POLL_USECS; printf("t= %lf t_c= %lf pp0_0= %le pck_0= %le dram_0= %le pp0_1= %le pck_1= %le dram_1= %le\n", walltime(&sysv_wallclock) - walltime(&sysv_t0), walltime(&wallclock), energy(values[0])/interval, energy(values[1])/interval, energy(values[2])/interval, energy(values[3])/interval, energy(values[4])/interval, energy(values[5])/interval); if (PAPI_reset(event_set)) error(true, true, "PAPI reset failed.\n"); if (PAPI_start(event_set)) error(true, true, "PAPI start failed.\n"); } void start_logging() { if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) error(true, true, "PAPI library init error.\n"); if (PAPI_create_eventset(&event_set)) error(true, true, "PAPI library create event set error.\n"); if (PAPI_add_named_event(event_set, "PP0_ENERGY:PACKAGE0")) error(true, true, "PAPI library add named event failed.\n"); if (PAPI_add_named_event(event_set, "PACKAGE_ENERGY:PACKAGE0")) error(true, true, "PAPI library add named event failed.\n"); if (PAPI_add_named_event(event_set, "DRAM_ENERGY:PACKAGE0")) error(true, true, "PAPI library add named event failed.\n"); if (PAPI_add_named_event(event_set, "PP0_ENERGY:PACKAGE1")) error(true, true, "PAPI library add named event failed.\n"); if (PAPI_add_named_event(event_set, "PACKAGE_ENERGY:PACKAGE1")) error(true, true, "PAPI library add named event failed.\n"); if (PAPI_add_named_event(event_set, "DRAM_ENERGY:PACKAGE1")) error(true, true, "PAPI library add named event failed.\n"); if (PAPI_reset(event_set)) error(true, true, "PAPI reset failed.\n"); signal(SIGALRM, &alrm_handler); struct itimerval itimer; itimer.it_interval.tv_sec = itimer.it_value.tv_sec = POLL_SECS; itimer.it_interval.tv_usec = itimer.it_value.tv_usec = POLL_USECS; setitimer(ITIMER_REAL, &itimer, NULL); gettimeofday(&sysv_t0, NULL); sysv_wallclock = sysv_t0; wallclock.tv_sec = wallclock.tv_usec = 0; if (PAPI_start(event_set)) error(true, true, "PAPI start failed.\n"); } void stop_logging() { struct itimerval itimer; itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0; itimer.it_interval.tv_usec = itimer.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itimer, NULL); long long values[6]; if (PAPI_stop(event_set, values) != PAPI_OK) error(true, true, "Error PAPI_stop.\n"); double interval = walltime(&sysv_wallclock); gettimeofday(&sysv_wallclock, NULL); interval = walltime(&sysv_wallclock) - interval; wallclock.tv_sec += POLL_SECS; wallclock.tv_usec += POLL_USECS; printf("t= %lf t_c= %lf pp0_0= %le pck_0= %le dram_0= %le pp0_1= %le pck_1= %le dram_1= %le\n", walltime(&sysv_wallclock) - walltime(&sysv_t0), walltime(&wallclock), energy(values[0])/interval, energy(values[1])/interval, energy(values[2])/interval, energy(values[3])/interval, energy(values[4])/interval, energy(values[5])/interval); PAPI_shutdown(); }