Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
GDWR committed Feb 3, 2024
1 parent 1e5a8a2 commit 945810e
Showing 1 changed file with 152 additions and 0 deletions.
152 changes: 152 additions & 0 deletions scripts/tegrastats
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#!/usr/bin/env bash
# This file is part of the jetson_stats package (https://github.com/rbonghi/jetson_stats or http://rnext.it).
# Copyright (c) 2019-2023 Raffaello Bonghi.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.


# Emulator for NVIDIA Jetson tegrastats

red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`

usage()
{
if [ "$1" != "" ]; then
echo "${red}$1${reset}"
fi

echo "tegrastats, Emulator of NVIDIA Jetsons"
echo "Usage:"
echo "$0 [options]"
echo "options,"
echo " -h|--help | This help"
echo " --interval | Frequency interval"
echo " --test-model | Test the jetson version (Does not exist in real!!)"
}

tegrastats_out()
{
local JETSON_MODEL=$1
# Generate random value for GPU
local RAND_GPU=$(( $RANDOM % 100 + 0 ))
local RAND_GPU2=$(( $RANDOM % 100 + 0 ))

if [ "$JETSON_MODEL" = "TX1" ] ; then
# Jetson TX1
echo "RAM 385/3984MB (lfb 779x4MB) CPU [$(($RANDOM%100+0))%@204,$(($RANDOM%100+0))%@204,$(($RANDOM%100+0))%@204,$(($RANDOM%100+0))%@204] AO@31C CPU@25C GPU@22C [email protected] [email protected] PMIC@100C Tboard@29C [email protected]"
elif [ "$JETSON_MODEL" = "TX2" ] ; then
# Jetson TX2
echo "RAM 707/7854MB (lfb 1659x4MB) CPU [$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345] BCPU@30C MCPU@30C [email protected] PLL@30C Tboard@26C [email protected] PMIC@100C [email protected] VDD_IN 1038/1134 VDD_CPU 153/153 VDD_GPU 153/153 VDD_SOC 384/384 VDD_WIFI 38/124 VDD_DDR 192/192"
elif [ "$JETSON_MODEL" = "Xavier" ] ; then
# Jetson Xavier
echo "RAM 407/15823MB (lfb 3702x4MB) SWAP 0/7911MB (cached 0MB) CPU [$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265] EMC_FREQ 0% GR3D_FREQ $RAND_GPU% [email protected] GPU@28C iwlwifi@30C [email protected] PMIC@100C [email protected] [email protected] [email protected] Tboard@27C GPU 1155/1155 CPU 385/385 SOC 2504/2503 CV 0/0 VDDRQ 192/192 SYS5V 2692/2692"
elif [ "$JETSON_MODEL" = "Orin" ] ; then
# Jetson Orin
echo "01-03-2023 16:10:22 RAM 2257/30536MB (lfb 5392x4MB) SWAP 0/15268MB (cached 0MB) CPU [$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,0%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729] EMC_FREQ 0% GR3D_FREQ $RAND_GPU% CV0@-256C [email protected] Tboard@29C SOC2@39C [email protected] [email protected] CV1@-256C GPU@-256C [email protected] [email protected] CV2@-256C"
elif [ "$JETSON_MODEL" = "Nano" ] ; then
# Jetson Nano
echo "RAM 330/3964MB (lfb 758x4MB) SWAP 0/1982MB (cached 0MB) CPU [$(($RANDOM%100+0))%@102,$(($RANDOM%100+0))%@102,$(($RANDOM%100+0))%@102,$(($RANDOM%100+0))%@102] EMC_FREQ 0% GR3D_FREQ $RAND_GPU% [email protected] CPU@23C PMIC@100C [email protected] AO@27C [email protected] POM_5V_IN 933/933 POM_5V_GPU 0/0 POM_5V_CPU 84/84"
else
# Extra
echo "RAM 4722/7844MB (lfb 1x512kB) CPU [$(($RANDOM%100+0))%@2035,$(($RANDOM%100+0))%@2034,$(($RANDOM%100+0))%@2034,$(($RANDOM%100+0))%@2035,$(($RANDOM%100+0))%@2035,$(($RANDOM%100+0))%@2035] SWAP 149/1024MB (cached 7MB) EMC_FREQ 2%@1866 GR3D_FREQ $RAND_GPU%@1300 APE 150 MTS fg 0% bg 0% BCPU@-45C MCPU@-45C GPU@-51C PLL@45C [email protected] Tboard@37C [email protected] PMIC@100C [email protected] VDD_IN 14025/14416 VDD_CPU 2209/2538 VDD_GPU 6854/6903 VDD_SOC 1371/1370 VDD_WIFI 19/19 NVENC 716 NVDEC 716 VDD_DDR 2702/2702"
fi
}

tegrastats_out_sudo()
{
local JETSON_MODEL=$1
# Generate random value for GPU
local RAND_GPU=$(( $RANDOM % 100 + 0 ))
local RAND_GPU2=$(( $RANDOM % 100 + 0 ))

if [ "$JETSON_MODEL" = "TX1" ] ; then
# Jetson TX1 (SUDO)
echo "RAM 388/3984MB (lfb 779x4MB) IRAM 0/252kB(lfb 252kB) CPU [$(($RANDOM%100+0))%@1734,$(($RANDOM%100+0))%@1734,$(($RANDOM%100+0))%@1734,$(($RANDOM%100+0))%@1734] EMC_FREQ 0%@1600 GR3D_FREQ $RAND_GPU%@998 APE 25 [email protected] [email protected] GPU@23C [email protected] [email protected] PMIC@100C Tboard@28C thermal@24C"
elif [ "$JETSON_MODEL" = "TX2" ] ; then
# Jetson TX2 (SUDO)
echo "RAM 696/7854MB (lfb 1675x4MB) CPU [$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345,$(($RANDOM%100+0))%@345] EMC_FREQ 1%@665 GR3D_FREQ $RAND_GPU%@140 APE 150 MTS fg 0% bg 0% BCPU@30C MCPU@30C GPU@28C PLL@30C Tboard@26C Tdiode@27C PMIC@100C [email protected] VDD_IN 1383/1383 VDD_CPU 153/191 VDD_GPU 76/76 VDD_SOC 384/384 VDD_WIFI 364/335 VDD_DDR 192/201"
elif [ "$JETSON_MODEL" = "Xavier" ] ; then
# Jetson Xavier (SUDO)
echo "RAM 408/15823MB (lfb 3702x4MB) SWAP 0/7911MB (cached 0MB) CPU [$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265,$(($RANDOM%100+0))%@2265] EMC_FREQ 0%@2133 GR3D_FREQ $RAND_GPU%@1377 APE 150 MTS fg 0% bg 0% [email protected] GPU@28C iwlwifi@30C [email protected] PMIC@100C AUX@27C CPU@28C [email protected] Tboard@27C GPU 1155/1155 CPU 385/385 SOC 2502/2502 CV 0/0 VDDRQ 192/192 SYS5V 2692/2692"
elif [ "$JETSON_MODEL" = "Orin" ] ; then
# Jetson Orin (SUDO)
echo "01-03-2023 16:07:54 RAM 2257/30536MB (lfb 5392x4MB) SWAP 0/15268MB (cached 0MB) CPU [$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729,$(($RANDOM%100+0))%@729] EMC_FREQ 0%@204 GR3D_FREQ $RAND_GPU%@0 GR3D2_FREQ $RAND_GPU2%@0 NVJPG1 729 VIC_FREQ 115 APE 233 CV0@-256C [email protected] Tboard@29C [email protected] [email protected] [email protected] CV1@-256C GPU@-256C [email protected] [email protected] CV2@-256C VDD_GPU_SOC 2390mW/2390mW VDD_CPU_CV 796mW/796mW VIN_SYS_5V0 3522mW/3522mW NC 0mW/0mW VDDQ_VDD2_1V8AO 301mW/301mW NC 0mW/0mW"
elif [ "$JETSON_MODEL" = "Nano" ] ; then
# Jetson Nano (SUDO)
echo "RAM 331/3964MB (lfb 758x4MB) SWAP 0/1982MB (cached 0MB) IRAM 0/252kB(lfb 252kB) CPU [$(($RANDOM%100+0))%@102,$(($RANDOM%100+0))%@102,$(($RANDOM%100+0))%@102,$(($RANDOM%100+0))%@102] EMC_FREQ 3%@204 GR3D_FREQ $RAND_GPU%@76 APE 25 [email protected] [email protected] PMIC@100C [email protected] [email protected] thermal@23C POM_5V_IN 933/933 POM_5V_GPU 0/0 POM_5V_CPU 84/105"
else
# Extra
echo "RAM 4722/7844MB (lfb 1x512kB) CPU [$(($RANDOM%100+0))%@2035,$(($RANDOM%100+0))%@2034,$(($RANDOM%100+0))%@2034,$(($RANDOM%100+0))%@2035,$(($RANDOM%100+0))%@2035,$(($RANDOM%100+0))%@2035] SWAP 149/1024MB (cached 7MB) EMC_FREQ 2%@1866 GR3D_FREQ $RAND_GPU%@1300 APE 150 MTS fg 0% bg 0% BCPU@-45C MCPU@-45C GPU@-51C PLL@45C [email protected] Tboard@37C [email protected] PMIC@100C [email protected] VDD_IN 14025/14416 VDD_CPU 2209/2538 VDD_GPU 6854/6903 VDD_SOC 1371/1370 VDD_WIFI 19/19 NVENC 716 NVDEC 716 VDD_DDR 2702/2702"
fi
}

main()
{
local TEST_MODEL_FOLDER="/tmp/jetson_model"
local JETSON_MODEL=""
local INTERVAL=500

# Decode all information from startup
while [ -n "$1" ]; do
case "$1" in
--interval)
INTERVAL=$2
shift 1
;;
-h|--help)
usage
exit 0
;;
--test-model)
echo $2 > $TEST_MODEL_FOLDER
echo "${green}Write $2 in $TEST_MODEL_FOLDER${reset}"
exit 0
;;
*)
usage "[ERROR] Unknown option: $1"
exit 1
;;
esac
shift 1
done

# Evaluate time
# Read Jetson Model emulator
if [ -f $TEST_MODEL_FOLDER ] ; then
JETSON_MODEL=$(sed '1q;d' $TEST_MODEL_FOLDER)
fi
# Check if running with sudo or not
IS_SUDO=false
if [ $(id -u) -eq 0 ] ; then
IS_SUDO=true
fi

while true; do
# Print output tegrastats
if $IS_SUDO ; then
tegrastats_out_sudo $JETSON_MODEL
else
tegrastats_out $JETSON_MODEL
fi
# Go to sleep for an interval
sleep 1
done
}

main $@
exit 0

# EOF

0 comments on commit 945810e

Please sign in to comment.