gtop icon indicating copy to clipboard operation
gtop copied to clipboard

std::out_of_range exception

Open lalten opened this issue 8 years ago • 14 comments

$ 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

lalten avatar Nov 15 '17 13:11 lalten

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

martinkersner avatar Nov 16 '17 01:11 martinkersner

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.

Survial53 avatar Nov 16 '17 09:11 Survial53

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

lalten avatar Nov 16 '17 13:11 lalten

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

HoneyPatouceul avatar Dec 28 '17 17:12 HoneyPatouceul

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!

ghost avatar Feb 19 '18 10:02 ghost

Added support for TX1 R28.1.

gtop.cc.txt

HoneyPatouceul avatar Feb 19 '18 16:02 HoneyPatouceul

Hi HoneyPatouceul,

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

Thanks!

ghost avatar Feb 19 '18 21:02 ghost

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 !

ghost avatar Feb 20 '18 10:02 ghost

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.

HoneyPatouceul avatar Feb 20 '18 13:02 HoneyPatouceul

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!

ghost avatar Feb 21 '18 09:02 ghost

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 avatar Nov 07 '18 14:11 ppizzo

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);
   }
 }

ppizzo avatar Nov 07 '18 14:11 ppizzo

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.

nextsunday avatar Apr 26 '19 08:04 nextsunday

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

peterlee909 avatar Feb 24 '20 08:02 peterlee909