OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """ |
| 6 This script uses ShowGlobals.exe to compare two PDBs to see what interesting |
| 7 globals are present in one but not the other. You can either pass in a .pdb file |
| 8 or you can pass in a .txt file that contains the results of calling ShowGlobals. |
| 9 This helps when investigating size regressions. Often code-size regressions are |
| 10 associated with global variable changes, and those global variables can be |
| 11 easier to track and investigate than the code. |
| 12 |
| 13 Typical output from ShowGlobals.exe is lines like these: |
| 14 |
| 15 #Dups DupSize Size Section Symbol name PDB name |
| 16 |
| 17 0 0 122784 2 kBrotliDictionary chrome.dll.pdb |
| 18 1 1824 0 0 LcidToLocaleNameTable chrome.dll.pdb |
| 19 """ |
| 20 |
| 21 import os |
| 22 import subprocess |
| 23 import sys |
| 24 |
| 25 |
| 26 def LoadSymbols(pdb_name): |
| 27 result = {} |
| 28 extension = os.path.splitext(pdb_name)[1].lower() |
| 29 if extension in ['.pdb']: |
| 30 command = 'ShowGlobals.exe "%s"' % pdb_name |
| 31 lines = subprocess.check_output(command).splitlines() |
| 32 elif extension in ['.txt']: |
| 33 lines = open(pdb_name).readlines() |
| 34 else: |
| 35 print 'Unrecognized extension in %s' % pdb_name |
| 36 return result |
| 37 for line in lines: |
| 38 parts = line.split('\t') |
| 39 if len(parts) >= 5 and not line.startswith('#'): |
| 40 # Put the first four columns (the numerical data associated with a symbol) |
| 41 # into a dictionary indexed by the fifth column, which is the symbol name. |
| 42 symbol_name = parts[4] |
| 43 result[symbol_name] = parts[:4] |
| 44 return result |
| 45 |
| 46 |
| 47 def ShowExtras(symbols_A, symbols_B, name_A, name_B): |
| 48 print 'Symbols that are in %s but not in %s' % (name_A, name_B) |
| 49 for key in symbols_A: |
| 50 if not key in symbols_B: |
| 51 # Print all the numerical data, followed by the symbol name, separated by |
| 52 # tabs. |
| 53 print '\t'.join(symbols_A[key] + [key]) |
| 54 print |
| 55 |
| 56 |
| 57 def ShowDifferences(symbols_A, symbols_B, name_A, name_B): |
| 58 print 'Symbols that are changed from %s to %s' % (name_A, name_B) |
| 59 for key in symbols_A: |
| 60 if key in symbols_B: |
| 61 value_a = symbols_A[key] |
| 62 value_b = symbols_B[key] |
| 63 if value_a != value_b: |
| 64 # Print the symbol name and then the two versions of the numerical data, |
| 65 # indented. |
| 66 print '%s changed from/to:' % key |
| 67 print '\t' + '\t'.join(value_a) |
| 68 print '\t' + '\t'.join(value_b) |
| 69 print |
| 70 |
| 71 |
| 72 def main(): |
| 73 symbols_1 = LoadSymbols(sys.argv[1]) |
| 74 symbols_2 = LoadSymbols(sys.argv[2]) |
| 75 |
| 76 if len(symbols_1) == 0: |
| 77 print 'No data found in %s - fastlink?' % sys.argv[1] |
| 78 return |
| 79 if len(symbols_2) == 0: |
| 80 print 'No data found in %s - fastlink?' % sys.argv[2] |
| 81 return |
| 82 |
| 83 print ('%d interesting globals in %s, %d interesting globals in %s' % |
| 84 (len(symbols_1), sys.argv[1], len(symbols_2), sys.argv[2])) |
| 85 |
| 86 ShowExtras(symbols_1, symbols_2, sys.argv[1], sys.argv[2]) |
| 87 ShowExtras(symbols_2, symbols_1, sys.argv[2], sys.argv[1]) |
| 88 ShowDifferences(symbols_1, symbols_2, sys.argv[1], sys.argv[2]) |
| 89 |
| 90 |
| 91 if __name__ == '__main__': |
| 92 sys.exit(main()) |
OLD | NEW |