[FFmpeg-devel] Discussion around: built in profiling.

Marc Hoffman mmhoffm
Mon Jun 25 17:05:43 CEST 2007

I know there has been some thoughts around this and I'm not sure what the
current plans are for internal profiling.  But I have been using this
mechanism to collect stats on execution times.

Basically, I define a new pair of macros PROF_BEGIN, PROF_END that are
defined to expand to START_TIMER, STOP_TIMER when GATHER_STATS is defined by
the compilation system.  This way the code can be littered with
PROF_BEGIN/PROF_END with out the need of #ifdef code sections.

Does anyone have thoughts around this type of infrastructure?  Also would
anyone mind if I changed the output of

14122033 dezicycles in sws_scale, 512 runs, 0 skips
154924245 dezicycles in avcodec_encode_video, 1024 runs, 0 skips


sws_scale: 14122033 dezicycles, 512 runs, 0 skips
avcodec_encode_video: 154924245 dezicycles, 1024 runs, 0 skips

Its easier to find things this way when your profiling lots of stuff.


mmh at yoda$ svn diff libavutil ffmpeg.c
Index: libavutil/common.h
--- libavutil/common.h  (revision 9419)
+++ libavutil/common.h  (working copy)
@@ -344,4 +344,12 @@
 #define STOP_TIMER(id) {}

+#define PROF_END(id)   STOP_TIMER(id)
+#define PROF_BEGIN()
+#define PROF_END(id)
 #endif /* COMMON_H */
Index: ffmpeg.c
--- ffmpeg.c    (revision 9419)
+++ ffmpeg.c    (working copy)
@@ -743,8 +743,10 @@
     if (ost->video_resample) {
         padding_src = NULL;
         final_picture = &ost->pict_tmp;
+       PROF_BEGIN();
         sws_scale(ost->img_resample_ctx, formatted_picture->data,
               0, ost->resample_height, resampling_dst->data,
+       PROF_END("sws_scale");

     if (ost->video_pad) {
@@ -800,9 +802,11 @@
             big_picture.pts= ost->sync_opts;
 //            big_picture.pts= av_rescale(ost->sync_opts,
AV_TIME_BASE*(int64_t)enc->time_base.num, enc->time_base.den);
 //av_log(NULL, AV_LOG_DEBUG, "%"PRId64" -> encoder\n", ost->sync_opts);
+           PROF_BEGIN();
             ret = avcodec_encode_video(enc,
                                        bit_buffer, bit_buffer_size,
+           PROF_END("avcodec_encode_video");
             if (ret == -1) {
                 fprintf(stderr, "Video encoding failed\n");

More information about the ffmpeg-devel mailing list