Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Side by Side Diff: base/trace_event/process_memory_totals_dump_provider.cc

Issue 1546033002: Switch to standard integer types in base/trace_event/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/process_memory_totals_dump_provider.h" 5 #include "base/trace_event/process_memory_totals_dump_provider.h"
6 6
7 #include <stddef.h>
8
7 #include "base/process/process_metrics.h" 9 #include "base/process/process_metrics.h"
8 #include "base/trace_event/process_memory_dump.h" 10 #include "base/trace_event/process_memory_dump.h"
9 #include "base/trace_event/process_memory_totals.h" 11 #include "base/trace_event/process_memory_totals.h"
12 #include "build/build_config.h"
10 13
11 #if defined(OS_LINUX) || defined(OS_ANDROID) 14 #if defined(OS_LINUX) || defined(OS_ANDROID)
12 #include <fcntl.h> 15 #include <fcntl.h>
13 16
14 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
15 18
16 namespace { 19 namespace {
17 bool kernel_supports_rss_peak_reset = true; 20 bool kernel_supports_rss_peak_reset = true;
18 const char kClearPeakRssCommand[] = "5"; 21 const char kClearPeakRssCommand[] = "5";
19 } 22 }
20 #endif 23 #endif
21 24
22 namespace base { 25 namespace base {
23 namespace trace_event { 26 namespace trace_event {
24 27
25 // static 28 // static
26 uint64 ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0; 29 uint64_t ProcessMemoryTotalsDumpProvider::rss_bytes_for_testing = 0;
27 30
28 // static 31 // static
29 ProcessMemoryTotalsDumpProvider* 32 ProcessMemoryTotalsDumpProvider*
30 ProcessMemoryTotalsDumpProvider::GetInstance() { 33 ProcessMemoryTotalsDumpProvider::GetInstance() {
31 return Singleton< 34 return Singleton<
32 ProcessMemoryTotalsDumpProvider, 35 ProcessMemoryTotalsDumpProvider,
33 LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get(); 36 LeakySingletonTraits<ProcessMemoryTotalsDumpProvider>>::get();
34 } 37 }
35 38
36 ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider() 39 ProcessMemoryTotalsDumpProvider::ProcessMemoryTotalsDumpProvider()
37 : process_metrics_(ProcessMetrics::CreateCurrentProcessMetrics()) {} 40 : process_metrics_(ProcessMetrics::CreateCurrentProcessMetrics()) {}
38 41
39 ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() { 42 ProcessMemoryTotalsDumpProvider::~ProcessMemoryTotalsDumpProvider() {
40 } 43 }
41 44
42 // Called at trace dump point time. Creates a snapshot the memory counters for 45 // Called at trace dump point time. Creates a snapshot the memory counters for
43 // the current process. 46 // the current process.
44 bool ProcessMemoryTotalsDumpProvider::OnMemoryDump(const MemoryDumpArgs& args, 47 bool ProcessMemoryTotalsDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
45 ProcessMemoryDump* pmd) { 48 ProcessMemoryDump* pmd) {
46 const uint64 rss_bytes = rss_bytes_for_testing 49 const uint64_t rss_bytes = rss_bytes_for_testing
47 ? rss_bytes_for_testing 50 ? rss_bytes_for_testing
48 : process_metrics_->GetWorkingSetSize(); 51 : process_metrics_->GetWorkingSetSize();
49 52
50 uint64 peak_rss_bytes = 0; 53 uint64_t peak_rss_bytes = 0;
51 54
52 #if !defined(OS_IOS) 55 #if !defined(OS_IOS)
53 peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize(); 56 peak_rss_bytes = process_metrics_->GetPeakWorkingSetSize();
54 #if defined(OS_LINUX) || defined(OS_ANDROID) 57 #if defined(OS_LINUX) || defined(OS_ANDROID)
55 if (kernel_supports_rss_peak_reset) { 58 if (kernel_supports_rss_peak_reset) {
56 // TODO(ssid): Fix crbug.com/461788 to write to the file from sandboxed 59 // TODO(ssid): Fix crbug.com/461788 to write to the file from sandboxed
57 // processes. 60 // processes.
58 int clear_refs_fd = open("/proc/self/clear_refs", O_WRONLY); 61 int clear_refs_fd = open("/proc/self/clear_refs", O_WRONLY);
59 if (clear_refs_fd > 0 && 62 if (clear_refs_fd > 0 &&
60 WriteFileDescriptor(clear_refs_fd, kClearPeakRssCommand, 63 WriteFileDescriptor(clear_refs_fd, kClearPeakRssCommand,
(...skipping 19 matching lines...) Expand all
80 pmd->process_totals()->set_peak_resident_set_bytes(peak_rss_bytes); 83 pmd->process_totals()->set_peak_resident_set_bytes(peak_rss_bytes);
81 pmd->set_has_process_totals(); 84 pmd->set_has_process_totals();
82 return true; 85 return true;
83 } 86 }
84 87
85 return false; 88 return false;
86 } 89 }
87 90
88 } // namespace trace_event 91 } // namespace trace_event
89 } // namespace base 92 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698