1# Copyright 2013 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 5import sys 6 7from lib.subcommand import SubCommand 8 9 10class StacktraceCommand(SubCommand): 11 def __init__(self): 12 super(StacktraceCommand, self).__init__( 13 'Usage: %prog stacktrace <dump>') 14 15 def do(self, sys_argv): 16 _, args = self._parse_args(sys_argv, 1) 17 dump_path = args[1] 18 (bucket_set, dump) = SubCommand.load_basic_files(dump_path, False) 19 20 StacktraceCommand._output(dump, bucket_set, sys.stdout) 21 return 0 22 23 @staticmethod 24 def _output(dump, bucket_set, out): 25 """Outputs a given stacktrace. 26 27 Args: 28 bucket_set: A BucketSet object. 29 out: A file object to output. 30 """ 31 for bucket_id, virtual, committed, allocs, frees in dump.iter_stacktrace: 32 bucket = bucket_set.get(bucket_id) 33 if not bucket: 34 continue 35 out.write('%d %d %d %d ' % (virtual, committed, allocs, frees)) 36 for frame in bucket.symbolized_stackfunction: 37 out.write(frame + ' ') 38 out.write('\n') 39