@@ -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()
@@ -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, ...)
{
@@ -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.");
}
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(+)