From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 8122D4CAC0
	for <ffmpegdev@gitmailbox.com>; Thu, 13 Mar 2025 09:31:29 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 047E868E74C;
	Thu, 13 Mar 2025 11:31:08 +0200 (EET)
Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com
 [209.85.214.170])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7A06968D3DA
 for <ffmpeg-devel@ffmpeg.org>; Thu, 13 Mar 2025 11:31:01 +0200 (EET)
Received: by mail-pl1-f170.google.com with SMTP id
 d9443c01a7336-224171d6826so16367755ad.3
 for <ffmpeg-devel@ffmpeg.org>; Thu, 13 Mar 2025 02:31:01 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1741858260; x=1742463060; darn=ffmpeg.org;
 h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date
 :references:in-reply-to:message-id:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=3IVYcpcn9EwJCLQvNEPRQ425rr5TbE+UsMxxlOqQ4MY=;
 b=A4svEIJBLCcO0ySDWW88raKcJ36OtwEf9/QhCb6HzIqblPqs4HSdM7+Saa9XQWtKQM
 5IkVeAQ0QUMR4hKEy9V+mgbxHfYqLTm3FhfR1CwdvAgu8UvGp4jkfVdUzxW+Py3rbd9g
 a/vgDyfDUnDBhImZNtMbkWFaYCWJH0ZFifNma+UrmKEtG8YYCzeM5GVbbfwyNTF0mV2K
 hsS28z4Bad+9DJK/DLy8JoZF1mrYOX6qW113kt/DRNOsglDAZQgxnE2ZyKkmVRUT1yCa
 4n5lIAo2J70uFS+rEFEbySwQTBFaWgbtZpsZ4jYDwEPFKxSN8NNAU/MdogslMy1+UQhz
 3Kgw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1741858260; x=1742463060;
 h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date
 :references:in-reply-to:message-id:from:x-gm-message-state:from:to
 :cc:subject:date:message-id:reply-to;
 bh=3IVYcpcn9EwJCLQvNEPRQ425rr5TbE+UsMxxlOqQ4MY=;
 b=Oj0mOoWBjY73ke7cLT1yTPV3/TeGUCbHQ3mOrxB8f9m7ZLiXyAxl7IPCKTjwat2Uaf
 g/lEDsBuxVhl8lUDia/SMGkUQyzuVd3nE1fU88gxjxDQ1FP/HQn+CYSa2idkTi+iFPNG
 xy2iff4zZrjAxyFQ2+8P9VAoKoNXLZFj41/AnoTDlBMUZDnjTKkSnvqGS9y1u6NL29oS
 kS8ZWuOxyep3U67f4Oqda/ez6a0oXItZHLTIPECpMnqCsgzAwfLYafSHUpA8jX6NUDqE
 8EvD0U6ofUS8bSBnRBiq2zqJU7sJ4/glxBoLz6TSZjwaTy540CZ4T3iacx0bRD4+ogkR
 3UiA==
X-Gm-Message-State: AOJu0Yxf7F5Tn8/PFkGeKSOXaZdVUau8+apsyTZpq3fMAN1w9xYmW7xh
 6fV0l3GepSFQ141PB+REMnceyKGjPkc63q+oh2jUyo7Q2ZUv294Tz9nsTrsZ
X-Gm-Gg: ASbGnctieBHOb16ktG84ScmUVsuOWm1XahuTp5HcrCGzI6GoInAkPp1GQCSGO9nzc2p
 RfP7DpyZoIQJlLUf9Y0SE1qdxg10ZfBEujSKb9BQJGxcJn8Y/iMC/6eL/iHa0efhZo4p+AAWCA1
 0NKe+u50/rgI/lOz1FNvYV+n9ALOlZC2rzxIEdRbO+n21NuOoiw71ksHUJQkkOIhiZLSloKM4ip
 8JUt/d/49ZfyBM22G2ycVVW2xR74HdPHcKBwE3MOp1HWDgfx58iGGqvenFQTzyeEKm4gy4o5SnR
 /9g1TPTG44oza8YMHIP8kX72hXbmpLyTOTjzMAUg0ikNsep9EBoE+W9QLIaVFk4=
X-Google-Smtp-Source: AGHT+IHk0c4EdWMjyFLKWkvh6YHGQLd71USTG5kir4Ct/1eYb/JzV0M3xWrok0tjmBgw9O96sPQmBw==
X-Received: by 2002:a05:6a00:2351:b0:736:34ff:be8 with SMTP id
 d2e1a72fcca58-736aaaab004mr38655987b3a.19.1741858259683; 
 Thu, 13 Mar 2025 02:30:59 -0700 (PDT)
Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50])
 by smtp.gmail.com with ESMTPSA id
 41be03b00d2f7-af56e9ff24csm856852a12.39.2025.03.13.02.30.59
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Thu, 13 Mar 2025 02:30:59 -0700 (PDT)
From: softworkz <ffmpegagent@gmail.com>
X-Google-Original-From: softworkz <softworkz@hotmail.com>
Message-Id: <bab6b9154905ab8561399ec23302e8b339c547d2.1741858241.git.ffmpegagent@gmail.com>
In-Reply-To: <pull.59.v6.ffstaging.FFmpeg.1741858241.ffmpegagent@gmail.com>
References: <pull.59.v5.ffstaging.FFmpeg.1741546887.ffmpegagent@gmail.com>
 <pull.59.v6.ffstaging.FFmpeg.1741858241.ffmpegagent@gmail.com>
Date: Thu, 13 Mar 2025 09:30:40 +0000
Fcc: Sent
MIME-Version: 1.0
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v6 2/3] fftools/opt_common: add memaddresses
 log flag
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: softworkz <softworkz@hotmail.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/bab6b9154905ab8561399ec23302e8b339c547d2.1741858241.git.ffmpegagent@gmail.com/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

From: softworkz <softworkz@hotmail.com>

This commit adds the memaddresses log flag.
When specifying this flag at the command line, context prefixes will
be printed with memory addresses like in earlier ffmpeg versions.
Memory addresses are no longer printed by default.

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

Example with memaddresses flag:

[hevc @ 0000018e72a89cc0] .....

without (new behavior):

[hevc #0] .....

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 fftools/cmdutils.c    |  1 +
 fftools/fftools_log.c | 67 +++++++++++++++++++++++++++++++++++++++----
 fftools/fftools_log.h |  5 ++++
 fftools/opt_common.c  |  6 ++++
 4 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 0bf453508d..fb05f3fd2f 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -46,6 +46,7 @@
 #include "libavutil/dict.h"
 #include "libavutil/opt.h"
 #include "cmdutils.h"
+
 #include "fftools_log.h"
 #include "fopen_utf8.h"
 #include "opt_common.h"
diff --git a/fftools/fftools_log.c b/fftools/fftools_log.c
index f8f098fef9..b83c8abcaa 100644
--- a/fftools/fftools_log.c
+++ b/fftools/fftools_log.c
@@ -59,6 +59,53 @@ static inline struct tm *ff_localtime_r(const time_t* clock, struct tm *result)
 #define localtime_r ff_localtime_r
 #endif
 
+#define MAX_CLASS_IDS 1000
+static struct class_ids {
+    void *avcl;
+    uint64_t class_hash;
+    unsigned id;
+} class_ids[MAX_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;
+    unsigned i, nb_ids = 0;
+    uint64_t class_hash;
+
+    for (i = 0; i < MAX_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 < MAX_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 MAX_CLASS_IDS entries in class_ids[]
+    return 0;
+}
+
 static AVMutex mutex = AV_MUTEX_INITIALIZER;
 
 #define LINE_SZ 1024
@@ -316,6 +363,15 @@ static void format_date_now(AVBPrint* bp_time, int include_date)
     }
 }
 
+static void log_formatprefix(AVBPrint* buffer, AVClass** avcl)
+{
+    const int print_mem = ff_log_flags & FF_LOG_PRINT_MEMADDRESSES;
+    if (print_mem)
+        av_bprintf(buffer+0, "[%s @ %p] ", item_name(avcl, *avcl), avcl);
+    else
+        av_bprintf(buffer+0, "[%s #%u] ", item_name(avcl, *avcl), get_class_id(avcl));
+}
+
 static void format_line(void *avcl, int level, const char *fmt, va_list vl,
                         AVBPrint part[5], int *print_prefix, int type[2])
 {
@@ -328,17 +384,16 @@ 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) {
+
         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);
+                log_formatprefix(part, parent);
                 if(type) type[0] = get_category(parent);
             }
         }
-        av_bprintf(part+1, "[%s @ %p] ",
-                   item_name(avcl, avc), avcl);
+        log_formatprefix(part, avcl);
+
         if(type) type[1] = get_category(avcl);
     }
 
diff --git a/fftools/fftools_log.h b/fftools/fftools_log.h
index 4dba15ff7f..6333e4d3c1 100644
--- a/fftools/fftools_log.h
+++ b/fftools/fftools_log.h
@@ -92,5 +92,10 @@ int ff_log_get_flags(void);
  */
 #define FF_LOG_PRINT_DATETIME 8
 
+/**
+ * Print memory addresses instead of logical ids in the AVClass prefix.
+ */
+#define FF_LOG_PRINT_MEMADDRESSES 16
+
 
 #endif /* FFTOOLS_FFTOOLS_LOG_H */
diff --git a/fftools/opt_common.c b/fftools/opt_common.c
index 702f62a6fe..53b6fb2257 100644
--- a/fftools/opt_common.c
+++ b/fftools/opt_common.c
@@ -1305,6 +1305,12 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg)
             } else {
                 flags |= FF_LOG_PRINT_DATETIME;
             }
+        } else if (av_strstart(token, "memaddresses", &arg)) {
+            if (cmd == '-') {
+                flags &= ~FF_LOG_PRINT_MEMADDRESSES;
+            } else {
+                flags |= FF_LOG_PRINT_MEMADDRESSES;
+            }
         } else {
             break;
         }
-- 
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".