Feature Request: Query-like Usage for `tegrastats` Command

Hi All,

I was using [b]nvidia-smi[/b] and got excited about the convenience of it’s one-time query usage like the following:

[b]$ nvidia-smi --query-gpu=gpu_name,gpu_bus_id,vbios_version --format=csv[/b]

For now, [b]tegrastats[/b] is a tool that continuously yielding the performance information. Is that possible to do the similar functionality using tegrastats?

Thanks,
Jack

Hi Jack, you can see the documentation for tegrastats utility here, it does not currently seem to support the one-time mode you are asking. The --interval argument can be used to query the information slower if you desire. In theory you could write a shell script that ran tegrastats with --interval, and then killed tegrastats after it ran once.

In the future we are looking to upgrade the tool. In the meantime what you can do, since tegrastats gets information from sysfs files, is you could make a simple script to read the files you are interested in. You can determine which files tegrastats is reading from with strace:

$ sudo apt-get install strace
$ sudo sh -c "strace /usr/bin/tegrastats 2>&1 | grep open"

Press Ctrl+C after a second or two, and you can go see the files to read the performance information from:

openat(AT_FDCWD, "/sys/kernel/debug/bpmp/debug/clk/ape/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/clk/ape/clk_rate", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/bpmp/debug/clk/emc/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/clock/emc/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/clk/emc/clk_rate", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/actmon_avg_activity/mc_all", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/bpmp/debug/clk/gpcclk/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/clk/gpcclk/clk_rate", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/devices/17000000.gp10b/load", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/devices/18000000.vgpu/load", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/devices/17810000.vgpu/load", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/devices/platform/gpu.0/load", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/devices/gpu.0/load", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/clk/nvenc/clk_enable_count", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/clk/nvenc1/clk_enable_count", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/dev/nvbpmpdebugfs/bpmp_debug/clk/nvenc1/state", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/bpmp/debug/clk/nvenc/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/clk/nvenc/clk_rate", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/bpmp/debug/clk/nvenc1/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/dev/nvbpmpdebugfs/bpmp_debug/clk/nvenc1/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/clk/nvdec/clk_enable_count", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/clk/nvdec1/clk_enable_count", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/dev/nvbpmpdebugfs/bpmp_debug/clk/nvdec1/state", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/bpmp/debug/clk/nvdec/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/clk/nvdec/clk_rate", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/bpmp/debug/clk/nvdec1/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/dev/nvbpmpdebugfs/bpmp_debug/clk/nvdec1/rate", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/devices/system/cpu/present", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_cur_freq", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/gpu_pci/clocks/gpc2clk", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/bus/pci/drivers/nvgpu/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/sys/bus/pci/drivers/nvgpu/module/load", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/kernel/debug/nvmap/iram/size", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/nvmap/iram/clients", O_RDONLY) = 3
openat(AT_FDCWD, "/proc/meminfo", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/kernel/debug/tegra_denver/nvmstats/instantaneous_stats", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/devices/virtual/thermal/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/sys/devices/virtual/thermal/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone3/temp", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone3/type", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone1/temp", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone1/type", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone4/temp", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone4/type", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone2/temp", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone2/type", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone0/temp", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone0/type", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone5/temp", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/devices/virtual/thermal/thermal_zone5/type", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/bus/i2c/devices/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/sys/bus/i2c/devices/0-0040/name", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/bus/i2c/devices/0-0041/name", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/bus/i2c/devices/1-0040/name", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/bus/i2c/devices/1-0041/name", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/bus/i2c/devices/6-0040/name", O_RDONLY) = 3
openat(AT_FDCWD, "/sys/bus/i2c/devices/6-0040/iio_device/", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
openat(AT_FDCWD, "/sys/bus/i2c/devices/6-0040/iio_device/rail_name_1", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/bus/i2c/devices/6-0040/iio_device/in_power1_input", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/bus/i2c/devices/6-0040/iio_device/rail_name_2", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/bus/i2c/devices/6-0040/iio_device/in_power2_input", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/bus/i2c/devices/6-0040/iio_device/rail_name_0", O_RDONLY) = 4
openat(AT_FDCWD, "/sys/bus/i2c/devices/6-0040/iio_device/in_power0_input", O_RDONLY) = 4

You can ‘cat’ these files from a script with sudo privilege to read the info.
Other users have used this technique to create their own tools, like gtop and tx-utils.

(moving this thread to Jetson Nano forum)

Those materials are really helpful.
Thanks a lot for being proactive on this!
Jack