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

Unified Diff: tools/memory_inspector/memory_inspector/backends/android/memdump_parser.py

Issue 574663002: [Android] memory_inspector: move backends one folder up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 months 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 side-by-side diff with in-line comments
Download patch
Index: tools/memory_inspector/memory_inspector/backends/android/memdump_parser.py
diff --git a/tools/memory_inspector/memory_inspector/backends/android/memdump_parser.py b/tools/memory_inspector/memory_inspector/backends/android/memdump_parser.py
deleted file mode 100644
index a60ea2503ffdbfa9686b86ee2ff7056746edd511..0000000000000000000000000000000000000000
--- a/tools/memory_inspector/memory_inspector/backends/android/memdump_parser.py
+++ /dev/null
@@ -1,87 +0,0 @@
-# Copyright 2014 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-"""This parser turns the am memdump output into a |memory_map.Map| instance."""
-
-import base64
-import logging
-import re
-
-from memory_inspector.core import memory_map
-
-
-def Parse(lines):
- """Parses the output of memdump.
-
- memdump (see chrome/src/tools/memdump) is a Linux/Android binary meant to be
- executed on the target device which extracts memory map information about one
- or more processes. In principle is can be seen as an alternative to cat-ing
- /proc/PID/smaps, but with extra features (multiprocess accounting and resident
- pages reporting).
-
- The expected memdump output looks like this:
- ------------------------------------------------------------------------------
- [ PID=1234]
- 1000-2000 r-xp 0 private_unevictable=4096 private=8192 shared_app=[] \
- shared_other_unevictable=4096 shared_other=4096 "/lib/foo.so" [v///fv0D]
- ... other entries like the one above.
- ------------------------------------------------------------------------------
- The output is extremely similar to /proc/PID/smaps, with the following notes:
- - unevictable has pretty much the same meaning of "dirty", in VM terms.
- - private and shared_other are cumulative. This means the the "clean" part
- must be calculated as difference of (private - private_unevictable).
- - The final field [v///fv0D] is a base64 encoded bitmap which contains the
- information about which pages inside the mapping are resident (present).
- See tests/android_backend_test.py for a more complete example.
-
- Args:
- lines: array of strings containing memdump output.
-
- Returns:
- An instance of |memory_map.Map|.
- """
- RE = (r'^([0-9a-f]+)-([0-9a-f]+)\s+'
- r'([rwxps-]{4})\s+'
- r'([0-9a-f]+)\s+'
- r'private_unevictable=(\d+) private=(\d+) '
- r'shared_app=(.*?) '
- r'shared_other_unevictable=(\d+) shared_other=(\d+) '
- r'\"(.*)\" '
- r'\[([a-zA-Z0-9+/=-_:]*)\]$')
- map_re = re.compile(RE)
- skip_first_n_lines = 1
- maps = memory_map.Map()
-
- for line in lines:
- line = line.rstrip('\r\n')
-
- if skip_first_n_lines > 0:
- skip_first_n_lines -= 1
- continue
-
- m = map_re.match(line)
- if not m:
- logging.warning('Skipping unrecognized memdump line "%s"' % line)
- continue
-
- start = int(m.group(1), 16)
- end = int(m.group(2), 16) - 1 # end addr is inclusive in memdump output.
- if (start > end):
- # Sadly, this actually happened. Probably a kernel bug, see b/17402069.
- logging.warning('Skipping unfeasible mmap "%s"' % line)
- continue
- entry = memory_map.MapEntry(
- start=start,
- end=end,
- prot_flags=m.group(3),
- mapped_file=m.group(10),
- mapped_offset=int(m.group(4), 16))
- entry.priv_dirty_bytes = int(m.group(5))
- entry.priv_clean_bytes = int(m.group(6)) - entry.priv_dirty_bytes
- entry.shared_dirty_bytes = int(m.group(8))
- entry.shared_clean_bytes = int(m.group(9)) - entry.shared_dirty_bytes
- entry.resident_pages = [ord(c) for c in base64.b64decode(m.group(11))]
- maps.Add(entry)
-
- return maps

Powered by Google App Engine
This is Rietveld 408576698