utils: add v4l2-tracer utility
PATCH v3 1/1 utils: add v4l2-tracer utility
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 send the same video frame data to the kernel driver. The JSON file can be replayed in different environments or on different machines.
---
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
README | 8 + configure.ac | 12 + utils/Makefile.am | 5 + utils/v4l2-tracer/.gitignore | 7 + utils/v4l2-tracer/Makefile.am | 32 + utils/v4l2-tracer/libv4l2tracer.cpp | 307 +++++ utils/v4l2-tracer/retrace-helper.cpp | 250 ++++ utils/v4l2-tracer/retrace.cpp | 1374 ++++++++++++++++++++++ utils/v4l2-tracer/retrace.h | 41 + utils/v4l2-tracer/trace-helper.cpp | 503 ++++++++ utils/v4l2-tracer/trace.cpp | 588 +++++++++ utils/v4l2-tracer/trace.h | 73 ++ utils/v4l2-tracer/v4l2-tracer-common.cpp | 453 +++++++ utils/v4l2-tracer/v4l2-tracer-common.h | 82 ++ utils/v4l2-tracer/v4l2-tracer-gen.pl | 840 +++++++++++++ utils/v4l2-tracer/v4l2-tracer.1.in | 111 ++ utils/v4l2-tracer/v4l2-tracer.cpp | 412 +++++++ 17 files changed, 5098 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
@@ -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
@@ -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
@@ -311,6 +313,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],
@@ -645,6 +656,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
@@ -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
@@ -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 +32 -0
@@ -0,0 +1,32 @@ +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 +307 -0
307 lines not on this page · raw message
utils/v4l2-tracer/retrace-helper.cpp new file +250 -0
250 lines not on this page · raw message
utils/v4l2-tracer/retrace.cpp new file +1374 -0
1,374 lines not on this page · raw message
utils/v4l2-tracer/retrace.h new file +41 -0
41 lines not on this page · raw message
utils/v4l2-tracer/trace-helper.cpp new file +503 -0
503 lines not on this page · raw message
utils/v4l2-tracer/trace.cpp new file +588 -0
425 lines not on this page · raw message
utils/v4l2-tracer/trace.h new file +73 -0
73 lines not on this page · raw message
utils/v4l2-tracer/v4l2-tracer-common.cpp new file +453 -0
453 lines not on this page · raw message
utils/v4l2-tracer/v4l2-tracer-common.h new file +82 -0
82 lines not on this page · raw message
utils/v4l2-tracer/v4l2-tracer-gen.pl new file +840 -0
840 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 +412 -0
412 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.
PATCH 1/1 v4l2-tracer: add support for most basic controls
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.
---
Hi Deb,
I think this is a nice addition for your v3 patch. Support for these common simple controls is easy to add, and it makes for much better tracing.
Hans
---
utils/v4l2-tracer/retrace.cpp +16 -0
@@ -734,7 +734,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_int64(value_obj); + } break; }
utils/v4l2-tracer/trace.cpp +12 -2
@@ -405,9 +405,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_uint64(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_uint64(p->value)); + } break; }
Re: [PATCH] v4l2-tracer: add support for most basic controls
Hi Hans,
Thanks for this! I have one question below
Quoted 30 lines · Hans Verkuil
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.
Signed-off-by Hans Verkuil <[email protected]>---
Hi Deb,I think this is a nice addition for your v3 patch. Support for these common simple controls is easy to add, and it makes for much better tracing.
Hans
---utils/v4l2-tracer/retrace.cpp +6
-0@@ -734,7 +734,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; +
utils/v4l2-tracer/retrace.cpp struct v4l2_ext_control *retrace_v4l2_ext_control(json_object *parent_obj, int c · line 752
Quoted 10 lines
utils/v4l2-tracer/retrace.cpp +9
-0+ 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_int64(value_obj);
The json library integers don't map to exactly what we need but should this be just a plain int since value is __s32?
Quoted 16 lines
utils/v4l2-tracer/retrace.cpp +1
-0+ } break; }utils/v4l2-tracer/trace.cpp +4
-0@@ -405,9 +405,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:
utils/v4l2-tracer/trace.cpp void trace_v4l2_ext_control(void *arg, json_object *parent_obj, std::string key_ · line 419
Quoted 10 lines
utils/v4l2-tracer/trace.cpp +7
-2+ json_object_object_add(v4l2_ext_control_obj, "value64", json_object_new_uint64(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_uint64(p->value));
Same here I'm thinking to change uint64 to just int?
Quoted 5 lines
utils/v4l2-tracer/trace.cpp +1
-0+ } break; }
PATCH v2 1/1 v4l2-tracer: add support for most basic controls
In reply to Deborah BrouwerThe 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.
---
Changes since v1:
- Use int64 instead of uint64 for "value64" (copy-paste error).
- Use int instead of int64 for "value".
---
utils/v4l2-tracer/retrace.cpp +16 -0
@@ -734,7 +734,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
@@ -405,9 +405,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; }