Changeset 235113 in webkit


Ignore:
Timestamp:
Aug 21, 2018 6:27:42 AM (6 years ago)
Author:
Carlos Garcia Campos
Message:

[Linux] Cache the memory footprint and only update it after 1 second
https://bugs.webkit.org/show_bug.cgi?id=188791

Reviewed by Yusuke Suzuki.

Getting the memory footprint is an expensive operation in Linux. When called multiple times, the CPU usage is
too much (see bug #188787). We could cache the result for at least 1 second to ensure we don't call it more than
once per second.

  • wtf/linux/MemoryFootprintLinux.cpp:

(WTF::forEachLine):
(WTF::computeMemoryFootprint):
(WTF::memoryFootprint):

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r235106 r235113  
     12018-08-21  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [Linux] Cache the memory footprint and only update it after 1 second
     4        https://bugs.webkit.org/show_bug.cgi?id=188791
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        Getting the memory footprint is an expensive operation in Linux. When called multiple times, the CPU usage is
     9        too much (see bug #188787). We could cache the result for at least 1 second to ensure we don't call it more than
     10        once per second.
     11
     12        * wtf/linux/MemoryFootprintLinux.cpp:
     13        (WTF::forEachLine):
     14        (WTF::computeMemoryFootprint):
     15        (WTF::memoryFootprint):
     16
    1172018-08-20  Saam barati  <sbarati@apple.com>
    218
  • trunk/Source/WTF/wtf/linux/MemoryFootprintLinux.cpp

    r234733 r235113  
    2828
    2929#if OS(LINUX)
     30#include "MonotonicTime.h"
    3031#include <stdio.h>
    3132#include <wtf/StdLibExtras.h>
     
    3637
    3738#if OS(LINUX)
     39static const Seconds s_memoryFootprintUpdateInterval = 1_s;
     40
    3841template<typename Functor>
    3942static void forEachLine(FILE* file, Functor functor)
     
    4649    free(buffer);
    4750}
    48 #endif
    4951
    50 size_t memoryFootprint()
     52static size_t computeMemoryFootprint()
    5153{
    52 #if OS(LINUX)
    5354    FILE* file = fopen("/proc/self/smaps", "r");
    5455    if (!file)
     
    8788    fclose(file);
    8889    return totalPrivateDirtyInKB * KB;
     90}
     91#endif
     92
     93size_t memoryFootprint()
     94{
     95#if OS(LINUX)
     96    static size_t footprint = 0;
     97    static MonotonicTime previousUpdateTime = { };
     98    Seconds elapsed = MonotonicTime::now() - previousUpdateTime;
     99    if (elapsed >= s_memoryFootprintUpdateInterval) {
     100        footprint = computeMemoryFootprint();
     101        previousUpdateTime = MonotonicTime::now();
     102    }
     103
     104    return footprint;
    89105#endif
    90106    return 0;
Note: See TracChangeset for help on using the changeset viewer.