Skip to contentSkip to conversation

utils: add v4l2-tracer utility

PATCH In review Deborah Brouwer 3 participants 6 messages Nov 30, 2022 – Dec 6, 2022 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

v4 cover utils: add v4l2-tracer utility

Hi all - thank you very much for your reviews.

This is a patch series now to add Hans' patch
for tracing basic controls.

Changes since v3:
- fix clang-tidy warnings
- fix memory leaks in auto-generated code
- strings: check for nullptr before assignment
- remove unnecessary checks for nullptr before free()
- polling: check return value
- dynamic arrays: check memory allocation
- put format-specific info (h264) into a union
- add comment to the top of auto-generated files
- replace array with std::vector for media topology
- move debug/verbose options to helper functions
- fix auto-gen script to include a few extra controls

Changes since v2:
- remove duplication in entries for numbers/strings
- use media topology to find retrace devices
- add specific ioctls to trace
- in help msg change 'data' -> 'video frame data'
- trace mem_array with space after every byte
- add to trace files package version, SHA, date
- retracer also generates a JSON retrace file
- default trace format is "pretty"
- add a "compact" format option
- consolidate options for tracer/retracer
- remove mutex locks as unnecessary
- add more autogenerated functions
- add 'clean' command to remove fd/addresses

Changes since v1:
- auto-generate code from uAPI headers
- generated code adds some ability to trace
VP9/HEVC which compiles but still needs work
- generated code adds full support for MPEG2
- fix multiplanar decoding for vicodec
- change library name to libv4l2tracer
- update README
- expand help to show options
- remove extraneous files from gitignore

Example:

Trace an application decoding VP8:

v4l2-tracer trace gst-launch-1.0 -- filesrc
location=test-25fps.vp8 ! parsebin !
v4l2slvp8dec ! videocodectestsink

Or trace an application decoding FWHT:

v4l2-tracer trace v4l2-ctl -d3 --stream-mmap
--stream-out-mmap --stream-from-hdr
test-25fps.fwht --stream-to out.yuv

A trace file is generated: 71827_trace.json

Retrace the trace file:
v4l2-tracer retrace 71827_trace.json

Specify nodes if using a different driver:
v4l2-tracer -d0 -m0 retrace 71827_trace.json

A retrace file is generated: 71827_trace_retrace.json

Remove irrelevant differences (optional)
e.g. file descriptors and addresses:
v4l2-tracer clean 71827_trace.json
v4l2-tracer clean 71827_trace_retrace.json

Clean files are generated:
clean_71827_trace.json
clean_71827_trace_retrace.json

Use an application to compare the files:
kdiff3 clean_71827_trace.json clean_71827_trace_retrace.json

Deborah Brouwer (1):
utils: add v4l2-tracer utility

Hans Verkuil (1):
v4l2-tracer: add support for most basic controls

 README                                   |    8 +
 configure.ac                             |   12 +
 utils/Makefile.am                        |    5 +
 utils/v4l2-tracer/.gitignore             |    7 +
 utils/v4l2-tracer/Makefile.am            |   36 +
 utils/v4l2-tracer/libv4l2tracer.cpp      |  303 +++++
 utils/v4l2-tracer/retrace-helper.cpp     |  262 +++++
 utils/v4l2-tracer/retrace.cpp            | 1373 ++++++++++++++++++++++
 utils/v4l2-tracer/retrace.h              |   43 +
 utils/v4l2-tracer/trace-helper.cpp       |  500 ++++++++
 utils/v4l2-tracer/trace.cpp              |  603 ++++++++++
 utils/v4l2-tracer/trace.h                |   75 ++
 utils/v4l2-tracer/v4l2-tracer-common.cpp |  476 ++++++++
 utils/v4l2-tracer/v4l2-tracer-common.h   |   79 ++
 utils/v4l2-tracer/v4l2-tracer-gen.pl     |  879 ++++++++++++++
 utils/v4l2-tracer/v4l2-tracer.1.in       |  111 ++
 utils/v4l2-tracer/v4l2-tracer.cpp        |  415 +++++++
 17 files changed, 5187 insertions(+)
 create mode 100644 utils/v4l2-tracer/.gitignore
 create mode 100644 utils/v4l2-tracer/Makefile.am
 create mode 100644 utils/v4l2-tracer/libv4l2tracer.cpp
 create mode 100644 utils/v4l2-tracer/retrace-helper.cpp
 create mode 100644 utils/v4l2-tracer/retrace.cpp
 create mode 100644 utils/v4l2-tracer/retrace.h
 create mode 100644 utils/v4l2-tracer/trace-helper.cpp
 create mode 100644 utils/v4l2-tracer/trace.cpp
 create mode 100644 utils/v4l2-tracer/trace.h
 create mode 100644 utils/v4l2-tracer/v4l2-tracer-common.cpp
 create mode 100644 utils/v4l2-tracer/v4l2-tracer-common.h
 create mode 100755 utils/v4l2-tracer/v4l2-tracer-gen.pl
 create mode 100644 utils/v4l2-tracer/v4l2-tracer.1.in
 create mode 100644 utils/v4l2-tracer/v4l2-tracer.cpp
Signature · 1 line
2.38.0
#2 lore raw

PATCH v4 2/2 v4l2-tracer: add support for most basic controls

From: Hans Verkuil <[email protected]>

The v4l2-tracer utility didn't support tracing simple controls without a payload (i.e. the 'size' field is 0) and just a simple value.

This adds support for that, plus the four standard INTEGER64 controls that use field value64.

---
 utils/v4l2-tracer/retrace.cpp | 16 ++++++++++++++++
 utils/v4l2-tracer/trace.cpp   | 14 ++++++++++++--
 2 files changed, 28 insertions(+), 2 deletions(-)
utils/v4l2-tracer/retrace.cpp +16 -0
index 9b03d3bb..36a218d3 100644
@@ -726,7 +726,23 @@ struct v4l2_ext_control *retrace_v4l2_ext_control(json_object *parent_obj, int c
 		p->value = retrace_v4l2_ext_control_value(v4l2_ext_control_obj,
 		                                          v4l2_stateless_hevc_start_code_val_def);
 		break;
+	case V4L2_CID_MPEG_VIDEO_DEC_PTS:
+	case V4L2_CID_MPEG_VIDEO_DEC_FRAME:
+	case V4L2_CID_MPEG_VIDEO_DEC_CONCEAL_COLOR:
+	case V4L2_CID_PIXEL_RATE: {
+		json_object *value64_obj;
+
+		if (json_object_object_get_ex(v4l2_ext_control_obj, "value64", &value64_obj))
+			p->value64 = json_object_get_int64(value64_obj);
+		break;
+	}
 	default:
+		if (!p->size) {
+			json_object *value_obj;
+
+			if (json_object_object_get_ex(v4l2_ext_control_obj, "value", &value_obj))
+				p->value = json_object_get_int(value_obj);
+		}
 		break;
 	}
 
utils/v4l2-tracer/trace.cpp +12 -2
index cff78315..d5a09ad7 100644
@@ -410,9 +410,19 @@ void trace_v4l2_ext_control(void *arg, json_object *parent_obj, std::string key_
 	case V4L2_CID_STATELESS_MPEG2_QUANTISATION:
 		trace_v4l2_ctrl_mpeg2_quantisation_gen(p->p_mpeg2_quantisation, v4l2_ext_control_obj);
 		break;
+	case V4L2_CID_MPEG_VIDEO_DEC_PTS:
+	case V4L2_CID_MPEG_VIDEO_DEC_FRAME:
+	case V4L2_CID_MPEG_VIDEO_DEC_CONCEAL_COLOR:
+	case V4L2_CID_PIXEL_RATE:
+		json_object_object_add(v4l2_ext_control_obj, "value64", json_object_new_int64(p->value64));
+		break;
 	default:
-		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
-		fprintf(stderr, "warning: cannot trace control: %s\n", val2s(p->id, control_val_def).c_str());
+		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 {
+			json_object_object_add(v4l2_ext_control_obj, "value", json_object_new_int(p->value));
+		}
 		break;
 	}
 
Signature · 1 line
2.38.0
#1 lore raw

PATCH v4 1/2 utils: add v4l2-tracer utility

In reply to Deborah Brouwer

The v4l2-tracer traces, records and replays userspace applications that implement the v4l2 memory-to-memory stateless video decoder interface. It writes the traced system calls and video frame data to a file in JSON format. It reads the JSON file to replay the same system calls and to send the same video frame data to the kernel driver. The JSON file can be replayed in different environments or on different machines.

---
 README                                   |    8 +
 configure.ac                             |   12 +
 utils/Makefile.am                        |    5 +
 utils/v4l2-tracer/.gitignore             |    7 +
 utils/v4l2-tracer/Makefile.am            |   36 +
 utils/v4l2-tracer/libv4l2tracer.cpp      |  303 +++++
 utils/v4l2-tracer/retrace-helper.cpp     |  262 +++++
 utils/v4l2-tracer/retrace.cpp            | 1357 ++++++++++++++++++++++
 utils/v4l2-tracer/retrace.h              |   43 +
 utils/v4l2-tracer/trace-helper.cpp       |  500 ++++++++
 utils/v4l2-tracer/trace.cpp              |  593 ++++++++++
 utils/v4l2-tracer/trace.h                |   75 ++
 utils/v4l2-tracer/v4l2-tracer-common.cpp |  476 ++++++++
 utils/v4l2-tracer/v4l2-tracer-common.h   |   79 ++
 utils/v4l2-tracer/v4l2-tracer-gen.pl     |  879 ++++++++++++++
 utils/v4l2-tracer/v4l2-tracer.1.in       |  111 ++
 utils/v4l2-tracer/v4l2-tracer.cpp        |  415 +++++++
 17 files changed, 5161 insertions(+)
 create mode 100644 utils/v4l2-tracer/.gitignore
 create mode 100644 utils/v4l2-tracer/Makefile.am
 create mode 100644 utils/v4l2-tracer/libv4l2tracer.cpp
 create mode 100644 utils/v4l2-tracer/retrace-helper.cpp
 create mode 100644 utils/v4l2-tracer/retrace.cpp
 create mode 100644 utils/v4l2-tracer/retrace.h
 create mode 100644 utils/v4l2-tracer/trace-helper.cpp
 create mode 100644 utils/v4l2-tracer/trace.cpp
 create mode 100644 utils/v4l2-tracer/trace.h
 create mode 100644 utils/v4l2-tracer/v4l2-tracer-common.cpp
 create mode 100644 utils/v4l2-tracer/v4l2-tracer-common.h
 create mode 100755 utils/v4l2-tracer/v4l2-tracer-gen.pl
 create mode 100644 utils/v4l2-tracer/v4l2-tracer.1.in
 create mode 100644 utils/v4l2-tracer/v4l2-tracer.cpp
README +8 -0
index a7759171..8c5561ae 100644
@@ -45,6 +45,8 @@ you'll need also:
 	alsa-lib-devel doxygen libjpeg-turbo-devel qt5-qtbase-devel
 	libudev-devel mesa-libGLU-devel
 
+The v4l2-tracer also needs the json-c library.
+On Debian: libjson-c-dev; on Fedora: json-c-devel.
 
 After downloading and installing the needed packages, you should run:
 
@@ -227,6 +229,12 @@ v4l2-sysfs-path:
 FIXME add description.
 Installed by make install under <prefix>/bin.
 
+v4l2-tracer:
+Tool to trace, record and replay userspace applications
+that implement the v4l2 memory-to-memory stateless video
+decoder interface.
+Installed by 'make install' under <prefix>/bin.
+
 xc3028-firmware:
 Xceive XC2028/3028 tuner module firmware manipulation tool.
 xc3028-firmware does not get installed by make install.
configure.ac +12 -0
index 45423081..2b26e3dd 100644
@@ -32,6 +32,8 @@ AC_CONFIG_FILES([Makefile
 	utils/v4l2-ctl/Makefile
 	utils/v4l2-dbg/Makefile
 	utils/v4l2-sysfs-path/Makefile
+	utils/v4l2-tracer/Makefile
+	utils/v4l2-tracer/v4l2-tracer.1
 	utils/qv4l2/Makefile
 	utils/libcecutil/Makefile
 	utils/cec-ctl/Makefile
@@ -312,6 +314,15 @@ AS_IF([test "x$with_libudev" != xno -o "x$enable_libdvbv5" != xno],
 
 AC_SUBST([JPEG_LIBS])
 
+JSONC_VERSION_REQUIRED="0.15";
+PKG_CHECK_MODULES(JSONC, [json-c >= $JSONC_VERSION_REQUIRED], [jsonc_pkgconfig=yes], [jsonc_pkgconfig=no])
+AC_SUBST([JSONC_CFLAGS])
+AC_SUBST([JSONC_LIBS])
+AM_CONDITIONAL([HAVE_JSONC], [test x$jsonc_pkgconfig = xyes])
+if test "x$jsonc_pkgconfig" = "xno"; then
+    AC_MSG_WARN(json-c $JSONC_VERSION_REQUIRED or higher required for v4l2-tracer)
+fi
+
 # Check for pthread
 
 AS_IF([test x$enable_shared != xno],
@@ -646,6 +657,7 @@ compile time options summary
     QT version                 : $QT_VERSION
     ALSA support               : $USE_ALSA
     SDL support		       : $sdl_pc
+    JSON-C                     : $jsonc_pkgconfig >= $JSONC_VERSION_REQUIRED
 
     build dynamic libs         : $enable_shared
     build static libs          : $enable_static
utils/Makefile.am +5 -0
index 0e68a612..6f59515e 100644
@@ -15,6 +15,11 @@ SUBDIRS = \
 	cec-follower \
 	rds-ctl
 
+if HAVE_JSONC
+SUBDIRS += \
+	v4l2-tracer
+endif
+
 if WITH_LIBDVBV5
 SUBDIRS += \
 	dvb
utils/v4l2-tracer/.gitignore new file +7 -0
new file mode 100644
index 00000000..48fbfc47
@@ -0,0 +1,7 @@
+trace-gen.h
+trace-gen.cpp
+retrace-gen.cpp
+retrace-gen.h
+v4l2-tracer-info-gen.h
+v4l2-tracer
+v4l2-tracer.1
utils/v4l2-tracer/Makefile.am new file +36 -0
new file mode 100644
index 00000000..b72ee1e9
@@ -0,0 +1,36 @@
+if HAVE_JSONC
+
+lib_LTLIBRARIES = libv4l2tracer.la
+libv4l2tracer_la_SOURCES = libv4l2tracer.cpp trace-gen.cpp trace-helper.cpp trace.cpp \
+v4l2-tracer-common.cpp $(top_srcdir)/utils/common/v4l2-info.cpp \
+$(top_srcdir)/utils/common/media-info.cpp
+libv4l2tracer_la_CPPFLAGS = -I$(top_srcdir)/utils/common $(JSONC_CFLAGS)
+libv4l2tracer_la_LDFLAGS = -avoid-version -module -shared -export-dynamic -ldl $(JSONC_LIBS)
+libv4l2tracer_la_LIBTOOLFLAGS = --tag=disable-static
+
+bin_PROGRAMS = v4l2-tracer
+man_MANS = v4l2-tracer.1
+
+v4l2_tracer_SOURCES = v4l2-tracer.cpp retrace-gen.cpp retrace-helper.cpp retrace.cpp \
+v4l2-tracer-common.cpp $(top_srcdir)/utils/common/v4l2-info.cpp \
+$(top_srcdir)/utils/common/media-info.cpp
+v4l2_tracer_CPPFLAGS = -I$(top_srcdir)/utils/common -DLIBTRACER_PATH=$(libdir) $(JSONC_CFLAGS) \
+$(GIT_SHA) $(GIT_COMMIT_CNT) $(GIT_COMMIT_DATE)
+v4l2_tracer_LDFLAGS = -lrt -lpthread $(JSONC_LIBS)
+
+V4L2_TRACER_GEN_PREREQS = $(top_srcdir)/include/linux/v4l2-controls.h \
+$(top_srcdir)/include/linux/videodev2.h $(top_srcdir)/include/linux/media.h \
+$(top_srcdir)/include/linux/v4l2-common.h
+V4L2_TRACER_GEN = trace-gen.cpp trace-gen.h retrace-gen.cpp retrace-gen.h v4l2-tracer-info-gen.h
+v4l2-tracer.cpp: $(V4L2_TRACER_GEN)
+$(V4L2_TRACER_GEN): gen.intermediate;
+.INTERMEDIATE: gen.intermediate
+gen.intermediate: v4l2-tracer-gen.pl $(V4L2_TRACER_GEN_PREREQS)
+	$(AM_V_GEN) $(top_srcdir)/utils/v4l2-tracer/v4l2-tracer-gen.pl $(V4L2_TRACER_GEN_PREREQS)
+
+clean-local:
+	-rm -vf $(V4L2_TRACER_GEN)
+
+EXTRA_DIST = v4l2-tracer.1, v4l2-tracer-gen.pl
+
+endif
utils/v4l2-tracer/libv4l2tracer.cpp new file +303 -0

303 lines not on this page · raw message

utils/v4l2-tracer/retrace-helper.cpp new file +262 -0

262 lines not on this page · raw message

utils/v4l2-tracer/retrace.cpp new file +1357 -0

1,357 lines not on this page · raw message

utils/v4l2-tracer/retrace.h new file +43 -0

43 lines not on this page · raw message

utils/v4l2-tracer/trace-helper.cpp new file +500 -0

500 lines not on this page · raw message

utils/v4l2-tracer/trace.cpp new file +593 -0

431 lines not on this page · raw message

utils/v4l2-tracer/trace.h new file +75 -0

75 lines not on this page · raw message

utils/v4l2-tracer/v4l2-tracer-common.cpp new file +476 -0

476 lines not on this page · raw message

utils/v4l2-tracer/v4l2-tracer-common.h new file +79 -0

79 lines not on this page · raw message

utils/v4l2-tracer/v4l2-tracer-gen.pl new file +879 -0

879 lines not on this page · raw message

utils/v4l2-tracer/v4l2-tracer.1.in new file +111 -0

111 lines not on this page · raw message

utils/v4l2-tracer/v4l2-tracer.cpp new file +415 -0

415 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.38.0

Part of the diff is not shown here. View the raw message.

#5 lore raw
In reply to Deborah Brouwer

Hi Deb,

Quoted 4 lines · Deborah Brouwer

Hi all - thank you very much for your reviews.

This is a patch series now to add Hans' patch
for tracing basic controls.

All merged!

Thank you very much for this nice utility, I think it will be quite useful.

Regards,

Hans

Quoted 115 lines

Changes since v3:
- fix clang-tidy warnings
- fix memory leaks in auto-generated code
- strings: check for nullptr before assignment
- remove unnecessary checks for nullptr before free()
- polling: check return value
- dynamic arrays: check memory allocation
- put format-specific info (h264) into a union
- add comment to the top of auto-generated files
- replace array with std::vector for media topology
- move debug/verbose options to helper functions
- fix auto-gen script to include a few extra controls

Changes since v2:
- remove duplication in entries for numbers/strings
- use media topology to find retrace devices
- add specific ioctls to trace
- in help msg change 'data' -> 'video frame data'
- trace mem_array with space after every byte
- add to trace files package version, SHA, date
- retracer also generates a JSON retrace file
- default trace format is "pretty"
- add a "compact" format option
- consolidate options for tracer/retracer
- remove mutex locks as unnecessary
- add more autogenerated functions
- add 'clean' command to remove fd/addresses

Changes since v1:
- auto-generate code from uAPI headers
- generated code adds some ability to trace
VP9/HEVC which compiles but still needs work
- generated code adds full support for MPEG2
- fix multiplanar decoding for vicodec
- change library name to libv4l2tracer
- update README
- expand help to show options
- remove extraneous files from gitignore

Example:

Trace an application decoding VP8:

v4l2-tracer trace gst-launch-1.0 -- filesrc
location=test-25fps.vp8 ! parsebin !
v4l2slvp8dec ! videocodectestsink

Or trace an application decoding FWHT:

v4l2-tracer trace v4l2-ctl -d3 --stream-mmap
--stream-out-mmap --stream-from-hdr
test-25fps.fwht --stream-to out.yuv

A trace file is generated: 71827_trace.json

Retrace the trace file:
v4l2-tracer retrace 71827_trace.json

Specify nodes if using a different driver:
v4l2-tracer -d0 -m0 retrace 71827_trace.json

A retrace file is generated: 71827_trace_retrace.json

Remove irrelevant differences (optional)
e.g. file descriptors and addresses:
v4l2-tracer clean 71827_trace.json
v4l2-tracer clean 71827_trace_retrace.json

Clean files are generated:
clean_71827_trace.json
clean_71827_trace_retrace.json

Use an application to compare the files:
kdiff3 clean_71827_trace.json clean_71827_trace_retrace.json

Deborah Brouwer (1):
utils: add v4l2-tracer utility

Hans Verkuil (1):
v4l2-tracer: add support for most basic controls

 README                                   |    8 +
 configure.ac                             |   12 +
 utils/Makefile.am                        |    5 +
 utils/v4l2-tracer/.gitignore             |    7 +
 utils/v4l2-tracer/Makefile.am            |   36 +
 utils/v4l2-tracer/libv4l2tracer.cpp      |  303 +++++
 utils/v4l2-tracer/retrace-helper.cpp     |  262 +++++
 utils/v4l2-tracer/retrace.cpp            | 1373 ++++++++++++++++++++++
 utils/v4l2-tracer/retrace.h              |   43 +
 utils/v4l2-tracer/trace-helper.cpp       |  500 ++++++++
 utils/v4l2-tracer/trace.cpp              |  603 ++++++++++
 utils/v4l2-tracer/trace.h                |   75 ++
 utils/v4l2-tracer/v4l2-tracer-common.cpp |  476 ++++++++
 utils/v4l2-tracer/v4l2-tracer-common.h   |   79 ++
 utils/v4l2-tracer/v4l2-tracer-gen.pl     |  879 ++++++++++++++
 utils/v4l2-tracer/v4l2-tracer.1.in       |  111 ++
 utils/v4l2-tracer/v4l2-tracer.cpp        |  415 +++++++
 17 files changed, 5187 insertions(+)
 create mode 100644 utils/v4l2-tracer/.gitignore
 create mode 100644 utils/v4l2-tracer/Makefile.am
 create mode 100644 utils/v4l2-tracer/libv4l2tracer.cpp
 create mode 100644 utils/v4l2-tracer/retrace-helper.cpp
 create mode 100644 utils/v4l2-tracer/retrace.cpp
 create mode 100644 utils/v4l2-tracer/retrace.h
 create mode 100644 utils/v4l2-tracer/trace-helper.cpp
 create mode 100644 utils/v4l2-tracer/trace.cpp
 create mode 100644 utils/v4l2-tracer/trace.h
 create mode 100644 utils/v4l2-tracer/v4l2-tracer-common.cpp
 create mode 100644 utils/v4l2-tracer/v4l2-tracer-common.h
 create mode 100755 utils/v4l2-tracer/v4l2-tracer-gen.pl
 create mode 100644 utils/v4l2-tracer/v4l2-tracer.1.in
 create mode 100644 utils/v4l2-tracer/v4l2-tracer.cpp