diff options
Diffstat (limited to 'scripts/pybootchartgui/pybootchartgui/main.py.in')
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/main.py.in | 171 |
1 files changed, 171 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..265cb18383 --- /dev/null +++ b/scripts/pybootchartgui/pybootchartgui/main.py.in | |||
@@ -0,0 +1,171 @@ | |||
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 | |||
19 | from __future__ import print_function | ||
20 | |||
21 | import sys | ||
22 | import os | ||
23 | import optparse | ||
24 | |||
25 | from . import parsing | ||
26 | from . import batch | ||
27 | |||
28 | def _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("-n", "--no-prune", action="store_false", dest="prune", default=True, | ||
44 | help="do not prune the process tree") | ||
45 | parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False, | ||
46 | help="suppress informational messages") | ||
47 | parser.add_option("-t", "--boot-time", action="store_true", dest="boottime", default=False, | ||
48 | help="only display the boot time of the boot in text format (stdout)") | ||
49 | parser.add_option("--very-quiet", action="store_true", dest="veryquiet", default=False, | ||
50 | help="suppress all messages except errors") | ||
51 | parser.add_option("--verbose", action="store_true", dest="verbose", default=False, | ||
52 | help="print all messages") | ||
53 | parser.add_option("--profile", action="store_true", dest="profile", default=False, | ||
54 | help="profile rendering of chart (only useful when in batch mode indicated by -f)") | ||
55 | parser.add_option("--show-pid", action="store_true", dest="show_pid", default=False, | ||
56 | help="show process ids in the bootchart as 'processname [pid]'") | ||
57 | parser.add_option("--show-all", action="store_true", dest="show_all", default=False, | ||
58 | help="show all process information in the bootchart as '/process/path/exe [pid] [args]'") | ||
59 | parser.add_option("--crop-after", dest="crop_after", metavar="PROCESS", default=None, | ||
60 | help="crop chart when idle after PROCESS is started") | ||
61 | parser.add_option("--annotate", action="append", dest="annotate", metavar="PROCESS", default=None, | ||
62 | help="annotate position where PROCESS is started; can be specified multiple times. " + | ||
63 | "To create a single annotation when any one of a set of processes is started, use commas to separate the names") | ||
64 | parser.add_option("--annotate-file", dest="annotate_file", metavar="FILENAME", default=None, | ||
65 | help="filename to write annotation points to") | ||
66 | return parser | ||
67 | |||
68 | class Writer: | ||
69 | def __init__(self, write, options): | ||
70 | self.write = write | ||
71 | self.options = options | ||
72 | |||
73 | def error(self, msg): | ||
74 | self.write(msg) | ||
75 | |||
76 | def warn(self, msg): | ||
77 | if not self.options.quiet: | ||
78 | self.write(msg) | ||
79 | |||
80 | def info(self, msg): | ||
81 | if self.options.verbose: | ||
82 | self.write(msg) | ||
83 | |||
84 | def status(self, msg): | ||
85 | if not self.options.quiet: | ||
86 | self.write(msg) | ||
87 | |||
88 | def _mk_writer(options): | ||
89 | def write(s): | ||
90 | print(s) | ||
91 | return Writer(write, options) | ||
92 | |||
93 | def _get_filename(path): | ||
94 | """Construct a usable filename for outputs""" | ||
95 | dname = "." | ||
96 | fname = "bootchart" | ||
97 | if path != None: | ||
98 | if os.path.isdir(path): | ||
99 | dname = path | ||
100 | else: | ||
101 | fname = path | ||
102 | return os.path.join(dname, fname) | ||
103 | |||
104 | def main(argv=None): | ||
105 | try: | ||
106 | if argv is None: | ||
107 | argv = sys.argv[1:] | ||
108 | |||
109 | parser = _mk_options_parser() | ||
110 | options, args = parser.parse_args(argv) | ||
111 | writer = _mk_writer(options) | ||
112 | |||
113 | if len(args) == 0: | ||
114 | print("No path given, trying /var/log/bootchart.tgz") | ||
115 | args = [ "/var/log/bootchart.tgz" ] | ||
116 | |||
117 | res = parsing.Trace(writer, args, options) | ||
118 | |||
119 | if options.interactive or options.output == None: | ||
120 | from . import gui | ||
121 | gui.show(res, options) | ||
122 | elif options.boottime: | ||
123 | import math | ||
124 | proc_tree = res.proc_tree | ||
125 | if proc_tree.idle: | ||
126 | duration = proc_tree.idle | ||
127 | else: | ||
128 | duration = proc_tree.duration | ||
129 | dur = duration / 100.0 | ||
130 | print('%02d:%05.2f' % (math.floor(dur/60), dur - 60 * math.floor(dur/60))) | ||
131 | else: | ||
132 | if options.annotate_file: | ||
133 | f = open (options.annotate_file, "w") | ||
134 | try: | ||
135 | for time in res[4]: | ||
136 | if time is not None: | ||
137 | # output as ms | ||
138 | print(time * 10, file=f) | ||
139 | else: | ||
140 | print(file=f) | ||
141 | finally: | ||
142 | f.close() | ||
143 | filename = _get_filename(options.output) | ||
144 | res_list = parsing.split_res(res, options.num) | ||
145 | n = 1 | ||
146 | for r in res_list: | ||
147 | if len(res_list) == 1: | ||
148 | f = filename + "." + options.format | ||
149 | else: | ||
150 | f = filename + "_" + str(n) + "." + options.format | ||
151 | n = n + 1 | ||
152 | def render(): | ||
153 | batch.render(writer, r, options, f) | ||
154 | if options.profile: | ||
155 | import cProfile | ||
156 | import pstats | ||
157 | profile = '%s.prof' % os.path.splitext(filename)[0] | ||
158 | cProfile.runctx('render()', globals(), locals(), profile) | ||
159 | p = pstats.Stats(profile) | ||
160 | p.strip_dirs().sort_stats('time').print_stats(20) | ||
161 | else: | ||
162 | render() | ||
163 | |||
164 | return 0 | ||
165 | except parsing.ParseError as ex: | ||
166 | print(("Parse error: %s" % ex)) | ||
167 | return 2 | ||
168 | |||
169 | |||
170 | if __name__ == '__main__': | ||
171 | sys.exit(main()) | ||