Skip to contentSkip to conversation

v4l2-tracer: debug messages

PATCH New Deborah Brouwer 1 participant 3 messages Apr 11, 2023 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

v2 cover v4l2-tracer: debug messages

Changes since v1:
- split into two patches
- first patch moves debug option-checking out
of main code and into debug functions
- second patch introduces and applies the macro
for printing file, function and line number

Deborah Brouwer (2):
v4l2-tracer: print only if debugging option is set
v4l2-tracer: add macros to print debug info

 utils/v4l2-tracer/libv4l2tracer.cpp      |  35 ++----
 utils/v4l2-tracer/retrace-helper.cpp     |  41 +++----
 utils/v4l2-tracer/retrace.cpp            | 129 ++++++++---------------
 utils/v4l2-tracer/trace-helper.cpp       |  52 +++------
 utils/v4l2-tracer/trace.cpp              |  15 +--
 utils/v4l2-tracer/v4l2-tracer-common.cpp |   6 +-
 utils/v4l2-tracer/v4l2-tracer-common.h   |  16 +++
 utils/v4l2-tracer/v4l2-tracer.cpp        |  45 +++-----
 8 files changed, 121 insertions(+), 218 deletions(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH v2 1/2 v4l2-tracer: print only if debugging option is set

When a print function is used only for debugging, check for the debug option within the print function itself. This makes the main code easier to read.

---
 utils/v4l2-tracer/libv4l2tracer.cpp  |  6 +++---
 utils/v4l2-tracer/retrace-helper.cpp |  2 ++
 utils/v4l2-tracer/retrace.cpp        | 22 +++++++++++-----------
 utils/v4l2-tracer/trace-helper.cpp   | 13 +++++++++----
 4 files changed, 25 insertions(+), 18 deletions(-)
utils/v4l2-tracer/libv4l2tracer.cpp +3 -3
index a9f039c7..cc7d5657 100644
@@ -83,8 +83,8 @@ int open(const char *path, int oflag, ...)
 
 	if (is_debug()) {
 		fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-		print_devices();
 	}
+	print_devices();
 
 	return fd;
 }
@@ -119,8 +119,8 @@ int open64(const char *path, int oflag, ...)
 
 	if (is_debug()) {
 		fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-		print_devices();
 	}
+	print_devices();
 
 	return fd;
 }
@@ -156,8 +156,8 @@ int close(int fd)
 
 	if (is_debug()) {
 		fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-		print_devices();
 	}
+	print_devices();
 
 	return (*original_close)(fd);
 }
utils/v4l2-tracer/retrace-helper.cpp +2 -0
index 03b0466b..f58987ac 100644
@@ -256,6 +256,8 @@ void compare_program_versions(json_object *v4l2_tracer_info_obj)
 
 void print_context(void)
 {
+	if (!is_debug())
+		return;
 	print_fds();
 	print_buffers_retrace();
 	fprintf(stderr, "\n");
utils/v4l2-tracer/retrace.cpp +11 -11
index 8667826c..0e6600da 100644
@@ -59,8 +59,8 @@ void retrace_mmap(json_object *mmap_obj, bool is_mmap64)
 			perror("mmap");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 		exit(EXIT_FAILURE);
 	}
 
@@ -82,8 +82,8 @@ void retrace_mmap(json_object *mmap_obj, bool is_mmap64)
 			perror("mmap");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 	}
 }
 
@@ -176,8 +176,8 @@ void retrace_open(json_object *jobj, bool is_open64)
 			perror("open");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 	}
 }
 
@@ -199,8 +199,8 @@ void retrace_close(json_object *jobj)
 		perror("close");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 	}
 }
 
@@ -354,8 +354,8 @@ void retrace_vidioc_querybuf(int fd_retrace, json_object *ioctl_args_user)
 		perror("VIDIOC_QUERYBUF");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 	}
 
 	free(buf);
@@ -380,8 +380,8 @@ void retrace_vidioc_qbuf(int fd_retrace, json_object *ioctl_args_user)
 		perror("VIDIOC_QBUF");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 	}
 
 	free(ptr);
@@ -417,8 +417,8 @@ void retrace_vidioc_dqbuf(int fd_retrace, json_object *ioctl_args_user)
 		perror("VIDIOC_DQBUF");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 	}
 
 	if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
@@ -440,8 +440,8 @@ void retrace_vidioc_prepare_buf(int fd_retrace, json_object *ioctl_args_user)
 		perror("VIDIOC_PREPARE_BUF");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 	}
 
 	if (buf->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ||
@@ -460,8 +460,8 @@ void retrace_vidioc_create_bufs(int fd_retrace, json_object *ioctl_args)
 		perror("VIDIOC_CREATE_BUFS");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 	}
 
 	free(ptr);
@@ -967,8 +967,8 @@ void retrace_vidioc_s_ext_ctrls(int fd_retrace, json_object *ioctl_args)
 		perror("VIDIOC_S_EXT_CTRLS");
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_context();
 		}
+		print_context();
 	}
 }
 
@@ -1352,8 +1352,8 @@ void retrace_mem(json_object *mem_obj)
 		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
 		fprintf(stderr, "%s, bytesused: %d, offset: %d, addr: %ld\n",
 		        buftype2s(type).c_str(), bytesused, offset, buffer_address_retrace);
-		print_context();
 	}
+	print_context();
 }
 
 void retrace_object(json_object *jobj)
utils/v4l2-tracer/trace-helper.cpp +9 -4
index 0030272b..0b6382ee 100644
@@ -39,6 +39,8 @@ std::string get_device(int fd)
 
 void print_devices(void)
 {
+	if (!is_debug())
+		return;
 	if (ctx_trace.devices.size())
 		fprintf(stderr, "Devices:\n");
 	for (auto &device_pair : ctx_trace.devices)
@@ -47,6 +49,8 @@ void print_devices(void)
 
 void print_decode_order(void)
 {
+	if (!is_debug())
+		return;
 	fprintf(stderr, "Decode order: ");
 	for (auto &num : ctx_trace.decode_order)
 		fprintf(stderr, "%ld, ",  num);
@@ -65,8 +69,7 @@ void set_decode_order(long decode_order)
 	if (it == ctx_trace.decode_order.end())
 		ctx_trace.decode_order.push_front(decode_order);
 
-	if (is_debug())
-		print_decode_order();
+	print_decode_order();
 }
 
 long get_decode_order(void)
@@ -230,6 +233,8 @@ bool buffer_is_mapped(unsigned long buffer_address)
 
 void print_buffers_trace(void)
 {
+	if (!is_debug())
+		return;
 	for (auto &b : ctx_trace.buffers) {
 		fprintf(stderr, "fd: %d, %s, index: %d, display_order: %ld, bytesused: %d, ",
 		        b.fd, buftype2s(b.type).c_str(), b.index, b.display_order, b.bytesused);
@@ -367,9 +372,9 @@ void qbuf_setup(struct v4l2_buffer *buf)
 
 		if (is_debug()) {
 			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-			print_decode_order();
-			print_buffers_trace();
 		}
+		print_decode_order();
+		print_buffers_trace();
 	}
 }
 
Signature · 1 line
2.39.1
#2 lore raw

PATCH v2 2/2 v4l2-tracer: add macros to print debug info

In reply to Deborah Brouwer

Instead of repeating the same code to print file, function and line info, replace it with a macro so that it is easier to read and maintain. Use the line_info() macro if the information should always be printed, otherwise use debug_line_info() to print only when the debug option is set.

Use __FILE_NAME__ (if available) instead of __FILE__ to avoid printing the entire relative path of the file location.

---
 utils/v4l2-tracer/libv4l2tracer.cpp      |  29 +-----
 utils/v4l2-tracer/retrace-helper.cpp     |  39 +++------
 utils/v4l2-tracer/retrace.cpp            | 107 +++++++----------------
 utils/v4l2-tracer/trace-helper.cpp       |  39 ++-------
 utils/v4l2-tracer/trace.cpp              |  15 ++--
 utils/v4l2-tracer/v4l2-tracer-common.cpp |   6 +-
 utils/v4l2-tracer/v4l2-tracer-common.h   |  16 ++++
 utils/v4l2-tracer/v4l2-tracer.cpp        |  45 ++++------
 8 files changed, 96 insertions(+), 200 deletions(-)
utils/v4l2-tracer/libv4l2tracer.cpp +3 -26
index cc7d5657..2ab2fbe4 100644
@@ -67,11 +67,7 @@ int open(const char *path, int oflag, ...)
 	int (*original_open)(const char *path, int oflag, ...) = nullptr;
 	original_open = (int (*)(const char*, int, ...)) dlsym(RTLD_NEXT, "open");
 	int fd = (*original_open)(path, oflag, mode);
-
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "fd: %d, path: %s\n", fd, path);
-	}
+	debug_line_info("\n\tfd: %d, path: %s", fd, path);
 
 	if (getenv("V4L2_TRACER_PAUSE_TRACE") != nullptr)
 		return fd;
@@ -80,10 +76,6 @@ int open(const char *path, int oflag, ...)
 		trace_open(fd, path, oflag, mode, false);
 		add_device(fd, path);
 	}
-
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-	}
 	print_devices();
 
 	return fd;
@@ -103,11 +95,7 @@ int open64(const char *path, int oflag, ...)
 	int (*original_open64)(const char *path, int oflag, ...) = nullptr;
 	original_open64 = (int (*)(const char*, int, ...)) dlsym(RTLD_NEXT, "open64");
 	int fd = (*original_open64)(path, oflag, mode);
-
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "fd: %d, path: %s\n", fd, path);
-	}
+	debug_line_info("\n\tfd: %d, path: %s", fd, path);
 
 	if (getenv("V4L2_TRACER_PAUSE_TRACE") != nullptr)
 		return fd;
@@ -116,10 +104,6 @@ int open64(const char *path, int oflag, ...)
 		add_device(fd, path);
 		trace_open(fd, path, oflag, mode, true);
 	}
-
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-	}
 	print_devices();
 
 	return fd;
@@ -135,10 +119,7 @@ int close(int fd)
 		return (*original_close)(fd);
 
 	std::string path = get_device(fd);
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "fd: %d, path: %s\n", fd, path.c_str());
-	}
+	debug_line_info("\n\tfd: %d, path: %s", fd, path.c_str());
 
 	/* Only trace the close if a corresponding open was also traced. */
 	if (!path.empty()) {
@@ -153,10 +134,6 @@ int close(int fd)
 		if (!ctx_trace.devices.size())
 			close_json_file();
 	}
-
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-	}
 	print_devices();
 
 	return (*original_close)(fd);
utils/v4l2-tracer/retrace-helper.cpp +12 -27
index f58987ac..3c68986f 100644
@@ -118,18 +118,12 @@ std::string get_path_retrace_from_path_trace(std::string path_trace, json_object
 	/* If user set the media or video path just return that path. */
 	if (is_media && (getenv("V4L2_TRACER_OPTION_SET_MEDIA_DEVICE") != nullptr)) {
 		path_media = getenv("V4L2_TRACER_OPTION_SET_MEDIA_DEVICE");
-		if (is_debug()) {
-			fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-			fprintf(stderr, "Use path set by user: %s ", path_media.c_str());
-		}
+		debug_line_info("\n\tUse path set by user: %s", path_media.c_str());
 		return path_media;
 	}
 	if (is_video && (getenv("V4L2_TRACER_OPTION_SET_VIDEO_DEVICE") != nullptr)) {
 		path_video = getenv("V4L2_TRACER_OPTION_SET_VIDEO_DEVICE");
-		if (is_debug()) {
-			fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-			fprintf(stderr, "Use path set by user: %s ", path_video.c_str());
-		}
+		debug_line_info("\n\tUse path set by user: %s", path_video.c_str());
 		return path_video;
 	}
 
@@ -143,8 +137,7 @@ std::string get_path_retrace_from_path_trace(std::string path_trace, json_object
 
 	path_media = get_path_media(driver);
 	if (path_media.empty()) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "warning: driver: %s not found\n", driver.c_str());
+		line_info("\n\tWarning: driver: \'%s\' not found.", driver.c_str());
 		return "";
 	}
 
@@ -206,21 +199,15 @@ void write_to_output_buffer(unsigned char *buffer_pointer, int bytesused, json_o
 				i++;
 				byteswritten++;
 			} catch (std::invalid_argument& ia) {
-				fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-				fprintf(stderr, "\'%s\' is an invalid argument.\n",
-				        compressed_video_data.substr(i,2).c_str());
+				line_info("\n\t\'%s\' is an invalid argument.\n",
+				          compressed_video_data.substr(i,2).c_str());
 			} catch (std::out_of_range& oor) {
-				fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-				fprintf(stderr, "\'%s\' is out of range.\n",
-				        compressed_video_data.substr(i,2).c_str());
+				line_info("\n\t\'%s\' is out of range.\n",
+				          compressed_video_data.substr(i,2).c_str());
 			}
 		}
 	}
-
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "bytesused: %d, byteswritten: %d\n", bytesused, byteswritten);
-	}
+	debug_line_info("\n\tbytesused: %d, byteswritten: %d", bytesused, byteswritten);
 }
 
 void compare_program_versions(json_object *v4l2_tracer_info_obj)
@@ -232,9 +219,8 @@ void compare_program_versions(json_object *v4l2_tracer_info_obj)
 		package_version_trace = json_object_get_string(package_version_obj);
 	std::string package_version_retrace = PACKAGE_VERSION;
 	if (package_version_trace != package_version_retrace) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "warning: trace package version \'%s\' does not match current: \'%s\':\n",
-		        package_version_trace.c_str(), package_version_retrace.c_str());
+		line_info("\n\tWarning: trace package version \'%s\' does not match current: \'%s\'",
+		          package_version_trace.c_str(), package_version_retrace.c_str());
 		print_v4l2_tracer_info();
 		return;
 	}
@@ -246,9 +232,8 @@ void compare_program_versions(json_object *v4l2_tracer_info_obj)
 		git_sha_trace = json_object_get_string(git_sha_obj);
 	std::string git_sha_retrace = (STRING(GIT_SHA));
 	if (git_sha_trace != git_sha_retrace) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "warning: sha in trace file \'%s\' does not match current sha: \'%s\'\n",
-		        git_sha_trace.c_str(),  git_sha_retrace.c_str());
+		line_info("\n\tWarning: sha in trace file \'%s\' does not match current sha: \'%s\'",
+		          git_sha_trace.c_str(),  git_sha_retrace.c_str());
 		print_v4l2_tracer_info();
 		return;
 	}
utils/v4l2-tracer/retrace.cpp +34 -73

263 lines not on this page · raw message

utils/v4l2-tracer/trace-helper.cpp +8 -31
index 0b6382ee..e5094b67 100644
@@ -19,10 +19,7 @@ bool is_video_or_media_device(const char *path)
 
 void add_device(int fd, std::string path)
 {
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "fd: %d, path: %s\n", fd, path.c_str());
-	}
+	debug_line_info("\n\tfd: %d, path: %s", fd, path.c_str());
 	std::pair<int, std::string> new_pair = std::make_pair(fd, path);
 	ctx_trace.devices.insert(new_pair);
 }
@@ -59,10 +56,7 @@ void print_decode_order(void)
 
 void set_decode_order(long decode_order)
 {
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "%ld\n", decode_order);
-	}
+	debug_line_info("\n\t%ld", decode_order);
 
 	std::list<long>::iterator it;
 	it = find(ctx_trace.decode_order.begin(), ctx_trace.decode_order.end(), decode_order);
@@ -185,10 +179,7 @@ long get_buffer_bytesused_trace(int fd, __u32 offset)
 
 void set_buffer_display_order(int fd, __u32 offset, long display_order)
 {
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "%ld\n", display_order);
-	}
+	debug_line_info("\n\t%ld", display_order);
 	for (auto &b : ctx_trace.buffers) {
 		if ((b.fd == fd) && (b.offset == offset)) {
 			b.display_order = display_order;
@@ -263,9 +254,7 @@ void s_ext_ctrls_setup(struct v4l2_ext_controls *ext_controls)
 	if (ext_controls->which != V4L2_CTRL_WHICH_REQUEST_VAL)
 		return;
 
-	if (is_debug())
-		fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-
+	debug_line_info();
 	/*
 	 * Since userspace sends H264 frames out of order, get information
 	 * about the correct display order of each frame so that v4l2-tracer
@@ -287,7 +276,7 @@ void s_ext_ctrls_setup(struct v4l2_ext_controls *ext_controls)
 			int pic_order_cnt_lsb = ctrl.p_h264_decode_params->pic_order_cnt_lsb;
 
 			if (is_debug()) {
-				fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
+				line_info();
 				fprintf(stderr, "\tprev_pic_order_cnt_lsb: %d\n", prev_pic_order_cnt_lsb);
 				fprintf(stderr, "\tprev_pic_order_cnt_msb: %ld\n", prev_pic_order_cnt_msb);
 				fprintf(stderr, "\tpic_order_cnt_lsb: %d\n", pic_order_cnt_lsb);
@@ -318,10 +307,7 @@ void s_ext_ctrls_setup(struct v4l2_ext_controls *ext_controls)
 				pic_order_cnt_msb = prev_pic_order_cnt_msb + (pic_order_cnt_lsb - prev_pic_order_cnt_lsb);
 			}
 
-			if (is_debug()) {
-				fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-				fprintf(stderr, "\tpic_order_cnt_msb: %ld\n", pic_order_cnt_msb);
-			}
+			debug_line_info("\n\tpic_order_cnt_msb: %ld", pic_order_cnt_msb);
 			ctx_trace.fmt.h264.pic_order_cnt_lsb = pic_order_cnt_lsb;
 			set_decode_order(pic_order_cnt_msb);
 			break;
@@ -334,10 +320,7 @@ void s_ext_ctrls_setup(struct v4l2_ext_controls *ext_controls)
 
 void qbuf_setup(struct v4l2_buffer *buf)
 {
-	if (is_debug()) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "%s, index: %d\n", buftype2s((int) buf->type).c_str(), buf->index);
-	}
+	debug_line_info("\n\t%s, index: %d", buftype2s((int) buf->type).c_str(), buf->index);
 
 	int buf_fd = get_buffer_fd_trace(buf->type, buf->index);
 	__u32 buf_offset = get_buffer_offset_trace(buf->type, buf->index);
@@ -369,10 +352,6 @@ void qbuf_setup(struct v4l2_buffer *buf)
 			set_decode_order(get_decode_order() + 1);
 
 		set_buffer_display_order(buf_fd, buf_offset, get_decode_order());
-
-		if (is_debug()) {
-			fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
-		}
 		print_decode_order();
 		print_buffers_trace();
 	}
@@ -380,9 +359,7 @@ void qbuf_setup(struct v4l2_buffer *buf)
 
 void streamoff_cleanup(v4l2_buf_type buf_type)
 {
-
-	if (is_debug())
-		fprintf(stderr, "%s:%s:%d\n", __FILE__, __func__, __LINE__);
+	debug_line_info();
 	if (is_verbose() || (getenv("V4L2_TRACER_OPTION_WRITE_DECODED_TO_YUV_FILE") != nullptr)) {
 		fprintf(stderr, "VIDIOC_STREAMOFF: %s\n", buftype2s(buf_type).c_str());
 		fprintf(stderr, "%s, %s %s, width: %d, height: %d\n",
utils/v4l2-tracer/trace.cpp +5 -10
index a393d0d4..4c7062ab 100644
@@ -181,11 +181,8 @@ void trace_mem_decoded(void)
 			 */
 			if (it->bytesused < expected_length)
 				break;
-			if (is_debug()) {
-				fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-				fprintf(stderr, "displaying: %ld, %s, index: %d\n",
-				        it->display_order, buftype2s(it->type).c_str(), it->index);
-			}
+			debug_line_info("\n\tDisplaying: %ld, %s, index: %d",
+			                it->display_order, buftype2s(it->type).c_str(), it->index);
 			displayed_count++;
 
 			if (getenv("V4L2_TRACER_OPTION_WRITE_DECODED_TO_YUV_FILE") != nullptr) {
@@ -417,12 +414,10 @@ void trace_v4l2_ext_control(void *arg, json_object *parent_obj, std::string key_
 		json_object_object_add(v4l2_ext_control_obj, "value64", json_object_new_int64(p->value64));
 		break;
 	default:
-		if (p->size) {
-			fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-			fprintf(stderr, "warning: cannot trace control: %s\n", val2s(p->id, control_val_def).c_str());
-		} else {
+		if (p->size)
+			line_info("\n\tWarning: cannot trace control: %s", val2s(p->id, control_val_def).c_str());
+		else
 			json_object_object_add(v4l2_ext_control_obj, "value", json_object_new_int(p->value));
-		}
 		break;
 	}
 
utils/v4l2-tracer/v4l2-tracer-common.cpp +2 -4
index 869347a1..1b0ab2af 100644
@@ -211,11 +211,9 @@ long s2number(const char *char_str)
 	try {
 		num = std::strtol(str.c_str(), nullptr, 0); /* base is auto-detected */
 	} catch (std::invalid_argument& ia) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "string \'%s\' is invalid\n", str.c_str());
+		line_info("\n\tString \'%s\' is invalid.", str.c_str());
 	} catch (std::out_of_range& oor) {
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "string \'%s\' is out of range\n", str.c_str());
+		line_info("\n\tString \'%s\' is out of range.", str.c_str());
 	}
 	return num;
 }
utils/v4l2-tracer/v4l2-tracer-common.h +16 -0
index ab8b78e3..c8b5dbd4 100644
@@ -39,6 +39,22 @@
 #define STRERR(x) strerror(x)
 #endif
 
+#ifndef __FILE_NAME__
+#define __FILE_NAME__ __FILE__
+#endif
+
+#define line_info(fmt, args...)					\
+	do {								\
+		fprintf(stderr, "%s:%s:%d " fmt "\n",			\
+		        __FILE_NAME__, __func__, __LINE__, ##args);	\
+	} while (0)							\
+
+#define debug_line_info(fmt, args...)		\
+	do {					\
+		if (is_debug())			\
+			line_info(fmt, ##args);	\
+	} while (0)				\
+
 struct val_def {
 	__s64 val;
 	const char *str;
utils/v4l2-tracer/v4l2-tracer.cpp +16 -29

127 lines not on this page · raw message

Signature · 1 line
2.39.1