diff options
| author | Christopher Ferris <cferris@google.com> | 2018-07-10 19:24:46 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-07-10 19:24:46 +0000 |
| commit | 062202eb398f547c8426b2a3ea77f5636ac8e7db (patch) | |
| tree | ac769076eb16d5844c9d4d037077cbbace1df584 /scripts | |
| parent | 1506d72a4b924d9f81aaedc5fcd70f1295de2a83 (diff) | |
| parent | b558fe4d53cf641f68c2086b3847690c56e0f9cf (diff) | |
| download | android_development-062202eb398f547c8426b2a3ea77f5636ac8e7db.tar.gz android_development-062202eb398f547c8426b2a3ea77f5636ac8e7db.tar.bz2 android_development-062202eb398f547c8426b2a3ea77f5636ac8e7db.zip | |
Merge "Detect if num field is valid on v1.0 version."
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/native_heapdump_viewer.py | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/scripts/native_heapdump_viewer.py b/scripts/native_heapdump_viewer.py index 32b99db3c..b74b1b52c 100755 --- a/scripts/native_heapdump_viewer.py +++ b/scripts/native_heapdump_viewer.py @@ -117,11 +117,52 @@ def GetVersion(native_heap): return m.group('version') return None +def NumFieldValid(native_heap): + """Determine if the num field is valid. + + Malloc debug for N incorrectly set the num field to the number of + backtraces instead of the number of allocations with the same size and + backtrace. Read the file and if at least three lines all have the field + set to the number of backtraces values, then consider this generated by + the buggy malloc debug and indicate the num field is not valid. + + Returns: + True if the num field is valid. + False if the num field is not valid and should be ignored. + """ + + re_backtrace = re.compile("Backtrace\s+size:\s+(?P<backtrace_size>\d+)") + + re_line = re.compile("z\s+(?P<zygote>\d+)\s+sz\s+(?P<size>\d+)\s+num\s+(?P<num_allocations>\d+)") + matched = 0 + backtrace_size = 0 + for line in open(native_heap, "r"): + if backtrace_size == 0: + m = re_backtrace.match(line) + if m: + backtrace_size = int(m.group('backtrace_size')) + parts = line.split() + if len(parts) > 7 and parts[0] == "z" and parts[2] == "sz": + m = re_line.match(line) + if m: + num_allocations = int(m.group('num_allocations')) + if num_allocations == backtrace_size: + # At least three lines must match this pattern before + # considering this the old buggy version of malloc debug. + matched += 1 + if matched == 3: + return False + else: + return True + return matched == 0 + version = GetVersion(native_heap) if not version or version == "v1.0": # Version v1.0 was produced by a buggy version of malloc debug where the # num field was set incorrectly. - num_field_valid = False + # Unfortunately, Android P produced a v1.0 version that does set the + # num field. Do one more check to see if this is the broken version. + num_field_valid = NumFieldValid(native_heap) else: num_field_valid = True |
