martinkersner / gtop

CPU, GPU and memory viewer utilizing information provided by tegrastats
GNU General Public License v3.0
91 stars 49 forks source link

std::out_of_range exception #1

Open lalten opened 6 years ago

lalten commented 6 years ago
$ sudo ./gtop 
terminate called after throwing an instance of 'std::out_of_range'
                                                                    what():  vector::_M_range_check: __n (which is 1) >= this->size() (which is 1)
                                                                                                                                                  Aborted (core dumped)

I built the code with $ g++ -std=c++14 gtop.cc utils.cc display.cc -o gtop -pedantic -Wall -Wextra -lncurses -lpthread -g and gdb reveals:

(gdb) bt
#0  0x0000007fb7f0e30c in __pthread_cond_wait (cond=0x423718 <cv>, mutex=0x4236e8 <m>) at pthread_cond_wait.c:186
#1  0x0000007fb7e24e10 in std::condition_variable::wait(std::unique_lock<std::mutex>&) () from /usr/lib/aarch64-linux-gnu/libstdc++.so.6
#2  0x00000000004048dc in std::condition_variable::wait<main()::<lambda()> >(std::unique_lock<std::mutex> &, <lambda()>) (this=0x423718 <cv>, __lock=..., __p=...) at /usr/include/c++/5/condition_variable:98
#3  0x00000000004039d8 in main () at gtop.cc:45

This is on a Nvidia Jetson TX2 with ubuntu 16.04.03 and kernel 4.4.38

martinkersner commented 6 years ago

Hi @lalten ,

It could be caused by different output of tegrastats, maybe the output format changed. Unfortunately, I don't have access to TX2 anymore, so I can't debug it.

Cheers Martin

Survial53 commented 6 years ago

Hi @lalten, to resolve this issue need next change: replase string get_gpu_stats(ts, stats.at(13)); to get_gpu_stats(ts, stats.at(11)); in file [gtop.cc]() ( function: tegrastats parse_tegrastats(const char * buffer)).

As @martinkersner said, it looks like the format has be changed.

lalten commented 6 years ago

Thanks for the suggestion @Survial53. Unfortunately, I get the same error.

My diff is

diff --git a/gtop.cc b/gtop.cc
index d511ebc..7d9e0fd 100644
--- a/gtop.cc
+++ b/gtop.cc
@@ -130,7 +130,7 @@ tegrastats parse_tegrastats(const char * buffer) {
       break;
     case TX2:
       get_cpu_stats_tx2(ts, stats.at(5));
-      get_gpu_stats(ts, stats.at(13));
+      get_gpu_stats(ts, stats.at(11));
       break;
     case TK1: // TODO
       break;

The output of sudo ~/tegrastats looks like this:

$ sudo ~/tegrastats 
RAM 3210/7851MB (lfb 50x512kB) SWAP 160/8192MB (cached 11MB) cpu [0%@1574,off,off,0%@1574,0%@1575,0%@1575] EMC 32%@1600 APE 150 NVDEC 268 MSENC 1164 GR3D 99%@726
RAM 3210/7851MB (lfb 50x512kB) SWAP 160/8192MB (cached 11MB) cpu [46%@499,off,off,41%@499,32%@501,26%@499] EMC 32%@1600 APE 150 NVDEC 268 MSENC 1164 GR3D 99%@522
RAM 3210/7851MB (lfb 50x512kB) SWAP 160/8192MB (cached 11MB) cpu [48%@652,off,off,40%@653,38%@655,34%@655] EMC 32%@1600 APE 150 NVDEC 268 MSENC 1164 GR3D 93%@930
RAM 3210/7851MB (lfb 50x512kB) SWAP 160/8192MB (cached 11MB) cpu [43%@960,off,off,39%@959,36%@960,40%@960] EMC 32%@1600 APE 150 NVDEC 268 MSENC 1164 GR3D 94%@726
HoneyPatouceul commented 6 years ago

You may have to increase STATS_BUFFER_SIZE in file gtop.hh, for example: const int STATS_BUFFER_SIZE = 512; Also note that the test for which Jetson relying on tegrastats output length is no longer valid, so it may think it is a TX1.

On TX2 with R28.2.0, the right indexes for cpu info and gpu info are 5 and 9. Note however that enabling swap would change these. Below is dirty attempt gtop.cc to make it more versatile (currently only works with TX2 on L4T R28.2.0, but should be easy to add support for other targets): gtop.cc.txt

ghost commented 6 years ago

Hi Martin, I am trying to use your tool of GUI for Tegra TX1. However I am getting the folling compilation warning

root@tegra-ubuntu:~/gstop/gtop-master# make g++ -std=c++11 gtop.cc utils.cc display.cc -o gtop -pedantic -Wall -Wextra -lncurses -lpthread gtop.cc:193:6: warning: unused parameter ‘d’ [-Wunused-parameter] void display_stats(const dimensions & d, const tegrastats & ts) {

then when I execute the sudo ./gtop. I am getting the following error. root@tegra-ubuntu:~/gstop/gtop-master# ./gtop terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check Aborted Even I have increased the c const int STATS_BUFFER_SIZE = 1024;

But still nothing works!

This is the output I get from the ~/tegrastats

RAM 748/3854MB (lfb 676x4MB) SWAP 0/0MB (cached 0MB) cpu [14%,43%,11%,12%]@1912 EMC 24%@1600 AVP 82%@13 VDE 0 GR3D 52%@998 EDP limit 1912 RAM 748/3854MB (lfb 676x4MB) SWAP 0/0MB (cached 0MB) cpu [25%,40%,9%,6%]@1912 EMC 19%@1600 AVP 70%@12 VDE 0 GR3D 51%@921 EDP limit 1912 RAM 748/3854MB (lfb 676x4MB) SWAP 0/0MB (cached 0MB) cpu [71%,26%,32%,20%]@1912 EMC 23%@1600 AVP 41%@12 VDE 0 GR3D 83%@921 EDP limit 1912 RAM 748/3854MB (lfb 676x4MB) SWAP 0/0MB (cached 0MB) cpu [96%,27%,38%,30%]@1912 EMC 26%@1600 AVP 13%@12 VDE 0 GR3D 51%@921 EDP limit 1912

Could you please help me fix this problem.

Thanks!

HoneyPatouceul commented 6 years ago

Added support for TX1 R28.1.

gtop.cc.txt

ghost commented 6 years ago

Hi HoneyPatouceul,

Thanks a lot! I will test the code, when I have access to the machine in the morning.

Thanks!

ghost commented 6 years ago

Hi Honeypatouceul,

I have tried your gtop.cc.txt but still it does not work. I am getting this following error.

[sudo] password for ubuntu: Found L4T version 23-1.1 Error: CPU index undefined for L4T version 23-1.1

Could you please help me to fix this issue.

Thanks !

HoneyPatouceul commented 6 years ago

I have added support for R28.1, but you're running a very old R23.1 version. You would have to create indexes for R23.1 such as :

static const std::map<std::string, int> TX1cpuIdxMap = {
    std::make_pair ("23-1.1", 5),
    std::make_pair ("28-1.0", 5)
};
static const std::map<std::string, int> TX1gpuIdxMap = {
    std::make_pair ("23-1.1", 11),
    std::make_pair ("28-1.0", 7)
};

Not sure about the GPU index (11), you should check and may let us know.

ghost commented 6 years ago

Its working for 23.1

static const std::map<std::string, int> TX1cpuIdxMap = { std::make_pair ("23-1.1", 5), std::make_pair ("28-1.0", 5) }; static const std::map<std::string, int> TX1gpuIdxMap = { std::make_pair ("23-1.1", 7), std::make_pair ("28-1.0", 7) };

The GPU index is same as the R28.1, that is (7)

Thanks!

ppizzo commented 5 years ago

Hi, I modified gtop.cc in order to work on TX1 with L4T version 28-2.0. Below the changes (on top of new gtop.cc linked by @HoneyPatouceul some posts ago):

Added new indexes for 28-2.0:

static const std::map<std::string, int> TX1cpuIdxMap = {
        std::make_pair ("28-1.0", 5),
        std::make_pair ("28-2.0", 8)
};
static const std::map<std::string, int> TX1gpuIdxMap = {
        std::make_pair ("28-1.0", 7),
        std::make_pair ("28-2.0", 12)
};

I do not have a TX2 to check, but the format of tegrastats' output should be the same, at least for CPU and GR3D_FREQ metrics. Therefore I just modified get_cpu_stats_tx1() with a straightforward pass through call to the corresponding TX2 function:

void get_cpu_stats_tx1(tegrastats & ts, const std::string & str) {
  return get_cpu_stats_tx2(ts, str);
}

It works now on my TX1.

Hope it helps!

Pietro

ppizzo commented 5 years ago

Below the patch:

--- gtop.cc 2018-11-07 20:47:56.483822500 +0100
+++ gtop.cc.txt 2018-02-19 17:36:47.000000000 +0100
@@ -8,7 +8,6 @@
 std::mutex m;
 std::condition_variable cv;
 tegrastats t_stats;
-char l4t_version[8];

 bool processed = false;
 bool ready     = false;
@@ -21,12 +20,10 @@
 static const std::map<std::string, int> TK1gpuIdxMap = {
 };
 static const std::map<std::string, int> TX1cpuIdxMap = {
-   std::make_pair ("28-1.0", 5),
-   std::make_pair ("28-2.0", 8)
+   std::make_pair ("28-1.0", 5)
 };
 static const std::map<std::string, int> TX1gpuIdxMap = {
-   std::make_pair ("28-1.0", 7),
-   std::make_pair ("28-2.0", 12)
+   std::make_pair ("28-1.0", 7)
 };
 static const std::map<std::string, int> TX2cpuIdxMap = {
    std::make_pair ("28-2.0", 5)
@@ -82,6 +79,7 @@
   }
   fclose(fid);

+  char l4t_version[8];
   l4t_version[0] = l4tStr[3];
   l4t_version[1] = l4tStr[4];
   l4t_version[2] = '-';
@@ -269,20 +267,16 @@
 }

 void get_cpu_stats_tx1(tegrastats & ts, const std::string & str) {
-  if (strcmp(l4t_version, "28-2.0")>=0)
-    return get_cpu_stats_tx2(ts, str);
-  else {
-    auto cpu_stats = tokenize(str, '@');
-    auto cpu_usage_all = cpu_stats.at(0);
-    ts.cpu_freq.push_back(std::stoi(cpu_stats.at(1)));
-    auto cpu_usage = tokenize(cpu_usage_all.substr(1, cpu_usage_all.size()-2), ',');
-
-    for (const auto & u: cpu_usage) {
-      if (u != "off")
-        ts.cpu_usage.push_back(std::stoi(u.substr(0, u.size()-1)));
-      else
-        ts.cpu_usage.push_back(0);
-    }
+  auto cpu_stats = tokenize(str, '@');
+  auto cpu_usage_all = cpu_stats.at(0);
+  ts.cpu_freq.push_back(std::stoi(cpu_stats.at(1)));
+  auto cpu_usage = tokenize(cpu_usage_all.substr(1, cpu_usage_all.size()-2), ',');
+
+  for (const auto & u: cpu_usage) {
+    if (u != "off")
+      ts.cpu_usage.push_back(std::stoi(u.substr(0, u.size()-1)));
+    else
+      ts.cpu_usage.push_back(0);
   }
 }
nextsunday commented 5 years ago

Below the patch:

--- gtop.cc   2018-11-07 20:47:56.483822500 +0100
+++ gtop.cc.txt   2018-02-19 17:36:47.000000000 +0100
@@ -8,7 +8,6 @@
 std::mutex m;
 std::condition_variable cv;
 tegrastats t_stats;
-char l4t_version[8];

 bool processed = false;
 bool ready     = false;
@@ -21,12 +20,10 @@
 static const std::map<std::string, int> TK1gpuIdxMap = {
 };
 static const std::map<std::string, int> TX1cpuIdxMap = {
- std::make_pair ("28-1.0", 5),
- std::make_pair ("28-2.0", 8)
+ std::make_pair ("28-1.0", 5)
 };
 static const std::map<std::string, int> TX1gpuIdxMap = {
- std::make_pair ("28-1.0", 7),
- std::make_pair ("28-2.0", 12)
+ std::make_pair ("28-1.0", 7)
 };
 static const std::map<std::string, int> TX2cpuIdxMap = {
  std::make_pair ("28-2.0", 5)
@@ -82,6 +79,7 @@
   }
   fclose(fid);

+  char l4t_version[8];
   l4t_version[0] = l4tStr[3];
   l4t_version[1] = l4tStr[4];
   l4t_version[2] = '-';
@@ -269,20 +267,16 @@
 }

 void get_cpu_stats_tx1(tegrastats & ts, const std::string & str) {
-  if (strcmp(l4t_version, "28-2.0")>=0)
-    return get_cpu_stats_tx2(ts, str);
-  else {
-    auto cpu_stats = tokenize(str, '@');
-    auto cpu_usage_all = cpu_stats.at(0);
-    ts.cpu_freq.push_back(std::stoi(cpu_stats.at(1)));
-    auto cpu_usage = tokenize(cpu_usage_all.substr(1, cpu_usage_all.size()-2), ',');
-
-    for (const auto & u: cpu_usage) {
-      if (u != "off")
-        ts.cpu_usage.push_back(std::stoi(u.substr(0, u.size()-1)));
-      else
-        ts.cpu_usage.push_back(0);
-    }
+  auto cpu_stats = tokenize(str, '@');
+  auto cpu_usage_all = cpu_stats.at(0);
+  ts.cpu_freq.push_back(std::stoi(cpu_stats.at(1)));
+  auto cpu_usage = tokenize(cpu_usage_all.substr(1, cpu_usage_all.size()-2), ',');
+
+  for (const auto & u: cpu_usage) {
+    if (u != "off")
+      ts.cpu_usage.push_back(std::stoi(u.substr(0, u.size()-1)));
+    else
+      ts.cpu_usage.push_back(0);
   }
 }

Thanks for your correction. But it is not work on my Jetson Nano. Can you add more code for Jetson Nano.

Thanks in advance.

peterlee909 commented 4 years ago

Same error. Did anybody fix the problem? Does gtop work on DRIVE Xavier?