[FFmpeg-devel] [PATCH 3/5] libavutil: enable indentation of dynamic call graph
Martin Carroll
martin.carroll at alcatel-lucent.com
Mon Jul 2 21:24:28 CEST 2012
To make it easier to view the program's dynamic call graph,
the logger can now be configured to push and pop indentation
levels on the log messages. The new macros LOGPUSH and LOGPOP
respectively increase and decrease the current indentation
level and also print information about the name and file
location of the function that is being entered or returned
from. To enable this feature, the variable do_pushpop in
libavutil/log.c must be set to 1.
Signed-off-by: Martin Carroll <martin.carroll at alcatel-lucent.com>
---
libavutil/log.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
libavutil/log.h | 8 ++++++++
2 files changed, 64 insertions(+)
diff --git a/libavutil/log.c b/libavutil/log.c
index 448843f..74c915a 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -45,6 +45,7 @@ typedef struct {
void *fcn;
int instance_num_of_fcn;
int sole_instance_of_fcn;
+ int indent;
} Thread_info;
static Thread_info thread_info[MAX_THREAD_INFOS];
@@ -52,6 +53,7 @@ static int num_thread_infos = 0;
static int av_log_level = AV_LOG_INFO;
static int flags;
+static int do_pushpop = 0; // set to 1 to enable calls to LOGPUSH, LOGPOP, and LOGHERE
static int print_threadid = 0; // set to 1 to prefix all log messages with name or id of thread
#if defined(_WIN32) && !defined(__MINGW32CE__)
@@ -192,6 +194,7 @@ void av_log_set_threadname(pthread_t pid, const char * name, void *fcn)
}
}
info = &thread_info[num_thread_infos];
+ info->indent = 0;
info->pid = pid;
info->fcn = fcn;
info->instance_num_of_fcn = instance_num_of_fcn;
@@ -215,6 +218,49 @@ static Thread_info* lookup_thread_info()
return NULL;
}
+void
+av_log_push(const char *file, int line, const char *fcn)
+{
+ if (!do_pushpop) return;
+ Thread_info *info = lookup_thread_info();
+ if (info) {
+ av_log(NULL, av_log_level, "->%s @ %s:%d\n", fcn, file, line);
+ ++info->indent;
+ }
+}
+
+void
+av_log_pop(const char *file, int line, const char *fcn)
+{
+ if (!do_pushpop) return;
+ Thread_info *info = lookup_thread_info();
+ if (info) {
+ --info->indent;
+ av_log(NULL, av_log_level, "<-%s @ %s:%d\n", fcn, file, line);
+ }
+}
+
+void
+av_log_popi(const char *file, int line, const char *fcn, int ret)
+{
+ if (!do_pushpop) return;
+ Thread_info *info = lookup_thread_info();
+ if (info) {
+ --info->indent;
+ av_log(NULL, av_log_level, "<-%s=%d @ %s:%d\n", fcn, ret, file, line);
+ }
+}
+
+void
+av_log_here(const char *file, int line, const char *fcn)
+{
+ if (!do_pushpop) return;
+ Thread_info *info = lookup_thread_info();
+ if (info) {
+ av_log(NULL, av_log_level, "^%s @ %s:%d\n", fcn, file, line);
+ }
+}
+
static void format_line(void *ptr, int level, const char *fmt, va_list vl,
char part[5][LINE_SZ], int part_size, int *print_prefix, int type[2])
{
@@ -244,6 +290,16 @@ static void format_line(void *ptr, int level, const char *fmt, va_list vl,
snprintf(part[2], part_size, "%s: ", info->name);
else
snprintf(part[2], part_size, "%s(%d): ", info->name, info->instance_num_of_fcn);
+
+ char *ptr = part[3];
+ char *part_end = ptr + 512;
+ char *space = " ";
+ int spacelen = strlen(space);
+ for (i = 0; i < info->indent && ptr + spacelen + 1 < part_end; ++i) {
+ strcpy(ptr, space);
+ ptr += spacelen;
+ }
+ *ptr = 0;
}
else
snprintf(part[2], part_size, "%08x: ", pthread_self());
diff --git a/libavutil/log.h b/libavutil/log.h
index ea85224..7f67459 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -168,6 +168,14 @@ typedef struct AVClass {
*/
void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4);
void av_log_set_threadname(pthread_t pid, const char* name, void *fcn);
+void av_log_push(const char *file, int line, const char *fcn);
+void av_log_pop(const char *file, int line, const char *fcn);
+void av_log_popi(const char *file, int line, const char *fcn, int ret);
+void av_log_here(const char *file, int line, const char *fcn);
+#define LOGPUSH av_log_push(__FILE__, __LINE__, __func__)
+#define LOGPOP av_log_pop(__FILE__, __LINE__, __func__)
+#define LOGPOPI(ret) av_log_popi(__FILE__, __LINE__, __func__, (int)ret)
+#define LOGHERE av_log_here(__FILE__, __LINE__, __func__)
void av_vlog(void *avcl, int level, const char *fmt, va_list);
int av_log_get_level(void);
void av_log_set_level(int);
--
1.7.10.4
More information about the ffmpeg-devel
mailing list