// report generator #include #include "common.h" extern keypresses_t keypresses; static double work_time; static double idle_time; #define REPORT(t, s, v...) do { \ fprintf(report_fp, "%s: " t "\n", s, v); \ } while (0) void gen_report(FILE* report_fp) { LOG(LOG_DEBUG, "total keypresses: %d\n", keypresses.length); rewind(report_fp); work_time = 0; idle_time = 0; if (keypresses.length > 2) { double last_press = keypresses.keys[0].when; for (int i = 1; i < keypresses.length; i++) { keypress_t* press = &keypresses.keys[i]; if (press->when < last_press + IDLE_TIME) { work_time += press->when - last_press; } else { idle_time += press->when - last_press - IDLE_TIME; } last_press = press->when; LOG(LOG_INSANEDEBUG, "%d %d %d\n", keypresses.keys[i].when, keypresses.length); } } REPORT("%d", "total keypresses", keypresses.length); REPORT("%.1fs", "work time", work_time); REPORT("%.1f k/s", "avg keys/sec", keypresses.length / work_time); REPORT("%.1fs", "idle time", idle_time); fflush(report_fp); }