From 103ff3515ea4c37d7924fca6fee61d83da8d2744 Mon Sep 17 00:00:00 2001 From: "jwmak@chromium.org" Date: Thu, 22 Aug 2013 07:19:30 +0000 Subject: Move some platform-specific functions up in the code to make it cleaner. This does not add new code or functionality. BUG= Review URL: https://chromiumcodereview.appspot.com/22694007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@218925 0039d316-1c4b-4281-b951-d872f2087c98 --- base/process/process_metrics.h | 33 ++++++++++++++++----------------- base/process/process_metrics_linux.cc | 14 +++++++------- 2 files changed, 23 insertions(+), 24 deletions(-) (limited to 'base/process') diff --git a/base/process/process_metrics.h b/base/process/process_metrics.h index c1b462a..8a7fb13 100644 --- a/base/process/process_metrics.h +++ b/base/process/process_metrics.h @@ -216,12 +216,27 @@ class BASE_EXPORT ProcessMetrics { // Returns 0 if it can't compute the commit charge. BASE_EXPORT size_t GetSystemCommitCharge(); +#if defined(OS_POSIX) +// Returns the maximum number of file descriptors that can be open by a process +// at once. If the number is unavailable, a conservative best guess is returned. +size_t GetMaxFds(); +#endif // defined(OS_POSIX) + #if defined(OS_LINUX) || defined(OS_ANDROID) // Parse the data found in /proc//stat and return the sum of the // CPU-related ticks. Returns -1 on parse error. // Exposed for testing. BASE_EXPORT int ParseProcStatCPU(const std::string& input); +// Get the number of threads of |process| as available in /proc//stat. +// This should be used with care as no synchronization with running threads is +// done. This is mostly useful to guarantee being single-threaded. +// Returns 0 on failure. +BASE_EXPORT int GetNumberOfThreads(ProcessHandle process); + +// /proc/self/exe refers to the current executable. +BASE_EXPORT extern const char kProcSelfExe[]; + // Data from /proc/meminfo about system-wide memory consumption. // Values are in KB. struct BASE_EXPORT SystemMemoryInfoKB { @@ -241,29 +256,13 @@ struct BASE_EXPORT SystemMemoryInfoKB { int gem_objects; long long gem_size; }; + // Retrieves data from /proc/meminfo about system-wide memory consumption. // Fills in the provided |meminfo| structure. Returns true on success. // Exposed for memory debugging widget. BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); #endif // defined(OS_LINUX) || defined(OS_ANDROID) -#if defined(OS_LINUX) || defined(OS_ANDROID) -// Get the number of threads of |process| as available in /proc//stat. -// This should be used with care as no synchronization with running threads is -// done. This is mostly useful to guarantee being single-threaded. -// Returns 0 on failure. -BASE_EXPORT int GetNumberOfThreads(ProcessHandle process); - -// /proc/self/exe refers to the current executable. -BASE_EXPORT extern const char kProcSelfExe[]; -#endif // defined(OS_LINUX) || defined(OS_ANDROID) - -#if defined(OS_POSIX) -// Returns the maximum number of file descriptors that can be open by a process -// at once. If the number is unavailable, a conservative best guess is returned. -size_t GetMaxFds(); -#endif // defined(OS_POSIX) - // Collects and holds performance metrics for system memory and disk. // Provides functionality to retrieve the data on various platforms and // to serialize the stored data. diff --git a/base/process/process_metrics_linux.cc b/base/process/process_metrics_linux.cc index 1c86ee4..8d1a57c 100644 --- a/base/process/process_metrics_linux.cc +++ b/base/process/process_metrics_linux.cc @@ -382,6 +382,13 @@ int ParseProcStatCPU(const std::string& input) { return utime + stime; } +const char kProcSelfExe[] = "/proc/self/exe"; + +int GetNumberOfThreads(ProcessHandle process) { + return internal::ReadProcStatsAndGetFieldAsInt(process, + internal::VM_NUMTHREADS); +} + namespace { // The format of /proc/meminfo is: @@ -506,11 +513,4 @@ bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo) { return true; } -const char kProcSelfExe[] = "/proc/self/exe"; - -int GetNumberOfThreads(ProcessHandle process) { - return internal::ReadProcStatsAndGetFieldAsInt(process, - internal::VM_NUMTHREADS); -} - } // namespace base -- cgit v1.1