add CPU spin support on OpenBSD (#471)

* add CPU spin support on OpenBSD

* use consistent ifdefs
This commit is contained in:
Robert Nagy 2021-12-15 13:29:32 +01:00 committed by GitHub
parent db279644c3
commit 126fcaef25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,9 @@ struct cpu_usage {
int nice; int nice;
int system; int system;
int idle; int idle;
#if defined(__OpenBSD__)
int spin;
#endif
int total; int total;
}; };
@ -151,7 +154,12 @@ void print_cpu_usage(cpu_usage_ctx_t *ctx) {
curr_all.nice = cp_time[CP_NICE]; curr_all.nice = cp_time[CP_NICE];
curr_all.system = cp_time[CP_SYS]; curr_all.system = cp_time[CP_SYS];
curr_all.idle = cp_time[CP_IDLE]; curr_all.idle = cp_time[CP_IDLE];
#if defined(__OpenBSD__)
curr_all.spin = cp_time[CP_SPIN];
curr_all.total = curr_all.user + curr_all.nice + curr_all.system + curr_all.idle + curr_all.spin;
#else
curr_all.total = curr_all.user + curr_all.nice + curr_all.system + curr_all.idle; curr_all.total = curr_all.user + curr_all.nice + curr_all.system + curr_all.idle;
#endif
diff_idle = curr_all.idle - prev_all.idle; diff_idle = curr_all.idle - prev_all.idle;
diff_total = curr_all.total - prev_all.total; diff_total = curr_all.total - prev_all.total;
diff_usage = (diff_total ? (1000 * (diff_total - diff_idle) / diff_total + 5) / 10 : 0); diff_usage = (diff_total ? (1000 * (diff_total - diff_idle) / diff_total + 5) / 10 : 0);