#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/controller/memory_usage_monitor_posix.h"
#include <fcntl.h>
#include <inttypes.h>
#include <unistd.h>
#include <utility>
#include "build/build_config.h"
#include "third_party/blink/public/platform/platform.h"
namespace blink {
namespace {
bool ReadFileContents(int fd, base::span<char> contents) { … }
static MemoryUsageMonitor* g_instance_for_testing = …;
MemoryUsageMonitorPosix& GetMemoryUsageMonitor() { … }
}
MemoryUsageMonitor& MemoryUsageMonitor::Instance() { … }
void MemoryUsageMonitor::SetInstanceForTesting(MemoryUsageMonitor* instance) { … }
bool MemoryUsageMonitorPosix::CalculateProcessMemoryFootprint(
int statm_fd,
int status_fd,
uint64_t* private_footprint,
uint64_t* swap_footprint,
uint64_t* vm_size,
uint64_t* vm_hwm_size) { … }
void MemoryUsageMonitorPosix::GetProcessMemoryUsage(MemoryUsage& usage) { … }
#if BUILDFLAG(IS_ANDROID)
void MemoryUsageMonitorPosix::ResetFileDescriptors() {
if (file_descriptors_reset_)
return;
file_descriptors_reset_ = true;
if (!statm_fd_.is_valid())
statm_fd_.reset(open("/proc/self/statm", O_RDONLY));
if (!status_fd_.is_valid())
status_fd_.reset(open("/proc/self/status", O_RDONLY));
}
#endif
void MemoryUsageMonitorPosix::SetProcFiles(base::File statm_file,
base::File status_file) { … }
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
void MemoryUsageMonitorPosix::Bind(
mojo::PendingReceiver<mojom::blink::MemoryUsageMonitorLinux> receiver) { … }
#endif
}