diff options
author | feng@chromium.org <feng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-14 20:01:56 +0000 |
---|---|---|
committer | feng@chromium.org <feng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-14 20:01:56 +0000 |
commit | 6e3294cdca9cd936435d5e01be494a8a93962cf9 (patch) | |
tree | 1570e81ff60c26cb61014633938f56456d77111c /tools/android | |
parent | 96ef359f84cc167700afcbcecfaada5f2ed05f77 (diff) | |
download | chromium_src-6e3294cdca9cd936435d5e01be494a8a93962cf9.zip chromium_src-6e3294cdca9cd936435d5e01be494a8a93962cf9.tar.gz chromium_src-6e3294cdca9cd936435d5e01be494a8a93962cf9.tar.bz2 |
Add an option to print out summary of memory usage
With -a, memdump prints total print, app shared,
and other shared memory usage in KB. Example output:
pid private shared_app shared_other (KB)
15802 71292 36860 26512
15818 12636 36860 11568
Test with and without -a, with and without pids in
command-line, works as expected.
BUG=
Review URL: https://chromiumcodereview.appspot.com/16832005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206481 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/android')
-rw-r--r-- | tools/android/memdump/memdump.cc | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/tools/android/memdump/memdump.cc b/tools/android/memdump/memdump.cc index d405c34..70dbace 100644 --- a/tools/android/memdump/memdump.cc +++ b/tools/android/memdump/memdump.cc @@ -293,6 +293,33 @@ void DumpProcessesMemoryMaps( } } +void DumpProcessesMemoryMapsInShortFormat( + const std::vector<ProcessMemory>& processes_memory) { + std::string buf; + const int KB_PER_PAGE = PAGE_SIZE >> 10; + std::cout << "pid\tprivate\t\tshared_app\tshared_other (KB)\n"; + for (std::vector<ProcessMemory>::const_iterator it = processes_memory.begin(); + it != processes_memory.end(); ++it) { + const ProcessMemory& process_memory = *it; + long total_private = 0, total_app_shared = 0, total_other_shared = 0; + const std::vector<MemoryMap>& memory_maps = process_memory.memory_maps; + for (std::vector<MemoryMap>::const_iterator it = memory_maps.begin(); + it != memory_maps.end(); ++it) { + const MemoryMap& memory_map = *it; + total_private += memory_map.private_count; + total_app_shared += memory_map.app_shared_count; + total_other_shared += memory_map.other_shared_count; + } + base::SStringPrintf( + &buf, "%d\t%d\t\t%d\t\t%d\n", + process_memory.pid, + total_private * KB_PER_PAGE, + total_app_shared * KB_PER_PAGE, + total_other_shared * KB_PER_PAGE); + std::cout << buf; + } +} + bool CollectProcessMemoryInformation(int page_count_fd, ProcessMemory* process_memory) { const pid_t pid = process_memory->pid; @@ -325,10 +352,19 @@ void KillAll(const std::vector<pid_t>& pids, int signal_number) { } // namespace int main(int argc, char** argv) { + bool short_output = false; if (argc == 1) { - LOG(ERROR) << "Usage: " << argv[0] << " <PID1>... <PIDN>"; + LOG(ERROR) << "Usage: " << argv[0] << " [-a] <PID1>... <PIDN>"; return EXIT_FAILURE; } + if (!strncmp(argv[1], "-a", 2)) { + if (argc == 2) { + LOG(ERROR) << "Usage: " << argv[0] << " [-a] <PID1>... <PIDN>"; + return EXIT_FAILURE; + } + short_output = true; + ++argv; + } std::vector<pid_t> pids; for (const char* const* ptr = argv + 1; *ptr; ++ptr) { pid_t pid; @@ -336,6 +372,16 @@ int main(int argc, char** argv) { return EXIT_FAILURE; pids.push_back(pid); } + + // Currently memdump does not count pages shared by more than + // 2 browser and render processes correctly. + // Bail out early in -a mode if more than 2 pids are given to avoid + // confusion. + if (short_output && pids.size() > 2) { + LOG(ERROR) << "Sorry, '-a' cannot be used for more than 2 PIDs."; + return EXIT_FAILURE; + } + std::vector<ProcessMemory> processes_memory(pids.size()); { int page_count_fd = open("/proc/kpagecount", O_RDONLY); @@ -357,6 +403,9 @@ int main(int argc, char** argv) { } } ClassifyPages(&processes_memory); - DumpProcessesMemoryMaps(processes_memory); + if (short_output) + DumpProcessesMemoryMapsInShortFormat(processes_memory); + else + DumpProcessesMemoryMaps(processes_memory); return EXIT_SUCCESS; } |