Getting per-thread CPU time on *BSD
Harald Eilertsen
harald+jdklists at volse.no
Mon Jun 16 14:21:15 UTC 2025
Hi again,
I think it should be possible to get what you need via the
clock_gettime() call with the clock id returned by
pthread_getcpuclockid() for the target thread.
https://man.freebsd.org/cgi/man.cgi?query=clock_gettime
https://man.freebsd.org/cgi/man.cgi?query=pthread_getcpuclockid
>From what I can see these calls are also supported on OpenBSD and
NetBSD.
One note, though: These calls return (afaict) the acumulated sys+user
time of the thread in one timespec struct, not as separate sys+user
times.
If that's ok, I'm happy to try to implement it. Is there a test that can
be used to check the implementation?
Take Care!
Harald
More information about the bsd-port-dev
mailing list