process_metrics.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// This file contains routines for gathering resource statistics for processes 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// running on the system. 790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#ifndef BASE_PROCESS_PROCESS_METRICS_H_ 990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#define BASE_PROCESS_PROCESS_METRICS_H_ 1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <string> 1290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/base_export.h" 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/basictypes.h" 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/process.h" 16eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_MACOSX) 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include <mach/mach.h> 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace base { 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_WIN) 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct IoCounters : public IO_COUNTERS { 2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#elif defined(OS_POSIX) 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct IoCounters { 2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) uint64_t ReadOperationCount; 3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) uint64_t WriteOperationCount; 3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) uint64_t OtherOperationCount; 3290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) uint64_t ReadTransferCount; 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) uint64_t WriteTransferCount; 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) uint64_t OtherTransferCount; 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Working Set (resident) memory usage broken down by 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// 4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// On Windows: 4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// priv (private): These pages (kbytes) cannot be shared with any other process. 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// shareable: These pages (kbytes) can be shared with other processes under 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// the right circumstances. 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// shared : These pages (kbytes) are currently shared with at least one 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// other process. 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// 4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// On Linux: 4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// priv: Pages mapped only by this process 4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// shared: PSS or 0 if the kernel doesn't support this 5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// shareable: 0 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// On OS X: TODO(thakis): Revise. 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// priv: Memory. 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// shared: 0 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// shareable: 0 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct WorkingSetKBytes { 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) WorkingSetKBytes() : priv(0), shareable(0), shared(0) {} 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t priv; 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t shareable; 6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t shared; 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Committed (resident + paged) memory usage broken down by 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// private: These pages cannot be shared with any other process. 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// mapped: These pages are mapped into the view of a section (backed by 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// pagefile.sys) 6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// image: These pages are mapped into the view of an image section (backed by 6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// file system) 6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct CommittedKBytes { 7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CommittedKBytes() : priv(0), mapped(0), image(0) {} 7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t priv; 7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t mapped; 7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t image; 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 7590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Free memory (Megabytes marked as free) in the 2G process address space. 7790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// total : total amount in megabytes marked as free. Maximum value is 2048. 7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// largest : size of the largest contiguous amount of memory found. It is 7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// always smaller or equal to FreeMBytes::total. 8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// largest_ptr: starting address of the largest memory block. 8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct FreeMBytes { 8290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t total; 8390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t largest; 8490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void* largest_ptr; 8590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 8690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 8790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Convert a POSIX timeval to microseconds. 8890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)BASE_EXPORT int64 TimeValToMicroseconds(const struct timeval& tv); 8990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Provides performance metrics for a specified process (CPU usage, memory and 9190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// IO counters). To use it, invoke CreateProcessMetrics() to get an instance 9290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// for a specific process, then access the information with the different get 9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// methods. 9490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)class BASE_EXPORT ProcessMetrics { 9590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ~ProcessMetrics(); 9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 9890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Creates a ProcessMetrics for the specified process. 9990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The caller owns the returned object. 10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if !defined(OS_MACOSX) || defined(OS_IOS) 10190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static ProcessMetrics* CreateProcessMetrics(ProcessHandle process); 10290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#else 10390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) class PortProvider { 10490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) public: 10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual ~PortProvider() {} 10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Should return the mach task for |process| if possible, or else 10890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // |MACH_PORT_NULL|. Only processes that this returns tasks for will have 10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // metrics on OS X (except for the current process, which always gets 11090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // metrics). 11190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) virtual mach_port_t TaskForPid(ProcessHandle process) const = 0; 11290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) }; 11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 11490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // The port provider needs to outlive the ProcessMetrics object returned by 11590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // this function. If NULL is passed as provider, the returned object 11690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // only returns valid metrics if |process| is the current process. 11790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) static ProcessMetrics* CreateProcessMetrics(ProcessHandle process, 11890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) PortProvider* port_provider); 11990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // !defined(OS_MACOSX) || defined(OS_IOS) 12090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the current space allocated for the pagefile, in bytes (these pages 12290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // may or may not be in memory). On Linux, this returns the total virtual 12390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // memory size. 12490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t GetPagefileUsage() const; 12590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the peak space allocated for the pagefile, in bytes. 12690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t GetPeakPagefileUsage() const; 12790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the current working set size, in bytes. On Linux, this returns 12890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // the resident set size. 12990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t GetWorkingSetSize() const; 13090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the peak working set size, in bytes. 13190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t GetPeakWorkingSetSize() const; 13290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns private and sharedusage, in bytes. Private bytes is the amount of 13390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // memory currently allocated to a process that cannot be shared. Returns 13490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // false on platform specific error conditions. Note: |private_bytes| 13590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // returns 0 on unsupported OSes: prior to XP SP2. 13690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool GetMemoryBytes(size_t* private_bytes, 13790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) size_t* shared_bytes); 13890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Fills a CommittedKBytes with both resident and paged 13990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // memory usage as per definition of CommittedBytes. 14090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void GetCommittedKBytes(CommittedKBytes* usage) const; 14190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Fills a WorkingSetKBytes containing resident private and shared memory 14290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // usage in bytes, as per definition of WorkingSetBytes. 14390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const; 14490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 14590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Computes the current process available memory for allocation. 14690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // It does a linear scan of the address space querying each memory region 14790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // for its free (unallocated) status. It is useful for estimating the memory 14890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // load and fragmentation. 14990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool CalculateFreeMemory(FreeMBytes* free) const; 15090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 15190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns the CPU usage in percent since the last time this method was 15290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // called. The first time this method is called it returns 0 and will return 15390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // the actual CPU info on subsequent calls. 15490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // On Windows, the CPU usage value is for all CPUs. So if you have 2 CPUs and 15590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // your process is using all the cycles of 1 CPU and not the other CPU, this 15690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // method returns 50. 15790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) double GetCPUUsage(); 15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 15990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Retrieves accounting information for all I/O operations performed by the 16090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // process. 16190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // If IO information is retrieved successfully, the function returns true 16290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // and fills in the IO_COUNTERS passed in. The function returns false 16390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // otherwise. 16490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) bool GetIOCounters(IoCounters* io_counters) const; 16590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 16690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) private: 16790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if !defined(OS_MACOSX) || defined(OS_IOS) 16890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) explicit ProcessMetrics(ProcessHandle process); 16990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#else 17090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ProcessMetrics(ProcessHandle process, PortProvider* port_provider); 17190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // !defined(OS_MACOSX) || defined(OS_IOS) 17290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 173868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#if defined(OS_LINUX) || defined(OS_ANDROID) 174868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool GetWorkingSetKBytesStatm(WorkingSetKBytes* ws_usage) const; 175868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 176868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#if defined(OS_CHROMEOS) 178868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool GetWorkingSetKBytesTotmaps(WorkingSetKBytes *ws_usage) const; 179868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#endif 180868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 18190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ProcessHandle process_; 18290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 18390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int processor_count_; 18490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 18590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Used to store the previous times and CPU usage counts so we can 18690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // compute the CPU usage between calls. 18790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int64 last_time_; 18890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int64 last_system_time_; 18990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if !defined(OS_IOS) 19190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_MACOSX) 19290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Queries the port provider if it's set. 19390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) mach_port_t TaskForPid(ProcessHandle process) const; 19490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 19590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) PortProvider* port_provider_; 19690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#elif defined(OS_POSIX) 19790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Jiffie count at the last_time_ we updated. 19890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int last_cpu_; 19990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // defined(OS_POSIX) 20090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // !defined(OS_IOS) 20190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(ProcessMetrics); 20390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 20490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Returns the memory committed by the system in KBytes. 20690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Returns 0 if it can't compute the commit charge. 20790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)BASE_EXPORT size_t GetSystemCommitCharge(); 20890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#if defined(OS_LINUX) || defined(OS_ANDROID) 21090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Parse the data found in /proc/<pid>/stat and return the sum of the 21190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// CPU-related ticks. Returns -1 on parse error. 21290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Exposed for testing. 21390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)BASE_EXPORT int ParseProcStatCPU(const std::string& input); 21490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 21590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Data from /proc/meminfo about system-wide memory consumption. 21690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Values are in KB. 21790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)struct BASE_EXPORT SystemMemoryInfoKB { 21890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) SystemMemoryInfoKB(); 21990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 22090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int total; 22190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int free; 22290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int buffers; 22390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int cached; 22490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int active_anon; 22590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int inactive_anon; 22690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int active_file; 22790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int inactive_file; 22890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int shmem; 22990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 23090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Gem data will be -1 if not supported. 23190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int gem_objects; 23290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) long long gem_size; 23390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}; 23490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Retrieves data from /proc/meminfo about system-wide memory consumption. 23590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Fills in the provided |meminfo| structure. Returns true on success. 23690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Exposed for memory debugging widget. 23790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)BASE_EXPORT bool GetSystemMemoryInfo(SystemMemoryInfoKB* meminfo); 23890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // defined(OS_LINUX) || defined(OS_ANDROID) 23990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 24090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} // namespace base 24190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 24290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#endif // BASE_PROCESS_PROCESS_METRICS_H_ 243