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

Side by Side Diff: tools/win/pdb_compare_globals.py

Issue 2592323002: Script to compare global variables between two PDBs (Closed)
Patch Set: Created 3 years, 12 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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(pdbA, pdbB, nameA, nameB):
stanisc 2016/12/22 21:13:20 pdbA and pdbB names are a bit confusing because th
brucedawson 2016/12/22 21:35:00 How about symbols_1/symbols_2 and symbols_A/symbol
48 print 'Symbols that are in %s but not in %s' % (nameA, nameB)
49 for key in pdbA:
50 if not key in pdbB:
51 # Print all the numerical data, followed by the symbol name, separated by
52 # tabs.
53 print '\t'.join(pdbA[key] + [key])
54 print
55
56
57 def ShowDifferences(pdbA, pdbB, nameA, nameB):
58 print 'Symbols that are changed from %s to %s' % (nameA, nameB)
59 for key in pdbA:
60 if key in pdbB:
stanisc 2016/12/22 21:13:20 if key in pdbA and key in pdbB ?
brucedawson 2016/12/22 21:35:00 The key is guaranteed to be in pdbA because we are
stanisc 2016/12/22 21:48:21 What I meant is to replace two "if" statements, th
brucedawson 2016/12/22 22:03:29 I don't think that works because then we don't kno
61 value_a = pdbA[key]
62 value_b = pdbB[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(pdbA[key])
68 print '\t' + '\t'.join(pdbB[key])
stanisc 2016/12/22 21:13:20 replace pdbA[key] with value_a and pdbB[key] with
brucedawson 2016/12/22 21:35:00 Good catch. Done.
69 print
70
71
72 def main():
73 pdb1 = LoadSymbols(sys.argv[1])
74 pdb2 = LoadSymbols(sys.argv[2])
75
76 if len(pdb1) == 0:
77 print 'No data found in %s - fastlink?' % sys.argv[1]
78 return
79 if len(pdb2) == 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(pdb1), sys.argv[1], len(pdb2), sys.argv[2]))
85
86 ShowExtras(pdb1, pdb2, sys.argv[1], sys.argv[2])
87 ShowExtras(pdb2, pdb1, sys.argv[2], sys.argv[1])
88 ShowDifferences(pdb1, pdb2, sys.argv[1], sys.argv[2])
89
90
91 if __name__ == '__main__':
92 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698