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

Ramiro Polla ramiro.polla
Sun Feb 21 17:17:09 CET 2010


On Sun, Feb 21, 2010 at 8:51 AM, Reimar D?ffinger
<Reimar.Doeffinger at gmx.de> wrote:
> On Sun, Feb 21, 2010 at 01:39:27PM +0300, Michael Kostylev wrote:
>>
>> On Sun Feb 21 09:04:46 2010
>> Reimar D?ffinger wrote:
>>
>> >>> +check_struct "sys/time.h sys/resource.h" "struct rusage" ru_maxrss
>> >>
>> >> Why the sys/time.h? ?sys/resource.h doesn't require that.
>> >
>> > My man page recommends it as more portable.
>>
>> Needless to mention that OpenBSD requires them both.
>
> Ok, re-added it then.
>
>> But the ru_maxrss field always contains zero while getrusage() returns no
>> error. On NetBSD too.
>
> Some BSD version should have it at least.
> But yes, support for it is very spotty unfortunately.
> So not sure if it makes so much sense, however it seemed like the easiest
> way to get that kind of information for FATE - it wouldn't be a big deal
> if only 1 or 2 systems supported it correctly.

> @@ -3535,6 +3540,24 @@
>  #endif
>  }
>
> +static int64_t getmaxrss(void)
> +{
> +#if HAVE_GETRUSAGE && HAVE_STRUCT_RUSAGE_RU_MAXRSS
> +    struct rusage rusage;
> +    getrusage(RUSAGE_SELF, &rusage);
> +    return (int64_t)rusage.ru_maxrss * 1024;
> +#elif HAVE_GETPROCESSMEMORYINFO
> +    HANDLE proc;
> +    PROCESS_MEMORY_COUNTERS memcounters;
> +    proc = GetCurrentProcess();
> +    memcounters.cb = sizeof(memcounters);
> +    GetProcessMemoryInfo(proc, &memcounters, sizeof(memcounters));
> +    return memcounters.PeakPagefileUsage;
> +#else
> +    return 0;

> +#endif
> +}
> +
>  static void parse_matrix_coeffs(uint16_t *dest, const char *str)
>  {
>      int i;
> @@ -4029,7 +4052,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=%ikB\n", ti / 1000000.0, maxrss);

It might be better to only print maxrss if it's nonzero:

int maxrss = getmaxrss() / 1024;
printf("bench: utime=%0.3fs", ti / 1000000.0);
if (maxrss)
    printf(" maxrss=%ikB", maxrss);
printf("\n");

>      }
>
>      return av_exit(0);



More information about the ffmpeg-devel mailing list