Skip to content

Commit

Permalink
Merge r235113 - [Linux] Cache the memory footprint and only update it…
Browse files Browse the repository at this point in the history
… 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):
  • Loading branch information
carlosgcampos committed Aug 24, 2018
1 parent 5473bfa commit 1142f62
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
16 changes: 16 additions & 0 deletions Source/WTF/ChangeLog
@@ -1,3 +1,19 @@
2018-08-21 Carlos Garcia Campos <cgarcia@igalia.com>

[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):

2018-08-20 Saam barati <sbarati@apple.com>

Inline DataView accesses into DFG/FTL
Expand Down
22 changes: 19 additions & 3 deletions Source/WTF/wtf/linux/MemoryFootprintLinux.cpp
Expand Up @@ -27,6 +27,7 @@
#include "MemoryFootprint.h"

#if OS(LINUX)
#include "MonotonicTime.h"
#include <stdio.h>
#include <wtf/StdLibExtras.h>
#include <wtf/text/StringView.h>
Expand All @@ -35,6 +36,8 @@
namespace WTF {

#if OS(LINUX)
static const Seconds s_memoryFootprintUpdateInterval = 1_s;

template<typename Functor>
static void forEachLine(FILE* file, Functor functor)
{
Expand All @@ -45,11 +48,9 @@ static void forEachLine(FILE* file, Functor functor)
}
free(buffer);
}
#endif

size_t memoryFootprint()
static size_t computeMemoryFootprint()
{
#if OS(LINUX)
FILE* file = fopen("/proc/self/smaps", "r");
if (!file)
return 0;
Expand Down Expand Up @@ -86,6 +87,21 @@ size_t memoryFootprint()
});
fclose(file);
return totalPrivateDirtyInKB * KB;
}
#endif

size_t memoryFootprint()
{
#if OS(LINUX)
static size_t footprint = 0;
static MonotonicTime previousUpdateTime = { };
Seconds elapsed = MonotonicTime::now() - previousUpdateTime;
if (elapsed >= s_memoryFootprintUpdateInterval) {
footprint = computeMemoryFootprint();
previousUpdateTime = MonotonicTime::now();
}

return footprint;
#endif
return 0;
}
Expand Down

0 comments on commit 1142f62

Please sign in to comment.