Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: softworkz <ffmpegagent@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: softworkz <softworkz@hotmail.com>,
	Soft Works <softworkz-at-hotmail.com@ffmpeg.org>,
	Nicolas George <george@nsup.org>, Gyan Doshi <ffmpeg@gyani.pro>
Subject: [FFmpeg-devel] [PATCH v2 1/3] avutil/log: Replace addresses in log output with simple ids
Date: Wed, 05 Mar 2025 18:19:41 +0000
Message-ID: <3a289533a7c787303da38faf64a6603327467490.1741198783.git.ffmpegagent@gmail.com> (raw)
In-Reply-To: <pull.59.v2.ffstaging.FFmpeg.1741198783.ffmpegagent@gmail.com>

From: softworkz <softworkz@hotmail.com>

..and individual numbering. The benefits are:

- Smaller log file sizes
- The disambiguation is much easier to recognize and to follow
- It eventually allows comparing and viewing log file diffs
  without almost every line being different due to those addresses

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 doc/APIchanges      |  3 ++
 libavutil/log.c     | 68 +++++++++++++++++++++++++++++++++++++++++----
 libavutil/log.h     |  5 ++++
 libavutil/version.h |  2 +-
 4 files changed, 71 insertions(+), 7 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 5a64836e25..76d9b4f71b 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -1,5 +1,8 @@
 The last version increases of all libraries were on 2024-03-07
 
+2025-03-xx - xxxxxxxxxx - lavu 59.59.100 - log.h
+  Add flag AV_LOG_PRINT_MEMADDRESSES.
+
 API changes, most recent first:
 
 2025-03-01 - xxxxxxxxxx - lavu 59.58.100 - pixfmt.h
diff --git a/libavutil/log.c b/libavutil/log.c
index c5ee876a88..6f18943fdd 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -57,6 +57,55 @@ static AVMutex mutex = AV_MUTEX_INITIALIZER;
 
 static int av_log_level = AV_LOG_INFO;
 static int flags;
+static int nb_class_ids;
+
+#define NB_CLASS_IDS 1000
+static struct class_ids {
+    void *avcl;
+    uint64_t class_hash;
+    unsigned id;
+} class_ids[NB_CLASS_IDS];
+
+static uint64_t fnv_hash(const char *str)
+{
+    // FNV-1a 64-bit hash algorithm
+    uint64_t hash = 0xcbf29ce484222325ULL;
+    while (*str) {
+        hash ^= (unsigned char)*str++;
+        hash *= 0x100000001b3ULL;
+    }
+    return hash;
+}
+
+static unsigned get_class_id(void* avcl)
+{
+    AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
+    const char* class_name = avc->item_name(avcl);
+    unsigned i, nb_ids = 0;
+    uint64_t class_hash;
+
+    for (i = 0; i < NB_CLASS_IDS && class_ids[i].avcl; i++) {
+        if (class_ids[i].avcl == avcl)
+            return class_ids[i].id;
+    }
+
+    class_hash = fnv_hash(avc->class_name);
+
+    for (i = 0; i < NB_CLASS_IDS; i++) {
+        if (class_ids[i].class_hash == class_hash)
+            nb_ids++;
+
+        if (!class_ids[i].avcl) {
+            class_ids[i].avcl = avcl;
+            class_ids[i].class_hash = class_hash;
+            class_ids[i].id = nb_ids;
+            return class_ids[i].id;
+        }
+    }
+
+    // exceeded NB_CLASS_IDS entries in class_ids[]
+    return 0;
+}
 
 #define NB_LEVELS 8
 #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
@@ -327,17 +376,24 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
 
     if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
     if (*print_prefix && avc) {
+        const int print_mem = flags & AV_LOG_PRINT_MEMADDRESSES;
+
         if (avc->parent_log_context_offset) {
-            AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
-                                   avc->parent_log_context_offset);
+            AVClass** parent = *(AVClass ***) ((uint8_t *)avcl + avc->parent_log_context_offset);
             if (parent && *parent) {
-                av_bprintf(part+0, "[%s @ %p] ",
-                           item_name(parent, *parent), parent);
+                if (print_mem)
+                    av_bprintf(part+0, "[%s @ %p] ", item_name(parent, *parent), parent);
+                else
+                    av_bprintf(part+0, "[%s #%u] ", item_name(parent, *parent), get_class_id(parent));
+
                 if(type) type[0] = get_category(parent);
             }
         }
-        av_bprintf(part+1, "[%s @ %p] ",
-                   item_name(avcl, avc), avcl);
+        if (print_mem)
+            av_bprintf(part+1, "[%s @ %p] ", item_name(avcl, avc), avcl);
+        else
+            av_bprintf(part+1, "[%s #%u] ", item_name(avcl, avc), get_class_id(avcl));
+
         if(type) type[1] = get_category(avcl);
     }
 
diff --git a/libavutil/log.h b/libavutil/log.h
index dd094307ce..450b4544b9 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -416,6 +416,11 @@ int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
  */
 #define AV_LOG_PRINT_DATETIME 8
 
+/**
+ * Print memory addresses instead of logical ids in the AVClass prefix.
+ */
+#define AV_LOG_PRINT_MEMADDRESSES 16
+
 void av_log_set_flags(int arg);
 int av_log_get_flags(void);
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 4b584fd569..b6467e2a6d 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR  58
+#define LIBAVUTIL_VERSION_MINOR  59
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
ffmpeg-codebot

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2025-03-05 18:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-05 15:38 [FFmpeg-devel] [PATCH] " softworkz
2025-03-05 15:40 ` Nicolas George
2025-03-05 15:45   ` Soft Works
2025-03-05 15:48   ` Soft Works
2025-03-05 15:42 ` Soft Works
2025-03-05 16:23 ` Gyan Doshi
2025-03-05 16:30   ` Soft Works
2025-03-05 17:14     ` Gyan Doshi
2025-03-05 18:19 ` [FFmpeg-devel] [PATCH v2 0/3] " ffmpegagent
2025-03-05 18:19   ` softworkz [this message]
2025-03-05 18:19   ` [FFmpeg-devel] [PATCH v2 2/3] fftools/opt_common: add memaddresses log flag softworkz
2025-03-05 18:19   ` [FFmpeg-devel] [PATCH v2 3/3] doc/fftools-common-opts: document " softworkz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3a289533a7c787303da38faf64a6603327467490.1741198783.git.ffmpegagent@gmail.com \
    --to=ffmpegagent@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=ffmpeg@gyani.pro \
    --cc=george@nsup.org \
    --cc=softworkz-at-hotmail.com@ffmpeg.org \
    --cc=softworkz@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git