cleanup
This commit is contained in:
parent
1030b6e50e
commit
624bd7a23b
18
src/macos.c
18
src/macos.c
@ -2,13 +2,15 @@
|
||||
#include <time.h>
|
||||
#include <mach/mach_time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "lfmacos.h"
|
||||
|
||||
#define NS_TO_SECONDS 1000000000.0
|
||||
#define NEW_PROCESS_SENTINEL (-1.0)
|
||||
|
||||
ProcessData *new_ProcessData() {
|
||||
ProcessData *pd = malloc(sizeof(ProcessData));
|
||||
pd->last_total_consumed = -1.0;
|
||||
pd->last_total_consumed = NEW_PROCESS_SENTINEL;
|
||||
return pd;
|
||||
}
|
||||
|
||||
@ -24,18 +26,18 @@ int update_process(pid_t pid, ProcessData *proc) {
|
||||
const double ns_per_tick = (double)info.numer / (double)info.denom;
|
||||
|
||||
time(&(proc->timestamp));
|
||||
proc->total_kernel_time = (taskinfo.pti_total_system * ns_per_tick) / 1000000000.0;
|
||||
proc->total_user_time = (taskinfo.pti_total_user * ns_per_tick) / 1000000000.0;
|
||||
proc->total_kernel_time = (taskinfo.pti_total_system * ns_per_tick) / NS_TO_SECONDS;
|
||||
proc->total_user_time = (taskinfo.pti_total_user * ns_per_tick) / NS_TO_SECONDS;
|
||||
proc->virtual_memory = taskinfo.pti_virtual_size;
|
||||
proc->resident_memory = taskinfo.pti_resident_size;
|
||||
|
||||
if (proc->last_total_consumed > -1.0) {
|
||||
proc->percent_cpu = fabs(100.0 *
|
||||
(proc->total_user_time + proc->total_kernel_time - proc->last_total_consumed) /
|
||||
(proc->last_timestamp - proc->timestamp));
|
||||
if (proc->last_total_consumed != NEW_PROCESS_SENTINEL) {
|
||||
time_t t = proc->timestamp - proc->last_timestamp;
|
||||
proc->percent_cpu = 100.0 * (proc->total_user_time + proc->total_kernel_time - proc->last_total_consumed) / t;
|
||||
} else {
|
||||
proc->percent_cpu = 0.0;
|
||||
}
|
||||
|
||||
proc->last_timestamp = proc->timestamp;
|
||||
proc->last_total_consumed = proc->total_kernel_time + proc->total_user_time;
|
||||
|
||||
|
@ -179,6 +179,10 @@ void test_math() {
|
||||
printf("Binary: %s\n", s2);
|
||||
printf("Decimal: %d\n", binstr_to_int(s2));
|
||||
|
||||
i = 10;
|
||||
i = clamp_int(i, 2, 5);
|
||||
assert(i == 5);
|
||||
|
||||
printf("\nGenerate line from 0,0 to 2,5\n");
|
||||
size_t sz = 0;
|
||||
Point *line = bresenham(0, 0, 2, 5, &sz);
|
||||
|
Loading…
x
Reference in New Issue
Block a user