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
This commit is contained in:
2026-07-09 08:39:09 +03:00
parent 2a3eca5b36
commit e03a26cf01

View File

@@ -1,9 +1,26 @@
#include <sys/times.h> #include <sys/times.h>
#include <time.h>
#include <unistd.h>
#include <BAN/Assert.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) clock_t times(struct tms* buffer)
{ {
(void)buffer; // FIXME: system time, child times
ASSERT_NOT_REACHED(); *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);
} }