[FFmpeg-devel] [PATCH] print memory usage with -benchmark

Måns Rullgård mans
Sun Feb 21 01:22:29 CET 2010


Reimar D?ffinger <Reimar.Doeffinger at gmx.de> writes:

> On Sun, Feb 21, 2010 at 12:13:21AM +0100, Reimar D?ffinger wrote:
>> I fear it is untested, the Windows part because I don't have Windows at hand,
>> and the Linux/BSD/... part because it seems my kernel is too old, it always
>> returns 0.
>> I hope someone else can confirm its usefulness...
>
> And already the first fix.
> I think it needs a 2.6.32 or later kernel for Linux.
>
> Index: configure
> ===================================================================
> --- configure	(revision 21924)
> +++ configure	(working copy)
> @@ -1026,8 +1026,10 @@
>      fork
>      getaddrinfo
>      gethrtime
> +    GetProcessMemoryInfo
>      GetProcessTimes
>      getrusage
> +    struct_rusage_ru_maxrss
>      inet_aton
>      inline_asm
>      isatty
> @@ -2491,6 +2493,7 @@
>  check_func  getaddrinfo $network_extralibs
>  check_func  gethrtime
>  check_func  getrusage
> +check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss

Why the sys/time.h?  sys/resource.h doesn't require that.

>  check_func  inet_aton $network_extralibs
>  check_func  isatty
>  check_func  ${malloc_prefix}memalign            && enable memalign
> @@ -2499,6 +2502,7 @@
>  check_func  setrlimit
>  check_func_headers io.h setmode
>  check_func_headers lzo/lzo1x.h lzo1x_999_compress
> +check_func_headers windows.h GetProcessMemoryInfo
>  check_func_headers windows.h GetProcessTimes
>  check_func_headers windows.h VirtualAlloc
>  
> Index: ffmpeg.c
> ===================================================================
> --- ffmpeg.c	(revision 21924)
> +++ ffmpeg.c	(working copy)
> @@ -3535,6 +3535,23 @@
>  #endif
>  }
>  
> +static int64_t getmaxrss(void)
> +{
> +#if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
> +    struct rusage rusage;
> +    getrusage(RUSAGE_SELF, &rusage);
> +    return rusage.ru_maxrss * 1024;
> +#elif HAVE_GETPROCESSMEMORYINFO
> +    HANDLE proc;
> +    PROCESS_MEMORY_COUNTERS memcounters;
> +    proc = GetCurrentProcess();
> +    GetProcessMemoryInfo(proc, &memcounters);
> +    return memcounters.PeakPagefileUsage;
> +#else
> +    return 0;
> +#endif
> +}
> +
>  static void parse_matrix_coeffs(uint16_t *dest, const char *str)
>  {
>      int i;
> @@ -4029,7 +4046,8 @@
>          av_exit(1);
>      ti = getutime() - ti;
>      if (do_benchmark) {
> -        printf("bench: utime=%0.3fs\n", ti / 1000000.0);
> +        int maxrss = getmaxrss() / 1024;
> +        printf("bench: utime=%0.3fs maxrss: %i kB\n", ti / 1000000.0, maxrss);

I suggest printing maxrss=%i for consistency with the utime field.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list