chromium/services/resource_coordinator/public/cpp/memory_instrumentation/os_metrics_linux.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <dlfcn.h>
#include <fcntl.h>
#include <stdint.h>
#include <sys/prctl.h>

#include <memory>

#include "base/android/library_loader/anchor_functions.h"
#include "base/android/library_loader/anchor_functions_buildflags.h"
#include "base/debug/elf_reader.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/format_macros.h"
#include "base/memory/page_size.h"
#include "base/metrics/histogram_macros.h"
#include "base/process/process_metrics.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "services/resource_coordinator/public/cpp/memory_instrumentation/os_metrics.h"
#include "third_party/abseil-cpp/absl/strings/ascii.h"

// Symbol with virtual address of the start of ELF header of the current binary.
extern char __ehdr_start;

namespace memory_instrumentation {

namespace {

VmRegion;
VmRegionPtr;

const char kClearPeakRssCommand[] =;
const uint32_t kMaxLineSize =;

// TODO(chiniforooshan): Many of the utility functions in this anonymous
// namespace should move to base/process/process_metrics_linux.cc to make the
// code a lot cleaner.  However, we should do so after we made sure the metrics
// we are experimenting with here have real value.
base::FilePath GetProcPidDir(base::ProcessId pid) {}

bool GetResidentAndSharedPagesFromStatmFile(int fd,
                                            uint64_t* resident_pages,
                                            uint64_t* shared_pages) {}

bool ResetPeakRSSIfPossible(base::ProcessId pid) {}

std::unique_ptr<base::ProcessMetrics> CreateProcessMetrics(
    base::ProcessId pid) {}

struct ModuleData {};

ModuleData GetMainModuleData() {}

bool ParseSmapsHeader(const char* header_line,
                      const ModuleData& main_module_data,
                      VmRegion* region) {}

uint64_t ReadCounterBytes(char* counter_line) {}

uint32_t ParseSmapsCounter(char* counter_line, VmRegion* region) {}

uint32_t ReadLinuxProcSmapsFile(FILE* smaps_file,
                                std::vector<VmRegionPtr>* maps) {}

// RAII class making the current process dumpable via prctl(PR_SET_DUMPABLE, 1),
// in case it is not currently dumpable as described in proc(5) and prctl(2).
// Noop if the original dumpable state could not be determined.
class ScopedProcessSetDumpable {};

}  // namespace

FILE* g_proc_smaps_for_testing =;

// static
void OSMetrics::SetProcSmapsForTesting(FILE* f) {}

// static
bool OSMetrics::FillOSMemoryDump(base::ProcessId pid,
                                 mojom::RawOSMemDump* dump) {}

// static
std::vector<VmRegionPtr> OSMetrics::GetProcessMemoryMaps(base::ProcessId pid) {}

// static
OSMetrics::MappedAndResidentPagesDumpState OSMetrics::GetMappedAndResidentPages(
    const size_t start_address,
    const size_t end_address,
    std::vector<uint8_t>* accessed_pages_bitmap) {}

// static
size_t OSMetrics::GetPeakResidentSetSize(base::ProcessId pid) {}

}  // namespace memory_instrumentation