summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/process/process_metrics.cc8
-rw-r--r--base/process/process_metrics.h10
-rw-r--r--base/trace_event/process_memory_totals_dump_provider.cc14
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database.cc9
-rw-r--r--content/browser/browser_main_loop.cc7
-rw-r--r--content/child/blink_platform_impl.cc18
6 files changed, 22 insertions, 44 deletions
diff --git a/base/process/process_metrics.cc b/base/process/process_metrics.cc
index e486339..6d99383 100644
--- a/base/process/process_metrics.cc
+++ b/base/process/process_metrics.cc
@@ -43,6 +43,14 @@ scoped_ptr<Value> SystemMetrics::ToValue() const {
return res.Pass();
}
+ProcessMetrics* ProcessMetrics::CreateCurrentProcessMetrics() {
+#if !defined(OS_MACOSX) || defined(OS_IOS)
+ return CreateProcessMetrics(base::GetCurrentProcessHandle());
+#else
+ return CreateProcessMetrics(base::GetCurrentProcessHandle(), nullptr);
+#endif // !defined(OS_MACOSX) || defined(OS_IOS)
+}
+
double ProcessMetrics::GetPlatformIndependentCPUUsage() {
#if defined(OS_WIN)
return GetCPUUsage() * processor_count_;
diff --git a/base/process/process_metrics.h b/base/process/process_metrics.h
index 327483a..40c9644 100644
--- a/base/process/process_metrics.h
+++ b/base/process/process_metrics.h
@@ -90,8 +90,9 @@ struct CommittedKBytes {
BASE_EXPORT int64 TimeValToMicroseconds(const struct timeval& tv);
// Provides performance metrics for a specified process (CPU usage, memory and
-// IO counters). To use it, invoke CreateProcessMetrics() to get an instance
-// for a specific process, then access the information with the different get
+// IO counters). Use CreateCurrentProcessMetrics() to get an instance for the
+// current process, or CreateProcessMetrics() to get an instance for an
+// arbitrary process. Then, access the information with the different get
// methods.
class BASE_EXPORT ProcessMetrics {
public:
@@ -110,6 +111,11 @@ class BASE_EXPORT ProcessMetrics {
PortProvider* port_provider);
#endif // !defined(OS_MACOSX) || defined(OS_IOS)
+ // Creates a ProcessMetrics for the current process. This a cross-platform
+ // convenience wrapper for CreateProcessMetrics().
+ // The caller owns the returned object.
+ static ProcessMetrics* CreateCurrentProcessMetrics();
+
// Returns the current space allocated for the pagefile, in bytes (these pages
// may or may not be in memory). On Linux, this returns the total virtual
// memory size.
diff --git a/base/trace_event/process_memory_totals_dump_provider.cc b/base/trace_event/process_memory_totals_dump_provider.cc
index c057deb..83015f8 100644
--- a/base/trace_event/process_memory_totals_dump_provider.cc
+++ b/base/trace_event/process_memory_totals_dump_provider.cc
@@ -25,17 +25,6 @@ namespace trace_event {
// static
uint64 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0;
-namespace {
-
-ProcessMetrics* CreateProcessMetricsForCurrentProcess() {
-#if !defined(OS_MACOSX) || defined(OS_IOS)
- return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle());
-#else
- return ProcessMetrics::CreateProcessMetrics(GetCurrentProcessHandle(), NULL);
-#endif
-}
-} // namespace
-
// static
ProcessMemoryTotalsDumpProvider*
ProcessMemoryTotalsDumpProvider::GetInstance() {
@@ -45,8 +34,7 @@ ProcessMemoryTotalsDumpProvider::GetInstance() {
}
ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider()
- : process_metrics_(CreateProcessMetricsForCurrentProcess()) {
-}
+ : process_metrics_(ProcessMetrics::CreateCurrentProcessMetrics()) {}
ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() {
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_database.cc b/chrome/browser/safe_browsing/safe_browsing_database.cc
index 80c16f7..845e362 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database.cc
@@ -1431,15 +1431,8 @@ void SafeBrowsingDatabaseNew::UpdatePrefixSetUrlStore(
// Measure the amount of IO during the filter build.
base::IoCounters io_before, io_after;
- base::ProcessHandle handle = base::GetCurrentProcessHandle();
scoped_ptr<base::ProcessMetrics> metric(
-#if !defined(OS_MACOSX)
- base::ProcessMetrics::CreateProcessMetrics(handle)
-#else
- // Getting stats only for the current process is enough, so NULL is fine.
- base::ProcessMetrics::CreateProcessMetrics(handle, NULL)
-#endif
- );
+ base::ProcessMetrics::CreateCurrentProcessMetrics());
// IoCounters are currently not supported on Mac, and may not be
// available for Linux, so we check the result and only show IO
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index 70db843..8566b99 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -374,12 +374,7 @@ class BrowserMainLoop::MemoryObserver : public base::MessageLoop::TaskObserver {
void DidProcessTask(const base::PendingTask& pending_task) override {
#if !defined(OS_IOS) // No ProcessMetrics on IOS.
scoped_ptr<base::ProcessMetrics> process_metrics(
- base::ProcessMetrics::CreateProcessMetrics(
-#if defined(OS_MACOSX)
- base::GetCurrentProcessHandle(), NULL));
-#else
- base::GetCurrentProcessHandle()));
-#endif
+ base::ProcessMetrics::CreateCurrentProcessMetrics());
size_t private_bytes;
process_metrics->GetMemoryBytes(&private_bytes, NULL);
LOCAL_HISTOGRAM_MEMORY_KB("Memory.BrowserUsed", private_bytes >> 10);
diff --git a/content/child/blink_platform_impl.cc b/content/child/blink_platform_impl.cc
index 67c6f8e..b21a722 100644
--- a/content/child/blink_platform_impl.cc
+++ b/content/child/blink_platform_impl.cc
@@ -1215,20 +1215,6 @@ blink::WebString BlinkPlatformImpl::signedPublicKeyAndChallengeString(
return blink::WebString("");
}
-static scoped_ptr<base::ProcessMetrics> CurrentProcessMetrics() {
- using base::ProcessMetrics;
-#if defined(OS_MACOSX)
- return scoped_ptr<ProcessMetrics>(
- // The default port provider is sufficient to get data for the current
- // process.
- ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle(),
- NULL));
-#else
- return scoped_ptr<ProcessMetrics>(
- ProcessMetrics::CreateProcessMetrics(base::GetCurrentProcessHandle()));
-#endif
-}
-
static size_t getMemoryUsageMB(bool bypass_cache) {
size_t current_mem_usage = 0;
MemoryUsageCache* mem_usage_cache_singleton = MemoryUsageCache::GetInstance();
@@ -1268,7 +1254,9 @@ size_t BlinkPlatformImpl::numberOfProcessors() {
bool BlinkPlatformImpl::processMemorySizesInBytes(
size_t* private_bytes,
size_t* shared_bytes) {
- return CurrentProcessMetrics()->GetMemoryBytes(private_bytes, shared_bytes);
+ scoped_ptr<base::ProcessMetrics> current_process_metrics(
+ base::ProcessMetrics::CreateCurrentProcessMetrics());
+ return current_process_metrics->GetMemoryBytes(private_bytes, shared_bytes);
}
bool BlinkPlatformImpl::memoryAllocatorWasteInBytes(size_t* size) {