beetlebug▾
/

ztcl::sysinfo sample

Gives one sample of the host as a dict.

ztcl::sysinfo sample ?-parts LIST? ?-gpu BOOLEAN? ?-detail PIDS? ?-interval MS?

Description

Gives a dict with the key os (linux, macos, or windows), the key missing, and each part of -parts that the OS gives. The parts and their units are in the module page: CPU time in ns, bytes, packets, mC, mW, and MHz.

procs is a table of two keys: cols, the names of the columns, and rows, one list for each process. A cell that the OS refuses, such as the memory of a process of another user, is empty.

missing is a dict of the reasons: its key is a part, such as fs, or a key of a part, such as cpu.freq.

The call charges one compute unit for each part and one for each process.

Options

OptionTypeDefaultDescription
-partslistall the partsThe parts of the sample.
-gpuboolean0Adds the GPU time of each process.
-detaillistemptyAdds the command line of these processes.
-intervalinteger1000The time between two samples of the caller.

-parts LIST

The parts of the sample.

The parts to read: host, uptime, cpu, mem, procs, disks, fs, net, gpus, sensors, power, and os_extra. The key os is in each sample, so -parts os gives the OS with no other read.

% dict get [ztcl::sysinfo sample -parts os] missing
% ztcl::sysinfo sample -parts disk
bad part "disk": must be os, host, uptime, cpu, mem, procs, disks, fs, net, gpus, sensors, power, or os_extra
-errorcode ZTCL SYSINFO PART

-gpu BOOLEAN

Adds the GPU time of each process.

With a true value, each GPU of gpus gets the key procs: a dict of each process that has used the GPU, with its GPU time busy_ns. The read is slow, so it is off by default.

% dict exists [ztcl::sysinfo sample -parts os -gpu 1] os
1
% ztcl::sysinfo sample -gpu maybe
expected boolean value but got "maybe"
-errorcode TCL VALUE NUMBER

-detail PIDS

Adds the command line of these processes.

The column cmd of each process of the list gets its command line, with the words joined by spaces. The column is empty for the other processes, and for a process of another user. The read is slow, so a monitor asks for the processes that it shows.

% llength [dict keys [ztcl::sysinfo sample -parts os -detail {1 2}]]
2
% ztcl::sysinfo sample -detail {1 x}
expected integer but got "x"
-errorcode TCL VALUE NUMBER

-interval MS

The time between two samples of the caller.

A backend that measures a rate itself, over the time between two calls, uses it. The macOS backend reads only counters, and needs none.

% dict exists [ztcl::sysinfo sample -parts os -interval 500] os
1
% ztcl::sysinfo sample -interval -1
bad interval "-1": must be 0 or more
-errorcode NONE

Returns

The dict of the sample.

Examples

% dict keys [ztcl::sysinfo sample -parts os]
os missing

% dict exists [ztcl::sysinfo s -parts os] os
1

Errors

% ztcl::sysinfo sample -bogus 1
bad option "-bogus": must be -parts, -gpu, -detail, or -interval
-errorcode TCL LOOKUP INDEX option

% ztcl::sysinfo sample -gpu
wrong # args: should be "ztcl::sysinfo sample ?-parts list? ?-gpu boolean? ?-detail pids? ?-interval ms?"
-errorcode TCL WRONGARGS

Facts

Capability
sysinfo. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.10