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 <time.h>
|
||||||
#include <mach/mach_time.h>
|
#include <mach/mach_time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#include "lfmacos.h"
|
#include "lfmacos.h"
|
||||||
|
|
||||||
|
#define NS_TO_SECONDS 1000000000.0
|
||||||
|
#define NEW_PROCESS_SENTINEL (-1.0)
|
||||||
|
|
||||||
ProcessData *new_ProcessData() {
|
ProcessData *new_ProcessData() {
|
||||||
ProcessData *pd = malloc(sizeof(ProcessData));
|
ProcessData *pd = malloc(sizeof(ProcessData));
|
||||||
pd->last_total_consumed = -1.0;
|
pd->last_total_consumed = NEW_PROCESS_SENTINEL;
|
||||||
return pd;
|
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;
|
const double ns_per_tick = (double)info.numer / (double)info.denom;
|
||||||
|
|
||||||
time(&(proc->timestamp));
|
time(&(proc->timestamp));
|
||||||
proc->total_kernel_time = (taskinfo.pti_total_system * 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) / 1000000000.0;
|
proc->total_user_time = (taskinfo.pti_total_user * ns_per_tick) / NS_TO_SECONDS;
|
||||||
proc->virtual_memory = taskinfo.pti_virtual_size;
|
proc->virtual_memory = taskinfo.pti_virtual_size;
|
||||||
proc->resident_memory = taskinfo.pti_resident_size;
|
proc->resident_memory = taskinfo.pti_resident_size;
|
||||||
|
|
||||||
if (proc->last_total_consumed > -1.0) {
|
if (proc->last_total_consumed != NEW_PROCESS_SENTINEL) {
|
||||||
proc->percent_cpu = fabs(100.0 *
|
time_t t = proc->timestamp - proc->last_timestamp;
|
||||||
(proc->total_user_time + proc->total_kernel_time - proc->last_total_consumed) /
|
proc->percent_cpu = 100.0 * (proc->total_user_time + proc->total_kernel_time - proc->last_total_consumed) / t;
|
||||||
(proc->last_timestamp - proc->timestamp));
|
|
||||||
} else {
|
} else {
|
||||||
proc->percent_cpu = 0.0;
|
proc->percent_cpu = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
proc->last_timestamp = proc->timestamp;
|
proc->last_timestamp = proc->timestamp;
|
||||||
proc->last_total_consumed = proc->total_kernel_time + proc->total_user_time;
|
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("Binary: %s\n", s2);
|
||||||
printf("Decimal: %d\n", binstr_to_int(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");
|
printf("\nGenerate line from 0,0 to 2,5\n");
|
||||||
size_t sz = 0;
|
size_t sz = 0;
|
||||||
Point *line = bresenham(0, 0, 2, 5, &sz);
|
Point *line = bresenham(0, 0, 2, 5, &sz);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user