Re: [PATCH] v4l2-tracer: use __FILE_NAME__ if available

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 31/03/2023 20:59, Deborah Brouwer wrote:
> Use __FILE_NAME__ if available to avoid printing the entire relative path
> in verbose and debug messages, otherwise fall back to __FILE__.
> 
> Signed-off-by: Deborah Brouwer <deborah.brouwer@xxxxxxxxxxxxx>
> ---
>  utils/v4l2-tracer/libv4l2tracer.cpp      | 12 +++---
>  utils/v4l2-tracer/retrace-helper.cpp     | 16 ++++----
>  utils/v4l2-tracer/retrace.cpp            | 52 ++++++++++++------------
>  utils/v4l2-tracer/trace-helper.cpp       | 18 ++++----
>  utils/v4l2-tracer/trace.cpp              |  4 +-
>  utils/v4l2-tracer/v4l2-tracer-common.cpp |  4 +-
>  utils/v4l2-tracer/v4l2-tracer-common.h   |  6 +++
>  utils/v4l2-tracer/v4l2-tracer.cpp        | 28 ++++++-------
>  8 files changed, 73 insertions(+), 67 deletions(-)
> 
> diff --git a/utils/v4l2-tracer/libv4l2tracer.cpp b/utils/v4l2-tracer/libv4l2tracer.cpp
> index a9f039c7..fc6f3939 100644
> --- a/utils/v4l2-tracer/libv4l2tracer.cpp
> +++ b/utils/v4l2-tracer/libv4l2tracer.cpp
> @@ -69,7 +69,7 @@ int open(const char *path, int oflag, ...)
>  	int fd = (*original_open)(path, oflag, mode);
>  
>  	if (is_debug()) {
> -		fprintf(stderr, "%s:%s:%d: ", __FILE__, __func__, __LINE__);
> +		fprintf(stderr, "%s:%s:%d: ", __FNAME__, __func__, __LINE__);

That's not quite what I had in mind.

All these messages are all the same, it's much better to introduce a macro
for it, similar to e.g. the info macro in v4l2-compliance.h.

That way these '__FILE__, __func__, __LINE__' bits are only used in the macro,
and it simplifies all these messages in v4l2-tracer.

Something like this goes into trace.h:

#ifndef __FILE_NAME__
#define __FILE_NAME__ __FILE__
#endif

#define info(fmt, args...)                                      \
        do {                                                    \
                fprintf(stderr, "%s:%s:%d" fmt, ##args, __FILE_NAME__, __func__, __LINE__);       \
        } while (0)


>  		fprintf(stderr, "fd: %d, path: %s\n", fd, path);

And then this becomes:

		info(": fd: %d, path: %s\n", fd, path);

I'm not sure if calling it 'info' is the right name in this case,
I leave that to you.

Regards,

	Hans





[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux