In this section, i will explain how to monitor Nano/xavier power consumption.
at first, see following links.
Jetson Nano / TX1 Software-based Power Consumption Modeling
Jetson Xavier AGX / NX Software-based Power Consumption Modeling
Jetson Nano provide power consumption information at “/sys/bus/i2c/drivers/ina3221x/6–0040/iio:device0/<COMMAND>”. you can replace <COMMAND> for your objective. For example, if you want to monitoring power of GPU power rail, type “cat /sys/bus/i2c/drivers/ina3221x/6–0040/iio:device0/in_power1_input” to check it.
Jetson Xavier AGX also have same step. But location was different. you can refer “/sys/bus/i2c/drivers/ina3221x/1–0040/iio:device0/<COMMAND>” to monitor your device.
And now, In my case, i need to monitoring their power consumption of every second and average power consumption. So i implement C++ to monitoring it.
Jetson Xavier AGX Software-based Power Consumption Monitoring
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <termio.h>
#include <unistd.h>
#include <time.h>using namespace std;
int main(){
ifstream gpuPowerFile,cpuPowerFile,SOCPowerFile,CVPowerFile,DDRPowerFile,SYS5VPowerFile;
int totalCount=0;
int sumofPower=0;
char input=0;
time_t start=time(NULL);
while(true){
string str;
int power=0;
int voltage=0;
int val;
gpuPowerFile.open("/sys/bus/i2c/drivers/ina3221x/1-0040/iio:device0/in_power0_input");
cpuPowerFile.open("/sys/bus/i2c/drivers/ina3221x/1-0040/iio:device0/in_power1_input");
SOCPowerFile.open("/sys/bus/i2c/drivers/ina3221x/1-0040/iio:device0/in_power2_input");
CVPowerFile.open("/sys/bus/i2c/drivers/ina3221x/1-0041/iio:device1/in_power0_input");
DDRPowerFile.open("/sys/bus/i2c/drivers/ina3221x/1-0041/iio:device1/in_power1_input");
SYS5VPowerFile.open("/sys/bus/i2c/drivers/ina3221x/1-0041/iio:device1/in_power2_input");
gpuPowerFile>>str;
val=atoi(str.c_str());
cout<<"GPU Power:"<<val<<"mW"<<endl;
power+=val;
str.clear();
cpuPowerFile>>str;
val=atoi(str.c_str());
cout<<"CPU Power:"<<val<<"mW"<<endl;
power+=val;
str.clear();
SOCPowerFile>>str;
val=atoi(str.c_str());
cout<<"SOC Power:"<<val<<"mW"<<endl;
power+=val;
str.clear();
CVPowerFile>>str;
val=atoi(str.c_str());
cout<<"CV Power:"<<val<<"mW"<<endl;
power+=val;
str.clear();
DDRPowerFile>>str;
val=atoi(str.c_str());
cout<<"DDR Power:"<<val<<"mW"<<endl;
power+=val;
str.clear();
SYS5VPowerFile>>str;
val=atoi(str.c_str());
cout<<"SYS5V Power:"<<val<<"mW"<<endl;
power+=val;
str.clear();
gpuPowerFile.close();
cpuPowerFile.close();
SOCPowerFile.close();
CVPowerFile.close();
DDRPowerFile.close();
SYS5VPowerFile.close();
cout<<"Total Power:"<<power<<"mW"<<endl;
sumofPower+=power;
totalCount++;
cout<<"AveragePower: "<<sumofPower/totalCount<<endl;
time_t end=time(NULL);
cout<<"Time: "<<(double)(end-start)<<endl;
sleep(1);
}
}
It’s pretty simple. this code open information file, calculate average power consumption, and print it for every second.
Here is the other code for Jetson Nano
Jetson Nano Software-based Power Consumption Monitoring
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <termio.h>
#include <unistd.h>
#include <time.h>using namespace std;
int main(){
ifstream gpuPowerFile,cpuPowerFile,SOCPowerFile,CVPowerFile,DDRPowerFile,SYS5VPowerFile;
int totalCount=0;
int sumofPower=0;
char input=0;
time_t start=time(NULL);
while(true){
string str;
int power=0;
int voltage=0;
int val;
gpuPowerFile.open("/sys/bus/i2c/drivers/ina3221x/6-0040/iio:device0/in_power1_input");
cpuPowerFile.open("/sys/bus/i2c/drivers/ina3221x/6-0040/iio:device0/in_power2_input");
SOCPowerFile.open("/sys/bus/i2c/drivers/ina3221x/6-0040/iio:device0//in_power0_input");
gpuPowerFile>>str;
val=atoi(str.c_str());
cout<<"GPU Power:"<<val<<"mW"<<endl;
power+=val;
str.clear();
cpuPowerFile>>str;
val=atoi(str.c_str());
cout<<"CPU Power:"<<val<<"mW"<<endl;
power+=val;
str.clear();
SOCPowerFile>>str;
val=atoi(str.c_str());
cout<<"IN Power:"<<val<<"mW"<<endl;
power+=val;
str.clear();
gpuPowerFile.close();
cpuPowerFile.close();
SOCPowerFile.close();
cout<<"Total Power:"<<power<<"mW"<<endl;
sumofPower+=power;
totalCount++;
cout<<"AveragePower: "<<sumofPower/totalCount<<endl;
time_t end=time(NULL);
cout<<"Time: "<<(double)(end-start)<<endl;
sleep(1);
}
}