Chromium Code Reviews| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 } | 193 } |
| 194 return true; | 194 return true; |
| 195 } | 195 } |
| 196 | 196 |
| 197 // Fills |committed_pages| in with the set of committed pages contained in the | 197 // Fills |committed_pages| in with the set of committed pages contained in the |
| 198 // provided memory map. | 198 // provided memory map. |
| 199 bool GetPagesForMemoryMap(int pagemap_fd, | 199 bool GetPagesForMemoryMap(int pagemap_fd, |
| 200 const MemoryMap& memory_map, | 200 const MemoryMap& memory_map, |
| 201 std::vector<PageInfo>* committed_pages, | 201 std::vector<PageInfo>* committed_pages, |
| 202 BitSet* committed_pages_bits) { | 202 BitSet* committed_pages_bits) { |
| 203 off64_t offset = memory_map.start_address / kPageSize; | |
|
Philippe
2014/02/26 12:05:48
Nit: const off64_t offset
Reviewers in Chromium w
hyunki
2014/02/27 01:15:06
Done.
| |
| 204 if (lseek64(pagemap_fd, offset * sizeof(PageMapEntry), SEEK_SET) < 0) { | |
| 205 PLOG(ERROR) << "lseek"; | |
| 206 return false; | |
| 207 } | |
| 203 for (uint addr = memory_map.start_address, page_index = 0; | 208 for (uint addr = memory_map.start_address, page_index = 0; |
| 204 addr < memory_map.end_address; | 209 addr < memory_map.end_address; |
| 205 addr += kPageSize, ++page_index) { | 210 addr += kPageSize, ++page_index) { |
| 206 DCHECK_EQ(0, addr % kPageSize); | 211 DCHECK_EQ(0, addr % kPageSize); |
| 207 PageMapEntry page_map_entry = {}; | 212 PageMapEntry page_map_entry = {}; |
| 208 COMPILE_ASSERT(sizeof(PageMapEntry) == sizeof(uint64), unexpected_size); | 213 COMPILE_ASSERT(sizeof(PageMapEntry) == sizeof(uint64), unexpected_size); |
| 209 const off64_t offset = addr / kPageSize; | 214 offset++; |
|
Philippe
2014/02/26 12:05:48
Nit: You don't seem to be using |offset| in the lo
hyunki
2014/02/27 01:15:06
Done.
| |
| 210 if (!ReadFromFileAtOffset(pagemap_fd, offset, &page_map_entry)) | 215 ssize_t bytes = read(pagemap_fd, &page_map_entry, sizeof(PageMapEntry)); |
|
Philippe
2014/02/26 12:05:48
Nit: sizeof(page_map_entry) would be slightly bett
hyunki
2014/02/27 01:15:06
Done.
| |
| 216 if (bytes != sizeof(PageMapEntry) && bytes != 0) { | |
| 217 PLOG(ERROR) << "read"; | |
| 211 return false; | 218 return false; |
| 219 } | |
| 212 if (page_map_entry.present) { // Ignore non-committed pages. | 220 if (page_map_entry.present) { // Ignore non-committed pages. |
| 213 if (page_map_entry.page_frame_number == 0) | 221 if (page_map_entry.page_frame_number == 0) |
| 214 continue; | 222 continue; |
| 215 PageInfo page_info = {}; | 223 PageInfo page_info = {}; |
| 216 page_info.page_frame_number = page_map_entry.page_frame_number; | 224 page_info.page_frame_number = page_map_entry.page_frame_number; |
| 217 committed_pages->push_back(page_info); | 225 committed_pages->push_back(page_info); |
| 218 committed_pages_bits->set(page_index); | 226 committed_pages_bits->set(page_index); |
| 219 } | 227 } |
| 220 } | 228 } |
| 221 return true; | 229 return true; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 } | 520 } |
| 513 } | 521 } |
| 514 | 522 |
| 515 ClassifyPages(&processes_memory); | 523 ClassifyPages(&processes_memory); |
| 516 if (short_output) | 524 if (short_output) |
| 517 DumpProcessesMemoryMapsInShortFormat(processes_memory); | 525 DumpProcessesMemoryMapsInShortFormat(processes_memory); |
| 518 else | 526 else |
| 519 DumpProcessesMemoryMapsInExtendedFormat(processes_memory); | 527 DumpProcessesMemoryMapsInExtendedFormat(processes_memory); |
| 520 return EXIT_SUCCESS; | 528 return EXIT_SUCCESS; |
| 521 } | 529 } |
| OLD | NEW |