summaryrefslogtreecommitdiffstats
path: root/scripts/pybootchartgui/pybootchartgui/main.py.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/pybootchartgui/pybootchartgui/main.py.in')
-rw-r--r--scripts/pybootchartgui/pybootchartgui/main.py.in187
1 files changed, 187 insertions, 0 deletions
diff --git a/scripts/pybootchartgui/pybootchartgui/main.py.in b/scripts/pybootchartgui/pybootchartgui/main.py.in
new file mode 100644
index 0000000000..21bb0be3a7
--- /dev/null
+++ b/scripts/pybootchartgui/pybootchartgui/main.py.in
@@ -0,0 +1,187 @@
1#
2# ***********************************************************************
3# Warning: This file is auto-generated from main.py.in - edit it there.
4# ***********************************************************************
5#
6# pybootchartgui is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10
11# pybootchartgui is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15
16# You should have received a copy of the GNU General Public License
17# along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>.
18
19from __future__ import print_function
20
21import sys
22import os
23import optparse
24
25from . import parsing
26from . import batch
27
28def _mk_options_parser():
29 """Make an options parser."""
30 usage = "%prog [options] /path/to/tmp/buildstats/<recipe-machine>/<BUILDNAME>/"
31 version = "%prog v1.0.0"
32 parser = optparse.OptionParser(usage, version=version)
33 parser.add_option("-i", "--interactive", action="store_true", dest="interactive", default=False,
34 help="start in active mode")
35 parser.add_option("-f", "--format", dest="format", default="png", choices=["png", "svg", "pdf"],
36 help="image format (png, svg, pdf); default format png")
37 parser.add_option("-o", "--output", dest="output", metavar="PATH", default=None,
38 help="output path (file or directory) where charts are stored")
39 parser.add_option("-s", "--split", dest="num", type=int, default=1,
40 help="split the output chart into <NUM> charts, only works with \"-o PATH\"")
41 parser.add_option("-m", "--mintime", dest="mintime", type=int, default=8,
42 help="only tasks longer than this time will be displayed")
43 parser.add_option("-M", "--minutes", action="store_true", dest="as_minutes", default=False,
44 help="display time in minutes instead of seconds")
45# parser.add_option("-n", "--no-prune", action="store_false", dest="prune", default=True,
46# help="do not prune the process tree")
47 parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False,
48 help="suppress informational messages")
49# parser.add_option("-t", "--boot-time", action="store_true", dest="boottime", default=False,
50# help="only display the boot time of the boot in text format (stdout)")
51 parser.add_option("--very-quiet", action="store_true", dest="veryquiet", default=False,
52 help="suppress all messages except errors")
53 parser.add_option("--verbose", action="store_true", dest="verbose", default=False,
54 help="print all messages")
55# parser.add_option("--profile", action="store_true", dest="profile", default=False,
56# help="profile rendering of chart (only useful when in batch mode indicated by -f)")
57# parser.add_option("--show-pid", action="store_true", dest="show_pid", default=False,
58# help="show process ids in the bootchart as 'processname [pid]'")
59 parser.add_option("--show-all", action="store_true", dest="show_all", default=False,
60 help="show all processes in the chart")
61# parser.add_option("--crop-after", dest="crop_after", metavar="PROCESS", default=None,
62# help="crop chart when idle after PROCESS is started")
63# parser.add_option("--annotate", action="append", dest="annotate", metavar="PROCESS", default=None,
64# help="annotate position where PROCESS is started; can be specified multiple times. " +
65# "To create a single annotation when any one of a set of processes is started, use commas to separate the names")
66# parser.add_option("--annotate-file", dest="annotate_file", metavar="FILENAME", default=None,
67# help="filename to write annotation points to")
68 parser.add_option("-T", "--full-time", action="store_true", dest="full_time", default=False,
69 help="display the full time regardless of which processes are currently shown")
70 return parser
71
72class Writer:
73 def __init__(self, write, options):
74 self.write = write
75 self.options = options
76
77 def error(self, msg):
78 self.write(msg)
79
80 def warn(self, msg):
81 if not self.options.quiet:
82 self.write(msg)
83
84 def info(self, msg):
85 if self.options.verbose:
86 self.write(msg)
87
88 def status(self, msg):
89 if not self.options.quiet:
90 self.write(msg)
91
92def _mk_writer(options):
93 def write(s):
94 print(s)
95 return Writer(write, options)
96
97def _get_filename(path):
98 """Construct a usable filename for outputs"""
99 dname = "."
100 fname = "bootchart"
101 if path != None:
102 if os.path.isdir(path):
103 dname = path
104 else:
105 fname = path
106 return os.path.join(dname, fname)
107
108def main(argv=None):
109 try:
110 if argv is None:
111 argv = sys.argv[1:]
112
113 parser = _mk_options_parser()
114 options, args = parser.parse_args(argv)
115
116 # Default values for disabled options
117 options.prune = True
118 options.boottime = False
119 options.profile = False
120 options.show_pid = False
121 options.crop_after = None
122 options.annotate = None
123 options.annotate_file = None
124
125 writer = _mk_writer(options)
126
127 if len(args) == 0:
128 print("No path given, trying /var/log/bootchart.tgz")
129 args = [ "/var/log/bootchart.tgz" ]
130
131 res = parsing.Trace(writer, args, options)
132
133 if options.interactive or options.output == None:
134 from . import gui
135 gui.show(res, options)
136 elif options.boottime:
137 import math
138 proc_tree = res.proc_tree
139 if proc_tree.idle:
140 duration = proc_tree.idle
141 else:
142 duration = proc_tree.duration
143 dur = duration / 100.0
144 print('%02d:%05.2f' % (math.floor(dur/60), dur - 60 * math.floor(dur/60)))
145 else:
146 if options.annotate_file:
147 f = open (options.annotate_file, "w")
148 try:
149 for time in res[4]:
150 if time is not None:
151 # output as ms
152 print(time * 10, file=f)
153 else:
154 print(file=f)
155 finally:
156 f.close()
157 filename = _get_filename(options.output)
158 res_list = parsing.split_res(res, options)
159 n = 1
160 width = len(str(len(res_list)))
161 s = "_%%0%dd." % width
162 for r in res_list:
163 if len(res_list) == 1:
164 f = filename + "." + options.format
165 else:
166 f = filename + s % n + options.format
167 n = n + 1
168 def render():
169 batch.render(writer, r, options, f)
170 if options.profile:
171 import cProfile
172 import pstats
173 profile = '%s.prof' % os.path.splitext(filename)[0]
174 cProfile.runctx('render()', globals(), locals(), profile)
175 p = pstats.Stats(profile)
176 p.strip_dirs().sort_stats('time').print_stats(20)
177 else:
178 render()
179
180 return 0
181 except parsing.ParseError as ex:
182 print(("Parse error: %s" % ex))
183 return 2
184
185
186if __name__ == '__main__':
187 sys.exit(main())