Skip to content

Commit e686825

Browse files
committed
avutil/log: Replace addresses in log output with simple ids
..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>
1 parent 5c5be37 commit e686825

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

libavutil/log.c

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,55 @@ static AVMutex mutex = AV_MUTEX_INITIALIZER;
5757

5858
static int av_log_level = AV_LOG_INFO;
5959
static int flags;
60+
static int nb_class_ids;
61+
62+
#define NB_CLASS_IDS 1000
63+
static struct class_ids {
64+
void *avcl;
65+
uint64_t class_hash;
66+
unsigned id;
67+
} class_ids[NB_CLASS_IDS];
68+
69+
static uint64_t fnv_hash(const char *str)
70+
{
71+
// FNV-1a 64-bit hash algorithm
72+
uint64_t hash = 0xcbf29ce484222325ULL;
73+
while (*str) {
74+
hash ^= (unsigned char)*str++;
75+
hash *= 0x100000001b3ULL;
76+
}
77+
return hash;
78+
}
79+
80+
static unsigned get_class_id(void* avcl)
81+
{
82+
AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
83+
const char* class_name = avc->item_name(avcl);
84+
unsigned i, nb_ids = 0;
85+
uint64_t class_hash;
86+
87+
for (i = 0; i < NB_CLASS_IDS && class_ids[i].avcl; i++) {
88+
if (class_ids[i].avcl == avcl)
89+
return class_ids[i].id;
90+
}
91+
92+
class_hash = fnv_hash(avc->class_name);
93+
94+
for (i = 0; i < NB_CLASS_IDS; i++) {
95+
if (class_ids[i].class_hash == class_hash)
96+
nb_ids++;
97+
98+
if (!class_ids[i].avcl) {
99+
class_ids[i].avcl = avcl;
100+
class_ids[i].class_hash = class_hash;
101+
class_ids[i].id = nb_ids;
102+
return class_ids[i].id;
103+
}
104+
}
105+
106+
// exceeded NB_CLASS_IDS entries in class_ids[]
107+
return 0;
108+
}
60109

61110
#define NB_LEVELS 8
62111
#if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
@@ -331,13 +380,13 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
331380
AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
332381
avc->parent_log_context_offset);
333382
if (parent && *parent) {
334-
av_bprintf(part+0, "[%s @ %p] ",
335-
item_name(parent, *parent), parent);
383+
av_bprintf(part+0, "[%s #%u] ",
384+
item_name(parent, *parent), get_class_id(parent));
336385
if(type) type[0] = get_category(parent);
337386
}
338387
}
339-
av_bprintf(part+1, "[%s @ %p] ",
340-
item_name(avcl, avc), avcl);
388+
av_bprintf(part+1, "[%s #%u] ",
389+
item_name(avcl, avc), get_class_id(avcl));
341390
if(type) type[1] = get_category(avcl);
342391
}
343392

0 commit comments

Comments
 (0)