v4l2-tracer: misc fixes and improvements
cover v4l2-tracer: misc fixes and improvements
This series continues to make the v4l2-tracer more robust by fixing errors and integrating uAPI changes.
It depends on this series to sync with kernel headers:
https://lore.kernel.org/linux-media/[email protected]/
Deborah Brouwer (6):
v4l2-tracer: look in more places for libv4l2tracer
v4l2-tracer: ignore single line comments when parsing headers
v4l2-tracer: add re/tracing for MAX_NUM_BUFFERS
v4l2-tracer: add re/tracing for AV1 controls
v4l2-tracer: stop waiting to handle a signal
v4l2-tracer: use stat to verify that retrace file exists
utils/v4l2-tracer/retrace.cpp | 19 ++++++++++--- utils/v4l2-tracer/trace.cpp | 12 +++++++++ utils/v4l2-tracer/v4l2-tracer-common.h | 1 + utils/v4l2-tracer/v4l2-tracer-gen.pl | 5 ++-- utils/v4l2-tracer/v4l2-tracer-info-gen.h | 1 + utils/v4l2-tracer/v4l2-tracer.cpp | 34 +++++++++++++++++++----- 6 files changed, 60 insertions(+), 12 deletions(-)
base-commit: c8adf732788e3ab317024553c7b2137e3a541269
Signature · 1 line
2.41.0
PATCH 1/6 v4l2-tracer: look in more places for libv4l2tracer
The v4l2-tracer already looks in the build and install directories for its library, but now it will also look in a truncated version of the LIBTRACER_PATH which is helpful if it was installed by a cross-build. If all else fails, it also allows the user to set a custom path using the LD_PRELOAD environment variable.
Exit if the libv4l2tracer.so can’t be found.
--- utils/v4l2-tracer/v4l2-tracer.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
utils/v4l2-tracer/v4l2-tracer.cpp +22 -3
@@ -306,13 +306,31 @@ int tracer(int argc, char *argv[], bool retrace) else idx++; - /* look for libv4l2tracer next to the executable */ libv4l2tracer_path = program.replace(program.begin() + idx, program.end(), "libv4l2tracer.so"); - /* otherwise, use the installation path */ - if (stat(libv4l2tracer_path.c_str(), &sb) == -1) + if (stat(libv4l2tracer_path.c_str(), &sb) == -1) { + /* If not found, get the libv4l2tracer library from the meson install path 'prefix' */ libv4l2tracer_path = std::string(LIBTRACER_PATH) + "/libv4l2tracer.so"; + /* Otherwise, guess where the library might be for a cross-build. */ + if (stat(libv4l2tracer_path.c_str(), &sb) == -1) { + std::size_t idx = libv4l2tracer_path.find("/home"); + libv4l2tracer_path = libv4l2tracer_path.substr(idx); + + /* Finally, check if the user set a custom path using LD_PRELOAD. */ + if (stat(libv4l2tracer_path.c_str(), &sb) == -1) { + if (getenv("LD_PRELOAD")) + libv4l2tracer_path = std::string(getenv("LD_PRELOAD")); + + if (stat(libv4l2tracer_path.c_str(), &sb) == -1) { + fprintf(stderr, "Exiting: can't find libv4l2tracer library\n"); + fprintf(stderr, "Set a custom libv4l2tracer library path using: LD_PRELOAD\n"); + exit(EXIT_FAILURE); + } + } + } + } + if (is_verbose()) fprintf(stderr, "Loading libv4l2tracer: %s\n", libv4l2tracer_path.c_str()); setenv("LD_PRELOAD", libv4l2tracer_path.c_str(), 0);
@@ -355,6 +373,7 @@ int tracer(int argc, char *argv[], bool retrace) fprintf(stderr, "%s", trace_filename.c_str()); fprintf(stderr, "\n"); + unsetenv("LD_PRELOAD"); return exec_result; }
Signature · 1 line
2.41.0
PATCH 2/6 v4l2-tracer: ignore single line comments when parsing headers
In reply to Deborah BrouwerJust in case there are single-line comments that start with '//', ignore them in the autogeneration script.
--- utils/v4l2-tracer/v4l2-tracer-gen.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
utils/v4l2-tracer/v4l2-tracer-gen.pl +2 -1
@@ -151,7 +151,8 @@ sub clean_up_line { $line =~ s/^\s+//; # remove leading whitespace $line =~ s/.*\# define.*//; # zero out line if it has defines inside a structure (e.g. v4l2_jpegcompression) $line =~ s/^\s*\/?\s?\*.*//; # zero out line if it has comments where the line starts with start with /* / * or just * - $line =~ s/\s*\/\*.*//; # remove comments at the end of a line following a member + $line =~ s/\s*\/\*.*//; # remove comments /* */ at the end of a line following a member + $line =~ s/\s*\/\/.*//; # remove comments // at the end of a line following a member $line =~ s/\*\/$//; # zero out line if it has comments that begin without any slashs or asterisks but end with */ # zero out lines that don't have a ; or { because they are comments but without any identifying slashes or asteriks if ($line !~ /.*[\;|\{].*/) {
Signature · 1 line
2.41.0
PATCH 3/6 v4l2-tracer: add re/tracing for MAX_NUM_BUFFERS
In reply to Deborah BrouwerIn the last sync of the kernel headers, the autogeneration script failed to pick up the new flag V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS, so add it.
--- utils/v4l2-tracer/v4l2-tracer-gen.pl | 2 +- utils/v4l2-tracer/v4l2-tracer-info-gen.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
utils/v4l2-tracer/v4l2-tracer-gen.pl +1 -1
@@ -943,7 +943,7 @@ while (<>) { } if (grep {/^#define V4L2_BUF_CAP_SUPPORTS_MMAP\s+/} $_) { printf $fh_common_info_h "constexpr flag_def v4l2_buf_cap_flag_def[] = {\n"; - flag_def_gen("V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS"); + flag_def_gen("V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS"); next; } if (grep {/^#define V4L2_STD_PAL_B\s+/} $_) {
utils/v4l2-tracer/v4l2-tracer-info-gen.h +1 -0
@@ -1518,6 +1518,7 @@ constexpr flag_def v4l2_buf_cap_flag_def[] = { { V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS, "V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS" }, { V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF, "V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF" }, { V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS, "V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS" }, + { V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS, "V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS" }, { 0, "" } };
Signature · 1 line
2.41.0
PATCH 4/6 v4l2-tracer: add re/tracing for AV1 controls
In reply to Deborah BrouwerHook up the existing autogenerated AV1 tracing and retracing functions so that they are called by the tracer and retracer.
--- utils/v4l2-tracer/retrace.cpp | 12 ++++++++++++ utils/v4l2-tracer/trace.cpp | 12 ++++++++++++ 2 files changed, 24 insertions(+)
utils/v4l2-tracer/retrace.cpp +12 -0
@@ -876,6 +876,18 @@ struct v4l2_ext_control *retrace_v4l2_ext_control(json_object *parent_obj, int c case V4L2_CID_STATELESS_MPEG2_QUANTISATION: p->ptr = retrace_v4l2_ctrl_mpeg2_quantisation_gen(v4l2_ext_control_obj); break; + case V4L2_CID_STATELESS_AV1_SEQUENCE: + p->ptr = retrace_v4l2_ctrl_av1_sequence_gen(v4l2_ext_control_obj); + break; + case V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY: + p->ptr = retrace_v4l2_ctrl_av1_tile_group_entry_gen(v4l2_ext_control_obj); + break; + case V4L2_CID_STATELESS_AV1_FRAME: + p->ptr = retrace_v4l2_ctrl_av1_frame_gen(v4l2_ext_control_obj); + break; + case V4L2_CID_STATELESS_AV1_FILM_GRAIN: + p->ptr = retrace_v4l2_ctrl_av1_film_grain_gen(v4l2_ext_control_obj); + break; default: line_info("\n\tWarning: cannot retrace control: %s", val2s(p->id, control_val_def).c_str());
utils/v4l2-tracer/trace.cpp +12 -0
@@ -412,6 +412,18 @@ void trace_v4l2_ext_control(void *arg, json_object *parent_obj, std::string key_ case V4L2_CID_PIXEL_RATE: json_object_object_add(v4l2_ext_control_obj, "value64", json_object_new_int64(p->value64)); break; + case V4L2_CID_STATELESS_AV1_SEQUENCE: + trace_v4l2_ctrl_av1_sequence_gen(p->p_av1_sequence, v4l2_ext_control_obj); + break; + case V4L2_CID_STATELESS_AV1_TILE_GROUP_ENTRY: + trace_v4l2_ctrl_av1_tile_group_entry_gen(p->p_av1_tile_group_entry, v4l2_ext_control_obj); + break; + case V4L2_CID_STATELESS_AV1_FRAME: + trace_v4l2_ctrl_av1_frame_gen(p->p_av1_frame, v4l2_ext_control_obj); + break; + case V4L2_CID_STATELESS_AV1_FILM_GRAIN: + trace_v4l2_ctrl_av1_film_grain_gen(p->p_av1_film_grain, v4l2_ext_control_obj); + break; default: if (p->size) line_info("\n\tWarning: cannot trace control: %s", val2s(p->id, control_val_def).c_str());
Signature · 1 line
2.41.0
PATCH 5/6 v4l2-tracer: stop waiting to handle a signal
In reply to Deborah BrouwerUsually the v4l2-tracer will wait for its tracee to handle a signal e.g. from ctrl+c before the v4l2-tracer exits, but if there is no tracee, then the v4l2-tracer waits forever.
Exit gracefully by waiting only if a tracee exists.
--- utils/v4l2-tracer/v4l2-tracer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
utils/v4l2-tracer/v4l2-tracer.cpp +6 -3
@@ -16,9 +16,12 @@ pid_t tracee_pid = 0; void v4l2_tracer_sig_handler(int signum) { line_info("\n\tReceived signum: %d", signum); - kill(tracee_pid, signum); - /* Wait for tracee to handle the signal first before v4l2-tracer exits. */ - wait(nullptr); + + /* If there is a tracee, wait for it to handle the signal first before exiting. */ + if (tracee_pid) { + kill(tracee_pid, signum); + wait(nullptr); + } } enum Options {
Signature · 1 line
2.41.0
PATCH 6/6 v4l2-tracer: use stat to verify that retrace file exists
In reply to Deborah BrouwerInstead of opening and closing the file to see if it exists, just use stat. This avoids cluttering a trace with extra opens/closes. Also change the return value to give a better description of the failure to the calling function.
--- utils/v4l2-tracer/retrace.cpp | 7 +++---- utils/v4l2-tracer/v4l2-tracer-common.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-)
utils/v4l2-tracer/retrace.cpp +3 -4
@@ -1537,12 +1537,11 @@ void retrace_array(json_object *root_array_obj) int retrace(std::string trace_filename) { - FILE *trace_file = fopen(trace_filename.c_str(), "r"); - if (trace_file == nullptr) { + struct stat sb; + if (stat(trace_filename.c_str(), &sb) == -1) { line_info("\n\tTrace file error: \'%s\'", trace_filename.c_str()); - return 1; + return -EINVAL; } - fclose(trace_file); fprintf(stderr, "Retracing: %s\n", trace_filename.c_str());
utils/v4l2-tracer/v4l2-tracer-common.h +1 -0
@@ -26,6 +26,7 @@#include <sys/ioctl.h> #include <sys/mman.h> #include <sys/types.h> +#include <sys/stat.h> #include <unistd.h> #include <unordered_map> #include <vector>
Signature · 1 line
2.41.0