OS thread
Represents a thread captured for the current native macOS process, including its execution state and resource usage
Original source
The native thread information are provided by MacOsOSThread, which inherits OSThread.
The public threadDetails property exposes the common List<OSThread> type
KInfo's source
Retrieve operatingSystem as shown in the Operating system API.
The examples require a non-empty thread list; check it before calling first()
val currentProcess: MacOsOSProcess = operatingSystem.procTaskAllInfo
val threadDetails: List<OSThread> = currentProcess.threadDetails
val sample: OSThread = threadDetails.first()
The thread values belong to the process snapshot. Retrieve operatingSystem.procTaskAllInfo again to collect updated
thread information
Properties
threadId
The zero-based index assigned during native thread enumeration. This identifier belongs to the snapshot and is not a persistent native thread ID; skipped entries can leave gaps
name
The native thread name, which can be empty
state
The thread execution state. The native mapping returns RUNNING, STOPPED, SLEEPING, WAITING, or OTHER.
Native waiting threads map to SLEEPING, while uninterruptible threads map to WAITING
See the shared state entries
threadCpuLoadCumulative
The CPU usage value reported by macOS, divided by its native usage scale. Despite the property name, this is
not calculated as CPU time divided by the thread's lifetime. Multiply by 100 to display a percentage of one CPU
val threadCpuLoadCumulative: Double = sample.threadCpuLoadCumulative
println(threadCpuLoadCumulative) // e.g. 0.07
threadCpuLoadBetweenTicks
The ratio of CPU time gained to elapsed time since the previous registered sample for this native thread.
The first sample, an interval shorter than one second, or a decrease in CPU time uses threadCpuLoadCumulative
as a fallback
Collect another process snapshot after at least one second to obtain another thread sample. Reading this property on the same thread object returns its stored value
val threadCpuLoadBetweenTicks: Double = sample.threadCpuLoadBetweenTicks
println(threadCpuLoadBetweenTicks) // e.g. 0.1
owningProcessId
The identifier of the process that owns the thread
startMemoryAddress
The thread start memory address. The native implementation does not retrieve this value and returns 0
contextSwitches
The thread context switch count. The native implementation does not retrieve this value and returns 0
minorFaults
The thread minor fault count. The native implementation does not retrieve this value and returns 0
majorFaults
The thread major fault count. The native implementation does not retrieve this value and returns 0
kernelTime
The cumulative time spent by the thread in kernel mode, converted from native nanoseconds to whole milliseconds
userTime
The cumulative time spent by the thread in user mode, converted from native nanoseconds to whole milliseconds
upTime
The thread uptime in milliseconds. The native implementation does not retrieve this value and returns 0
startTime
The thread start time in milliseconds since the Unix epoch. The native implementation does not retrieve this value and returns 0
priority
The current scheduling priority reported for the thread
updateAttributes
Whether this object supports updating its attributes. The native implementation returns false; retrieve a new
process snapshot and read its threadDetails for updated thread information