All of lore.kernel.org
 help / color / mirror / Atom feed
From: Deborah Brouwer <deborah.brouwer@collabora.com>
To: linux-media@vger.kernel.org
Cc: hverkuil-cisco@xs4all.nl,
	Deborah Brouwer <deborah.brouwer@collabora.com>
Subject: [PATCH 1/8] v4l2-info/v4l2-tracer: add macro to mark the trace
Date: Mon, 13 Nov 2023 12:06:12 -0800	[thread overview]
Message-ID: <f80a3f7f25f465034ce16262aa2952049242ee53.1699904350.git.deborah.brouwer@collabora.com> (raw)
In-Reply-To: <cover.1699904350.git.deborah.brouwer@collabora.com>

Add a macro to write to /dev/null. A v4l-utils application that is being
traced can call this macro to inject a comment into the JSON trace file.
It is helpful for debugging.

Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
---
 utils/common/v4l2-info.h            |  7 +++++++
 utils/v4l2-tracer/libv4l2tracer.cpp | 22 ++++++++++++++++++++++
 utils/v4l2-tracer/retrace.cpp       |  3 +++
 3 files changed, 32 insertions(+)

diff --git a/utils/common/v4l2-info.h b/utils/common/v4l2-info.h
index 6de5654c..2142952a 100644
--- a/utils/common/v4l2-info.h
+++ b/utils/common/v4l2-info.h
@@ -11,6 +11,13 @@
 #include <linux/videodev2.h>
 #include <linux/v4l2-subdev.h>
 
+#define v4l2_tracer_info(fmt, args...)					\
+	do {								\
+		char msg[256];						\
+		snprintf(msg, sizeof(msg), "v4l2-tracer: " fmt, ##args);\
+		write(open("/dev/null", O_WRONLY), msg, strlen(msg));	\
+	} while (0)
+
 /*
  * The max value comes from a check in the kernel source code
  * drivers/media/v4l2-core/v4l2-ioctl.c check_array_args()
diff --git a/utils/v4l2-tracer/libv4l2tracer.cpp b/utils/v4l2-tracer/libv4l2tracer.cpp
index 7286f321..c6a74afb 100644
--- a/utils/v4l2-tracer/libv4l2tracer.cpp
+++ b/utils/v4l2-tracer/libv4l2tracer.cpp
@@ -88,6 +88,28 @@ int open(const char *path, int oflag, ...)
 	return fd;
 }
 
+ssize_t write(int fd, const void *buf, size_t count)
+{
+	ssize_t (*original_write)(int fd, const void *buf, size_t count) = nullptr;
+	original_write = (ssize_t (*)(int, const void *, size_t)) dlsym(RTLD_NEXT, "write");
+	ssize_t ret = (*original_write)(fd, buf, count);
+
+	/*
+	 * If the write message starts with "v4l2-tracer", then assume it came from the
+	 * v4l2_tracer_info macro and trace it.
+	 */
+	std::string buf_string(static_cast<const char*>(buf), count);
+	if (buf_string.find("v4l2-tracer") == 0) {
+
+		json_object *write_obj = json_object_new_object();
+		json_object_object_add(write_obj, "write", json_object_new_string((const char*)buf));
+		write_json_object_to_json_file(write_obj);
+		json_object_put(write_obj);
+	}
+
+	return ret;
+}
+
 #if defined(linux) && defined(__GLIBC__)
 int open64(const char *path, int oflag, ...)
 {
diff --git a/utils/v4l2-tracer/retrace.cpp b/utils/v4l2-tracer/retrace.cpp
index 88e70ea9..14c42568 100644
--- a/utils/v4l2-tracer/retrace.cpp
+++ b/utils/v4l2-tracer/retrace.cpp
@@ -1507,6 +1507,9 @@ void retrace_object(json_object *jobj)
 	if (json_object_object_get_ex(jobj, "Trace", &temp_obj)) {
 		return;
 	}
+	if (json_object_object_get_ex(jobj, "write", &temp_obj)) {
+		return;
+	}
 	line_info("\n\tWarning: unexpected JSON object in trace file.");
 }
 
-- 
2.41.0


  reply	other threads:[~2023-11-13 20:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 20:06 [PATCH 0/8] v4l2-tracer: expand to stateful decoding Deborah Brouwer
2023-11-13 20:06 ` Deborah Brouwer [this message]
2023-11-13 20:06 ` [PATCH 2/8] v4l2-tracer: replace buftype2s with val2s Deborah Brouwer
2023-11-13 20:06 ` [PATCH 3/8] v4l2-tracer: remove buffers by type and index Deborah Brouwer
2023-11-13 20:06 ` [PATCH 4/8] v4l2-tracer: remove compress_frame_count Deborah Brouwer
2023-11-13 20:06 ` [PATCH 5/8] v4l2-tracer: get decoded bytesused from DQBUF Deborah Brouwer
2023-11-13 20:06 ` [PATCH 6/8] v4l2-tracer: create an option to trace userspace args Deborah Brouwer
2023-11-13 20:06 ` [PATCH 7/8] v4l2-tracer: stop retracing failed ioctls Deborah Brouwer
2023-11-13 20:06 ` [PATCH 8/8] v4l2-tracer: auto generate flags for DECODER_CMD Deborah Brouwer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f80a3f7f25f465034ce16262aa2952049242ee53.1699904350.git.deborah.brouwer@collabora.com \
    --to=deborah.brouwer@collabora.com \
    --cc=hverkuil-cisco@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.