#define _XOPEN_SOURCE 500 #include "cpuUtil.h" void get_cpu_usage(int cpu_cores, char buf[PANE_BUF], int *cpu_utils, int i, int tdelay) { ///_|> descry: return total cpu usage over a period ///_|> cpu_cores: number of cpu cores to consider in calculations ///_|> buf: buffer to write pane to ///_|> cpu_utils: data array ///_|> i: current datapoint in data array ///_|> returning: void double pre_cpu_util = read_cpu_util(); usleep(tdelay); // Augmented the given algo double cpu_util = (read_cpu_util() - pre_cpu_util) / (cpu_cores * tdelay); cpu_utils[i] = min((int)ceil(1e5 * cpu_util), 10.0); draw_cpu_title(buf, min(cpu_util * 1e6, 100.0)); draw_graph(buf, cpu_utils, i); }