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

std::out_of_range exception #1

Open
lalten opened this issue Nov 15, 2017 · 14 comments
Open

std::out_of_range exception #1

lalten opened this issue Nov 15, 2017 · 14 comments

Comments

@lalten
Copy link

lalten commented Nov 15, 2017

$ 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
Copy link
Owner

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
Copy link

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
Copy link
Author

lalten commented Nov 16, 2017

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
Copy link

HoneyPatouceul commented Dec 28, 2017

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
Copy link

ghost commented Feb 19, 2018

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
Copy link

HoneyPatouceul commented Feb 19, 2018

Added support for TX1 R28.1.

gtop.cc.txt

@ghost
Copy link

ghost commented Feb 19, 2018

Hi HoneyPatouceul,

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

Thanks!

@ghost
Copy link

ghost commented Feb 20, 2018

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
Copy link

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
Copy link

ghost commented Feb 21, 2018

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!

YoshiRi added a commit to YoshiRi/gtop that referenced this issue Jun 3, 2018
@ppizzo
Copy link

ppizzo commented Nov 7, 2018

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
Copy link

ppizzo commented Nov 7, 2018

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants