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

Unified Diff: tools/win/pdb_compare_globals.py

Issue 2592323002: Script to compare global variables between two PDBs (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/win/pdb_compare_globals.py
diff --git a/tools/win/pdb_compare_globals.py b/tools/win/pdb_compare_globals.py
new file mode 100644
index 0000000000000000000000000000000000000000..0f9a6071327033061139655ecacfeddfd75da588
--- /dev/null
+++ b/tools/win/pdb_compare_globals.py
@@ -0,0 +1,92 @@
+# Copyright (c) 2016 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 script uses ShowGlobals.exe to compare two PDBs to see what interesting
+globals are present in one but not the other. You can either pass in a .pdb file
+or you can pass in a .txt file that contains the results of calling ShowGlobals.
+This helps when investigating size regressions. Often code-size regressions are
+associated with global variable changes, and those global variables can be
+easier to track and investigate than the code.
+
+Typical output from ShowGlobals.exe is lines like these:
+
+ #Dups DupSize Size Section Symbol name PDB name
+
+ 0 0 122784 2 kBrotliDictionary chrome.dll.pdb
+ 1 1824 0 0 LcidToLocaleNameTable chrome.dll.pdb
+"""
+
+import os
+import subprocess
+import sys
+
+
+def LoadSymbols(pdb_name):
+ result = {}
+ extension = os.path.splitext(pdb_name)[1].lower()
+ if extension in ['.pdb']:
+ command = 'ShowGlobals.exe "%s"' % pdb_name
+ lines = subprocess.check_output(command).splitlines()
+ elif extension in ['.txt']:
+ lines = open(pdb_name).readlines()
+ else:
+ print 'Unrecognized extension in %s' % pdb_name
+ return result
+ for line in lines:
+ parts = line.split('\t')
+ if len(parts) >= 5 and not line.startswith('#'):
+ # Put the first four columns (the numerical data associated with a symbol)
+ # into a dictionary indexed by the fifth column, which is the symbol name.
+ symbol_name = parts[4]
+ result[symbol_name] = parts[:4]
+ return result
+
+
+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
+ print 'Symbols that are in %s but not in %s' % (nameA, nameB)
+ for key in pdbA:
+ if not key in pdbB:
+ # Print all the numerical data, followed by the symbol name, separated by
+ # tabs.
+ print '\t'.join(pdbA[key] + [key])
+ print
+
+
+def ShowDifferences(pdbA, pdbB, nameA, nameB):
+ print 'Symbols that are changed from %s to %s' % (nameA, nameB)
+ for key in pdbA:
+ 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
+ value_a = pdbA[key]
+ value_b = pdbB[key]
+ if value_a != value_b:
+ # Print the symbol name and then the two versions of the numerical data,
+ # indented.
+ print '%s changed from/to:' % key
+ print '\t' + '\t'.join(pdbA[key])
+ 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.
+ print
+
+
+def main():
+ pdb1 = LoadSymbols(sys.argv[1])
+ pdb2 = LoadSymbols(sys.argv[2])
+
+ if len(pdb1) == 0:
+ print 'No data found in %s - fastlink?' % sys.argv[1]
+ return
+ if len(pdb2) == 0:
+ print 'No data found in %s - fastlink?' % sys.argv[2]
+ return
+
+ print ('%d interesting globals in %s, %d interesting globals in %s' %
+ (len(pdb1), sys.argv[1], len(pdb2), sys.argv[2]))
+
+ ShowExtras(pdb1, pdb2, sys.argv[1], sys.argv[2])
+ ShowExtras(pdb2, pdb1, sys.argv[2], sys.argv[1])
+ ShowDifferences(pdb1, pdb2, sys.argv[1], sys.argv[2])
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« 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