Files
banan-os/userspace/libraries/LibC/sys/times.cpp
Bananymous e03a26cf01 LibC: Don't ASSERT in times
Return the current process CPU time as user time. We don't have a way to
get system/user time separation or CPU times of child processes
2026-07-20 04:07:23 +03:00

27 lines
567 B
C++

#include <sys/times.h>
#include <time.h>
#include <unistd.h>
static inline clock_t timespec_to_clock_t(const timespec& ts)
{
static clock_t clock_tick = -1;
if (clock_tick == -1)
clock_tick = sysconf(_SC_CLK_TCK);
return ts.tv_sec * clock_tick + ts.tv_nsec * clock_tick / 1'000'000'000;
}
clock_t times(struct tms* buffer)
{
// FIXME: system time, child times
*buffer = {};
timespec ts;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
buffer->tms_utime = timespec_to_clock_t(ts);
clock_gettime(CLOCK_MONOTONIC, &ts);
return timespec_to_clock_t(ts);
}