Revert of Remove RenderViewObserver as RendererCldDataProviderFactory arg. (patchset...
[chromium-blink-merge.git] / tools / deep_memory_profiler / dmprof.py
blob85c1f6d8c0f288a3e970d00434e6b5814a86dc15
1 # Copyright (c) 2012 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.
5 """The Deep Memory Profiler analyzer script.
7 See http://dev.chromium.org/developers/deep-memory-profiler for details.
8 """
10 import logging
11 import sys
13 from lib.exceptions import ParsingException
14 import subcommands
17 LOGGER = logging.getLogger('dmprof')
20 def main():
21 COMMANDS = {
22 'addr': subcommands.AddrCommand,
23 'buckets': subcommands.BucketsCommand,
24 'cat': subcommands.CatCommand,
25 'csv': subcommands.CSVCommand,
26 'expand': subcommands.ExpandCommand,
27 'json': subcommands.JSONCommand,
28 'list': subcommands.ListCommand,
29 'map': subcommands.MapCommand,
30 'pprof': subcommands.PProfCommand,
31 'stacktrace': subcommands.StacktraceCommand,
32 'upload': subcommands.UploadCommand,
35 if len(sys.argv) < 2 or (not sys.argv[1] in COMMANDS):
36 sys.stderr.write("""Usage: dmprof <command> [options] [<args>]
38 Commands:
39 buckets Dump a bucket list with resolving symbols
40 cat Categorize memory usage (under development)
41 csv Classify memory usage in CSV
42 expand Show all stacktraces contained in the specified component
43 json Classify memory usage in JSON
44 list Classify memory usage in simple listing format
45 map Show history of mapped regions
46 pprof Format the profile dump so that it can be processed by pprof
47 stacktrace Convert runtime addresses to symbol names
48 upload Upload dumped files
50 Quick Reference:
51 dmprof buckets <first-dump>
52 dmprof cat <first-dump>
53 dmprof csv [-p POLICY] <first-dump>
54 dmprof expand <dump> <policy> <component> <depth>
55 dmprof json [-p POLICY] <first-dump>
56 dmprof list [-p POLICY] <first-dump>
57 dmprof map <first-dump> <policy>
58 dmprof pprof [-c COMPONENT] <dump> <policy>
59 dmprof stacktrace <dump>
60 dmprof upload [--gsutil path/to/gsutil] <first-dump> <destination-gs-path>
61 """)
62 sys.exit(1)
63 action = sys.argv.pop(1)
65 LOGGER.setLevel(logging.DEBUG)
66 handler = logging.StreamHandler()
67 handler.setLevel(logging.INFO)
68 formatter = logging.Formatter('%(message)s')
69 handler.setFormatter(formatter)
70 LOGGER.addHandler(handler)
72 try:
73 errorcode = COMMANDS[action]().do(sys.argv)
74 except ParsingException, e:
75 errorcode = 1
76 sys.stderr.write('Exit by parsing error: %s\n' % e)
78 return errorcode
81 if __name__ == '__main__':
82 sys.exit(main())