Skip to contentSkip to conversation

v4l2-tracer: fix trace path name creation

PATCH In review Peter Seiderer 2 participants 2 messages Mar 30, 2023 – Mar 31, 2023 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 v4l2-tracer: fix trace path name creation

Fix trace path name creation for poor man's development boards (e.g. Raspberry Pi) without RTC (starting at unix epoche aka time 0) by forcing initial trace_id creation with 6 valid digits.

Fixes:

terminate called after throwing an instance of 'std::out_of_range'

    what():  basic_string::substr: __pos (which is 5) > this->size() (which is 3)

Aborted

---
 utils/v4l2-tracer/v4l2-tracer.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
utils/v4l2-tracer/v4l2-tracer.cpp +2 -4
index cb873d83..1a9a7d75 100644
@@ -241,11 +241,9 @@ int tracer(int argc, char *argv[], bool retrace)
 		trace_id = json_file_name.substr(0, json_file_name.find(".json"));
 		trace_id += "_retrace";
 	} else {
-		const int timestamp_start_pos = 5;
-		trace_id = std::to_string(time(nullptr));
-		// trace_id = trace_id.substr(timestamp_start_pos, std::string::npos) + "_trace";
+		const int timestamp_start_pos = 1;
+		trace_id = std::to_string(100000 + time(nullptr) % 100000);
 		trace_id = trace_id.substr(timestamp_start_pos) + "_trace";
-
 	}
 	setenv("TRACE_ID", trace_id.c_str(), 0);
 	std::string trace_filename = trace_id + ".json";
Signature · 1 line
2.40.0
#1 lore raw
Quoted 20 lines · Peter Seiderer

Fix trace path name creation for poor man's development boards (e.g. Raspberry Pi) without RTC (starting at unix epoche aka time 0) by forcing initial trace_id creation with 6 valid digits.

Fixes:

terminate called after throwing an instance of 'std::out_of_range'

    what():  basic_string::substr: __pos (which is 5) > this->size() (which is 3)

Aborted

---
 utils/v4l2-tracer/v4l2-tracer.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
utils/v4l2-tracer/v4l2-tracer.cpp +0 -0
index cb873d83..1a9a7d75 100644

utils/v4l2-tracer/v4l2-tracer.cpp int tracer(int argc, char *argv[], bool retrace) · line 248

Quoted 10 lines
utils/v4l2-tracer/v4l2-tracer.cpp +2 -4
@@ -241,11 +241,9 @@ int tracer(int argc, char *argv[], bool retrace)
 		trace_id = json_file_name.substr(0, json_file_name.find(".json"));
 		trace_id += "_retrace";
 	} else {
-		const int timestamp_start_pos = 5;
-		trace_id = std::to_string(time(nullptr));
-		// trace_id = trace_id.substr(timestamp_start_pos, std::string::npos) + "_trace";
+		const int timestamp_start_pos = 1;
+		trace_id = std::to_string(100000 + time(nullptr) % 100000);
 		trace_id = trace_id.substr(timestamp_start_pos) + "_trace";
-

Thanks for this patch, I checked and the file names are still working as expected for traced, retraced and cleaned files, so looks good to me.

Quoted 6 lines
utils/v4l2-tracer/v4l2-tracer.cpp +0 -0
 	}
 	setenv("TRACE_ID", trace_id.c_str(), 0);
 	std::string trace_filename = trace_id + ".json";
Signature · 1 line
2.40.0