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

Unified Diff: tools/cygprofile/check_orderfile.py

Issue 891713002: Script checking that the observed function order matches an orderfile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Spacing, naming, unused imports. Created 5 years, 11 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/cygprofile/check_orderfile.py
diff --git a/tools/cygprofile/check_orderfile.py b/tools/cygprofile/check_orderfile.py
new file mode 100755
index 0000000000000000000000000000000000000000..3a7f4d89c3ac8e377fbda1b1c0594eea7fef4817
--- /dev/null
+++ b/tools/cygprofile/check_orderfile.py
@@ -0,0 +1,80 @@
+#!/usr/bin/python
+# Copyright 2015 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.
+
+"""Check that symbols are ordered into a binary as they appear in the orderfile.
+"""
+
+import logging
+import sys
+
+import symbol_extractor
+import patch_orderfile
pasko 2015/02/02 10:00:30 nit: alpha
Benoit L 2015/02/02 13:11:45 Done.
+
+
+_MAX_WARNINGS_TO_PRINT = 200
+
+
+def _CountMisorderedSymbols(symbols, symbol_infos):
+ """Count the number of misordered symbols, and log them.
+
+ Args:
+ symbols: ordered sequence of symbols from the orderfile
+ symbol_infos: list of SymbolInfo from the binary
pasko 2015/02/02 10:00:30 nit: s/list/ordered list/ (seems tiny-ish confusin
Benoit L 2015/02/02 13:11:45 Done.
+
+ Returns:
+ (misordered_pairs_count, matched_symbols, unmatched_symbols)
pasko 2015/02/02 10:00:30 matched_symbols_count and unmatched_symbols_count?
Benoit L 2015/02/02 13:11:45 Done.
+ """
+ name_to_symbol_info = symbol_extractor.CreateNameToSymbolInfo(symbol_infos)
pasko 2015/02/02 10:00:30 here we are creating a mapping [name -> info], but
Benoit L 2015/02/02 13:11:45 Yes, I think it is better to keep the whole Symbol
pasko 2015/02/02 14:32:37 OK, given your consideration, seems like a good en
+ matched_symbol_infos = []
+ missing_count = 0
+
+ # Find the SymbolInfo matching the orderfile symbols in the binary.
+ for symbol in symbols:
+ if symbol in name_to_symbol_info:
+ matched_symbol_infos.append(name_to_symbol_info[symbol])
+ else:
+ missing_count += 1
+ if missing_count < _MAX_WARNINGS_TO_PRINT:
+ logging.warning('Symbol "%s" is in the orderfile, not in the binary' %
+ symbol)
+ logging.warning('%d matched symbols, %d un-matched (Only the first %d '
pasko 2015/02/02 10:00:30 this warning should be under: if missing_count > 0
Benoit L 2015/02/02 13:11:45 I think that printing the number of matched symbol
pasko 2015/02/02 14:32:37 ok, then let's make it log.info to avoid the sea o
+ 'unmatched symbols are shown)' % (
+ len(matched_symbol_infos), missing_count,
+ _MAX_WARNINGS_TO_PRINT))
+
+ # In the order of the orderfile, find all the symbols that are at an offset
+ # smaller than their immediate predecessor, and record the pair.
+ misordered_symbol_infos = []
+ previous_symbol_info = symbol_extractor.SymbolInfo(
+ name='', offset=-1, size=0, section='')
+ for symbol_info in matched_symbol_infos:
+ if symbol_info.offset < previous_symbol_info.offset:
+ misordered_symbol_infos.append((symbol_info, previous_symbol_info))
+ previous_symbol_info = symbol_info
+
+ if len(misordered_symbol_infos) > 0:
+ for (first, second) in misordered_symbol_infos:
pasko 2015/02/02 10:00:30 Iterating for it second time makes it harder to re
Benoit L 2015/02/02 13:11:45 Done, but still printing the whole SymbolInfo (for
pasko 2015/02/02 14:32:37 Acknowledged.
+ logging.warning("Unordered pair: %s - %s" % (str(first), str(second)))
+ return (len(misordered_symbol_infos), len(matched_symbol_infos),
+ missing_count)
+
+
+def main():
+ if len(sys.argv) != 4:
+ logging.error('Usage: check_orderfile.py binary orderfile threshold')
pasko 2015/02/02 10:00:30 I'm about polishing again: can threshold be option
Benoit L 2015/02/02 13:11:45 Done.
+ return 1
+ (binary_filename, orderfile_filename, threshold) = sys.argv[1:]
+ threshold = int(threshold)
+
+ symbols = patch_orderfile._GetSymbolsFromOrderfile(orderfile_filename)
+ symbol_infos = symbol_extractor.SymbolInfosFromBinary(binary_filename)
+ (misordered_pairs_count, _, _) = _CountMisorderedSymbols(
pasko 2015/02/02 10:00:30 Please mention in the comment the non-obvious obse
Benoit L 2015/02/02 13:11:45 Done.
+ symbols, symbol_infos)
+ return misordered_pairs_count > threshold
+
+
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.INFO)
+ sys.exit(main())
« no previous file with comments | « no previous file | tools/cygprofile/check_orderfile_unittest.py » ('j') | tools/cygprofile/check_orderfile_unittest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698