Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / tools / deep_memory_profiler / dmprof.py
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.
4
5 """The Deep Memory Profiler analyzer script.
6
7 See http://dev.chromium.org/developers/deep-memory-profiler for details.
8 """
9
10 import logging
11 import sys
12
13 from lib.exceptions import ParsingException
14 import subcommands
15
16
17 LOGGER = logging.getLogger('dmprof')
18
19
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,
33   }
34
35   if len(sys.argv) < 2 or (not sys.argv[1] in COMMANDS):
36     sys.stderr.write("""Usage: dmprof <command> [options] [<args>]
37
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
49
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)
64
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)
71
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)
77
78   return errorcode
79
80
81 if __name__ == '__main__':
82   sys.exit(main())