static void measure_one_cycle(void) { struct timespec ts1, ts2, delta, sleep; int rc; current_sum_utime = 0; current_sum_stime = 0; current_sum_cpu_utime = 0; current_sum_cpu_stime = 0; if (nr_cycles) output->print_cycle_start(); else output->print_sync(); new_cycle = 1; rc = clock_gettime(CLOCK_MONOTONIC, &ts1); if (rc < 0) DIE_PERROR("clock_gettime failed"); query_tasks(); query_memory(); query_cpus(opt_all_cpus); print_tasks(); print_memory(); print_cpus(opt_all_cpus); rc = clock_gettime(CLOCK_MONOTONIC, &ts2); if (rc < 0) DIE_PERROR("clock_gettime failed"); timespec_delta(&ts1, &ts2, &delta); if (nr_cycles) output->print_cycle_end(&delta); /* check if we can meet the target measurement interval */ if (delta.tv_sec > target.tv_sec || (delta.tv_sec == target.tv_sec && delta.tv_nsec > target.tv_nsec)) { output->exit_output(); DIE("Target measurement intervall too small. Current overhead: %u seconds %lu ms\n", (int) delta.tv_sec, delta.tv_nsec / NSECS_PER_MSEC); } /* now go sleeping for the rest of the measurement interval */ if (nr_cycles) timespec_delta(&delta, &target, &sleep); else timespec_delta(&delta, &ts_sync, &sleep); wait_for_cycle_end(&sleep); nr_cycles++; }
static Error handler_script(int fd, struct dispinfo *d) { XEvent event; extern char *names[]; /* check for broken connection */ XSync(d->disp, 0); if (xerror) goto error; again: /* while there are events waiting for us? */ while (XPending(d->disp)) { XNextEvent(d->disp, &event); DXDebug("X", "event %s", names[event.type]); if (xerror) goto error; switch (event.type) { case Expose: d->refresh = 1; break; case ButtonPress: d->mouse_x = event.xbutton.x; d->mouse_y = event.xbutton.y; d->refresh = 1; switch (event.xbutton.button) { case 1: d->query = 1; break; case 2: DXPrintAlloc(d->which); break; default: break; } break; case ConfigureNotify: if ((d->win_width != event.xconfigure.width) || (d->win_height != event.xconfigure.height)) { resize_display(d, event.xconfigure.width, event.xconfigure.height); if (xerror) goto error; d->refresh = 1; } break; case DestroyNotify: cleanup_memory_visual(d); if (xerror) goto error; return OK; default: break; } } /* no more events pending. do we need to refresh the window? * query what blocks are underneath the mouse location? */ if (d->refresh) { report_memory(d); d->refresh = 0; } if (d->query) { query_memory(d); d->query = 0; } /* did more events happen while we were reporting or querying memory? */ if (XPending(d->disp)) goto again; if (xerror) goto error; return OK; error: xerror = 0; return ERROR; }