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

Side by Side Diff: tools/binary_size/libsupersize/console.py

Issue 2817813003: supersize: Add "diff" command (Closed)
Patch Set: review commetns Created 3 years, 8 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 | « tools/binary_size/libsupersize/archive.py ('k') | tools/binary_size/libsupersize/describe.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2017 The Chromium Authors. All rights reserved. 1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """An interactive console for looking analyzing .size files.""" 5 """An interactive console for looking analyzing .size files."""
6 6
7 import argparse 7 import argparse
8 import atexit 8 import atexit
9 import code 9 import code
10 import contextlib 10 import contextlib
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 cls._readline_initialized = True 199 cls._readline_initialized = True
200 # Without initializing readline, arrow keys don't even work! 200 # Without initializing readline, arrow keys don't even work!
201 readline.parse_and_bind('tab: complete') 201 readline.parse_and_bind('tab: complete')
202 history_file = os.path.join(os.path.expanduser('~'), 202 history_file = os.path.join(os.path.expanduser('~'),
203 '.binary_size_query_history') 203 '.binary_size_query_history')
204 if os.path.exists(history_file): 204 if os.path.exists(history_file):
205 readline.read_history_file(history_file) 205 readline.read_history_file(history_file)
206 atexit.register(lambda: readline.write_history_file(history_file)) 206 atexit.register(lambda: readline.write_history_file(history_file))
207 207
208 def Eval(self, query): 208 def Eval(self, query):
209 eval_result = eval(query, self._variables) 209 exec query in self._variables
210 if eval_result:
211 self._PrintFunc(eval_result)
212 210
213 def GoInteractive(self): 211 def GoInteractive(self):
214 _Session._InitReadline() 212 _Session._InitReadline()
215 code.InteractiveConsole(self._variables).interact(self._CreateBanner()) 213 code.InteractiveConsole(self._variables).interact(self._CreateBanner())
216 214
217 215
218 def AddArguments(parser): 216 def AddArguments(parser):
219 parser.add_argument( 217 parser.add_argument(
220 'inputs', nargs='+', 218 'inputs', nargs='+',
221 help='Input .size files to load. For a single file, it will be mapped to ' 219 help='Input .size files to load. For a single file, it will be mapped to '
222 'the variable "size_info". For multiple inputs, the names will be ' 220 'the variable "size_info". For multiple inputs, the names will be '
223 'size_info1, size_info2, etc.') 221 'size_info1, size_info2, etc.')
224 parser.add_argument( 222 parser.add_argument('--query',
225 '--query', help='Print the result of the given snippet. Example: ' 223 help='Execute the given snippet. '
226 'size_info.symbols.WhereInSection("d")' 224 'Example: Print(size_info)')
227 '.WhereBiggerThan(100)')
228 parser.add_argument('--tool-prefix', default='', 225 parser.add_argument('--tool-prefix', default='',
229 help='Path prefix for objdump. Required only for ' 226 help='Path prefix for objdump. Required only for '
230 'Disassemble().') 227 'Disassemble().')
231 parser.add_argument('--output-directory', 228 parser.add_argument('--output-directory',
232 help='Path to the root build directory. Used only for ' 229 help='Path to the root build directory. Used only for '
233 'Disassemble().') 230 'Disassemble().')
234 231
235 232
236 def Run(args, parser): 233 def Run(args, parser):
237 for path in args.inputs: 234 for path in args.inputs:
238 if not path.endswith('.size'): 235 if not path.endswith('.size'):
239 parser.error('All inputs must end with ".size"') 236 parser.error('All inputs must end with ".size"')
240 237
241 size_infos = [archive.LoadAndPostProcessSizeInfo(p) for p in args.inputs] 238 size_infos = [archive.LoadAndPostProcessSizeInfo(p) for p in args.inputs]
242 lazy_paths = paths.LazyPaths(args=args, input_file=args.inputs[0]) 239 lazy_paths = paths.LazyPaths(tool_prefix=args.tool_prefix,
240 output_directory=args.output_directory,
241 any_path_within_output_directory=args.inputs[0])
243 session = _Session(size_infos, lazy_paths) 242 session = _Session(size_infos, lazy_paths)
244 243
245 if args.query: 244 if args.query:
246 logging.info('Running query from command-line.') 245 logging.info('Running query from command-line.')
247 session.Eval(args.query) 246 session.Eval(args.query)
248 else: 247 else:
249 logging.info('Entering interactive console.') 248 logging.info('Entering interactive console.')
250 session.GoInteractive() 249 session.GoInteractive()
OLDNEW
« no previous file with comments | « tools/binary_size/libsupersize/archive.py ('k') | tools/binary_size/libsupersize/describe.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698