Skip to main content

Module cputime

Module cputime 

Source
Expand description

Per-thread CPU time (owned by the facade work, for the stall watchdog). Per-thread CPU time, for telling a slow handler from a preempted thread.

thread_times reads the calling thread’s CPU time and, on Linux, its count of voluntary context switches (the thread blocked: sleep, I/O, a contended lock). A loop thread that was only preempted shows wall time but neither CPU time nor voluntary switches.

  • Linux (64-bit): clock_gettime(CLOCK_THREAD_CPUTIME_ID) for the CPU time and getrusage(RUSAGE_THREAD) for the switches. getrusage’s CPU times are only as fresh as the last scheduler tick for a running thread, so they miss most of a short call.
  • Other Unix: clock_gettime(CLOCK_THREAD_CPUTIME_ID), CPU time only.
  • Windows: QueryThreadCycleTime, converted to nanoseconds with a cycle rate measured once (about 1.5 ms of spinning on the first call).

This file is owned by the facade work (the stall watchdog in simoom).

Structs§

ThreadTimes
CPU time used by the calling thread so far.

Functions§

thread_times
The calling thread’s CPU time, or None where it can’t be read.