| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <fcntl.h> | 5 #include <fcntl.h> |
| 6 #include <signal.h> | 6 #include <signal.h> |
| 7 #include <sys/types.h> | 7 #include <sys/types.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 memory_map.committed_pages_bits.AsB64String().c_str()); | 430 memory_map.committed_pages_bits.AsB64String().c_str()); |
| 431 std::cout << buf; | 431 std::cout << buf; |
| 432 } | 432 } |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 bool CollectProcessMemoryInformation(int page_count_fd, | 436 bool CollectProcessMemoryInformation(int page_count_fd, |
| 437 int page_flags_fd, | 437 int page_flags_fd, |
| 438 ProcessMemory* process_memory) { | 438 ProcessMemory* process_memory) { |
| 439 const pid_t pid = process_memory->pid; | 439 const pid_t pid = process_memory->pid; |
| 440 base::ScopedFD pagemap_fd(open( | 440 base::ScopedFD pagemap_fd(HANDLE_EINTR(open( |
| 441 base::StringPrintf("/proc/%d/pagemap", pid).c_str(), O_RDONLY)); | 441 base::StringPrintf("/proc/%d/pagemap", pid).c_str(), O_RDONLY))); |
| 442 if (!pagemap_fd.is_valid()) { | 442 if (!pagemap_fd.is_valid()) { |
| 443 PLOG(ERROR) << "open"; | 443 PLOG(ERROR) << "open"; |
| 444 return false; | 444 return false; |
| 445 } | 445 } |
| 446 std::vector<MemoryMap>* const process_maps = &process_memory->memory_maps; | 446 std::vector<MemoryMap>* const process_maps = &process_memory->memory_maps; |
| 447 if (!GetProcessMaps(pid, process_maps)) | 447 if (!GetProcessMaps(pid, process_maps)) |
| 448 return false; | 448 return false; |
| 449 for (std::vector<MemoryMap>::iterator it = process_maps->begin(); | 449 for (std::vector<MemoryMap>::iterator it = process_maps->begin(); |
| 450 it != process_maps->end(); ++it) { | 450 it != process_maps->end(); ++it) { |
| 451 std::vector<PageInfo>* const committed_pages = &it->committed_pages; | 451 std::vector<PageInfo>* const committed_pages = &it->committed_pages; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 482 std::vector<pid_t> pids; | 482 std::vector<pid_t> pids; |
| 483 for (const char* const* ptr = argv + 1; *ptr; ++ptr) { | 483 for (const char* const* ptr = argv + 1; *ptr; ++ptr) { |
| 484 pid_t pid; | 484 pid_t pid; |
| 485 if (!base::StringToInt(*ptr, &pid)) | 485 if (!base::StringToInt(*ptr, &pid)) |
| 486 return EXIT_FAILURE; | 486 return EXIT_FAILURE; |
| 487 pids.push_back(pid); | 487 pids.push_back(pid); |
| 488 } | 488 } |
| 489 | 489 |
| 490 std::vector<ProcessMemory> processes_memory(pids.size()); | 490 std::vector<ProcessMemory> processes_memory(pids.size()); |
| 491 { | 491 { |
| 492 base::ScopedFD page_count_fd(open("/proc/kpagecount", O_RDONLY)); | 492 base::ScopedFD page_count_fd( |
| 493 HANDLE_EINTR(open("/proc/kpagecount", O_RDONLY))); |
| 493 if (!page_count_fd.is_valid()) { | 494 if (!page_count_fd.is_valid()) { |
| 494 PLOG(ERROR) << "open /proc/kpagecount"; | 495 PLOG(ERROR) << "open /proc/kpagecount"; |
| 495 return EXIT_FAILURE; | 496 return EXIT_FAILURE; |
| 496 } | 497 } |
| 497 | 498 |
| 498 base::ScopedFD page_flags_fd(open("/proc/kpageflags", O_RDONLY)); | 499 base::ScopedFD page_flags_fd(open("/proc/kpageflags", O_RDONLY)); |
| 499 if (!page_flags_fd.is_valid()) { | 500 if (!page_flags_fd.is_valid()) { |
| 500 PLOG(ERROR) << "open /proc/kpageflags"; | 501 PLOG(ERROR) << "open /proc/kpageflags"; |
| 501 return EXIT_FAILURE; | 502 return EXIT_FAILURE; |
| 502 } | 503 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 516 } | 517 } |
| 517 } | 518 } |
| 518 | 519 |
| 519 ClassifyPages(&processes_memory); | 520 ClassifyPages(&processes_memory); |
| 520 if (short_output) | 521 if (short_output) |
| 521 DumpProcessesMemoryMapsInShortFormat(processes_memory); | 522 DumpProcessesMemoryMapsInShortFormat(processes_memory); |
| 522 else | 523 else |
| 523 DumpProcessesMemoryMapsInExtendedFormat(processes_memory); | 524 DumpProcessesMemoryMapsInExtendedFormat(processes_memory); |
| 524 return EXIT_SUCCESS; | 525 return EXIT_SUCCESS; |
| 525 } | 526 } |
| OLD | NEW |