Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AGX/Xavier support #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void display_cpu_stats(const int & row, const tegrastats & ts) {

if (ts.version == TX1)
display_bars(row+idx, BAR_OFFSET, u, ts.cpu_freq.at(0));
else if (ts.version == TX2)
else if (ts.version == TX2 || ts.version == AGX)
display_bars(row+idx, BAR_OFFSET, u, ts.cpu_freq.at(idx));

idx++;
Expand Down
2 changes: 1 addition & 1 deletion display.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const int WIDGET_MAX_COLS_INT8 = 100;
const float WIDGET_MAX_COLS_F32 = 100.0;
const float WIDGET_WIDTH = 0.7;

const int MEM_BUFFER_SIZE = 20;
const int MEM_BUFFER_SIZE = 60;
const float MEGA2GIGA = 1000.0;

struct bar {
Expand Down
31 changes: 29 additions & 2 deletions gtop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ tegrastats parse_tegrastats(const char * buffer) {
tegrastats ts;
auto stats = tokenize(buffer, ' ');

if (stats.size() >= 15)
if (stats.size() >= 15 && stats.size() <30) //Don't have TX* to test..
ts.version = TX1;
else if(stats.size() >=30)
ts.version = AGX;
else
ts.version = TX2;

Expand All @@ -134,6 +136,10 @@ tegrastats parse_tegrastats(const char * buffer) {
break;
case TK1: // TODO
break;
case AGX:
get_cpu_stats_agx(ts, stats.at(5));
get_gpu_stats(ts, stats.at(9));
break;
}

return ts;
Expand Down Expand Up @@ -173,10 +179,31 @@ void get_cpu_stats_tx2(tegrastats & ts, const std::string & str) {
}
}

void get_cpu_stats_agx(tegrastats & ts, const std::string & str) {
const auto cpu_stats = tokenize(str.substr(1, str.size()-1), ',');
const auto at = std::string("@");

for (const auto & u: cpu_stats) {
if (u.length() > 5) {
std::size_t found = at.find(u);
if (found == std::string::npos) {
auto cpu_info = tokenize(u, at.c_str()[0]);
ts.cpu_usage.push_back(std::stoi(cpu_info.at(0).substr(0, cpu_info.at(0).size()-1)));
ts.cpu_freq.push_back(std::stoi(cpu_info.at(1)));

}
}
else {
ts.cpu_usage.push_back(0);
ts.cpu_freq.push_back(0);
}
}
}

void get_gpu_stats(tegrastats & ts, const std::string & str) {
const auto gpu_stats = tokenize(str, '@');
const auto gpu_usage = gpu_stats.at(0);

ts.gpu_usage = std::stoi(gpu_usage.substr(0, gpu_usage.size()-1));
ts.gpu_freq = std::stoi(gpu_stats.at(1));
}
Expand Down
3 changes: 2 additions & 1 deletion gtop.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "display.hh"
#include "utils.hh"

const int STATS_BUFFER_SIZE = 256;
const int STATS_BUFFER_SIZE = 512;

const std::string TEGRASTATS_PATH = "~/tegrastats";
const std::string TEGRASTATSFAKE_PATH = "./tegrastats_fake";
Expand All @@ -31,6 +31,7 @@ tegrastats parse_tegrastats(const char *);

void get_cpu_stats_tx1(tegrastats &, const std::string &);
void get_cpu_stats_tx2(tegrastats &, const std::string &);
void get_cpu_stats_agx(tegrastats &, const std::string &);
void get_gpu_stats(tegrastats &, const std::string &);
void get_mem_stats(tegrastats &, const std::string &);

Expand Down
2 changes: 1 addition & 1 deletion utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <sys/stat.h>
#include <wordexp.h>

enum jetson_version {TK1, TX1, TX2};
enum jetson_version {TK1, TX1, TX2, AGX};

struct tegrastats {
int mem_usage;
Expand Down