diff options
author | Peter Kjellerstedt <peter.kjellerstedt@axis.com> | 2013-11-15 18:08:50 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-11-18 12:44:06 +0000 |
commit | d0e513d4371789d59bcb902497ca7c537a94c1f0 (patch) | |
tree | 1542d41042ac935aaaa9f6735170ffd8f9044c87 /scripts/pybootchartgui | |
parent | a52c9b9a76371ac3f29b0355fea08b788eb2dd10 (diff) | |
download | poky-d0e513d4371789d59bcb902497ca7c537a94c1f0.tar.gz |
pybootchartgui: Import pybootchartgui 0.14.5
This update the pybootchartgui code to the latest release from its new
location at "https://github.com/mmeeks/bootchart". This only imports
the relevant parts, and not all of bootchart2.
(From OE-Core rev: 6f1568e54a7808b2ab568618fc5bb244249579f1)
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/pybootchartgui')
-rw-r--r-- | scripts/pybootchartgui/AUTHORS | 10 | ||||
-rw-r--r-- | scripts/pybootchartgui/COPYING | 912 | ||||
-rw-r--r-- | scripts/pybootchartgui/MAINTAINERS | 3 | ||||
-rw-r--r-- | scripts/pybootchartgui/NEWS | 204 | ||||
-rw-r--r-- | scripts/pybootchartgui/README.pybootchart (renamed from scripts/pybootchartgui/README) | 19 | ||||
-rwxr-xr-x | scripts/pybootchartgui/pybootchartgui.py | 16 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/batch.py | 53 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/draw.py | 710 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/gui.py | 594 | ||||
l---------[-rw-r--r--] | scripts/pybootchartgui/pybootchartgui/main.py | 79 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/main.py.in | 171 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/parsing.py | 791 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/process_tree.py | 126 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/samples.py | 226 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/tests/parser_test.py | 82 | ||||
-rw-r--r-- | scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py | 30 |
16 files changed, 2563 insertions, 1463 deletions
diff --git a/scripts/pybootchartgui/AUTHORS b/scripts/pybootchartgui/AUTHORS index 45bd1ac823..672b7e9520 100644 --- a/scripts/pybootchartgui/AUTHORS +++ b/scripts/pybootchartgui/AUTHORS | |||
@@ -1,11 +1,11 @@ | |||
1 | Michael Meeks <michael.meeks@novell.com> | ||
1 | Anders Norgaard <anders.norgaard@gmail.com> | 2 | Anders Norgaard <anders.norgaard@gmail.com> |
3 | Scott James Remnant <scott@ubuntu.com> | ||
2 | Henning Niss <henningniss@gmail.com> | 4 | Henning Niss <henningniss@gmail.com> |
3 | 5 | Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> | |
4 | |||
5 | 6 | ||
6 | Contributors: | 7 | Contributors: |
7 | Brian Ewins | 8 | Brian Ewins |
8 | |||
9 | 9 | ||
10 | Based on work by: | 10 | Based on work by: |
11 | Ziga Mahkovec | 11 | Ziga Mahkovec |
diff --git a/scripts/pybootchartgui/COPYING b/scripts/pybootchartgui/COPYING index 94a9ed024d..ed87acf948 100644 --- a/scripts/pybootchartgui/COPYING +++ b/scripts/pybootchartgui/COPYING | |||
@@ -1,626 +1,285 @@ | |||
1 | GNU GENERAL PUBLIC LICENSE | 1 | GNU GENERAL PUBLIC LICENSE |
2 | Version 3, 29 June 2007 | 2 | Version 2, June 1991 |
3 | 3 | ||
4 | Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. |
5 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
5 | Everyone is permitted to copy and distribute verbatim copies | 6 | Everyone is permitted to copy and distribute verbatim copies |
6 | of this license document, but changing it is not allowed. | 7 | of this license document, but changing it is not allowed. |
7 | 8 | ||
8 | Preamble | 9 | Preamble |
9 | 10 | ||
10 | The GNU General Public License is a free, copyleft license for | 11 | The licenses for most software are designed to take away your |
11 | software and other kinds of works. | 12 | freedom to share and change it. By contrast, the GNU General Public |
12 | 13 | License is intended to guarantee your freedom to share and change free | |
13 | The licenses for most software and other practical works are designed | 14 | software--to make sure the software is free for all its users. This |
14 | to take away your freedom to share and change the works. By contrast, | 15 | General Public License applies to most of the Free Software |
15 | the GNU General Public License is intended to guarantee your freedom to | 16 | Foundation's software and to any other program whose authors commit to |
16 | share and change all versions of a program--to make sure it remains free | 17 | using it. (Some other Free Software Foundation software is covered by |
17 | software for all its users. We, the Free Software Foundation, use the | 18 | the GNU Library General Public License instead.) You can apply it to |
18 | GNU General Public License for most of our software; it applies also to | ||
19 | any other work released this way by its authors. You can apply it to | ||
20 | your programs, too. | 19 | your programs, too. |
21 | 20 | ||
22 | When we speak of free software, we are referring to freedom, not | 21 | When we speak of free software, we are referring to freedom, not |
23 | price. Our General Public Licenses are designed to make sure that you | 22 | price. Our General Public Licenses are designed to make sure that you |
24 | have the freedom to distribute copies of free software (and charge for | 23 | have the freedom to distribute copies of free software (and charge for |
25 | them if you wish), that you receive source code or can get it if you | 24 | this service if you wish), that you receive source code or can get it |
26 | want it, that you can change the software or use pieces of it in new | 25 | if you want it, that you can change the software or use pieces of it |
27 | free programs, and that you know you can do these things. | 26 | in new free programs; and that you know you can do these things. |
28 | 27 | ||
29 | To protect your rights, we need to prevent others from denying you | 28 | To protect your rights, we need to make restrictions that forbid |
30 | these rights or asking you to surrender the rights. Therefore, you have | 29 | anyone to deny you these rights or to ask you to surrender the rights. |
31 | certain responsibilities if you distribute copies of the software, or if | 30 | These restrictions translate to certain responsibilities for you if you |
32 | you modify it: responsibilities to respect the freedom of others. | 31 | distribute copies of the software, or if you modify it. |
33 | 32 | ||
34 | For example, if you distribute copies of such a program, whether | 33 | For example, if you distribute copies of such a program, whether |
35 | gratis or for a fee, you must pass on to the recipients the same | 34 | gratis or for a fee, you must give the recipients all the rights that |
36 | freedoms that you received. You must make sure that they, too, receive | 35 | you have. You must make sure that they, too, receive or can get the |
37 | or can get the source code. And you must show them these terms so they | 36 | source code. And you must show them these terms so they know their |
38 | know their rights. | 37 | rights. |
39 | 38 | ||
40 | Developers that use the GNU GPL protect your rights with two steps: | 39 | We protect your rights with two steps: (1) copyright the software, and |
41 | (1) assert copyright on the software, and (2) offer you this License | 40 | (2) offer you this license which gives you legal permission to copy, |
42 | giving you legal permission to copy, distribute and/or modify it. | 41 | distribute and/or modify the software. |
43 | 42 | ||
44 | For the developers' and authors' protection, the GPL clearly explains | 43 | Also, for each author's protection and ours, we want to make certain |
45 | that there is no warranty for this free software. For both users' and | 44 | that everyone understands that there is no warranty for this free |
46 | authors' sake, the GPL requires that modified versions be marked as | 45 | software. If the software is modified by someone else and passed on, we |
47 | changed, so that their problems will not be attributed erroneously to | 46 | want its recipients to know that what they have is not the original, so |
48 | authors of previous versions. | 47 | that any problems introduced by others will not reflect on the original |
49 | 48 | authors' reputations. | |
50 | Some devices are designed to deny users access to install or run | 49 | |
51 | modified versions of the software inside them, although the manufacturer | 50 | Finally, any free program is threatened constantly by software |
52 | can do so. This is fundamentally incompatible with the aim of | 51 | patents. We wish to avoid the danger that redistributors of a free |
53 | protecting users' freedom to change the software. The systematic | 52 | program will individually obtain patent licenses, in effect making the |
54 | pattern of such abuse occurs in the area of products for individuals to | 53 | program proprietary. To prevent this, we have made it clear that any |
55 | use, which is precisely where it is most unacceptable. Therefore, we | 54 | patent must be licensed for everyone's free use or not licensed at all. |
56 | have designed this version of the GPL to prohibit the practice for those | ||
57 | products. If such problems arise substantially in other domains, we | ||
58 | stand ready to extend this provision to those domains in future versions | ||
59 | of the GPL, as needed to protect the freedom of users. | ||
60 | |||
61 | Finally, every program is threatened constantly by software patents. | ||
62 | States should not allow patents to restrict development and use of | ||
63 | software on general-purpose computers, but in those that do, we wish to | ||
64 | avoid the special danger that patents applied to a free program could | ||
65 | make it effectively proprietary. To prevent this, the GPL assures that | ||
66 | patents cannot be used to render the program non-free. | ||
67 | 55 | ||
68 | The precise terms and conditions for copying, distribution and | 56 | The precise terms and conditions for copying, distribution and |
69 | modification follow. | 57 | modification follow. |
70 | 58 | ||
71 | TERMS AND CONDITIONS | 59 | GNU GENERAL PUBLIC LICENSE |
72 | 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |
73 | 0. Definitions. | 61 | |
74 | 62 | 0. This License applies to any program or other work which contains | |
75 | "This License" refers to version 3 of the GNU General Public License. | 63 | a notice placed by the copyright holder saying it may be distributed |
76 | 64 | under the terms of this General Public License. The "Program", below, | |
77 | "Copyright" also means copyright-like laws that apply to other kinds of | 65 | refers to any such program or work, and a "work based on the Program" |
78 | works, such as semiconductor masks. | 66 | means either the Program or any derivative work under copyright law: |
79 | 67 | that is to say, a work containing the Program or a portion of it, | |
80 | "The Program" refers to any copyrightable work licensed under this | 68 | either verbatim or with modifications and/or translated into another |
81 | License. Each licensee is addressed as "you". "Licensees" and | 69 | language. (Hereinafter, translation is included without limitation in |
82 | "recipients" may be individuals or organizations. | 70 | the term "modification".) Each licensee is addressed as "you". |
83 | 71 | ||
84 | To "modify" a work means to copy from or adapt all or part of the work | 72 | Activities other than copying, distribution and modification are not |
85 | in a fashion requiring copyright permission, other than the making of an | 73 | covered by this License; they are outside its scope. The act of |
86 | exact copy. The resulting work is called a "modified version" of the | 74 | running the Program is not restricted, and the output from the Program |
87 | earlier work or a work "based on" the earlier work. | 75 | is covered only if its contents constitute a work based on the |
88 | 76 | Program (independent of having been made by running the Program). | |
89 | A "covered work" means either the unmodified Program or a work based | 77 | Whether that is true depends on what the Program does. |
90 | on the Program. | 78 | |
91 | 79 | 1. You may copy and distribute verbatim copies of the Program's | |
92 | To "propagate" a work means to do anything with it that, without | 80 | source code as you receive it, in any medium, provided that you |
93 | permission, would make you directly or secondarily liable for | 81 | conspicuously and appropriately publish on each copy an appropriate |
94 | infringement under applicable copyright law, except executing it on a | 82 | copyright notice and disclaimer of warranty; keep intact all the |
95 | computer or modifying a private copy. Propagation includes copying, | 83 | notices that refer to this License and to the absence of any warranty; |
96 | distribution (with or without modification), making available to the | 84 | and give any other recipients of the Program a copy of this License |
97 | public, and in some countries other activities as well. | 85 | along with the Program. |
98 | 86 | ||
99 | To "convey" a work means any kind of propagation that enables other | 87 | You may charge a fee for the physical act of transferring a copy, and |
100 | parties to make or receive copies. Mere interaction with a user through | 88 | you may at your option offer warranty protection in exchange for a fee. |
101 | a computer network, with no transfer of a copy, is not conveying. | 89 | |
102 | 90 | 2. You may modify your copy or copies of the Program or any portion | |
103 | An interactive user interface displays "Appropriate Legal Notices" | 91 | of it, thus forming a work based on the Program, and copy and |
104 | to the extent that it includes a convenient and prominently visible | 92 | distribute such modifications or work under the terms of Section 1 |
105 | feature that (1) displays an appropriate copyright notice, and (2) | 93 | above, provided that you also meet all of these conditions: |
106 | tells the user that there is no warranty for the work (except to the | 94 | |
107 | extent that warranties are provided), that licensees may convey the | 95 | a) You must cause the modified files to carry prominent notices |
108 | work under this License, and how to view a copy of this License. If | 96 | stating that you changed the files and the date of any change. |
109 | the interface presents a list of user commands or options, such as a | 97 | |
110 | menu, a prominent item in the list meets this criterion. | 98 | b) You must cause any work that you distribute or publish, that in |
111 | 99 | whole or in part contains or is derived from the Program or any | |
112 | 1. Source Code. | 100 | part thereof, to be licensed as a whole at no charge to all third |
113 | 101 | parties under the terms of this License. | |
114 | The "source code" for a work means the preferred form of the work | 102 | |
115 | for making modifications to it. "Object code" means any non-source | 103 | c) If the modified program normally reads commands interactively |
116 | form of a work. | 104 | when run, you must cause it, when started running for such |
117 | 105 | interactive use in the most ordinary way, to print or display an | |
118 | A "Standard Interface" means an interface that either is an official | 106 | announcement including an appropriate copyright notice and a |
119 | standard defined by a recognized standards body, or, in the case of | 107 | notice that there is no warranty (or else, saying that you provide |
120 | interfaces specified for a particular programming language, one that | 108 | a warranty) and that users may redistribute the program under |
121 | is widely used among developers working in that language. | 109 | these conditions, and telling the user how to view a copy of this |
122 | 110 | License. (Exception: if the Program itself is interactive but | |
123 | The "System Libraries" of an executable work include anything, other | 111 | does not normally print such an announcement, your work based on |
124 | than the work as a whole, that (a) is included in the normal form of | 112 | the Program is not required to print an announcement.) |
125 | packaging a Major Component, but which is not part of that Major | 113 | |
126 | Component, and (b) serves only to enable use of the work with that | 114 | These requirements apply to the modified work as a whole. If |
127 | Major Component, or to implement a Standard Interface for which an | 115 | identifiable sections of that work are not derived from the Program, |
128 | implementation is available to the public in source code form. A | 116 | and can be reasonably considered independent and separate works in |
129 | "Major Component", in this context, means a major essential component | 117 | themselves, then this License, and its terms, do not apply to those |
130 | (kernel, window system, and so on) of the specific operating system | 118 | sections when you distribute them as separate works. But when you |
131 | (if any) on which the executable work runs, or a compiler used to | 119 | distribute the same sections as part of a whole which is a work based |
132 | produce the work, or an object code interpreter used to run it. | 120 | on the Program, the distribution of the whole must be on the terms of |
133 | 121 | this License, whose permissions for other licensees extend to the | |
134 | The "Corresponding Source" for a work in object code form means all | 122 | entire whole, and thus to each and every part regardless of who wrote it. |
135 | the source code needed to generate, install, and (for an executable | 123 | |
136 | work) run the object code and to modify the work, including scripts to | 124 | Thus, it is not the intent of this section to claim rights or contest |
137 | control those activities. However, it does not include the work's | 125 | your rights to work written entirely by you; rather, the intent is to |
138 | System Libraries, or general-purpose tools or generally available free | 126 | exercise the right to control the distribution of derivative or |
139 | programs which are used unmodified in performing those activities but | 127 | collective works based on the Program. |
140 | which are not part of the work. For example, Corresponding Source | 128 | |
141 | includes interface definition files associated with source files for | 129 | In addition, mere aggregation of another work not based on the Program |
142 | the work, and the source code for shared libraries and dynamically | 130 | with the Program (or with a work based on the Program) on a volume of |
143 | linked subprograms that the work is specifically designed to require, | 131 | a storage or distribution medium does not bring the other work under |
144 | such as by intimate data communication or control flow between those | 132 | the scope of this License. |
145 | subprograms and other parts of the work. | 133 | |
146 | 134 | 3. You may copy and distribute the Program (or a work based on it, | |
147 | The Corresponding Source need not include anything that users | 135 | under Section 2) in object code or executable form under the terms of |
148 | can regenerate automatically from other parts of the Corresponding | 136 | Sections 1 and 2 above provided that you also do one of the following: |
149 | Source. | 137 | |
150 | 138 | a) Accompany it with the complete corresponding machine-readable | |
151 | The Corresponding Source for a work in source code form is that | 139 | source code, which must be distributed under the terms of Sections |
152 | same work. | 140 | 1 and 2 above on a medium customarily used for software interchange; or, |
153 | 141 | ||
154 | 2. Basic Permissions. | 142 | b) Accompany it with a written offer, valid for at least three |
155 | 143 | years, to give any third party, for a charge no more than your | |
156 | All rights granted under this License are granted for the term of | 144 | cost of physically performing source distribution, a complete |
157 | copyright on the Program, and are irrevocable provided the stated | 145 | machine-readable copy of the corresponding source code, to be |
158 | conditions are met. This License explicitly affirms your unlimited | 146 | distributed under the terms of Sections 1 and 2 above on a medium |
159 | permission to run the unmodified Program. The output from running a | 147 | customarily used for software interchange; or, |
160 | covered work is covered by this License only if the output, given its | 148 | |
161 | content, constitutes a covered work. This License acknowledges your | 149 | c) Accompany it with the information you received as to the offer |
162 | rights of fair use or other equivalent, as provided by copyright law. | 150 | to distribute corresponding source code. (This alternative is |
163 | 151 | allowed only for noncommercial distribution and only if you | |
164 | You may make, run and propagate covered works that you do not | 152 | received the program in object code or executable form with such |
165 | convey, without conditions so long as your license otherwise remains | 153 | an offer, in accord with Subsection b above.) |
166 | in force. You may convey covered works to others for the sole purpose | 154 | |
167 | of having them make modifications exclusively for you, or provide you | 155 | The source code for a work means the preferred form of the work for |
168 | with facilities for running those works, provided that you comply with | 156 | making modifications to it. For an executable work, complete source |
169 | the terms of this License in conveying all material for which you do | 157 | code means all the source code for all modules it contains, plus any |
170 | not control copyright. Those thus making or running the covered works | 158 | associated interface definition files, plus the scripts used to |
171 | for you must do so exclusively on your behalf, under your direction | 159 | control compilation and installation of the executable. However, as a |
172 | and control, on terms that prohibit them from making any copies of | 160 | special exception, the source code distributed need not include |
173 | your copyrighted material outside their relationship with you. | 161 | anything that is normally distributed (in either source or binary |
174 | 162 | form) with the major components (compiler, kernel, and so on) of the | |
175 | Conveying under any other circumstances is permitted solely under | 163 | operating system on which the executable runs, unless that component |
176 | the conditions stated below. Sublicensing is not allowed; section 10 | 164 | itself accompanies the executable. |
177 | makes it unnecessary. | 165 | |
178 | 166 | If distribution of executable or object code is made by offering | |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. | 167 | access to copy from a designated place, then offering equivalent |
180 | 168 | access to copy the source code from the same place counts as | |
181 | No covered work shall be deemed part of an effective technological | 169 | distribution of the source code, even though third parties are not |
182 | measure under any applicable law fulfilling obligations under article | 170 | compelled to copy the source along with the object code. |
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or | 171 | |
184 | similar laws prohibiting or restricting circumvention of such | 172 | 4. You may not copy, modify, sublicense, or distribute the Program |
185 | measures. | 173 | except as expressly provided under this License. Any attempt |
186 | 174 | otherwise to copy, modify, sublicense or distribute the Program is | |
187 | When you convey a covered work, you waive any legal power to forbid | 175 | void, and will automatically terminate your rights under this License. |
188 | circumvention of technological measures to the extent such circumvention | 176 | However, parties who have received copies, or rights, from you under |
189 | is effected by exercising rights under this License with respect to | 177 | this License will not have their licenses terminated so long as such |
190 | the covered work, and you disclaim any intention to limit operation or | 178 | parties remain in full compliance. |
191 | modification of the work as a means of enforcing, against the work's | 179 | |
192 | users, your or third parties' legal rights to forbid circumvention of | 180 | 5. You are not required to accept this License, since you have not |
193 | technological measures. | 181 | signed it. However, nothing else grants you permission to modify or |
194 | 182 | distribute the Program or its derivative works. These actions are | |
195 | 4. Conveying Verbatim Copies. | 183 | prohibited by law if you do not accept this License. Therefore, by |
196 | 184 | modifying or distributing the Program (or any work based on the | |
197 | You may convey verbatim copies of the Program's source code as you | 185 | Program), you indicate your acceptance of this License to do so, and |
198 | receive it, in any medium, provided that you conspicuously and | 186 | all its terms and conditions for copying, distributing or modifying |
199 | appropriately publish on each copy an appropriate copyright notice; | 187 | the Program or works based on it. |
200 | keep intact all notices stating that this License and any | 188 | |
201 | non-permissive terms added in accord with section 7 apply to the code; | 189 | 6. Each time you redistribute the Program (or any work based on the |
202 | keep intact all notices of the absence of any warranty; and give all | 190 | Program), the recipient automatically receives a license from the |
203 | recipients a copy of this License along with the Program. | 191 | original licensor to copy, distribute or modify the Program subject to |
204 | 192 | these terms and conditions. You may not impose any further | |
205 | You may charge any price or no price for each copy that you convey, | 193 | restrictions on the recipients' exercise of the rights granted herein. |
206 | and you may offer support or warranty protection for a fee. | 194 | You are not responsible for enforcing compliance by third parties to |
207 | |||
208 | 5. Conveying Modified Source Versions. | ||
209 | |||
210 | You may convey a work based on the Program, or the modifications to | ||
211 | produce it from the Program, in the form of source code under the | ||
212 | terms of section 4, provided that you also meet all of these conditions: | ||
213 | |||
214 | a) The work must carry prominent notices stating that you modified | ||
215 | it, and giving a relevant date. | ||
216 | |||
217 | b) The work must carry prominent notices stating that it is | ||
218 | released under this License and any conditions added under section | ||
219 | 7. This requirement modifies the requirement in section 4 to | ||
220 | "keep intact all notices". | ||
221 | |||
222 | c) You must license the entire work, as a whole, under this | ||
223 | License to anyone who comes into possession of a copy. This | ||
224 | License will therefore apply, along with any applicable section 7 | ||
225 | additional terms, to the whole of the work, and all its parts, | ||
226 | regardless of how they are packaged. This License gives no | ||
227 | permission to license the work in any other way, but it does not | ||
228 | invalidate such permission if you have separately received it. | ||
229 | |||
230 | d) If the work has interactive user interfaces, each must display | ||
231 | Appropriate Legal Notices; however, if the Program has interactive | ||
232 | interfaces that do not display Appropriate Legal Notices, your | ||
233 | work need not make them do so. | ||
234 | |||
235 | A compilation of a covered work with other separate and independent | ||
236 | works, which are not by their nature extensions of the covered work, | ||
237 | and which are not combined with it such as to form a larger program, | ||
238 | in or on a volume of a storage or distribution medium, is called an | ||
239 | "aggregate" if the compilation and its resulting copyright are not | ||
240 | used to limit the access or legal rights of the compilation's users | ||
241 | beyond what the individual works permit. Inclusion of a covered work | ||
242 | in an aggregate does not cause this License to apply to the other | ||
243 | parts of the aggregate. | ||
244 | |||
245 | 6. Conveying Non-Source Forms. | ||
246 | |||
247 | You may convey a covered work in object code form under the terms | ||
248 | of sections 4 and 5, provided that you also convey the | ||
249 | machine-readable Corresponding Source under the terms of this License, | ||
250 | in one of these ways: | ||
251 | |||
252 | a) Convey the object code in, or embodied in, a physical product | ||
253 | (including a physical distribution medium), accompanied by the | ||
254 | Corresponding Source fixed on a durable physical medium | ||
255 | customarily used for software interchange. | ||
256 | |||
257 | b) Convey the object code in, or embodied in, a physical product | ||
258 | (including a physical distribution medium), accompanied by a | ||
259 | written offer, valid for at least three years and valid for as | ||
260 | long as you offer spare parts or customer support for that product | ||
261 | model, to give anyone who possesses the object code either (1) a | ||
262 | copy of the Corresponding Source for all the software in the | ||
263 | product that is covered by this License, on a durable physical | ||
264 | medium customarily used for software interchange, for a price no | ||
265 | more than your reasonable cost of physically performing this | ||
266 | conveying of source, or (2) access to copy the | ||
267 | Corresponding Source from a network server at no charge. | ||
268 | |||
269 | c) Convey individual copies of the object code with a copy of the | ||
270 | written offer to provide the Corresponding Source. This | ||
271 | alternative is allowed only occasionally and noncommercially, and | ||
272 | only if you received the object code with such an offer, in accord | ||
273 | with subsection 6b. | ||
274 | |||
275 | d) Convey the object code by offering access from a designated | ||
276 | place (gratis or for a charge), and offer equivalent access to the | ||
277 | Corresponding Source in the same way through the same place at no | ||
278 | further charge. You need not require recipients to copy the | ||
279 | Corresponding Source along with the object code. If the place to | ||
280 | copy the object code is a network server, the Corresponding Source | ||
281 | may be on a different server (operated by you or a third party) | ||
282 | that supports equivalent copying facilities, provided you maintain | ||
283 | clear directions next to the object code saying where to find the | ||
284 | Corresponding Source. Regardless of what server hosts the | ||
285 | Corresponding Source, you remain obligated to ensure that it is | ||
286 | available for as long as needed to satisfy these requirements. | ||
287 | |||
288 | e) Convey the object code using peer-to-peer transmission, provided | ||
289 | you inform other peers where the object code and Corresponding | ||
290 | Source of the work are being offered to the general public at no | ||
291 | charge under subsection 6d. | ||
292 | |||
293 | A separable portion of the object code, whose source code is excluded | ||
294 | from the Corresponding Source as a System Library, need not be | ||
295 | included in conveying the object code work. | ||
296 | |||
297 | A "User Product" is either (1) a "consumer product", which means any | ||
298 | tangible personal property which is normally used for personal, family, | ||
299 | or household purposes, or (2) anything designed or sold for incorporation | ||
300 | into a dwelling. In determining whether a product is a consumer product, | ||
301 | doubtful cases shall be resolved in favor of coverage. For a particular | ||
302 | product received by a particular user, "normally used" refers to a | ||
303 | typical or common use of that class of product, regardless of the status | ||
304 | of the particular user or of the way in which the particular user | ||
305 | actually uses, or expects or is expected to use, the product. A product | ||
306 | is a consumer product regardless of whether the product has substantial | ||
307 | commercial, industrial or non-consumer uses, unless such uses represent | ||
308 | the only significant mode of use of the product. | ||
309 | |||
310 | "Installation Information" for a User Product means any methods, | ||
311 | procedures, authorization keys, or other information required to install | ||
312 | and execute modified versions of a covered work in that User Product from | ||
313 | a modified version of its Corresponding Source. The information must | ||
314 | suffice to ensure that the continued functioning of the modified object | ||
315 | code is in no case prevented or interfered with solely because | ||
316 | modification has been made. | ||
317 | |||
318 | If you convey an object code work under this section in, or with, or | ||
319 | specifically for use in, a User Product, and the conveying occurs as | ||
320 | part of a transaction in which the right of possession and use of the | ||
321 | User Product is transferred to the recipient in perpetuity or for a | ||
322 | fixed term (regardless of how the transaction is characterized), the | ||
323 | Corresponding Source conveyed under this section must be accompanied | ||
324 | by the Installation Information. But this requirement does not apply | ||
325 | if neither you nor any third party retains the ability to install | ||
326 | modified object code on the User Product (for example, the work has | ||
327 | been installed in ROM). | ||
328 | |||
329 | The requirement to provide Installation Information does not include a | ||
330 | requirement to continue to provide support service, warranty, or updates | ||
331 | for a work that has been modified or installed by the recipient, or for | ||
332 | the User Product in which it has been modified or installed. Access to a | ||
333 | network may be denied when the modification itself materially and | ||
334 | adversely affects the operation of the network or violates the rules and | ||
335 | protocols for communication across the network. | ||
336 | |||
337 | Corresponding Source conveyed, and Installation Information provided, | ||
338 | in accord with this section must be in a format that is publicly | ||
339 | documented (and with an implementation available to the public in | ||
340 | source code form), and must require no special password or key for | ||
341 | unpacking, reading or copying. | ||
342 | |||
343 | 7. Additional Terms. | ||
344 | |||
345 | "Additional permissions" are terms that supplement the terms of this | ||
346 | License by making exceptions from one or more of its conditions. | ||
347 | Additional permissions that are applicable to the entire Program shall | ||
348 | be treated as though they were included in this License, to the extent | ||
349 | that they are valid under applicable law. If additional permissions | ||
350 | apply only to part of the Program, that part may be used separately | ||
351 | under those permissions, but the entire Program remains governed by | ||
352 | this License without regard to the additional permissions. | ||
353 | |||
354 | When you convey a copy of a covered work, you may at your option | ||
355 | remove any additional permissions from that copy, or from any part of | ||
356 | it. (Additional permissions may be written to require their own | ||
357 | removal in certain cases when you modify the work.) You may place | ||
358 | additional permissions on material, added by you to a covered work, | ||
359 | for which you have or can give appropriate copyright permission. | ||
360 | |||
361 | Notwithstanding any other provision of this License, for material you | ||
362 | add to a covered work, you may (if authorized by the copyright holders of | ||
363 | that material) supplement the terms of this License with terms: | ||
364 | |||
365 | a) Disclaiming warranty or limiting liability differently from the | ||
366 | terms of sections 15 and 16 of this License; or | ||
367 | |||
368 | b) Requiring preservation of specified reasonable legal notices or | ||
369 | author attributions in that material or in the Appropriate Legal | ||
370 | Notices displayed by works containing it; or | ||
371 | |||
372 | c) Prohibiting misrepresentation of the origin of that material, or | ||
373 | requiring that modified versions of such material be marked in | ||
374 | reasonable ways as different from the original version; or | ||
375 | |||
376 | d) Limiting the use for publicity purposes of names of licensors or | ||
377 | authors of the material; or | ||
378 | |||
379 | e) Declining to grant rights under trademark law for use of some | ||
380 | trade names, trademarks, or service marks; or | ||
381 | |||
382 | f) Requiring indemnification of licensors and authors of that | ||
383 | material by anyone who conveys the material (or modified versions of | ||
384 | it) with contractual assumptions of liability to the recipient, for | ||
385 | any liability that these contractual assumptions directly impose on | ||
386 | those licensors and authors. | ||
387 | |||
388 | All other non-permissive additional terms are considered "further | ||
389 | restrictions" within the meaning of section 10. If the Program as you | ||
390 | received it, or any part of it, contains a notice stating that it is | ||
391 | governed by this License along with a term that is a further | ||
392 | restriction, you may remove that term. If a license document contains | ||
393 | a further restriction but permits relicensing or conveying under this | ||
394 | License, you may add to a covered work material governed by the terms | ||
395 | of that license document, provided that the further restriction does | ||
396 | not survive such relicensing or conveying. | ||
397 | |||
398 | If you add terms to a covered work in accord with this section, you | ||
399 | must place, in the relevant source files, a statement of the | ||
400 | additional terms that apply to those files, or a notice indicating | ||
401 | where to find the applicable terms. | ||
402 | |||
403 | Additional terms, permissive or non-permissive, may be stated in the | ||
404 | form of a separately written license, or stated as exceptions; | ||
405 | the above requirements apply either way. | ||
406 | |||
407 | 8. Termination. | ||
408 | |||
409 | You may not propagate or modify a covered work except as expressly | ||
410 | provided under this License. Any attempt otherwise to propagate or | ||
411 | modify it is void, and will automatically terminate your rights under | ||
412 | this License (including any patent licenses granted under the third | ||
413 | paragraph of section 11). | ||
414 | |||
415 | However, if you cease all violation of this License, then your | ||
416 | license from a particular copyright holder is reinstated (a) | ||
417 | provisionally, unless and until the copyright holder explicitly and | ||
418 | finally terminates your license, and (b) permanently, if the copyright | ||
419 | holder fails to notify you of the violation by some reasonable means | ||
420 | prior to 60 days after the cessation. | ||
421 | |||
422 | Moreover, your license from a particular copyright holder is | ||
423 | reinstated permanently if the copyright holder notifies you of the | ||
424 | violation by some reasonable means, this is the first time you have | ||
425 | received notice of violation of this License (for any work) from that | ||
426 | copyright holder, and you cure the violation prior to 30 days after | ||
427 | your receipt of the notice. | ||
428 | |||
429 | Termination of your rights under this section does not terminate the | ||
430 | licenses of parties who have received copies or rights from you under | ||
431 | this License. If your rights have been terminated and not permanently | ||
432 | reinstated, you do not qualify to receive new licenses for the same | ||
433 | material under section 10. | ||
434 | |||
435 | 9. Acceptance Not Required for Having Copies. | ||
436 | |||
437 | You are not required to accept this License in order to receive or | ||
438 | run a copy of the Program. Ancillary propagation of a covered work | ||
439 | occurring solely as a consequence of using peer-to-peer transmission | ||
440 | to receive a copy likewise does not require acceptance. However, | ||
441 | nothing other than this License grants you permission to propagate or | ||
442 | modify any covered work. These actions infringe copyright if you do | ||
443 | not accept this License. Therefore, by modifying or propagating a | ||
444 | covered work, you indicate your acceptance of this License to do so. | ||
445 | |||
446 | 10. Automatic Licensing of Downstream Recipients. | ||
447 | |||
448 | Each time you convey a covered work, the recipient automatically | ||
449 | receives a license from the original licensors, to run, modify and | ||
450 | propagate that work, subject to this License. You are not responsible | ||
451 | for enforcing compliance by third parties with this License. | ||
452 | |||
453 | An "entity transaction" is a transaction transferring control of an | ||
454 | organization, or substantially all assets of one, or subdividing an | ||
455 | organization, or merging organizations. If propagation of a covered | ||
456 | work results from an entity transaction, each party to that | ||
457 | transaction who receives a copy of the work also receives whatever | ||
458 | licenses to the work the party's predecessor in interest had or could | ||
459 | give under the previous paragraph, plus a right to possession of the | ||
460 | Corresponding Source of the work from the predecessor in interest, if | ||
461 | the predecessor has it or can get it with reasonable efforts. | ||
462 | |||
463 | You may not impose any further restrictions on the exercise of the | ||
464 | rights granted or affirmed under this License. For example, you may | ||
465 | not impose a license fee, royalty, or other charge for exercise of | ||
466 | rights granted under this License, and you may not initiate litigation | ||
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that | ||
468 | any patent claim is infringed by making, using, selling, offering for | ||
469 | sale, or importing the Program or any portion of it. | ||
470 | |||
471 | 11. Patents. | ||
472 | |||
473 | A "contributor" is a copyright holder who authorizes use under this | ||
474 | License of the Program or a work on which the Program is based. The | ||
475 | work thus licensed is called the contributor's "contributor version". | ||
476 | |||
477 | A contributor's "essential patent claims" are all patent claims | ||
478 | owned or controlled by the contributor, whether already acquired or | ||
479 | hereafter acquired, that would be infringed by some manner, permitted | ||
480 | by this License, of making, using, or selling its contributor version, | ||
481 | but do not include claims that would be infringed only as a | ||
482 | consequence of further modification of the contributor version. For | ||
483 | purposes of this definition, "control" includes the right to grant | ||
484 | patent sublicenses in a manner consistent with the requirements of | ||
485 | this License. | 195 | this License. |
486 | 196 | ||
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free | 197 | 7. If, as a consequence of a court judgment or allegation of patent |
488 | patent license under the contributor's essential patent claims, to | 198 | infringement or for any other reason (not limited to patent issues), |
489 | make, use, sell, offer for sale, import and otherwise run, modify and | 199 | conditions are imposed on you (whether by court order, agreement or |
490 | propagate the contents of its contributor version. | ||
491 | |||
492 | In the following three paragraphs, a "patent license" is any express | ||
493 | agreement or commitment, however denominated, not to enforce a patent | ||
494 | (such as an express permission to practice a patent or covenant not to | ||
495 | sue for patent infringement). To "grant" such a patent license to a | ||
496 | party means to make such an agreement or commitment not to enforce a | ||
497 | patent against the party. | ||
498 | |||
499 | If you convey a covered work, knowingly relying on a patent license, | ||
500 | and the Corresponding Source of the work is not available for anyone | ||
501 | to copy, free of charge and under the terms of this License, through a | ||
502 | publicly available network server or other readily accessible means, | ||
503 | then you must either (1) cause the Corresponding Source to be so | ||
504 | available, or (2) arrange to deprive yourself of the benefit of the | ||
505 | patent license for this particular work, or (3) arrange, in a manner | ||
506 | consistent with the requirements of this License, to extend the patent | ||
507 | license to downstream recipients. "Knowingly relying" means you have | ||
508 | actual knowledge that, but for the patent license, your conveying the | ||
509 | covered work in a country, or your recipient's use of the covered work | ||
510 | in a country, would infringe one or more identifiable patents in that | ||
511 | country that you have reason to believe are valid. | ||
512 | |||
513 | If, pursuant to or in connection with a single transaction or | ||
514 | arrangement, you convey, or propagate by procuring conveyance of, a | ||
515 | covered work, and grant a patent license to some of the parties | ||
516 | receiving the covered work authorizing them to use, propagate, modify | ||
517 | or convey a specific copy of the covered work, then the patent license | ||
518 | you grant is automatically extended to all recipients of the covered | ||
519 | work and works based on it. | ||
520 | |||
521 | A patent license is "discriminatory" if it does not include within | ||
522 | the scope of its coverage, prohibits the exercise of, or is | ||
523 | conditioned on the non-exercise of one or more of the rights that are | ||
524 | specifically granted under this License. You may not convey a covered | ||
525 | work if you are a party to an arrangement with a third party that is | ||
526 | in the business of distributing software, under which you make payment | ||
527 | to the third party based on the extent of your activity of conveying | ||
528 | the work, and under which the third party grants, to any of the | ||
529 | parties who would receive the covered work from you, a discriminatory | ||
530 | patent license (a) in connection with copies of the covered work | ||
531 | conveyed by you (or copies made from those copies), or (b) primarily | ||
532 | for and in connection with specific products or compilations that | ||
533 | contain the covered work, unless you entered into that arrangement, | ||
534 | or that patent license was granted, prior to 28 March 2007. | ||
535 | |||
536 | Nothing in this License shall be construed as excluding or limiting | ||
537 | any implied license or other defenses to infringement that may | ||
538 | otherwise be available to you under applicable patent law. | ||
539 | |||
540 | 12. No Surrender of Others' Freedom. | ||
541 | |||
542 | If conditions are imposed on you (whether by court order, agreement or | ||
543 | otherwise) that contradict the conditions of this License, they do not | 200 | otherwise) that contradict the conditions of this License, they do not |
544 | excuse you from the conditions of this License. If you cannot convey a | 201 | excuse you from the conditions of this License. If you cannot |
545 | covered work so as to satisfy simultaneously your obligations under this | 202 | distribute so as to satisfy simultaneously your obligations under this |
546 | License and any other pertinent obligations, then as a consequence you may | 203 | License and any other pertinent obligations, then as a consequence you |
547 | not convey it at all. For example, if you agree to terms that obligate you | 204 | may not distribute the Program at all. For example, if a patent |
548 | to collect a royalty for further conveying from those to whom you convey | 205 | license would not permit royalty-free redistribution of the Program by |
549 | the Program, the only way you could satisfy both those terms and this | 206 | all those who receive copies directly or indirectly through you, then |
550 | License would be to refrain entirely from conveying the Program. | 207 | the only way you could satisfy both it and this License would be to |
551 | 208 | refrain entirely from distribution of the Program. | |
552 | 13. Use with the GNU Affero General Public License. | 209 | |
553 | 210 | If any portion of this section is held invalid or unenforceable under | |
554 | Notwithstanding any other provision of this License, you have | 211 | any particular circumstance, the balance of the section is intended to |
555 | permission to link or combine any covered work with a work licensed | 212 | apply and the section as a whole is intended to apply in other |
556 | under version 3 of the GNU Affero General Public License into a single | 213 | circumstances. |
557 | combined work, and to convey the resulting work. The terms of this | 214 | |
558 | License will continue to apply to the part which is the covered work, | 215 | It is not the purpose of this section to induce you to infringe any |
559 | but the special requirements of the GNU Affero General Public License, | 216 | patents or other property right claims or to contest validity of any |
560 | section 13, concerning interaction through a network will apply to the | 217 | such claims; this section has the sole purpose of protecting the |
561 | combination as such. | 218 | integrity of the free software distribution system, which is |
562 | 219 | implemented by public license practices. Many people have made | |
563 | 14. Revised Versions of this License. | 220 | generous contributions to the wide range of software distributed |
564 | 221 | through that system in reliance on consistent application of that | |
565 | The Free Software Foundation may publish revised and/or new versions of | 222 | system; it is up to the author/donor to decide if he or she is willing |
566 | the GNU General Public License from time to time. Such new versions will | 223 | to distribute software through any other system and a licensee cannot |
224 | impose that choice. | ||
225 | |||
226 | This section is intended to make thoroughly clear what is believed to | ||
227 | be a consequence of the rest of this License. | ||
228 | |||
229 | 8. If the distribution and/or use of the Program is restricted in | ||
230 | certain countries either by patents or by copyrighted interfaces, the | ||
231 | original copyright holder who places the Program under this License | ||
232 | may add an explicit geographical distribution limitation excluding | ||
233 | those countries, so that distribution is permitted only in or among | ||
234 | countries not thus excluded. In such case, this License incorporates | ||
235 | the limitation as if written in the body of this License. | ||
236 | |||
237 | 9. The Free Software Foundation may publish revised and/or new versions | ||
238 | of the General Public License from time to time. Such new versions will | ||
567 | be similar in spirit to the present version, but may differ in detail to | 239 | be similar in spirit to the present version, but may differ in detail to |
568 | address new problems or concerns. | 240 | address new problems or concerns. |
569 | 241 | ||
570 | Each version is given a distinguishing version number. If the | 242 | Each version is given a distinguishing version number. If the Program |
571 | Program specifies that a certain numbered version of the GNU General | 243 | specifies a version number of this License which applies to it and "any |
572 | Public License "or any later version" applies to it, you have the | 244 | later version", you have the option of following the terms and conditions |
573 | option of following the terms and conditions either of that numbered | 245 | either of that version or of any later version published by the Free |
574 | version or of any later version published by the Free Software | 246 | Software Foundation. If the Program does not specify a version number of |
575 | Foundation. If the Program does not specify a version number of the | 247 | this License, you may choose any version ever published by the Free Software |
576 | GNU General Public License, you may choose any version ever published | 248 | Foundation. |
577 | by the Free Software Foundation. | 249 | |
578 | 250 | 10. If you wish to incorporate parts of the Program into other free | |
579 | If the Program specifies that a proxy can decide which future | 251 | programs whose distribution conditions are different, write to the author |
580 | versions of the GNU General Public License can be used, that proxy's | 252 | to ask for permission. For software which is copyrighted by the Free |
581 | public statement of acceptance of a version permanently authorizes you | 253 | Software Foundation, write to the Free Software Foundation; we sometimes |
582 | to choose that version for the Program. | 254 | make exceptions for this. Our decision will be guided by the two goals |
583 | 255 | of preserving the free status of all derivatives of our free software and | |
584 | Later license versions may give you additional or different | 256 | of promoting the sharing and reuse of software generally. |
585 | permissions. However, no additional obligations are imposed on any | 257 | |
586 | author or copyright holder as a result of your choosing to follow a | 258 | NO WARRANTY |
587 | later version. | 259 | |
588 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |
589 | 15. Disclaimer of Warranty. | 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
590 | 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY | 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED |
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT | 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY | 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS |
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, | 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE |
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, |
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM | 268 | REPAIR OR CORRECTION. |
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF | 269 | |
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
599 | 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |
600 | 16. Limitation of Liability. | 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
601 | 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING | |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED |
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS | 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY |
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY | 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER |
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE | 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE |
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF | 278 | POSSIBILITY OF SUCH DAMAGES. |
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD | 279 | |
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), | 280 | END OF TERMS AND CONDITIONS |
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF | 281 | |
610 | SUCH DAMAGES. | 282 | How to Apply These Terms to Your New Programs |
611 | |||
612 | 17. Interpretation of Sections 15 and 16. | ||
613 | |||
614 | If the disclaimer of warranty and limitation of liability provided | ||
615 | above cannot be given local legal effect according to their terms, | ||
616 | reviewing courts shall apply local law that most closely approximates | ||
617 | an absolute waiver of all civil liability in connection with the | ||
618 | Program, unless a warranty or assumption of liability accompanies a | ||
619 | copy of the Program in return for a fee. | ||
620 | |||
621 | END OF TERMS AND CONDITIONS | ||
622 | |||
623 | How to Apply These Terms to Your New Programs | ||
624 | 283 | ||
625 | If you develop a new program, and you want it to be of the greatest | 284 | If you develop a new program, and you want it to be of the greatest |
626 | possible use to the public, the best way to achieve this is to make it | 285 | possible use to the public, the best way to achieve this is to make it |
@@ -628,15 +287,15 @@ free software which everyone can redistribute and change under these terms. | |||
628 | 287 | ||
629 | To do so, attach the following notices to the program. It is safest | 288 | To do so, attach the following notices to the program. It is safest |
630 | to attach them to the start of each source file to most effectively | 289 | to attach them to the start of each source file to most effectively |
631 | state the exclusion of warranty; and each file should have at least | 290 | convey the exclusion of warranty; and each file should have at least |
632 | the "copyright" line and a pointer to where the full notice is found. | 291 | the "copyright" line and a pointer to where the full notice is found. |
633 | 292 | ||
634 | <one line to give the program's name and a brief idea of what it does.> | 293 | <one line to give the program's name and a brief idea of what it does.> |
635 | Copyright (C) <year> <name of author> | 294 | Copyright (C) <year> <name of author> |
636 | 295 | ||
637 | This program is free software: you can redistribute it and/or modify | 296 | This program is free software; you can redistribute it and/or modify |
638 | it under the terms of the GNU General Public License as published by | 297 | it under the terms of the GNU General Public License as published by |
639 | the Free Software Foundation, either version 3 of the License, or | 298 | the Free Software Foundation; either version 2 of the License, or |
640 | (at your option) any later version. | 299 | (at your option) any later version. |
641 | 300 | ||
642 | This program is distributed in the hope that it will be useful, | 301 | This program is distributed in the hope that it will be useful, |
@@ -645,30 +304,37 @@ the "copyright" line and a pointer to where the full notice is found. | |||
645 | GNU General Public License for more details. | 304 | GNU General Public License for more details. |
646 | 305 | ||
647 | You should have received a copy of the GNU General Public License | 306 | You should have received a copy of the GNU General Public License |
648 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 307 | along with this program; if not, write to the Free Software |
308 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
309 | |||
649 | 310 | ||
650 | Also add information on how to contact you by electronic and paper mail. | 311 | Also add information on how to contact you by electronic and paper mail. |
651 | 312 | ||
652 | If the program does terminal interaction, make it output a short | 313 | If the program is interactive, make it output a short notice like this |
653 | notice like this when it starts in an interactive mode: | 314 | when it starts in an interactive mode: |
654 | 315 | ||
655 | <program> Copyright (C) <year> <name of author> | 316 | Gnomovision version 69, Copyright (C) year name of author |
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
657 | This is free software, and you are welcome to redistribute it | 318 | This is free software, and you are welcome to redistribute it |
658 | under certain conditions; type `show c' for details. | 319 | under certain conditions; type `show c' for details. |
659 | 320 | ||
660 | The hypothetical commands `show w' and `show c' should show the appropriate | 321 | The hypothetical commands `show w' and `show c' should show the appropriate |
661 | parts of the General Public License. Of course, your program's commands | 322 | parts of the General Public License. Of course, the commands you use may |
662 | might be different; for a GUI interface, you would use an "about box". | 323 | be called something other than `show w' and `show c'; they could even be |
663 | 324 | mouse-clicks or menu items--whatever suits your program. | |
664 | You should also get your employer (if you work as a programmer) or school, | 325 | |
665 | if any, to sign a "copyright disclaimer" for the program, if necessary. | 326 | You should also get your employer (if you work as a programmer) or your |
666 | For more information on this, and how to apply and follow the GNU GPL, see | 327 | school, if any, to sign a "copyright disclaimer" for the program, if |
667 | <http://www.gnu.org/licenses/>. | 328 | necessary. Here is a sample; alter the names: |
668 | 329 | ||
669 | The GNU General Public License does not permit incorporating your program | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program |
670 | into proprietary programs. If your program is a subroutine library, you | 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. |
671 | may consider it more useful to permit linking proprietary applications with | 332 | |
672 | the library. If this is what you want to do, use the GNU Lesser General | 333 | <signature of Ty Coon>, 1 April 1989 |
673 | Public License instead of this License. But first, please read | 334 | Ty Coon, President of Vice |
674 | <http://www.gnu.org/philosophy/why-not-lgpl.html>. | 335 | |
336 | This General Public License does not permit incorporating your program into | ||
337 | proprietary programs. If your program is a subroutine library, you may | ||
338 | consider it more useful to permit linking proprietary applications with the | ||
339 | library. If this is what you want to do, use the GNU Library General | ||
340 | Public License instead of this License. | ||
diff --git a/scripts/pybootchartgui/MAINTAINERS b/scripts/pybootchartgui/MAINTAINERS new file mode 100644 index 0000000000..c65e1315f1 --- /dev/null +++ b/scripts/pybootchartgui/MAINTAINERS | |||
@@ -0,0 +1,3 @@ | |||
1 | Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com> | ||
2 | Michael Meeks <michael.meeks@novell.com> | ||
3 | Harald Hoyer <harald@redhat.com> | ||
diff --git a/scripts/pybootchartgui/NEWS b/scripts/pybootchartgui/NEWS new file mode 100644 index 0000000000..7c5b2fc3a1 --- /dev/null +++ b/scripts/pybootchartgui/NEWS | |||
@@ -0,0 +1,204 @@ | |||
1 | bootchart2 0.14.5: | ||
2 | + pybootchartgui (Riccardo) | ||
3 | + Fix tests with python3 | ||
4 | + Fix parsing of files with non-ascii bytes | ||
5 | + Robustness fixes to taskstats and meminfo parsing | ||
6 | + More python3 fixes | ||
7 | |||
8 | bootchart2 0.14.4: | ||
9 | + bootchartd | ||
10 | + Add relevant EXIT_PROC for GNOME3, XFCE4, openbox | ||
11 | (Justin Lecher, Ben Eills) | ||
12 | + pybootchartgui (Riccardo) | ||
13 | + Fix some issues in --crop-after and --annotate | ||
14 | + Fix pybootchartgui process_tree tests | ||
15 | + More python3 fixes | ||
16 | |||
17 | bootchart2 0.14.2: | ||
18 | + pybootchartgui | ||
19 | + Fix some crashes in parsing.py (Jakub Czaplicki, Riccardo) | ||
20 | + speedup a bit meminfo parsing (Riccardo) | ||
21 | + Fix indentation for python3.2 (Riccardo) | ||
22 | |||
23 | bootchart2 0.14.1: | ||
24 | + bootchartd | ||
25 | + Expect dmesg only if started as init (Henry Yei) | ||
26 | + look for bootchart_init in the environment (Henry Gebhardt) | ||
27 | + pybootchartgui | ||
28 | + Fixup some tests (Riccardo) | ||
29 | + Support hp smart arrays block devices (Anders Norgaard, | ||
30 | Brian Murray) | ||
31 | + Fixes for -t, -o and -f options (Mladen Kuntner, Harald, Riccardo) | ||
32 | |||
33 | bootchart2 0.14.0: | ||
34 | + bootchartd | ||
35 | + Add ability to define custom commands | ||
36 | (Lucian Muresan, Peter Hjalmarsson) | ||
37 | + collector | ||
38 | + fix tmpfs mount leakage (Peter Hjalmarsson) | ||
39 | + pybootchartgui | ||
40 | + render cumulative I/O time chart (Sankar P) | ||
41 | + python3 compatibility fixes (Riccardo) | ||
42 | + Misc (Michael) | ||
43 | + remove confusing, obsolete setup.py | ||
44 | + install docs to /usr/share/ | ||
45 | + lot of fixes for easier packaging (Peter Hjalmarsson) | ||
46 | + add bootchart2, bootchartd and pybootchartgui manpages | ||
47 | (Francesca Ciceri, David Paleino) | ||
48 | |||
49 | bootchart2 0.12.6: | ||
50 | + bootchartd | ||
51 | + better check for initrd (Riccardo Magliocchetti) | ||
52 | + code cleanup (Riccardo) | ||
53 | + make the list of processes we are waiting for editable | ||
54 | in config file by EXIT_PROC (Riccardo) | ||
55 | + fix parsing of cmdline for alternative init system (Riccardo) | ||
56 | + fixed calling init in initramfs (Harald) | ||
57 | + exit 0 for start, if the collector is already running (Harald) | ||
58 | + collector | ||
59 | + try harder with taskstats (Michael) | ||
60 | + plug some small leaks (Riccardo) | ||
61 | + fix missing PROC_EVENTS detection (Harald) | ||
62 | + pybootchartgui (Michael) | ||
63 | + add kernel bootchart tab to interactive gui | ||
64 | + report bootchart version in cli interface | ||
65 | + improve rendering performance | ||
66 | + GUI improvements | ||
67 | + lot of cleanups | ||
68 | + Makefile | ||
69 | + do not python compile if NO_PYTHON_COMPILE is set (Harald) | ||
70 | + systemd service files | ||
71 | + added them and install (Harald, Wulf C. Krueger) | ||
72 | |||
73 | bootchart2 0.12.5: | ||
74 | + administrative snafu version; pull before pushing... | ||
75 | |||
76 | bootchart2 0.12.4: | ||
77 | + bootchartd | ||
78 | + reduce overhead caused by pidof (Riccardo Magliocchetti) | ||
79 | + collector | ||
80 | + attempt to retry ptrace to avoid bogus ENOSYS (Michael) | ||
81 | + add meminfo polling (Dave Martin) | ||
82 | + pybootchartgui | ||
83 | + handle dmesg timestamps with big delta (Riccardo) | ||
84 | + avoid divide by zero when rendering I/O utilization (Riccardo) | ||
85 | + add process grouping in the cumulative chart (Riccardo) | ||
86 | + fix cpu time calculation in cumulative chart (Riccardo) | ||
87 | + get i/o statistics for flash based devices (Riccardo) | ||
88 | + prettier coloring for the cumulative graphs (Michael) | ||
89 | + fix interactive CPU rendering (Michael) | ||
90 | + render memory usage graph (Dave Martin) | ||
91 | |||
92 | bootchart2 0.12.3 | ||
93 | + collector | ||
94 | + pclose after popen (Riccardo Magliocchetti (xrmx)) | ||
95 | + fix buffer overflow (xrmx) | ||
96 | + count 'processor:' in /proc/cpuinfo for ARM (Michael) | ||
97 | + get model name from that line too for ARM (xrmx) | ||
98 | + store /proc/cpuinfo in the boot-chart archive (xrmx) | ||
99 | + try harder to detect missing TASKSTATS (Michael) | ||
100 | + sanity-check invalid domain names (Michael) | ||
101 | + detect missing PROC_EVENTS more reliably (Michael) | ||
102 | + README fixes (xrmx, Michael) | ||
103 | + pybootchartgui | ||
104 | + make num_cpu parsing robust (Michael) | ||
105 | |||
106 | bootchart2 0.12.2 | ||
107 | + fix pthread compile / linking bug | ||
108 | |||
109 | bootchart2 0.12.1 | ||
110 | + pybootchartgui | ||
111 | + pylint cleanup | ||
112 | + handle empty traces more elegantly | ||
113 | + add '-t' / '--boot-time' argument (Matthew Bauer) | ||
114 | + collector | ||
115 | + now GPLv2 | ||
116 | + add rdinit support for very early initrd tracing | ||
117 | + cleanup / re-factor code into separate modules | ||
118 | + re-factor arg parsing, and parse remote process args | ||
119 | + handle missing bootchartd.conf cleanly | ||
120 | + move much of bootchartd from shell -> C | ||
121 | + drop dmesg and uname usage | ||
122 | + avoid rpm/dpkg with native version reporting | ||
123 | |||
124 | bootchart2 0.12.0 (Michael Meeks) | ||
125 | + collector | ||
126 | + use netlink PROC_EVENTS to generate parentage data | ||
127 | + finally kills any need for 'acct' et. al. | ||
128 | + also removes need to poll /proc => faster | ||
129 | + cleanup code to K&R, 8 stop tabs. | ||
130 | + pybootchartgui | ||
131 | + consume thread parentage data | ||
132 | |||
133 | bootchart2 0.11.4 (Michael Meeks) | ||
134 | + collector | ||
135 | + if run inside an initrd detect when /dev is writable | ||
136 | and remount ourselves into that. | ||
137 | + overflow buffers more elegantly in extremis | ||
138 | + dump full process path and command-line args | ||
139 | + calm down debugging output | ||
140 | + pybootchartgui | ||
141 | + can render logs in a directory again | ||
142 | + has a 'show more' option to show command-lines | ||
143 | |||
144 | bootchart2 0.11.3 (Michael Meeks) | ||
145 | + add $$ display to the bootchart header | ||
146 | + process command-line bits | ||
147 | + fix collection code, and rename stream to match | ||
148 | + enable parsing, add check button to UI, and --show-all | ||
149 | command-line option | ||
150 | + fix parsing of directories full of files. | ||
151 | |||
152 | bootchart2 0.11.2 (Michael Meeks) | ||
153 | + fix initrd sanity check to use the right proc path | ||
154 | + don't return a bogus error value when dumping state | ||
155 | + add -c to aid manual console debugging | ||
156 | |||
157 | bootchart2 0.11.1 (Michael Meeks) | ||
158 | + even simpler initrd setup | ||
159 | + create a single directory: /lib/bootchart/tmpfs | ||
160 | |||
161 | bootchart2 0.11 (Michael Meeks) | ||
162 | + bootchartd | ||
163 | + far, far simpler, less shell, more robustness etc. | ||
164 | + bootchart-collector | ||
165 | + remove the -p argument - we always mount proc | ||
166 | + requires /lib/bootchart (make install-chroot) to | ||
167 | be present (also in the initrd) [ with a kmsg | ||
168 | node included ] | ||
169 | + add a --probe-running mode | ||
170 | + ptrace re-write | ||
171 | + gives -much- better early-boot-time resolution | ||
172 | + unconditional chroot /lib/bootchart/chroot | ||
173 | + we mount proc there ourselves | ||
174 | + log extraction requires no common file-system view | ||
175 | |||
176 | |||
177 | bootchart2 0.10.1 (Kel Modderman) | ||
178 | + collector arg -m should mount /proc | ||
179 | + remove bogus vcsid code | ||
180 | + split collector install in Makefile | ||
181 | + remove bogus debug code | ||
182 | + accept process names containing spaces | ||
183 | |||
184 | bootchart2 0.10.0 | ||
185 | + rendering (Anders Norgaard) | ||
186 | + fix for unknown exceptions | ||
187 | + interactive UI (Michael) | ||
188 | + much faster rendering by manual clipping | ||
189 | + horizontal scaling | ||
190 | + remove annoying page-up/down bindings | ||
191 | + initrd portability & fixes (Federic Crozat) | ||
192 | + port to Mandriva | ||
193 | + improved process waiting | ||
194 | + inittab commenting fix | ||
195 | + improved initrd detection / jail tagging | ||
196 | + fix for un-detectable accton behaviour change | ||
197 | + implement a built-in usleep to help initrd deps (Michael) | ||
198 | |||
199 | bootchart2 0.0.9 | ||
200 | + fix initrd bug | ||
201 | |||
202 | bootchart2 0.0.8 | ||
203 | + add a filename string to the window title in interactive mode | ||
204 | + add a NEWS file | ||
diff --git a/scripts/pybootchartgui/README b/scripts/pybootchartgui/README.pybootchart index 1b97c442f3..8642e64679 100644 --- a/scripts/pybootchartgui/README +++ b/scripts/pybootchartgui/README.pybootchart | |||
@@ -1,13 +1,14 @@ | |||
1 | PYBOOTCHARTGUI | 1 | PYBOOTCHARTGUI |
2 | ---------------- | 2 | ---------------- |
3 | 3 | ||
4 | pybootchartgui is a tool for visualization and analysis of the | 4 | pybootchartgui is a tool (now included as part of bootchart2) for |
5 | GNU/Linux boot process. It renders the output of the boot-logger tool | 5 | visualization and analysis of the GNU/Linux boot process. It renders |
6 | bootchart (see http://www.bootchart.org/) to either the screen or | 6 | the output of the boot-logger tool bootchart (see |
7 | files of various formats. Bootchart collects information about the | 7 | http://www.bootchart.org/) to either the screen or files of various |
8 | processes, their dependencies, and resource consumption during boot of | 8 | formats. Bootchart collects information about the processes, their |
9 | a GNU/Linux system. The pybootchartgui tools visualizes the process | 9 | dependencies, and resource consumption during boot of a GNU/Linux |
10 | tree and overall resource utilization. | 10 | system. The pybootchartgui tools visualizes the process tree and |
11 | overall resource utilization. | ||
11 | 12 | ||
12 | pybootchartgui is a port of the visualization part of bootchart from | 13 | pybootchartgui is a port of the visualization part of bootchart from |
13 | Java to Python and Cairo. | 14 | Java to Python and Cairo. |
@@ -32,5 +33,5 @@ To get help for pybootchartgui, run | |||
32 | 33 | ||
33 | $ pybootchartgui --help | 34 | $ pybootchartgui --help |
34 | 35 | ||
35 | 36 | This code was originally hosted at: | |
36 | http://code.google.com/p/pybootchartgui/ | 37 | http://code.google.com/p/pybootchartgui/ |
diff --git a/scripts/pybootchartgui/pybootchartgui.py b/scripts/pybootchartgui/pybootchartgui.py index f301027805..947ce10338 100755 --- a/scripts/pybootchartgui/pybootchartgui.py +++ b/scripts/pybootchartgui/pybootchartgui.py | |||
@@ -1,4 +1,20 @@ | |||
1 | #!/usr/bin/python | 1 | #!/usr/bin/python |
2 | # | ||
3 | # This file is part of pybootchartgui. | ||
4 | |||
5 | # pybootchartgui is free software: you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published by | ||
7 | # the Free Software Foundation, either version 3 of the License, or | ||
8 | # (at your option) any later version. | ||
9 | |||
10 | # pybootchartgui is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | # GNU General Public License for more details. | ||
14 | |||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
2 | 18 | ||
3 | import sys | 19 | import sys |
4 | from pybootchartgui.main import main | 20 | from pybootchartgui.main import main |
diff --git a/scripts/pybootchartgui/pybootchartgui/batch.py b/scripts/pybootchartgui/pybootchartgui/batch.py index 3c1dbf8416..05c714e95e 100644 --- a/scripts/pybootchartgui/pybootchartgui/batch.py +++ b/scripts/pybootchartgui/pybootchartgui/batch.py | |||
@@ -1,23 +1,46 @@ | |||
1 | import cairo | 1 | # This file is part of pybootchartgui. |
2 | |||
3 | # pybootchartgui is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 3 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | |||
8 | # pybootchartgui is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
2 | 12 | ||
3 | import draw | 13 | # You should have received a copy of the GNU General Public License |
14 | # along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>. | ||
4 | 15 | ||
5 | def render(res, format, filename): | 16 | import cairo |
17 | from . import draw | ||
18 | from .draw import RenderOptions | ||
19 | |||
20 | def render(writer, trace, app_options, filename): | ||
6 | handlers = { | 21 | handlers = { |
7 | "png": (lambda w,h: cairo.ImageSurface(cairo.FORMAT_ARGB32,w,h), lambda sfc: sfc.write_to_png(filename)), | 22 | "png": (lambda w, h: cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h), \ |
8 | "pdf": (lambda w,h: cairo.PDFSurface(filename, w, h), lambda sfc: 0), | 23 | lambda sfc: sfc.write_to_png(filename)), |
9 | "svg": (lambda w,h: cairo.SVGSurface(filename, w, h), lambda sfc: 0) | 24 | "pdf": (lambda w, h: cairo.PDFSurface(filename, w, h), lambda sfc: 0), |
25 | "svg": (lambda w, h: cairo.SVGSurface(filename, w, h), lambda sfc: 0) | ||
10 | } | 26 | } |
11 | 27 | ||
12 | if not(handlers.has_key(format)): | 28 | if app_options.format is None: |
13 | print "Unknown format '%s'." % format | 29 | fmt = filename.rsplit('.', 1)[1] |
30 | else: | ||
31 | fmt = app_options.format | ||
32 | |||
33 | if not (fmt in handlers): | ||
34 | writer.error ("Unknown format '%s'." % fmt) | ||
14 | return 10 | 35 | return 10 |
15 | 36 | ||
16 | make_surface, write_surface = handlers[format] | 37 | make_surface, write_surface = handlers[fmt] |
17 | w,h = draw.extents(res) | 38 | options = RenderOptions (app_options) |
18 | w = max(w, draw.MIN_IMG_W) | 39 | (w, h) = draw.extents (options, 1.0, trace) |
19 | surface = make_surface(w,h) | 40 | w = max (w, draw.MIN_IMG_W) |
20 | ctx = cairo.Context(surface) | 41 | surface = make_surface (w, h) |
21 | draw.render(ctx, res) | 42 | ctx = cairo.Context (surface) |
22 | write_surface(surface) | 43 | draw.render (ctx, options, 1.0, trace) |
44 | write_surface (surface) | ||
45 | writer.status ("bootchart written to '%s'" % filename) | ||
23 | 46 | ||
diff --git a/scripts/pybootchartgui/pybootchartgui/draw.py b/scripts/pybootchartgui/pybootchartgui/draw.py index 1b872de75e..c3492c7cb9 100644 --- a/scripts/pybootchartgui/pybootchartgui/draw.py +++ b/scripts/pybootchartgui/pybootchartgui/draw.py | |||
@@ -1,6 +1,40 @@ | |||
1 | # This file is part of pybootchartgui. | ||
2 | |||
3 | # pybootchartgui is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 3 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | |||
8 | # pybootchartgui is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | |||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | |||
1 | import cairo | 17 | import cairo |
2 | import math | 18 | import math |
3 | import re | 19 | import re |
20 | import random | ||
21 | import colorsys | ||
22 | from operator import itemgetter | ||
23 | |||
24 | class RenderOptions: | ||
25 | |||
26 | def __init__(self, app_options): | ||
27 | # should we render a cumulative CPU time chart | ||
28 | self.cumulative = True | ||
29 | self.charts = True | ||
30 | self.kernel_only = False | ||
31 | self.app_options = app_options | ||
32 | |||
33 | def proc_tree (self, trace): | ||
34 | if self.kernel_only: | ||
35 | return trace.kernel_tree | ||
36 | else: | ||
37 | return trace.proc_tree | ||
4 | 38 | ||
5 | # Process tree background color. | 39 | # Process tree background color. |
6 | BACK_COLOR = (1.0, 1.0, 1.0, 1.0) | 40 | BACK_COLOR = (1.0, 1.0, 1.0, 1.0) |
@@ -12,11 +46,13 @@ BORDER_COLOR = (0.63, 0.63, 0.63, 1.0) | |||
12 | TICK_COLOR = (0.92, 0.92, 0.92, 1.0) | 46 | TICK_COLOR = (0.92, 0.92, 0.92, 1.0) |
13 | # 5-second tick line color. | 47 | # 5-second tick line color. |
14 | TICK_COLOR_BOLD = (0.86, 0.86, 0.86, 1.0) | 48 | TICK_COLOR_BOLD = (0.86, 0.86, 0.86, 1.0) |
49 | # Annotation colour | ||
50 | ANNOTATION_COLOR = (0.63, 0.0, 0.0, 0.5) | ||
15 | # Text color. | 51 | # Text color. |
16 | TEXT_COLOR = (0.0, 0.0, 0.0, 1.0) | 52 | TEXT_COLOR = (0.0, 0.0, 0.0, 1.0) |
17 | 53 | ||
18 | # Font family | 54 | # Font family |
19 | FONT_NAME = "Bitstream Vera Sans" | 55 | FONT_NAME = "Bitstream Vera Sans" |
20 | # Title text font. | 56 | # Title text font. |
21 | TITLE_FONT_SIZE = 18 | 57 | TITLE_FONT_SIZE = 18 |
22 | # Default text font. | 58 | # Default text font. |
@@ -25,7 +61,7 @@ TEXT_FONT_SIZE = 12 | |||
25 | AXIS_FONT_SIZE = 11 | 61 | AXIS_FONT_SIZE = 11 |
26 | # Legend font. | 62 | # Legend font. |
27 | LEGEND_FONT_SIZE = 12 | 63 | LEGEND_FONT_SIZE = 12 |
28 | 64 | ||
29 | # CPU load chart color. | 65 | # CPU load chart color. |
30 | CPU_COLOR = (0.40, 0.55, 0.70, 1.0) | 66 | CPU_COLOR = (0.40, 0.55, 0.70, 1.0) |
31 | # IO wait chart color. | 67 | # IO wait chart color. |
@@ -34,11 +70,19 @@ IO_COLOR = (0.76, 0.48, 0.48, 0.5) | |||
34 | DISK_TPUT_COLOR = (0.20, 0.71, 0.20, 1.0) | 70 | DISK_TPUT_COLOR = (0.20, 0.71, 0.20, 1.0) |
35 | # CPU load chart color. | 71 | # CPU load chart color. |
36 | FILE_OPEN_COLOR = (0.20, 0.71, 0.71, 1.0) | 72 | FILE_OPEN_COLOR = (0.20, 0.71, 0.71, 1.0) |
37 | 73 | # Mem cached color | |
74 | MEM_CACHED_COLOR = CPU_COLOR | ||
75 | # Mem used color | ||
76 | MEM_USED_COLOR = IO_COLOR | ||
77 | # Buffers color | ||
78 | MEM_BUFFERS_COLOR = (0.4, 0.4, 0.4, 0.3) | ||
79 | # Swap color | ||
80 | MEM_SWAP_COLOR = DISK_TPUT_COLOR | ||
81 | |||
38 | # Process border color. | 82 | # Process border color. |
39 | PROC_BORDER_COLOR = (0.71, 0.71, 0.71, 1.0) | 83 | PROC_BORDER_COLOR = (0.71, 0.71, 0.71, 1.0) |
40 | 84 | # Waiting process color. | |
41 | PROC_COLOR_D = (0.76, 0.48, 0.48, 0.125) | 85 | PROC_COLOR_D = (0.76, 0.48, 0.48, 0.5) |
42 | # Running process color. | 86 | # Running process color. |
43 | PROC_COLOR_R = CPU_COLOR | 87 | PROC_COLOR_R = CPU_COLOR |
44 | # Sleeping process color. | 88 | # Sleeping process color. |
@@ -62,8 +106,8 @@ SIG_COLOR = (0.0, 0.0, 0.0, 0.3125) | |||
62 | # Signature font. | 106 | # Signature font. |
63 | SIG_FONT_SIZE = 14 | 107 | SIG_FONT_SIZE = 14 |
64 | # Signature text. | 108 | # Signature text. |
65 | SIGNATURE = "http://code.google.com/p/pybootchartgui" | 109 | SIGNATURE = "http://github.com/mmeeks/bootchart" |
66 | 110 | ||
67 | # Process dependency line color. | 111 | # Process dependency line color. |
68 | DEP_COLOR = (0.75, 0.75, 0.75, 1.0) | 112 | DEP_COLOR = (0.75, 0.75, 0.75, 1.0) |
69 | # Process dependency line stroke. | 113 | # Process dependency line stroke. |
@@ -72,6 +116,10 @@ DEP_STROKE = 1.0 | |||
72 | # Process description date format. | 116 | # Process description date format. |
73 | DESC_TIME_FORMAT = "mm:ss.SSS" | 117 | DESC_TIME_FORMAT = "mm:ss.SSS" |
74 | 118 | ||
119 | # Cumulative coloring bits | ||
120 | HSV_MAX_MOD = 31 | ||
121 | HSV_STEP = 7 | ||
122 | |||
75 | # Configure task color | 123 | # Configure task color |
76 | TASK_COLOR_CONFIGURE = (1.0, 1.0, 0.00, 1.0) | 124 | TASK_COLOR_CONFIGURE = (1.0, 1.0, 0.00, 1.0) |
77 | # Compile task color. | 125 | # Compile task color. |
@@ -91,66 +139,67 @@ STATE_WAITING = 3 | |||
91 | STATE_STOPPED = 4 | 139 | STATE_STOPPED = 4 |
92 | STATE_ZOMBIE = 5 | 140 | STATE_ZOMBIE = 5 |
93 | 141 | ||
94 | STATE_COLORS = [(0,0,0,0), PROC_COLOR_R, PROC_COLOR_S, PROC_COLOR_D, PROC_COLOR_T, PROC_COLOR_Z, PROC_COLOR_X, PROC_COLOR_W] | 142 | STATE_COLORS = [(0, 0, 0, 0), PROC_COLOR_R, PROC_COLOR_S, PROC_COLOR_D, \ |
143 | PROC_COLOR_T, PROC_COLOR_Z, PROC_COLOR_X, PROC_COLOR_W] | ||
144 | |||
145 | # CumulativeStats Types | ||
146 | STAT_TYPE_CPU = 0 | ||
147 | STAT_TYPE_IO = 1 | ||
95 | 148 | ||
96 | # Convert ps process state to an int | 149 | # Convert ps process state to an int |
97 | def get_proc_state(flag): | 150 | def get_proc_state(flag): |
98 | return "RSDTZXW".index(flag) + 1 | 151 | return "RSDTZXW".find(flag) + 1 |
99 | |||
100 | 152 | ||
101 | def draw_text(ctx, text, color, x, y): | 153 | def draw_text(ctx, text, color, x, y): |
102 | ctx.set_source_rgba(*color) | 154 | ctx.set_source_rgba(*color) |
103 | ctx.move_to(x, y) | 155 | ctx.move_to(x, y) |
104 | ctx.show_text(text) | 156 | ctx.show_text(text) |
105 | 157 | ||
106 | |||
107 | def draw_fill_rect(ctx, color, rect): | 158 | def draw_fill_rect(ctx, color, rect): |
108 | ctx.set_source_rgba(*color) | 159 | ctx.set_source_rgba(*color) |
109 | ctx.rectangle(*rect) | 160 | ctx.rectangle(*rect) |
110 | ctx.fill() | 161 | ctx.fill() |
111 | |||
112 | 162 | ||
113 | def draw_rect(ctx, color, rect): | 163 | def draw_rect(ctx, color, rect): |
114 | ctx.set_source_rgba(*color) | 164 | ctx.set_source_rgba(*color) |
115 | ctx.rectangle(*rect) | 165 | ctx.rectangle(*rect) |
116 | ctx.stroke() | 166 | ctx.stroke() |
117 | 167 | ||
118 | |||
119 | def draw_legend_box(ctx, label, fill_color, x, y, s): | 168 | def draw_legend_box(ctx, label, fill_color, x, y, s): |
120 | draw_fill_rect(ctx, fill_color, (x, y - s, s, s)) | 169 | draw_fill_rect(ctx, fill_color, (x, y - s, s, s)) |
121 | draw_rect(ctx, PROC_BORDER_COLOR, (x, y - s, s, s)) | 170 | draw_rect(ctx, PROC_BORDER_COLOR, (x, y - s, s, s)) |
122 | draw_text(ctx, label, TEXT_COLOR, x + s + 5, y) | 171 | draw_text(ctx, label, TEXT_COLOR, x + s + 5, y) |
123 | 172 | ||
124 | |||
125 | def draw_legend_line(ctx, label, fill_color, x, y, s): | 173 | def draw_legend_line(ctx, label, fill_color, x, y, s): |
126 | draw_fill_rect(ctx, fill_color, (x, y - s/2, s + 1, 3)) | 174 | draw_fill_rect(ctx, fill_color, (x, y - s/2, s + 1, 3)) |
127 | ctx.arc(x + (s + 1)/2.0, y - (s - 3)/2.0, 2.5, 0, 2.0 * math.pi) | 175 | ctx.arc(x + (s + 1)/2.0, y - (s - 3)/2.0, 2.5, 0, 2.0 * math.pi) |
128 | ctx.fill() | 176 | ctx.fill() |
129 | draw_text(ctx, label, TEXT_COLOR, x + s + 5, y) | 177 | draw_text(ctx, label, TEXT_COLOR, x + s + 5, y) |
130 | |||
131 | 178 | ||
132 | def draw_label_in_box(ctx, color, label, x, y, w, maxx): | 179 | def draw_label_in_box(ctx, color, label, x, y, w, maxx): |
133 | label_w = ctx.text_extents(label)[2] | 180 | label_w = ctx.text_extents(label)[2] |
134 | label_x = x + w / 2 - label_w / 2 | 181 | label_x = x + w / 2 - label_w / 2 |
135 | if label_w + 10 > w: | 182 | if label_w + 10 > w: |
136 | label_x = x + w + 5 | 183 | label_x = x + w + 5 |
137 | if label_x + label_w > maxx: | 184 | if label_x + label_w > maxx: |
138 | label_x = x - label_w - 5 | 185 | label_x = x - label_w - 5 |
139 | draw_text(ctx, label, color, label_x, y) | 186 | draw_text(ctx, label, color, label_x, y) |
140 | 187 | ||
141 | 188 | def draw_sec_labels(ctx, rect, sec_w, nsecs): | |
142 | def draw_5sec_labels(ctx, rect, sec_w): | 189 | ctx.set_font_size(AXIS_FONT_SIZE) |
143 | ctx.set_font_size(AXIS_FONT_SIZE) | 190 | prev_x = 0 |
144 | for i in range(0, rect[2] + 1, sec_w): | 191 | for i in range(0, rect[2] + 1, sec_w): |
145 | if ((i / sec_w) % 30 == 0) : | 192 | if ((i / sec_w) % nsecs == 0) : |
146 | label = "%ds" % (i / sec_w) | 193 | label = "%ds" % (i / sec_w) |
147 | label_w = ctx.text_extents(label)[2] | 194 | label_w = ctx.text_extents(label)[2] |
148 | draw_text(ctx, label, TEXT_COLOR, rect[0] + i - label_w/2, rect[1] - 2) | 195 | x = rect[0] + i - label_w/2 |
149 | 196 | if x >= prev_x: | |
197 | draw_text(ctx, label, TEXT_COLOR, x, rect[1] - 2) | ||
198 | prev_x = x + label_w | ||
150 | 199 | ||
151 | def draw_box_ticks(ctx, rect, sec_w): | 200 | def draw_box_ticks(ctx, rect, sec_w): |
152 | draw_rect(ctx, BORDER_COLOR, tuple(rect)) | 201 | draw_rect(ctx, BORDER_COLOR, tuple(rect)) |
153 | 202 | ||
154 | ctx.set_line_cap(cairo.LINE_CAP_SQUARE) | 203 | ctx.set_line_cap(cairo.LINE_CAP_SQUARE) |
155 | 204 | ||
156 | for i in range(sec_w, rect[2] + 1, sec_w): | 205 | for i in range(sec_w, rect[2] + 1, sec_w): |
@@ -164,136 +213,211 @@ def draw_box_ticks(ctx, rect, sec_w): | |||
164 | 213 | ||
165 | ctx.set_line_cap(cairo.LINE_CAP_BUTT) | 214 | ctx.set_line_cap(cairo.LINE_CAP_BUTT) |
166 | 215 | ||
167 | def draw_chart(ctx, color, fill, chart_bounds, data, proc_tree): | 216 | def draw_annotations(ctx, proc_tree, times, rect): |
217 | ctx.set_line_cap(cairo.LINE_CAP_SQUARE) | ||
218 | ctx.set_source_rgba(*ANNOTATION_COLOR) | ||
219 | ctx.set_dash([4, 4]) | ||
220 | |||
221 | for time in times: | ||
222 | if time is not None: | ||
223 | x = ((time - proc_tree.start_time) * rect[2] / proc_tree.duration) | ||
224 | |||
225 | ctx.move_to(rect[0] + x, rect[1] + 1) | ||
226 | ctx.line_to(rect[0] + x, rect[1] + rect[3] - 1) | ||
227 | ctx.stroke() | ||
228 | |||
229 | ctx.set_line_cap(cairo.LINE_CAP_BUTT) | ||
230 | ctx.set_dash([]) | ||
231 | |||
232 | def draw_chart(ctx, color, fill, chart_bounds, data, proc_tree, data_range): | ||
168 | ctx.set_line_width(0.5) | 233 | ctx.set_line_width(0.5) |
169 | x_shift = proc_tree.start_time | 234 | x_shift = proc_tree.start_time |
170 | x_scale = proc_tree.duration | 235 | |
171 | 236 | def transform_point_coords(point, x_base, y_base, \ | |
172 | def transform_point_coords(point, x_base, y_base, xscale, yscale, x_trans, y_trans): | 237 | xscale, yscale, x_trans, y_trans): |
173 | x = (point[0] - x_base) * xscale + x_trans | 238 | x = (point[0] - x_base) * xscale + x_trans |
174 | y = (point[1] - y_base) * -yscale + y_trans + bar_h | 239 | y = (point[1] - y_base) * -yscale + y_trans + chart_bounds[3] |
175 | return x, y | 240 | return x, y |
176 | 241 | ||
177 | xscale = float(chart_bounds[2]) / max(x for (x,y) in data) | 242 | max_x = max (x for (x, y) in data) |
178 | yscale = float(chart_bounds[3]) / max(y for (x,y) in data) | 243 | max_y = max (y for (x, y) in data) |
179 | 244 | # avoid divide by zero | |
180 | first = transform_point_coords(data[0], x_shift, 0, xscale, yscale, chart_bounds[0], chart_bounds[1]) | 245 | if max_y == 0: |
181 | last = transform_point_coords(data[-1], x_shift, 0, xscale, yscale, chart_bounds[0], chart_bounds[1]) | 246 | max_y = 1.0 |
182 | 247 | xscale = float (chart_bounds[2]) / max_x | |
248 | # If data_range is given, scale the chart so that the value range in | ||
249 | # data_range matches the chart bounds exactly. | ||
250 | # Otherwise, scale so that the actual data matches the chart bounds. | ||
251 | if data_range: | ||
252 | yscale = float(chart_bounds[3]) / (data_range[1] - data_range[0]) | ||
253 | ybase = data_range[0] | ||
254 | else: | ||
255 | yscale = float(chart_bounds[3]) / max_y | ||
256 | ybase = 0 | ||
257 | |||
258 | first = transform_point_coords (data[0], x_shift, ybase, xscale, yscale, \ | ||
259 | chart_bounds[0], chart_bounds[1]) | ||
260 | last = transform_point_coords (data[-1], x_shift, ybase, xscale, yscale, \ | ||
261 | chart_bounds[0], chart_bounds[1]) | ||
262 | |||
183 | ctx.set_source_rgba(*color) | 263 | ctx.set_source_rgba(*color) |
184 | ctx.move_to(*first) | 264 | ctx.move_to(*first) |
185 | for point in data: | 265 | for point in data: |
186 | x, y = transform_point_coords(point, x_shift, 0, xscale, yscale, chart_bounds[0], chart_bounds[1]) | 266 | x, y = transform_point_coords (point, x_shift, ybase, xscale, yscale, \ |
267 | chart_bounds[0], chart_bounds[1]) | ||
187 | ctx.line_to(x, y) | 268 | ctx.line_to(x, y) |
188 | if fill: | 269 | if fill: |
189 | ctx.stroke_preserve() | 270 | ctx.stroke_preserve() |
190 | ctx.line_to(last[0], chart_bounds[1]+bar_h) | 271 | ctx.line_to(last[0], chart_bounds[1]+chart_bounds[3]) |
191 | ctx.line_to(first[0], chart_bounds[1]+bar_h) | 272 | ctx.line_to(first[0], chart_bounds[1]+chart_bounds[3]) |
192 | ctx.line_to(first[0], first[1]) | 273 | ctx.line_to(first[0], first[1]) |
193 | ctx.fill() | 274 | ctx.fill() |
194 | else: | 275 | else: |
195 | ctx.stroke() | 276 | ctx.stroke() |
196 | ctx.set_line_width(1.0) | 277 | ctx.set_line_width(1.0) |
197 | 278 | ||
198 | header_h = 280 | ||
199 | bar_h = 55 | 279 | bar_h = 55 |
280 | meminfo_bar_h = 2 * bar_h | ||
281 | header_h = 110 + 2 * (30 + bar_h) + 1 * (30 + meminfo_bar_h) | ||
200 | # offsets | 282 | # offsets |
201 | off_x, off_y = 10, 10 | 283 | off_x, off_y = 10, 10 |
202 | sec_w = 1 # the width of a second | 284 | sec_w_base = 1 # the width of a second |
203 | proc_h = 16 # the height of a process | 285 | proc_h = 16 # the height of a process |
204 | leg_s = 10 | 286 | leg_s = 10 |
205 | MIN_IMG_W = 800 | 287 | MIN_IMG_W = 800 |
288 | CUML_HEIGHT = 2000 # Increased value to accomodate CPU and I/O Graphs | ||
289 | OPTIONS = None | ||
206 | 290 | ||
291 | def extents(options, xscale, trace): | ||
292 | start = min(trace.start.keys()) | ||
293 | end = max(trace.end.keys()) | ||
207 | 294 | ||
208 | def extents(res): | 295 | w = int ((end - start) * sec_w_base * xscale) + 2*off_x |
209 | start = min(res.start.keys()) | 296 | h = proc_h * len(trace.processes) + header_h + 2 * off_y |
210 | end = max(res.end.keys()) | ||
211 | 297 | ||
212 | w = ((end - start) * sec_w) + 2*off_x | 298 | return (w, h) |
213 | h = proc_h * len(res.processes) + header_h + 2*off_y | ||
214 | 299 | ||
215 | return (w,h) | 300 | def clip_visible(clip, rect): |
301 | xmax = max (clip[0], rect[0]) | ||
302 | ymax = max (clip[1], rect[1]) | ||
303 | xmin = min (clip[0] + clip[2], rect[0] + rect[2]) | ||
304 | ymin = min (clip[1] + clip[3], rect[1] + rect[3]) | ||
305 | return (xmin > xmax and ymin > ymax) | ||
216 | 306 | ||
217 | # | 307 | def render_charts(ctx, options, clip, trace, curr_y, w, h, sec_w): |
218 | # Render the chart. | 308 | proc_tree = options.proc_tree(trace) |
219 | # | ||
220 | def render(ctx, res): | ||
221 | (w, h) = extents(res) | ||
222 | 309 | ||
223 | ctx.set_line_width(1.0) | ||
224 | ctx.select_font_face(FONT_NAME) | ||
225 | draw_fill_rect(ctx, WHITE, (0, 0, max(w, MIN_IMG_W), h)) | ||
226 | w -= 2*off_x | ||
227 | # draw the title and headers | ||
228 | #curr_y = draw_header(ctx, headers, off_x, proc_tree.duration) | ||
229 | curr_y = 0 | ||
230 | |||
231 | # render bar legend | 310 | # render bar legend |
232 | ctx.set_font_size(LEGEND_FONT_SIZE) | 311 | ctx.set_font_size(LEGEND_FONT_SIZE) |
233 | 312 | ||
234 | #print "w, h %s %s" % (w, h) | 313 | draw_legend_box(ctx, "CPU (user+sys)", CPU_COLOR, off_x, curr_y+20, leg_s) |
235 | 314 | draw_legend_box(ctx, "I/O (wait)", IO_COLOR, off_x + 120, curr_y+20, leg_s) | |
236 | #draw_legend_box(ctx, "CPU (user+sys)", CPU_COLOR, off_x, curr_y+20, leg_s) | ||
237 | #draw_legend_box(ctx, "I/O (wait)", IO_COLOR, off_x + 120, curr_y+20, leg_s) | ||
238 | 315 | ||
239 | # render I/O wait | 316 | # render I/O wait |
240 | #chart_rect = (off_x, curr_y+30, w, bar_h) | 317 | chart_rect = (off_x, curr_y+30, w, bar_h) |
241 | #draw_box_ticks(ctx, chart_rect, sec_w) | 318 | if clip_visible (clip, chart_rect): |
242 | #draw_chart(ctx, IO_COLOR, True, chart_rect, [(sample.time, sample.user + sample.sys + sample.io) for sample in cpu_stats], proc_tree) | 319 | draw_box_ticks (ctx, chart_rect, sec_w) |
243 | # render CPU load | 320 | draw_annotations (ctx, proc_tree, trace.times, chart_rect) |
244 | #draw_chart(ctx, CPU_COLOR, True, chart_rect, [(sample.time, sample.user + sample.sys) for sample in cpu_stats], proc_tree) | 321 | draw_chart (ctx, IO_COLOR, True, chart_rect, \ |
245 | 322 | [(sample.time, sample.user + sample.sys + sample.io) for sample in trace.cpu_stats], \ | |
246 | #curr_y = curr_y + 30 + bar_h | 323 | proc_tree, None) |
324 | # render CPU load | ||
325 | draw_chart (ctx, CPU_COLOR, True, chart_rect, \ | ||
326 | [(sample.time, sample.user + sample.sys) for sample in trace.cpu_stats], \ | ||
327 | proc_tree, None) | ||
328 | |||
329 | curr_y = curr_y + 30 + bar_h | ||
247 | 330 | ||
248 | # render second chart | 331 | # render second chart |
249 | #draw_legend_line(ctx, "Disk throughput", DISK_TPUT_COLOR, off_x, curr_y+20, leg_s) | 332 | draw_legend_line(ctx, "Disk throughput", DISK_TPUT_COLOR, off_x, curr_y+20, leg_s) |
250 | #draw_legend_box(ctx, "Disk utilization", IO_COLOR, off_x + 120, curr_y+20, leg_s) | 333 | draw_legend_box(ctx, "Disk utilization", IO_COLOR, off_x + 120, curr_y+20, leg_s) |
251 | 334 | ||
252 | # render I/O utilization | 335 | # render I/O utilization |
253 | #chart_rect = (off_x, curr_y+30, w, bar_h) | 336 | chart_rect = (off_x, curr_y+30, w, bar_h) |
254 | #draw_box_ticks(ctx, chart_rect, sec_w) | 337 | if clip_visible (clip, chart_rect): |
255 | #draw_chart(ctx, IO_COLOR, True, chart_rect, [(sample.time, sample.util) for sample in disk_stats], proc_tree) | 338 | draw_box_ticks (ctx, chart_rect, sec_w) |
256 | 339 | draw_annotations (ctx, proc_tree, trace.times, chart_rect) | |
340 | draw_chart (ctx, IO_COLOR, True, chart_rect, \ | ||
341 | [(sample.time, sample.util) for sample in trace.disk_stats], \ | ||
342 | proc_tree, None) | ||
343 | |||
257 | # render disk throughput | 344 | # render disk throughput |
258 | #max_sample = max(disk_stats, key=lambda s: s.tput) | 345 | max_sample = max (trace.disk_stats, key = lambda s: s.tput) |
259 | #draw_chart(ctx, DISK_TPUT_COLOR, False, chart_rect, [(sample.time, sample.tput) for sample in disk_stats], proc_tree) | 346 | if clip_visible (clip, chart_rect): |
260 | 347 | draw_chart (ctx, DISK_TPUT_COLOR, False, chart_rect, \ | |
261 | #pos_x = off_x + ((max_sample.time - proc_tree.start_time) * w / proc_tree.duration) | 348 | [(sample.time, sample.tput) for sample in trace.disk_stats], \ |
262 | pos_x = off_x | 349 | proc_tree, None) |
350 | |||
351 | pos_x = off_x + ((max_sample.time - proc_tree.start_time) * w / proc_tree.duration) | ||
263 | 352 | ||
264 | shift_x, shift_y = -20, 20 | 353 | shift_x, shift_y = -20, 20 |
265 | if (pos_x < off_x + 245): | 354 | if (pos_x < off_x + 245): |
266 | shift_x, shift_y = 5, 40 | 355 | shift_x, shift_y = 5, 40 |
267 | |||
268 | #label = "%dMB/s" % round((max_sample.tput) / 1024.0) | ||
269 | #draw_text(ctx, label, DISK_TPUT_COLOR, pos_x + shift_x, curr_y + shift_y) | ||
270 | |||
271 | |||
272 | 356 | ||
357 | label = "%dMB/s" % round ((max_sample.tput) / 1024.0) | ||
358 | draw_text (ctx, label, DISK_TPUT_COLOR, pos_x + shift_x, curr_y + shift_y) | ||
359 | |||
360 | curr_y = curr_y + 30 + bar_h | ||
361 | |||
362 | # render mem usage | ||
363 | chart_rect = (off_x, curr_y+30, w, meminfo_bar_h) | ||
364 | mem_stats = trace.mem_stats | ||
365 | if mem_stats and clip_visible (clip, chart_rect): | ||
366 | mem_scale = max(sample.records['MemTotal'] - sample.records['MemFree'] for sample in mem_stats) | ||
367 | draw_legend_box(ctx, "Mem cached (scale: %u MiB)" % (float(mem_scale) / 1024), MEM_CACHED_COLOR, off_x, curr_y+20, leg_s) | ||
368 | draw_legend_box(ctx, "Used", MEM_USED_COLOR, off_x + 240, curr_y+20, leg_s) | ||
369 | draw_legend_box(ctx, "Buffers", MEM_BUFFERS_COLOR, off_x + 360, curr_y+20, leg_s) | ||
370 | draw_legend_line(ctx, "Swap (scale: %u MiB)" % max([(sample.records['SwapTotal'] - sample.records['SwapFree'])/1024 for sample in mem_stats]), \ | ||
371 | MEM_SWAP_COLOR, off_x + 480, curr_y+20, leg_s) | ||
372 | draw_box_ticks(ctx, chart_rect, sec_w) | ||
373 | draw_annotations(ctx, proc_tree, trace.times, chart_rect) | ||
374 | draw_chart(ctx, MEM_BUFFERS_COLOR, True, chart_rect, \ | ||
375 | [(sample.time, sample.records['MemTotal'] - sample.records['MemFree']) for sample in trace.mem_stats], \ | ||
376 | proc_tree, [0, mem_scale]) | ||
377 | draw_chart(ctx, MEM_USED_COLOR, True, chart_rect, \ | ||
378 | [(sample.time, sample.records['MemTotal'] - sample.records['MemFree'] - sample.records['Buffers']) for sample in mem_stats], \ | ||
379 | proc_tree, [0, mem_scale]) | ||
380 | draw_chart(ctx, MEM_CACHED_COLOR, True, chart_rect, \ | ||
381 | [(sample.time, sample.records['Cached']) for sample in mem_stats], \ | ||
382 | proc_tree, [0, mem_scale]) | ||
383 | draw_chart(ctx, MEM_SWAP_COLOR, False, chart_rect, \ | ||
384 | [(sample.time, float(sample.records['SwapTotal'] - sample.records['SwapFree'])) for sample in mem_stats], \ | ||
385 | proc_tree, None) | ||
386 | |||
387 | curr_y = curr_y + meminfo_bar_h | ||
388 | |||
389 | return curr_y | ||
390 | |||
391 | def render_processes_chart(ctx, options, trace, curr_y, w, h, sec_w): | ||
273 | chart_rect = [off_x, curr_y+60, w, h - 2 * off_y - (curr_y+60) + proc_h] | 392 | chart_rect = [off_x, curr_y+60, w, h - 2 * off_y - (curr_y+60) + proc_h] |
274 | 393 | ||
275 | draw_legend_box(ctx, "Configure", TASK_COLOR_CONFIGURE, off_x , curr_y + 45, leg_s) | 394 | draw_legend_box (ctx, "Configure", \ |
276 | draw_legend_box(ctx, "Compile", TASK_COLOR_COMPILE, off_x+120, curr_y + 45, leg_s) | 395 | TASK_COLOR_CONFIGURE, off_x , curr_y + 45, leg_s) |
277 | draw_legend_box(ctx, "Install", TASK_COLOR_INSTALL, off_x+240, curr_y + 45, leg_s) | 396 | draw_legend_box (ctx, "Compile", \ |
278 | draw_legend_box(ctx, "Package", TASK_COLOR_PACKAGE, off_x+360, curr_y + 45, leg_s) | 397 | TASK_COLOR_COMPILE, off_x+120, curr_y + 45, leg_s) |
279 | draw_legend_box(ctx, "Populate Sysroot", TASK_COLOR_SYSROOT, off_x+480, curr_y + 45, leg_s) | 398 | draw_legend_box (ctx, "Install", \ |
280 | 399 | TASK_COLOR_INSTALL, off_x+240, curr_y + 45, leg_s) | |
400 | draw_legend_box (ctx, "Package", \ | ||
401 | TASK_COLOR_PACKAGE, off_x+360, curr_y + 45, leg_s) | ||
402 | draw_legend_box (ctx, "Populate Sysroot", \ | ||
403 | TASK_COLOR_SYSROOT, off_x+480, curr_y + 45, leg_s) | ||
404 | |||
281 | ctx.set_font_size(PROC_TEXT_FONT_SIZE) | 405 | ctx.set_font_size(PROC_TEXT_FONT_SIZE) |
282 | 406 | ||
283 | draw_box_ticks(ctx, chart_rect, sec_w) | 407 | draw_box_ticks(ctx, chart_rect, sec_w) |
284 | draw_5sec_labels(ctx, chart_rect, sec_w) | 408 | draw_sec_labels(ctx, chart_rect, sec_w, 30) |
285 | 409 | ||
286 | y = curr_y+60 | 410 | y = curr_y+60 |
287 | 411 | ||
288 | offset = min(res.start.keys()) | 412 | offset = min(trace.start.keys()) |
289 | for s in sorted(res.start.keys()): | 413 | for s in sorted(trace.start.keys()): |
290 | for val in sorted(res.start[s]): | 414 | for val in sorted(trace.start[s]): |
291 | task = val.split(":")[1] | 415 | task = val.split(":")[1] |
292 | #print val | 416 | #print val |
293 | #print res.processes[val][1] | 417 | #print trace.processes[val][1] |
294 | #print s | 418 | #print s |
295 | x = (s - offset) * sec_w | 419 | x = (s - offset) * sec_w |
296 | w = ((res.processes[val][1] - s) * sec_w) | 420 | w = ((trace.processes[val][1] - s) * sec_w) |
297 | 421 | ||
298 | #print "proc at %s %s %s %s" % (x, y, w, proc_h) | 422 | #print "proc at %s %s %s %s" % (x, y, w, proc_h) |
299 | col = None | 423 | col = None |
@@ -315,95 +439,419 @@ def render(ctx, res): | |||
315 | draw_label_in_box(ctx, PROC_TEXT_COLOR, val, x, y + proc_h - 4, w, proc_h) | 439 | draw_label_in_box(ctx, PROC_TEXT_COLOR, val, x, y + proc_h - 4, w, proc_h) |
316 | y = y + proc_h | 440 | y = y + proc_h |
317 | 441 | ||
442 | return curr_y | ||
443 | |||
444 | # | ||
445 | # Render the chart. | ||
446 | # | ||
447 | def render(ctx, options, xscale, trace): | ||
448 | (w, h) = extents (options, xscale, trace) | ||
449 | global OPTIONS | ||
450 | OPTIONS = options.app_options | ||
451 | |||
452 | # x, y, w, h | ||
453 | clip = ctx.clip_extents() | ||
454 | |||
455 | sec_w = int (xscale * sec_w_base) | ||
456 | ctx.set_line_width(1.0) | ||
457 | ctx.select_font_face(FONT_NAME) | ||
458 | draw_fill_rect(ctx, WHITE, (0, 0, max(w, MIN_IMG_W), h)) | ||
459 | w -= 2*off_x | ||
460 | curr_y = off_y; | ||
461 | |||
462 | curr_y = render_processes_chart (ctx, options, trace, curr_y, w, h, sec_w) | ||
463 | |||
464 | return | ||
465 | |||
466 | proc_tree = options.proc_tree (trace) | ||
467 | |||
468 | # draw the title and headers | ||
469 | if proc_tree.idle: | ||
470 | duration = proc_tree.idle | ||
471 | else: | ||
472 | duration = proc_tree.duration | ||
473 | |||
474 | if not options.kernel_only: | ||
475 | curr_y = draw_header (ctx, trace.headers, duration) | ||
476 | else: | ||
477 | curr_y = off_y; | ||
478 | |||
479 | if options.charts: | ||
480 | curr_y = render_charts (ctx, options, clip, trace, curr_y, w, h, sec_w) | ||
481 | |||
318 | # draw process boxes | 482 | # draw process boxes |
319 | #draw_process_bar_chart(ctx, proc_tree, curr_y + bar_h, w, h) | 483 | proc_height = h |
484 | if proc_tree.taskstats and options.cumulative: | ||
485 | proc_height -= CUML_HEIGHT | ||
320 | 486 | ||
321 | ctx.set_font_size(SIG_FONT_SIZE) | 487 | draw_process_bar_chart(ctx, clip, options, proc_tree, trace.times, |
322 | draw_text(ctx, SIGNATURE, SIG_COLOR, off_x + 5, h - off_y - 5) | 488 | curr_y, w, proc_height, sec_w) |
323 | 489 | ||
324 | def draw_process_bar_chart(ctx, proc_tree, curr_y, w, h): | 490 | curr_y = proc_height |
491 | ctx.set_font_size(SIG_FONT_SIZE) | ||
492 | draw_text(ctx, SIGNATURE, SIG_COLOR, off_x + 5, proc_height - 8) | ||
493 | |||
494 | # draw a cumulative CPU-time-per-process graph | ||
495 | if proc_tree.taskstats and options.cumulative: | ||
496 | cuml_rect = (off_x, curr_y + off_y, w, CUML_HEIGHT/2 - off_y * 2) | ||
497 | if clip_visible (clip, cuml_rect): | ||
498 | draw_cuml_graph(ctx, proc_tree, cuml_rect, duration, sec_w, STAT_TYPE_CPU) | ||
499 | |||
500 | # draw a cumulative I/O-time-per-process graph | ||
501 | if proc_tree.taskstats and options.cumulative: | ||
502 | cuml_rect = (off_x, curr_y + off_y * 100, w, CUML_HEIGHT/2 - off_y * 2) | ||
503 | if clip_visible (clip, cuml_rect): | ||
504 | draw_cuml_graph(ctx, proc_tree, cuml_rect, duration, sec_w, STAT_TYPE_IO) | ||
505 | |||
506 | def draw_process_bar_chart(ctx, clip, options, proc_tree, times, curr_y, w, h, sec_w): | ||
507 | header_size = 0 | ||
508 | if not options.kernel_only: | ||
509 | draw_legend_box (ctx, "Running (%cpu)", | ||
510 | PROC_COLOR_R, off_x , curr_y + 45, leg_s) | ||
511 | draw_legend_box (ctx, "Unint.sleep (I/O)", | ||
512 | PROC_COLOR_D, off_x+120, curr_y + 45, leg_s) | ||
513 | draw_legend_box (ctx, "Sleeping", | ||
514 | PROC_COLOR_S, off_x+240, curr_y + 45, leg_s) | ||
515 | draw_legend_box (ctx, "Zombie", | ||
516 | PROC_COLOR_Z, off_x+360, curr_y + 45, leg_s) | ||
517 | header_size = 45 | ||
518 | |||
519 | chart_rect = [off_x, curr_y + header_size + 15, | ||
520 | w, h - 2 * off_y - (curr_y + header_size + 15) + proc_h] | ||
521 | ctx.set_font_size (PROC_TEXT_FONT_SIZE) | ||
522 | |||
523 | draw_box_ticks (ctx, chart_rect, sec_w) | ||
524 | if sec_w > 100: | ||
525 | nsec = 1 | ||
526 | else: | ||
527 | nsec = 5 | ||
528 | draw_sec_labels (ctx, chart_rect, sec_w, nsec) | ||
529 | draw_annotations (ctx, proc_tree, times, chart_rect) | ||
325 | 530 | ||
326 | for root in proc_tree.process_tree: | 531 | y = curr_y + 60 |
327 | draw_processes_recursively(ctx, root, proc_tree, y, proc_h, chart_rect) | 532 | for root in proc_tree.process_tree: |
328 | y = y + proc_h * proc_tree.num_nodes([root]) | 533 | draw_processes_recursively(ctx, root, proc_tree, y, proc_h, chart_rect, clip) |
534 | y = y + proc_h * proc_tree.num_nodes([root]) | ||
329 | 535 | ||
330 | 536 | ||
331 | def draw_header(ctx, headers, off_x, duration): | 537 | def draw_header (ctx, headers, duration): |
332 | dur = duration / 100.0 | ||
333 | toshow = [ | 538 | toshow = [ |
334 | ('system.uname', 'uname', lambda s: s), | 539 | ('system.uname', 'uname', lambda s: s), |
335 | ('system.release', 'release', lambda s: s), | 540 | ('system.release', 'release', lambda s: s), |
336 | ('system.cpu', 'CPU', lambda s: re.sub('model name\s*:\s*', '', s, 1)), | 541 | ('system.cpu', 'CPU', lambda s: re.sub('model name\s*:\s*', '', s, 1)), |
337 | ('system.kernel.options', 'kernel options', lambda s: s), | 542 | ('system.kernel.options', 'kernel options', lambda s: s), |
338 | ('pseudo.header', 'time', lambda s: '%02d:%05.2f' % (math.floor(dur/60), dur - 60 * math.floor(dur/60))) | ||
339 | ] | 543 | ] |
340 | 544 | ||
341 | header_y = ctx.font_extents()[2] + 10 | 545 | header_y = ctx.font_extents()[2] + 10 |
342 | ctx.set_font_size(TITLE_FONT_SIZE) | 546 | ctx.set_font_size(TITLE_FONT_SIZE) |
343 | draw_text(ctx, headers['title'], TEXT_COLOR, off_x, header_y) | 547 | draw_text(ctx, headers['title'], TEXT_COLOR, off_x, header_y) |
344 | ctx.set_font_size(TEXT_FONT_SIZE) | 548 | ctx.set_font_size(TEXT_FONT_SIZE) |
345 | 549 | ||
346 | for (headerkey, headertitle, mangle) in toshow: | 550 | for (headerkey, headertitle, mangle) in toshow: |
347 | header_y += ctx.font_extents()[2] | 551 | header_y += ctx.font_extents()[2] |
348 | txt = headertitle + ': ' + mangle(headers.get(headerkey)) | 552 | if headerkey in headers: |
553 | value = headers.get(headerkey) | ||
554 | else: | ||
555 | value = "" | ||
556 | txt = headertitle + ': ' + mangle(value) | ||
349 | draw_text(ctx, txt, TEXT_COLOR, off_x, header_y) | 557 | draw_text(ctx, txt, TEXT_COLOR, off_x, header_y) |
350 | 558 | ||
559 | dur = duration / 100.0 | ||
560 | txt = 'time : %02d:%05.2f' % (math.floor(dur/60), dur - 60 * math.floor(dur/60)) | ||
561 | if headers.get('system.maxpid') is not None: | ||
562 | txt = txt + ' max pid: %s' % (headers.get('system.maxpid')) | ||
563 | |||
564 | header_y += ctx.font_extents()[2] | ||
565 | draw_text (ctx, txt, TEXT_COLOR, off_x, header_y) | ||
566 | |||
351 | return header_y | 567 | return header_y |
352 | 568 | ||
353 | def draw_processes_recursively(ctx, proc, proc_tree, y, proc_h, rect) : | 569 | def draw_processes_recursively(ctx, proc, proc_tree, y, proc_h, rect, clip) : |
354 | x = rect[0] + ((proc.start_time - proc_tree.start_time) * rect[2] / proc_tree.duration) | 570 | x = rect[0] + ((proc.start_time - proc_tree.start_time) * rect[2] / proc_tree.duration) |
355 | w = ((proc.duration) * rect[2] / proc_tree.duration) | 571 | w = ((proc.duration) * rect[2] / proc_tree.duration) |
356 | 572 | ||
357 | draw_process_activity_colors(ctx, proc, proc_tree, x, y, w, proc_h, rect) | 573 | draw_process_activity_colors(ctx, proc, proc_tree, x, y, w, proc_h, rect, clip) |
358 | draw_rect(ctx, PROC_BORDER_COLOR, (x, y, w, proc_h)) | 574 | draw_rect(ctx, PROC_BORDER_COLOR, (x, y, w, proc_h)) |
359 | draw_label_in_box(ctx, PROC_TEXT_COLOR, proc.cmd, x, y + proc_h - 4, w, rect[0] + rect[2]) | 575 | ipid = int(proc.pid) |
576 | if not OPTIONS.show_all: | ||
577 | cmdString = proc.cmd | ||
578 | else: | ||
579 | cmdString = '' | ||
580 | if (OPTIONS.show_pid or OPTIONS.show_all) and ipid is not 0: | ||
581 | cmdString = cmdString + " [" + str(ipid // 1000) + "]" | ||
582 | if OPTIONS.show_all: | ||
583 | if proc.args: | ||
584 | cmdString = cmdString + " '" + "' '".join(proc.args) + "'" | ||
585 | else: | ||
586 | cmdString = cmdString + " " + proc.exe | ||
587 | |||
588 | draw_label_in_box(ctx, PROC_TEXT_COLOR, cmdString, x, y + proc_h - 4, w, rect[0] + rect[2]) | ||
360 | 589 | ||
361 | next_y = y + proc_h | 590 | next_y = y + proc_h |
362 | for child in proc.child_list: | 591 | for child in proc.child_list: |
363 | child_x, child_y = draw_processes_recursively(ctx, child, proc_tree, next_y, proc_h, rect) | 592 | if next_y > clip[1] + clip[3]: |
593 | break | ||
594 | child_x, child_y = draw_processes_recursively(ctx, child, proc_tree, next_y, proc_h, rect, clip) | ||
364 | draw_process_connecting_lines(ctx, x, y, child_x, child_y, proc_h) | 595 | draw_process_connecting_lines(ctx, x, y, child_x, child_y, proc_h) |
365 | next_y = next_y + proc_h * proc_tree.num_nodes([child]) | 596 | next_y = next_y + proc_h * proc_tree.num_nodes([child]) |
366 | 597 | ||
367 | return x, y | 598 | return x, y |
368 | 599 | ||
369 | 600 | ||
370 | def draw_process_activity_colors(ctx, proc, proc_tree, x, y, w, proc_h, rect): | 601 | def draw_process_activity_colors(ctx, proc, proc_tree, x, y, w, proc_h, rect, clip): |
602 | |||
603 | if y > clip[1] + clip[3] or y + proc_h + 2 < clip[1]: | ||
604 | return | ||
605 | |||
371 | draw_fill_rect(ctx, PROC_COLOR_S, (x, y, w, proc_h)) | 606 | draw_fill_rect(ctx, PROC_COLOR_S, (x, y, w, proc_h)) |
372 | 607 | ||
373 | last_tx = -1 | 608 | last_tx = -1 |
374 | for sample in proc.samples : | 609 | for sample in proc.samples : |
375 | tx = rect[0] + round(((sample.time - proc_tree.start_time) * rect[2] / proc_tree.duration)) | 610 | tx = rect[0] + round(((sample.time - proc_tree.start_time) * rect[2] / proc_tree.duration)) |
611 | |||
612 | # samples are sorted chronologically | ||
613 | if tx < clip[0]: | ||
614 | continue | ||
615 | if tx > clip[0] + clip[2]: | ||
616 | break | ||
617 | |||
376 | tw = round(proc_tree.sample_period * rect[2] / float(proc_tree.duration)) | 618 | tw = round(proc_tree.sample_period * rect[2] / float(proc_tree.duration)) |
377 | if last_tx != -1 and abs(last_tx - tx) <= tw: | 619 | if last_tx != -1 and abs(last_tx - tx) <= tw: |
378 | tw -= last_tx - tx | 620 | tw -= last_tx - tx |
379 | tx = last_tx | 621 | tx = last_tx |
380 | 622 | tw = max (tw, 1) # nice to see at least something | |
623 | |||
381 | last_tx = tx + tw | 624 | last_tx = tx + tw |
382 | state = get_proc_state( sample.state ) | 625 | state = get_proc_state( sample.state ) |
383 | 626 | ||
384 | color = STATE_COLORS[state] | 627 | color = STATE_COLORS[state] |
385 | if state == STATE_RUNNING: | 628 | if state == STATE_RUNNING: |
386 | alpha = sample.cpu_sample.user + sample.cpu_sample.sys | 629 | alpha = min (sample.cpu_sample.user + sample.cpu_sample.sys, 1.0) |
387 | color = tuple(list(PROC_COLOR_R[0:3]) + [alpha]) | 630 | color = tuple(list(PROC_COLOR_R[0:3]) + [alpha]) |
631 | # print "render time %d [ tx %d tw %d ], sample state %s color %s alpha %g" % (sample.time, tx, tw, state, color, alpha) | ||
388 | elif state == STATE_SLEEPING: | 632 | elif state == STATE_SLEEPING: |
389 | continue | 633 | continue |
390 | 634 | ||
391 | draw_fill_rect(ctx, color, (tx, y, tw, proc_h)) | 635 | draw_fill_rect(ctx, color, (tx, y, tw, proc_h)) |
392 | 636 | ||
393 | |||
394 | def draw_process_connecting_lines(ctx, px, py, x, y, proc_h): | 637 | def draw_process_connecting_lines(ctx, px, py, x, y, proc_h): |
395 | ctx.set_source_rgba(*DEP_COLOR) | 638 | ctx.set_source_rgba(*DEP_COLOR) |
396 | ctx.set_dash([2,2]) | 639 | ctx.set_dash([2, 2]) |
397 | if abs(px - x) < 3: | 640 | if abs(px - x) < 3: |
398 | dep_off_x = 3 | 641 | dep_off_x = 3 |
399 | dep_off_y = proc_h / 4 | 642 | dep_off_y = proc_h / 4 |
400 | ctx.move_to(x, y + proc_h / 2) | 643 | ctx.move_to(x, y + proc_h / 2) |
401 | ctx.line_to(px - dep_off_x, y + proc_h / 2) | 644 | ctx.line_to(px - dep_off_x, y + proc_h / 2) |
402 | ctx.line_to(px - dep_off_x, py - dep_off_y) | 645 | ctx.line_to(px - dep_off_x, py - dep_off_y) |
403 | ctx.line_to(px, py - dep_off_y) | 646 | ctx.line_to(px, py - dep_off_y) |
404 | else: | 647 | else: |
405 | ctx.move_to(x, y + proc_h / 2) | 648 | ctx.move_to(x, y + proc_h / 2) |
406 | ctx.line_to(px, y + proc_h / 2) | 649 | ctx.line_to(px, y + proc_h / 2) |
407 | ctx.line_to(px, py) | 650 | ctx.line_to(px, py) |
408 | ctx.stroke() | 651 | ctx.stroke() |
409 | ctx.set_dash([]) | 652 | ctx.set_dash([]) |
653 | |||
654 | # elide the bootchart collector - it is quite distorting | ||
655 | def elide_bootchart(proc): | ||
656 | return proc.cmd == 'bootchartd' or proc.cmd == 'bootchart-colle' | ||
657 | |||
658 | class CumlSample: | ||
659 | def __init__(self, proc): | ||
660 | self.cmd = proc.cmd | ||
661 | self.samples = [] | ||
662 | self.merge_samples (proc) | ||
663 | self.color = None | ||
664 | |||
665 | def merge_samples(self, proc): | ||
666 | self.samples.extend (proc.samples) | ||
667 | self.samples.sort (key = lambda p: p.time) | ||
668 | |||
669 | def next(self): | ||
670 | global palette_idx | ||
671 | palette_idx += HSV_STEP | ||
672 | return palette_idx | ||
673 | |||
674 | def get_color(self): | ||
675 | if self.color is None: | ||
676 | i = self.next() % HSV_MAX_MOD | ||
677 | h = 0.0 | ||
678 | if i is not 0: | ||
679 | h = (1.0 * i) / HSV_MAX_MOD | ||
680 | s = 0.5 | ||
681 | v = 1.0 | ||
682 | c = colorsys.hsv_to_rgb (h, s, v) | ||
683 | self.color = (c[0], c[1], c[2], 1.0) | ||
684 | return self.color | ||
685 | |||
686 | |||
687 | def draw_cuml_graph(ctx, proc_tree, chart_bounds, duration, sec_w, stat_type): | ||
688 | global palette_idx | ||
689 | palette_idx = 0 | ||
690 | |||
691 | time_hash = {} | ||
692 | total_time = 0.0 | ||
693 | m_proc_list = {} | ||
694 | |||
695 | if stat_type is STAT_TYPE_CPU: | ||
696 | sample_value = 'cpu' | ||
697 | else: | ||
698 | sample_value = 'io' | ||
699 | for proc in proc_tree.process_list: | ||
700 | if elide_bootchart(proc): | ||
701 | continue | ||
702 | |||
703 | for sample in proc.samples: | ||
704 | total_time += getattr(sample.cpu_sample, sample_value) | ||
705 | if not sample.time in time_hash: | ||
706 | time_hash[sample.time] = 1 | ||
707 | |||
708 | # merge pids with the same cmd | ||
709 | if not proc.cmd in m_proc_list: | ||
710 | m_proc_list[proc.cmd] = CumlSample (proc) | ||
711 | continue | ||
712 | s = m_proc_list[proc.cmd] | ||
713 | s.merge_samples (proc) | ||
714 | |||
715 | # all the sample times | ||
716 | times = sorted(time_hash) | ||
717 | if len (times) < 2: | ||
718 | print("degenerate boot chart") | ||
719 | return | ||
720 | |||
721 | pix_per_ns = chart_bounds[3] / total_time | ||
722 | # print "total time: %g pix-per-ns %g" % (total_time, pix_per_ns) | ||
723 | |||
724 | # FIXME: we have duplicates in the process list too [!] - why !? | ||
725 | |||
726 | # Render bottom up, left to right | ||
727 | below = {} | ||
728 | for time in times: | ||
729 | below[time] = chart_bounds[1] + chart_bounds[3] | ||
730 | |||
731 | # same colors each time we render | ||
732 | random.seed (0) | ||
733 | |||
734 | ctx.set_line_width(1) | ||
735 | |||
736 | legends = [] | ||
737 | labels = [] | ||
738 | |||
739 | # render each pid in order | ||
740 | for cs in m_proc_list.values(): | ||
741 | row = {} | ||
742 | cuml = 0.0 | ||
743 | |||
744 | # print "pid : %s -> %g samples %d" % (proc.cmd, cuml, len (cs.samples)) | ||
745 | for sample in cs.samples: | ||
746 | cuml += getattr(sample.cpu_sample, sample_value) | ||
747 | row[sample.time] = cuml | ||
748 | |||
749 | process_total_time = cuml | ||
750 | |||
751 | # hide really tiny processes | ||
752 | if cuml * pix_per_ns <= 2: | ||
753 | continue | ||
754 | |||
755 | last_time = times[0] | ||
756 | y = last_below = below[last_time] | ||
757 | last_cuml = cuml = 0.0 | ||
758 | |||
759 | ctx.set_source_rgba(*cs.get_color()) | ||
760 | for time in times: | ||
761 | render_seg = False | ||
762 | |||
763 | # did the underlying trend increase ? | ||
764 | if below[time] != last_below: | ||
765 | last_below = below[last_time] | ||
766 | last_cuml = cuml | ||
767 | render_seg = True | ||
768 | |||
769 | # did we move up a pixel increase ? | ||
770 | if time in row: | ||
771 | nc = round (row[time] * pix_per_ns) | ||
772 | if nc != cuml: | ||
773 | last_cuml = cuml | ||
774 | cuml = nc | ||
775 | render_seg = True | ||
776 | |||
777 | # if last_cuml > cuml: | ||
778 | # assert fail ... - un-sorted process samples | ||
779 | |||
780 | # draw the trailing rectangle from the last time to | ||
781 | # before now, at the height of the last segment. | ||
782 | if render_seg: | ||
783 | w = math.ceil ((time - last_time) * chart_bounds[2] / proc_tree.duration) + 1 | ||
784 | x = chart_bounds[0] + round((last_time - proc_tree.start_time) * chart_bounds[2] / proc_tree.duration) | ||
785 | ctx.rectangle (x, below[last_time] - last_cuml, w, last_cuml) | ||
786 | ctx.fill() | ||
787 | # ctx.stroke() | ||
788 | last_time = time | ||
789 | y = below [time] - cuml | ||
790 | |||
791 | row[time] = y | ||
792 | |||
793 | # render the last segment | ||
794 | x = chart_bounds[0] + round((last_time - proc_tree.start_time) * chart_bounds[2] / proc_tree.duration) | ||
795 | y = below[last_time] - cuml | ||
796 | ctx.rectangle (x, y, chart_bounds[2] - x, cuml) | ||
797 | ctx.fill() | ||
798 | # ctx.stroke() | ||
799 | |||
800 | # render legend if it will fit | ||
801 | if cuml > 8: | ||
802 | label = cs.cmd | ||
803 | extnts = ctx.text_extents(label) | ||
804 | label_w = extnts[2] | ||
805 | label_h = extnts[3] | ||
806 | # print "Text extents %g by %g" % (label_w, label_h) | ||
807 | labels.append((label, | ||
808 | chart_bounds[0] + chart_bounds[2] - label_w - off_x * 2, | ||
809 | y + (cuml + label_h) / 2)) | ||
810 | if cs in legends: | ||
811 | print("ARGH - duplicate process in list !") | ||
812 | |||
813 | legends.append ((cs, process_total_time)) | ||
814 | |||
815 | below = row | ||
816 | |||
817 | # render grid-lines over the top | ||
818 | draw_box_ticks(ctx, chart_bounds, sec_w) | ||
819 | |||
820 | # render labels | ||
821 | for l in labels: | ||
822 | draw_text(ctx, l[0], TEXT_COLOR, l[1], l[2]) | ||
823 | |||
824 | # Render legends | ||
825 | font_height = 20 | ||
826 | label_width = 300 | ||
827 | LEGENDS_PER_COL = 15 | ||
828 | LEGENDS_TOTAL = 45 | ||
829 | ctx.set_font_size (TITLE_FONT_SIZE) | ||
830 | dur_secs = duration / 100 | ||
831 | cpu_secs = total_time / 1000000000 | ||
832 | |||
833 | # misleading - with multiple CPUs ... | ||
834 | # idle = ((dur_secs - cpu_secs) / dur_secs) * 100.0 | ||
835 | if stat_type is STAT_TYPE_CPU: | ||
836 | label = "Cumulative CPU usage, by process; total CPU: " \ | ||
837 | " %.5g(s) time: %.3g(s)" % (cpu_secs, dur_secs) | ||
838 | else: | ||
839 | label = "Cumulative I/O usage, by process; total I/O: " \ | ||
840 | " %.5g(s) time: %.3g(s)" % (cpu_secs, dur_secs) | ||
841 | |||
842 | draw_text(ctx, label, TEXT_COLOR, chart_bounds[0] + off_x, | ||
843 | chart_bounds[1] + font_height) | ||
844 | |||
845 | i = 0 | ||
846 | legends = sorted(legends, key=itemgetter(1), reverse=True) | ||
847 | ctx.set_font_size(TEXT_FONT_SIZE) | ||
848 | for t in legends: | ||
849 | cs = t[0] | ||
850 | time = t[1] | ||
851 | x = chart_bounds[0] + off_x + int (i/LEGENDS_PER_COL) * label_width | ||
852 | y = chart_bounds[1] + font_height * ((i % LEGENDS_PER_COL) + 2) | ||
853 | str = "%s - %.0f(ms) (%2.2f%%)" % (cs.cmd, time/1000000, (time/total_time) * 100.0) | ||
854 | draw_legend_box(ctx, str, cs.color, x, y, leg_s) | ||
855 | i = i + 1 | ||
856 | if i >= LEGENDS_TOTAL: | ||
857 | break | ||
diff --git a/scripts/pybootchartgui/pybootchartgui/gui.py b/scripts/pybootchartgui/pybootchartgui/gui.py index 310c3d1bcc..ddeb88cd9b 100644 --- a/scripts/pybootchartgui/pybootchartgui/gui.py +++ b/scripts/pybootchartgui/pybootchartgui/gui.py | |||
@@ -1,273 +1,347 @@ | |||
1 | # This file is part of pybootchartgui. | ||
2 | |||
3 | # pybootchartgui is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 3 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | |||
8 | # pybootchartgui is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | |||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
1 | import gobject | 16 | import gobject |
2 | import gtk | 17 | import gtk |
3 | import gtk.gdk | 18 | import gtk.gdk |
4 | import gtk.keysyms | 19 | import gtk.keysyms |
5 | 20 | from . import draw | |
6 | import draw | 21 | from .draw import RenderOptions |
7 | 22 | ||
8 | class PyBootchartWidget(gtk.DrawingArea): | 23 | class PyBootchartWidget(gtk.DrawingArea): |
9 | __gsignals__ = { | 24 | __gsignals__ = { |
10 | 'expose-event': 'override', | 25 | 'expose-event': 'override', |
11 | 'clicked' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gtk.gdk.Event)), | 26 | 'clicked' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_STRING, gtk.gdk.Event)), |
12 | 'position-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT, gobject.TYPE_INT)), | 27 | 'position-changed' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT, gobject.TYPE_INT)), |
13 | 'set-scroll-adjustments' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gtk.Adjustment, gtk.Adjustment)) | 28 | 'set-scroll-adjustments' : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gtk.Adjustment, gtk.Adjustment)) |
14 | } | 29 | } |
15 | 30 | ||
16 | def __init__(self, res): | 31 | def __init__(self, trace, options, xscale): |
17 | gtk.DrawingArea.__init__(self) | 32 | gtk.DrawingArea.__init__(self) |
18 | 33 | ||
19 | self.res = res | 34 | self.trace = trace |
20 | 35 | self.options = options | |
21 | self.set_flags(gtk.CAN_FOCUS) | 36 | |
22 | 37 | self.set_flags(gtk.CAN_FOCUS) | |
23 | self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK) | 38 | |
24 | self.connect("button-press-event", self.on_area_button_press) | 39 | self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK) |
25 | self.connect("button-release-event", self.on_area_button_release) | 40 | self.connect("button-press-event", self.on_area_button_press) |
26 | self.add_events(gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.BUTTON_RELEASE_MASK) | 41 | self.connect("button-release-event", self.on_area_button_release) |
27 | self.connect("motion-notify-event", self.on_area_motion_notify) | 42 | self.add_events(gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.BUTTON_RELEASE_MASK) |
28 | self.connect("scroll-event", self.on_area_scroll_event) | 43 | self.connect("motion-notify-event", self.on_area_motion_notify) |
29 | self.connect('key-press-event', self.on_key_press_event) | 44 | self.connect("scroll-event", self.on_area_scroll_event) |
30 | 45 | self.connect('key-press-event', self.on_key_press_event) | |
31 | self.connect('set-scroll-adjustments', self.on_set_scroll_adjustments) | 46 | |
32 | self.connect("size-allocate", self.on_allocation_size_changed) | 47 | self.connect('set-scroll-adjustments', self.on_set_scroll_adjustments) |
33 | self.connect("position-changed", self.on_position_changed) | 48 | self.connect("size-allocate", self.on_allocation_size_changed) |
34 | 49 | self.connect("position-changed", self.on_position_changed) | |
35 | self.zoom_ratio = 1.0 | 50 | |
36 | self.x, self.y = 0.0, 0.0 | 51 | self.zoom_ratio = 1.0 |
37 | 52 | self.xscale = xscale | |
38 | self.chart_width, self.chart_height = draw.extents(res) | 53 | self.x, self.y = 0.0, 0.0 |
39 | self.hadj = None | 54 | |
40 | self.vadj = None | 55 | self.chart_width, self.chart_height = draw.extents(self.options, self.xscale, self.trace) |
41 | 56 | self.hadj = None | |
42 | def do_expose_event(self, event): | 57 | self.vadj = None |
43 | cr = self.window.cairo_create() | 58 | self.hadj_changed_signal_id = None |
44 | 59 | self.vadj_changed_signal_id = None | |
45 | # set a clip region for the expose event | 60 | |
46 | cr.rectangle( | 61 | def do_expose_event(self, event): |
47 | event.area.x, event.area.y, | 62 | cr = self.window.cairo_create() |
48 | event.area.width, event.area.height | 63 | |
49 | ) | 64 | # set a clip region for the expose event |
50 | cr.clip() | 65 | cr.rectangle( |
51 | self.draw(cr, self.get_allocation()) | 66 | event.area.x, event.area.y, |
52 | return False | 67 | event.area.width, event.area.height |
53 | 68 | ) | |
54 | def draw(self, cr, rect): | 69 | cr.clip() |
55 | cr.set_source_rgba(1.0, 1.0, 1.0, 1.0) | 70 | self.draw(cr, self.get_allocation()) |
56 | cr.paint() | 71 | return False |
57 | cr.scale(self.zoom_ratio, self.zoom_ratio) | 72 | |
58 | cr.translate(-self.x, -self.y) | 73 | def draw(self, cr, rect): |
59 | draw.render(cr, self.res) | 74 | cr.set_source_rgba(1.0, 1.0, 1.0, 1.0) |
60 | 75 | cr.paint() | |
61 | def position_changed(self): | 76 | cr.scale(self.zoom_ratio, self.zoom_ratio) |
62 | self.emit("position-changed", self.x, self.y) | 77 | cr.translate(-self.x, -self.y) |
63 | 78 | draw.render(cr, self.options, self.xscale, self.trace) | |
64 | ZOOM_INCREMENT = 1.25 | 79 | |
65 | 80 | def position_changed(self): | |
66 | def zoom_image(self, zoom_ratio): | 81 | self.emit("position-changed", self.x, self.y) |
67 | self.zoom_ratio = zoom_ratio | 82 | |
68 | self._set_scroll_adjustments(self.hadj, self.vadj) | 83 | ZOOM_INCREMENT = 1.25 |
69 | self.queue_draw() | 84 | |
70 | 85 | def zoom_image (self, zoom_ratio): | |
71 | def zoom_to_rect(self, rect): | 86 | self.zoom_ratio = zoom_ratio |
72 | zoom_ratio = float(rect.width)/float(self.chart_width) | 87 | self._set_scroll_adjustments (self.hadj, self.vadj) |
73 | self.zoom_image(zoom_ratio) | 88 | self.queue_draw() |
74 | self.x = 0 | 89 | |
75 | self.position_changed() | 90 | def zoom_to_rect (self, rect): |
76 | 91 | zoom_ratio = float(rect.width)/float(self.chart_width) | |
77 | def on_zoom_in(self, action): | 92 | self.zoom_image(zoom_ratio) |
78 | self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT) | 93 | self.x = 0 |
79 | 94 | self.position_changed() | |
80 | def on_zoom_out(self, action): | 95 | |
81 | self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT) | 96 | def set_xscale(self, xscale): |
82 | 97 | old_mid_x = self.x + self.hadj.page_size / 2 | |
83 | def on_zoom_fit(self, action): | 98 | self.xscale = xscale |
84 | self.zoom_to_rect(self.get_allocation()) | 99 | self.chart_width, self.chart_height = draw.extents(self.options, self.xscale, self.trace) |
85 | 100 | new_x = old_mid_x | |
86 | def on_zoom_100(self, action): | 101 | self.zoom_image (self.zoom_ratio) |
87 | self.zoom_image(1.0) | 102 | |
88 | 103 | def on_expand(self, action): | |
89 | POS_INCREMENT = 100 | 104 | self.set_xscale (self.xscale * 1.5) |
90 | 105 | ||
91 | def on_key_press_event(self, widget, event): | 106 | def on_contract(self, action): |
92 | if event.keyval == gtk.keysyms.Left: | 107 | self.set_xscale (self.xscale / 1.5) |
93 | self.x -= self.POS_INCREMENT/self.zoom_ratio | 108 | |
94 | elif event.keyval == gtk.keysyms.Right: | 109 | def on_zoom_in(self, action): |
95 | self.x += self.POS_INCREMENT/self.zoom_ratio | 110 | self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT) |
96 | elif event.keyval == gtk.keysyms.Up: | 111 | |
97 | self.y -= self.POS_INCREMENT/self.zoom_ratio | 112 | def on_zoom_out(self, action): |
98 | elif event.keyval == gtk.keysyms.Down: | 113 | self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT) |
99 | self.y += self.POS_INCREMENT/self.zoom_ratio | 114 | |
100 | elif event.keyval == gtk.keysyms.Page_Up: | 115 | def on_zoom_fit(self, action): |
101 | self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT) | 116 | self.zoom_to_rect(self.get_allocation()) |
102 | elif event.keyval == gtk.keysyms.Page_Down: | 117 | |
103 | self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT) | 118 | def on_zoom_100(self, action): |
104 | else: | 119 | self.zoom_image(1.0) |
105 | return False | 120 | self.set_xscale(1.0) |
106 | self.queue_draw() | 121 | |
107 | self.position_changed() | 122 | def show_toggled(self, button): |
123 | self.options.app_options.show_all = button.get_property ('active') | ||
124 | self.queue_draw() | ||
125 | |||
126 | POS_INCREMENT = 100 | ||
127 | |||
128 | def on_key_press_event(self, widget, event): | ||
129 | if event.keyval == gtk.keysyms.Left: | ||
130 | self.x -= self.POS_INCREMENT/self.zoom_ratio | ||
131 | elif event.keyval == gtk.keysyms.Right: | ||
132 | self.x += self.POS_INCREMENT/self.zoom_ratio | ||
133 | elif event.keyval == gtk.keysyms.Up: | ||
134 | self.y -= self.POS_INCREMENT/self.zoom_ratio | ||
135 | elif event.keyval == gtk.keysyms.Down: | ||
136 | self.y += self.POS_INCREMENT/self.zoom_ratio | ||
137 | else: | ||
138 | return False | ||
139 | self.queue_draw() | ||
140 | self.position_changed() | ||
141 | return True | ||
142 | |||
143 | def on_area_button_press(self, area, event): | ||
144 | if event.button == 2 or event.button == 1: | ||
145 | area.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR)) | ||
146 | self.prevmousex = event.x | ||
147 | self.prevmousey = event.y | ||
148 | if event.type not in (gtk.gdk.BUTTON_PRESS, gtk.gdk.BUTTON_RELEASE): | ||
149 | return False | ||
150 | return False | ||
151 | |||
152 | def on_area_button_release(self, area, event): | ||
153 | if event.button == 2 or event.button == 1: | ||
154 | area.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.ARROW)) | ||
155 | self.prevmousex = None | ||
156 | self.prevmousey = None | ||
157 | return True | ||
158 | return False | ||
159 | |||
160 | def on_area_scroll_event(self, area, event): | ||
161 | if event.state & gtk.gdk.CONTROL_MASK: | ||
162 | if event.direction == gtk.gdk.SCROLL_UP: | ||
163 | self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT) | ||
108 | return True | 164 | return True |
109 | 165 | if event.direction == gtk.gdk.SCROLL_DOWN: | |
110 | def on_area_button_press(self, area, event): | 166 | self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT) |
111 | if event.button == 2 or event.button == 1: | ||
112 | area.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.FLEUR)) | ||
113 | self.prevmousex = event.x | ||
114 | self.prevmousey = event.y | ||
115 | if event.type not in (gtk.gdk.BUTTON_PRESS, gtk.gdk.BUTTON_RELEASE): | ||
116 | return False | ||
117 | return False | ||
118 | |||
119 | def on_area_button_release(self, area, event): | ||
120 | if event.button == 2 or event.button == 1: | ||
121 | area.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.ARROW)) | ||
122 | self.prevmousex = None | ||
123 | self.prevmousey = None | ||
124 | return True | ||
125 | return False | ||
126 | |||
127 | def on_area_scroll_event(self, area, event): | ||
128 | if event.direction == gtk.gdk.SCROLL_UP: | ||
129 | self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT) | ||
130 | return True | ||
131 | if event.direction == gtk.gdk.SCROLL_DOWN: | ||
132 | self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT) | ||
133 | return True | ||
134 | return False | ||
135 | |||
136 | def on_area_motion_notify(self, area, event): | ||
137 | state = event.state | ||
138 | if state & gtk.gdk.BUTTON2_MASK or state & gtk.gdk.BUTTON1_MASK: | ||
139 | x, y = int(event.x), int(event.y) | ||
140 | # pan the image | ||
141 | self.x += (self.prevmousex - x)/self.zoom_ratio | ||
142 | self.y += (self.prevmousey - y)/self.zoom_ratio | ||
143 | self.queue_draw() | ||
144 | self.prevmousex = x | ||
145 | self.prevmousey = y | ||
146 | self.position_changed() | ||
147 | return True | 167 | return True |
148 | 168 | return False | |
149 | def on_set_scroll_adjustments(self, area, hadj, vadj): | 169 | |
150 | self._set_scroll_adjustments(hadj, vadj) | 170 | def on_area_motion_notify(self, area, event): |
151 | 171 | state = event.state | |
152 | def on_allocation_size_changed(self, widget, allocation): | 172 | if state & gtk.gdk.BUTTON2_MASK or state & gtk.gdk.BUTTON1_MASK: |
153 | self.hadj.page_size = allocation.width | 173 | x, y = int(event.x), int(event.y) |
154 | self.hadj.page_increment = allocation.width * 0.9 | 174 | # pan the image |
155 | self.vadj.page_size = allocation.height | 175 | self.x += (self.prevmousex - x)/self.zoom_ratio |
156 | self.vadj.page_increment = allocation.height * 0.9 | 176 | self.y += (self.prevmousey - y)/self.zoom_ratio |
157 | 177 | self.queue_draw() | |
158 | def _set_scroll_adjustments(self, hadj, vadj): | 178 | self.prevmousex = x |
159 | if hadj == None: | 179 | self.prevmousey = y |
160 | hadj = gtk.Adjustment(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) | 180 | self.position_changed() |
161 | if vadj == None: | 181 | return True |
162 | vadj = gtk.Adjustment(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) | 182 | |
163 | 183 | def on_set_scroll_adjustments(self, area, hadj, vadj): | |
164 | if self.hadj != None and hadj != self.hadj: | 184 | self._set_scroll_adjustments (hadj, vadj) |
165 | self.hadj.disconnect(self.hadj_changed_signal_id) | 185 | |
166 | if self.vadj != None and vadj != self.vadj: | 186 | def on_allocation_size_changed(self, widget, allocation): |
167 | self.vadj.disconnect(self.vadj_changed_signal_id) | 187 | self.hadj.page_size = allocation.width |
168 | 188 | self.hadj.page_increment = allocation.width * 0.9 | |
169 | if hadj != None: | 189 | self.vadj.page_size = allocation.height |
170 | self.hadj = hadj | 190 | self.vadj.page_increment = allocation.height * 0.9 |
171 | self._set_adj_upper(self.hadj, self.zoom_ratio * self.chart_width) | 191 | |
172 | self.hadj_changed_signal_id = self.hadj.connect('value-changed', self.on_adjustments_changed) | 192 | def _set_adj_upper(self, adj, upper): |
173 | 193 | changed = False | |
174 | if vadj != None: | 194 | value_changed = False |
175 | self.vadj = vadj | 195 | |
176 | self._set_adj_upper(self.vadj, self.zoom_ratio * self.chart_height) | 196 | if adj.upper != upper: |
177 | self.vadj_changed_signal_id = self.vadj.connect('value-changed', self.on_adjustments_changed) | 197 | adj.upper = upper |
178 | 198 | changed = True | |
179 | def _set_adj_upper(self, adj, upper): | 199 | |
180 | changed = False | 200 | max_value = max(0.0, upper - adj.page_size) |
181 | value_changed = False | 201 | if adj.value > max_value: |
182 | 202 | adj.value = max_value | |
183 | if adj.upper != upper: | 203 | value_changed = True |
184 | adj.upper = upper | 204 | |
185 | changed = True | 205 | if changed: |
186 | 206 | adj.changed() | |
187 | max_value = max(0.0, upper - adj.page_size) | 207 | if value_changed: |
188 | if adj.value > max_value: | 208 | adj.value_changed() |
189 | adj.value = max_value | 209 | |
190 | value_changed = True | 210 | def _set_scroll_adjustments(self, hadj, vadj): |
191 | 211 | if hadj == None: | |
192 | if changed: | 212 | hadj = gtk.Adjustment(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) |
193 | adj.changed() | 213 | if vadj == None: |
194 | if value_changed: | 214 | vadj = gtk.Adjustment(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) |
195 | adj.value_changed() | 215 | |
196 | 216 | if self.hadj_changed_signal_id != None and \ | |
197 | def on_adjustments_changed(self, adj): | 217 | self.hadj != None and hadj != self.hadj: |
198 | self.x = self.hadj.value / self.zoom_ratio | 218 | self.hadj.disconnect (self.hadj_changed_signal_id) |
199 | self.y = self.vadj.value / self.zoom_ratio | 219 | if self.vadj_changed_signal_id != None and \ |
200 | self.queue_draw() | 220 | self.vadj != None and vadj != self.vadj: |
201 | 221 | self.vadj.disconnect (self.vadj_changed_signal_id) | |
202 | def on_position_changed(self, widget, x, y): | 222 | |
203 | self.hadj.value = x * self.zoom_ratio | 223 | if hadj != None: |
204 | self.vadj.value = y * self.zoom_ratio | 224 | self.hadj = hadj |
225 | self._set_adj_upper (self.hadj, self.zoom_ratio * self.chart_width) | ||
226 | self.hadj_changed_signal_id = self.hadj.connect('value-changed', self.on_adjustments_changed) | ||
227 | |||
228 | if vadj != None: | ||
229 | self.vadj = vadj | ||
230 | self._set_adj_upper (self.vadj, self.zoom_ratio * self.chart_height) | ||
231 | self.vadj_changed_signal_id = self.vadj.connect('value-changed', self.on_adjustments_changed) | ||
232 | |||
233 | def on_adjustments_changed(self, adj): | ||
234 | self.x = self.hadj.value / self.zoom_ratio | ||
235 | self.y = self.vadj.value / self.zoom_ratio | ||
236 | self.queue_draw() | ||
237 | |||
238 | def on_position_changed(self, widget, x, y): | ||
239 | self.hadj.value = x * self.zoom_ratio | ||
240 | self.vadj.value = y * self.zoom_ratio | ||
205 | 241 | ||
206 | PyBootchartWidget.set_set_scroll_adjustments_signal('set-scroll-adjustments') | 242 | PyBootchartWidget.set_set_scroll_adjustments_signal('set-scroll-adjustments') |
207 | 243 | ||
244 | class PyBootchartShell(gtk.VBox): | ||
245 | ui = ''' | ||
246 | <ui> | ||
247 | <toolbar name="ToolBar"> | ||
248 | <toolitem action="Expand"/> | ||
249 | <toolitem action="Contract"/> | ||
250 | <separator/> | ||
251 | <toolitem action="ZoomIn"/> | ||
252 | <toolitem action="ZoomOut"/> | ||
253 | <toolitem action="ZoomFit"/> | ||
254 | <toolitem action="Zoom100"/> | ||
255 | </toolbar> | ||
256 | </ui> | ||
257 | ''' | ||
258 | def __init__(self, window, trace, options, xscale): | ||
259 | gtk.VBox.__init__(self) | ||
260 | |||
261 | self.widget = PyBootchartWidget(trace, options, xscale) | ||
262 | |||
263 | # Create a UIManager instance | ||
264 | uimanager = self.uimanager = gtk.UIManager() | ||
265 | |||
266 | # Add the accelerator group to the toplevel window | ||
267 | accelgroup = uimanager.get_accel_group() | ||
268 | window.add_accel_group(accelgroup) | ||
269 | |||
270 | # Create an ActionGroup | ||
271 | actiongroup = gtk.ActionGroup('Actions') | ||
272 | self.actiongroup = actiongroup | ||
273 | |||
274 | # Create actions | ||
275 | actiongroup.add_actions(( | ||
276 | ('Expand', gtk.STOCK_ADD, None, None, None, self.widget.on_expand), | ||
277 | ('Contract', gtk.STOCK_REMOVE, None, None, None, self.widget.on_contract), | ||
278 | ('ZoomIn', gtk.STOCK_ZOOM_IN, None, None, None, self.widget.on_zoom_in), | ||
279 | ('ZoomOut', gtk.STOCK_ZOOM_OUT, None, None, None, self.widget.on_zoom_out), | ||
280 | ('ZoomFit', gtk.STOCK_ZOOM_FIT, 'Fit Width', None, None, self.widget.on_zoom_fit), | ||
281 | ('Zoom100', gtk.STOCK_ZOOM_100, None, None, None, self.widget.on_zoom_100), | ||
282 | )) | ||
283 | |||
284 | # Add the actiongroup to the uimanager | ||
285 | uimanager.insert_action_group(actiongroup, 0) | ||
286 | |||
287 | # Add a UI description | ||
288 | uimanager.add_ui_from_string(self.ui) | ||
289 | |||
290 | # Scrolled window | ||
291 | scrolled = gtk.ScrolledWindow() | ||
292 | scrolled.add(self.widget) | ||
293 | |||
294 | # toolbar / h-box | ||
295 | hbox = gtk.HBox(False, 8) | ||
296 | |||
297 | # Create a Toolbar | ||
298 | toolbar = uimanager.get_widget('/ToolBar') | ||
299 | hbox.pack_start(toolbar, True, True) | ||
300 | |||
301 | if not options.kernel_only: | ||
302 | # Misc. options | ||
303 | button = gtk.CheckButton("Show more") | ||
304 | button.connect ('toggled', self.widget.show_toggled) | ||
305 | hbox.pack_start (button, False, True) | ||
306 | |||
307 | self.pack_start(hbox, False) | ||
308 | self.pack_start(scrolled) | ||
309 | self.show_all() | ||
310 | |||
311 | def grab_focus(self, window): | ||
312 | window.set_focus(self.widget) | ||
313 | |||
314 | |||
208 | class PyBootchartWindow(gtk.Window): | 315 | class PyBootchartWindow(gtk.Window): |
209 | 316 | ||
210 | ui = ''' | 317 | def __init__(self, trace, app_options): |
211 | <ui> | 318 | gtk.Window.__init__(self) |
212 | <toolbar name="ToolBar"> | 319 | |
213 | <toolitem action="ZoomIn"/> | 320 | window = self |
214 | <toolitem action="ZoomOut"/> | 321 | window.set_title("Bootchart %s" % trace.filename) |
215 | <toolitem action="ZoomFit"/> | 322 | window.set_default_size(750, 550) |
216 | <toolitem action="Zoom100"/> | 323 | |
217 | </toolbar> | 324 | tab_page = gtk.Notebook() |
218 | </ui> | 325 | tab_page.show() |
219 | ''' | 326 | window.add(tab_page) |
220 | 327 | ||
221 | def __init__(self, res): | 328 | full_opts = RenderOptions(app_options) |
222 | gtk.Window.__init__(self) | 329 | full_tree = PyBootchartShell(window, trace, full_opts, 1.0) |
223 | 330 | tab_page.append_page (full_tree, gtk.Label("Full tree")) | |
224 | window = self | 331 | |
225 | window.set_title('Bootchart') | 332 | if trace.kernel is not None and len (trace.kernel) > 2: |
226 | window.set_default_size(512, 512) | 333 | kernel_opts = RenderOptions(app_options) |
227 | vbox = gtk.VBox() | 334 | kernel_opts.cumulative = False |
228 | window.add(vbox) | 335 | kernel_opts.charts = False |
229 | 336 | kernel_opts.kernel_only = True | |
230 | self.widget = PyBootchartWidget(res) | 337 | kernel_tree = PyBootchartShell(window, trace, kernel_opts, 5.0) |
231 | 338 | tab_page.append_page (kernel_tree, gtk.Label("Kernel boot")) | |
232 | # Create a UIManager instance | 339 | |
233 | uimanager = self.uimanager = gtk.UIManager() | 340 | full_tree.grab_focus(self) |
234 | 341 | self.show() | |
235 | # Add the accelerator group to the toplevel window | 342 | |
236 | accelgroup = uimanager.get_accel_group() | 343 | |
237 | window.add_accel_group(accelgroup) | 344 | def show(trace, options): |
238 | 345 | win = PyBootchartWindow(trace, options) | |
239 | # Create an ActionGroup | 346 | win.connect('destroy', gtk.main_quit) |
240 | actiongroup = gtk.ActionGroup('Actions') | 347 | gtk.main() |
241 | self.actiongroup = actiongroup | ||
242 | |||
243 | # Create actions | ||
244 | actiongroup.add_actions(( | ||
245 | ('ZoomIn', gtk.STOCK_ZOOM_IN, None, None, None, self.widget.on_zoom_in), | ||
246 | ('ZoomOut', gtk.STOCK_ZOOM_OUT, None, None, None, self.widget.on_zoom_out), | ||
247 | ('ZoomFit', gtk.STOCK_ZOOM_FIT, 'Fit Width', None, None, self.widget.on_zoom_fit), | ||
248 | ('Zoom100', gtk.STOCK_ZOOM_100, None, None, None, self.widget.on_zoom_100), | ||
249 | )) | ||
250 | |||
251 | # Add the actiongroup to the uimanager | ||
252 | uimanager.insert_action_group(actiongroup, 0) | ||
253 | |||
254 | # Add a UI description | ||
255 | uimanager.add_ui_from_string(self.ui) | ||
256 | |||
257 | # Scrolled window | ||
258 | scrolled = gtk.ScrolledWindow() | ||
259 | scrolled.add(self.widget) | ||
260 | |||
261 | # Create a Toolbar | ||
262 | toolbar = uimanager.get_widget('/ToolBar') | ||
263 | vbox.pack_start(toolbar, False) | ||
264 | vbox.pack_start(scrolled) | ||
265 | |||
266 | self.set_focus(self.widget) | ||
267 | |||
268 | self.show_all() | ||
269 | |||
270 | def show(res): | ||
271 | win = PyBootchartWindow(res) | ||
272 | win.connect('destroy', gtk.main_quit) | ||
273 | gtk.main() | ||
diff --git a/scripts/pybootchartgui/pybootchartgui/main.py b/scripts/pybootchartgui/pybootchartgui/main.py index e22636c23e..b45ae0a3d2 100644..120000 --- a/scripts/pybootchartgui/pybootchartgui/main.py +++ b/scripts/pybootchartgui/pybootchartgui/main.py | |||
@@ -1,78 +1 @@ | |||
1 | import sys | main.py.in \ No newline at end of file | |
2 | import os | ||
3 | import optparse | ||
4 | |||
5 | import parsing | ||
6 | import gui | ||
7 | import batch | ||
8 | |||
9 | def _mk_options_parser(): | ||
10 | """Make an options parser.""" | ||
11 | usage = "%prog [options] /path/to/tmp/buildstats/<recipe-machine>/<BUILDNAME>/" | ||
12 | version = "%prog v1.0.0" | ||
13 | parser = optparse.OptionParser(usage, version=version) | ||
14 | parser.add_option("-i", "--interactive", action="store_true", dest="interactive", default=False, | ||
15 | help="start in active mode") | ||
16 | parser.add_option("-f", "--format", dest="format", default="svg", choices=["svg", "pdf", "png"], | ||
17 | help="image format: svg, pdf, png, [default: %default]") | ||
18 | parser.add_option("-o", "--output", dest="output", metavar="PATH", default=None, | ||
19 | help="output path (file or directory) where charts are stored") | ||
20 | parser.add_option("-s", "--split", dest="num", type=int, default=1, | ||
21 | help="split the output chart into <NUM> charts, only works with \"-o PATH\"") | ||
22 | parser.add_option("-m", "--mintime", dest="mintime", type=int, default=8, | ||
23 | help="only tasks longer than this time will be displayed") | ||
24 | parser.add_option("-n", "--no-prune", action="store_false", dest="prune", default=True, | ||
25 | help="do not prune the process tree") | ||
26 | parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False, | ||
27 | help="suppress informational messages") | ||
28 | parser.add_option("--very-quiet", action="store_true", dest="veryquiet", default=False, | ||
29 | help="suppress all messages except errors") | ||
30 | parser.add_option("--verbose", action="store_true", dest="verbose", default=False, | ||
31 | help="print all messages") | ||
32 | return parser | ||
33 | |||
34 | def _get_filename(path): | ||
35 | """Construct a usable filename for outputs""" | ||
36 | dir = "." | ||
37 | file = "bootchart" | ||
38 | if os.path.isdir(path): | ||
39 | dir = path | ||
40 | elif path != None: | ||
41 | file = path | ||
42 | return os.path.join(dir, file) | ||
43 | |||
44 | def main(argv=None): | ||
45 | try: | ||
46 | if argv is None: | ||
47 | argv = sys.argv[1:] | ||
48 | |||
49 | parser = _mk_options_parser() | ||
50 | options, args = parser.parse_args(argv) | ||
51 | |||
52 | if len(args) == 0: | ||
53 | parser.error("insufficient arguments, expected at least one path.") | ||
54 | return 2 | ||
55 | |||
56 | res = parsing.parse(args, options.prune, options.mintime) | ||
57 | if options.interactive or options.output == None: | ||
58 | gui.show(res) | ||
59 | else: | ||
60 | filename = _get_filename(options.output) | ||
61 | res_list = parsing.split_res(res, options.num) | ||
62 | n = 1 | ||
63 | for r in res_list: | ||
64 | if len(res_list) == 1: | ||
65 | f = filename + "." + options.format | ||
66 | else: | ||
67 | f = filename + "_" + str(n) + "." + options.format | ||
68 | n = n + 1 | ||
69 | batch.render(r, options.format, f) | ||
70 | print "bootchart written to", f | ||
71 | return 0 | ||
72 | except parsing.ParseError, ex: | ||
73 | print("Parse error: %s" % ex) | ||
74 | return 2 | ||
75 | |||
76 | |||
77 | if __name__ == '__main__': | ||
78 | sys.exit(main()) | ||
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()) | ||
diff --git a/scripts/pybootchartgui/pybootchartgui/parsing.py b/scripts/pybootchartgui/pybootchartgui/parsing.py index 6343fd5a7b..c8a6a5721a 100644 --- a/scripts/pybootchartgui/pybootchartgui/parsing.py +++ b/scripts/pybootchartgui/pybootchartgui/parsing.py | |||
@@ -1,178 +1,638 @@ | |||
1 | # This file is part of pybootchartgui. | ||
2 | |||
3 | # pybootchartgui is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 3 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | |||
8 | # pybootchartgui is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | |||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | |||
1 | from __future__ import with_statement | 17 | from __future__ import with_statement |
2 | 18 | ||
3 | import os | 19 | import os |
4 | import string | 20 | import string |
5 | import re | 21 | import re |
22 | import sys | ||
6 | import tarfile | 23 | import tarfile |
24 | from time import clock | ||
7 | from collections import defaultdict | 25 | from collections import defaultdict |
26 | from functools import reduce | ||
27 | |||
28 | from .samples import * | ||
29 | from .process_tree import ProcessTree | ||
30 | |||
31 | if sys.version_info >= (3, 0): | ||
32 | long = int | ||
33 | |||
34 | # Parsing produces as its end result a 'Trace' | ||
35 | |||
36 | class Trace: | ||
37 | def __init__(self, writer, paths, options): | ||
38 | self.processes = {} | ||
39 | self.start = {} | ||
40 | self.end = {} | ||
41 | self.headers = None | ||
42 | self.disk_stats = None | ||
43 | self.ps_stats = None | ||
44 | self.taskstats = None | ||
45 | self.cpu_stats = None | ||
46 | self.cmdline = None | ||
47 | self.kernel = None | ||
48 | self.kernel_tree = None | ||
49 | self.filename = None | ||
50 | self.parent_map = None | ||
51 | self.mem_stats = None | ||
52 | |||
53 | parse_paths (writer, self, paths, options.mintime) | ||
54 | if not self.valid(): | ||
55 | raise ParseError("empty state: '%s' does not contain a valid bootchart" % ", ".join(paths)) | ||
56 | |||
57 | return | ||
58 | |||
59 | # Turn that parsed information into something more useful | ||
60 | # link processes into a tree of pointers, calculate statistics | ||
61 | self.compile(writer) | ||
62 | |||
63 | # Crop the chart to the end of the first idle period after the given | ||
64 | # process | ||
65 | if options.crop_after: | ||
66 | idle = self.crop (writer, options.crop_after) | ||
67 | else: | ||
68 | idle = None | ||
69 | |||
70 | # Annotate other times as the first start point of given process lists | ||
71 | self.times = [ idle ] | ||
72 | if options.annotate: | ||
73 | for procnames in options.annotate: | ||
74 | names = [x[:15] for x in procnames.split(",")] | ||
75 | for proc in self.ps_stats.process_map.values(): | ||
76 | if proc.cmd in names: | ||
77 | self.times.append(proc.start_time) | ||
78 | break | ||
79 | else: | ||
80 | self.times.append(None) | ||
81 | |||
82 | self.proc_tree = ProcessTree(writer, self.kernel, self.ps_stats, | ||
83 | self.ps_stats.sample_period, | ||
84 | self.headers.get("profile.process"), | ||
85 | options.prune, idle, self.taskstats, | ||
86 | self.parent_map is not None) | ||
87 | |||
88 | if self.kernel is not None: | ||
89 | self.kernel_tree = ProcessTree(writer, self.kernel, None, 0, | ||
90 | self.headers.get("profile.process"), | ||
91 | False, None, None, True) | ||
92 | |||
93 | def valid(self): | ||
94 | return len(self.processes) != 0 | ||
95 | return self.headers != None and self.disk_stats != None and \ | ||
96 | self.ps_stats != None and self.cpu_stats != None | ||
97 | |||
98 | |||
99 | def compile(self, writer): | ||
100 | |||
101 | def find_parent_id_for(pid): | ||
102 | if pid is 0: | ||
103 | return 0 | ||
104 | ppid = self.parent_map.get(pid) | ||
105 | if ppid: | ||
106 | # many of these double forks are so short lived | ||
107 | # that we have no samples, or process info for them | ||
108 | # so climb the parent hierarcy to find one | ||
109 | if int (ppid * 1000) not in self.ps_stats.process_map: | ||
110 | # print "Pid '%d' short lived with no process" % ppid | ||
111 | ppid = find_parent_id_for (ppid) | ||
112 | # else: | ||
113 | # print "Pid '%d' has an entry" % ppid | ||
114 | else: | ||
115 | # print "Pid '%d' missing from pid map" % pid | ||
116 | return 0 | ||
117 | return ppid | ||
118 | |||
119 | # merge in the cmdline data | ||
120 | if self.cmdline is not None: | ||
121 | for proc in self.ps_stats.process_map.values(): | ||
122 | rpid = int (proc.pid // 1000) | ||
123 | if rpid in self.cmdline: | ||
124 | cmd = self.cmdline[rpid] | ||
125 | proc.exe = cmd['exe'] | ||
126 | proc.args = cmd['args'] | ||
127 | # else: | ||
128 | # print "proc %d '%s' not in cmdline" % (rpid, proc.exe) | ||
129 | |||
130 | # re-parent any stray orphans if we can | ||
131 | if self.parent_map is not None: | ||
132 | for process in self.ps_stats.process_map.values(): | ||
133 | ppid = find_parent_id_for (int(process.pid // 1000)) | ||
134 | if ppid: | ||
135 | process.ppid = ppid * 1000 | ||
136 | |||
137 | # stitch the tree together with pointers | ||
138 | for process in self.ps_stats.process_map.values(): | ||
139 | process.set_parent (self.ps_stats.process_map) | ||
140 | |||
141 | # count on fingers variously | ||
142 | for process in self.ps_stats.process_map.values(): | ||
143 | process.calc_stats (self.ps_stats.sample_period) | ||
144 | |||
145 | def crop(self, writer, crop_after): | ||
146 | |||
147 | def is_idle_at(util, start, j): | ||
148 | k = j + 1 | ||
149 | while k < len(util) and util[k][0] < start + 300: | ||
150 | k += 1 | ||
151 | k = min(k, len(util)-1) | ||
152 | |||
153 | if util[j][1] >= 0.25: | ||
154 | return False | ||
155 | |||
156 | avgload = sum(u[1] for u in util[j:k+1]) / (k-j+1) | ||
157 | if avgload < 0.25: | ||
158 | return True | ||
159 | else: | ||
160 | return False | ||
161 | def is_idle(util, start): | ||
162 | for j in range(0, len(util)): | ||
163 | if util[j][0] < start: | ||
164 | continue | ||
165 | return is_idle_at(util, start, j) | ||
166 | else: | ||
167 | return False | ||
168 | |||
169 | names = [x[:15] for x in crop_after.split(",")] | ||
170 | for proc in self.ps_stats.process_map.values(): | ||
171 | if proc.cmd in names or proc.exe in names: | ||
172 | writer.info("selected proc '%s' from list (start %d)" | ||
173 | % (proc.cmd, proc.start_time)) | ||
174 | break | ||
175 | if proc is None: | ||
176 | writer.warn("no selected crop proc '%s' in list" % crop_after) | ||
177 | |||
178 | |||
179 | cpu_util = [(sample.time, sample.user + sample.sys + sample.io) for sample in self.cpu_stats] | ||
180 | disk_util = [(sample.time, sample.util) for sample in self.disk_stats] | ||
181 | |||
182 | idle = None | ||
183 | for i in range(0, len(cpu_util)): | ||
184 | if cpu_util[i][0] < proc.start_time: | ||
185 | continue | ||
186 | if is_idle_at(cpu_util, cpu_util[i][0], i) \ | ||
187 | and is_idle(disk_util, cpu_util[i][0]): | ||
188 | idle = cpu_util[i][0] | ||
189 | break | ||
190 | |||
191 | if idle is None: | ||
192 | writer.warn ("not idle after proc '%s'" % crop_after) | ||
193 | return None | ||
194 | |||
195 | crop_at = idle + 300 | ||
196 | writer.info ("cropping at time %d" % crop_at) | ||
197 | while len (self.cpu_stats) \ | ||
198 | and self.cpu_stats[-1].time > crop_at: | ||
199 | self.cpu_stats.pop() | ||
200 | while len (self.disk_stats) \ | ||
201 | and self.disk_stats[-1].time > crop_at: | ||
202 | self.disk_stats.pop() | ||
203 | |||
204 | self.ps_stats.end_time = crop_at | ||
205 | |||
206 | cropped_map = {} | ||
207 | for key, value in self.ps_stats.process_map.items(): | ||
208 | if (value.start_time <= crop_at): | ||
209 | cropped_map[key] = value | ||
210 | |||
211 | for proc in cropped_map.values(): | ||
212 | proc.duration = min (proc.duration, crop_at - proc.start_time) | ||
213 | while len (proc.samples) \ | ||
214 | and proc.samples[-1].time > crop_at: | ||
215 | proc.samples.pop() | ||
216 | |||
217 | self.ps_stats.process_map = cropped_map | ||
218 | |||
219 | return idle | ||
220 | |||
8 | 221 | ||
9 | from samples import * | ||
10 | from process_tree import ProcessTree | ||
11 | 222 | ||
12 | class ParseError(Exception): | 223 | class ParseError(Exception): |
13 | """Represents errors during parse of the bootchart.""" | 224 | """Represents errors during parse of the bootchart.""" |
14 | def __init__(self, value): | 225 | def __init__(self, value): |
15 | self.value = value | 226 | self.value = value |
16 | 227 | ||
17 | def __str__(self): | 228 | def __str__(self): |
18 | return self.value | 229 | return self.value |
19 | 230 | ||
20 | def _parse_headers(file): | 231 | def _parse_headers(file): |
21 | """Parses the headers of the bootchart.""" | 232 | """Parses the headers of the bootchart.""" |
22 | def parse((headers,last), line): | 233 | def parse(acc, line): |
23 | if '=' in line: last,value = map(string.strip, line.split('=', 1)) | 234 | (headers, last) = acc |
24 | else: value = line.strip() | 235 | if '=' in line: |
25 | headers[last] += value | 236 | last, value = map (lambda x: x.strip(), line.split('=', 1)) |
26 | return headers,last | 237 | else: |
27 | return reduce(parse, file.read().split('\n'), (defaultdict(str),''))[0] | 238 | value = line.strip() |
239 | headers[last] += value | ||
240 | return headers, last | ||
241 | return reduce(parse, file.read().decode('utf-8').split('\n'), (defaultdict(str),''))[0] | ||
28 | 242 | ||
29 | def _parse_timed_blocks(file): | 243 | def _parse_timed_blocks(file): |
30 | """Parses (ie., splits) a file into so-called timed-blocks. A | 244 | """Parses (ie., splits) a file into so-called timed-blocks. A |
31 | timed-block consists of a timestamp on a line by itself followed | 245 | timed-block consists of a timestamp on a line by itself followed |
32 | by zero or more lines of data for that point in time.""" | 246 | by zero or more lines of data for that point in time.""" |
33 | def parse(block): | 247 | def parse(block): |
34 | lines = block.split('\n') | 248 | lines = block.split('\n') |
35 | if not lines: | 249 | if not lines: |
36 | raise ParseError('expected a timed-block consisting a timestamp followed by data lines') | 250 | raise ParseError('expected a timed-block consisting a timestamp followed by data lines') |
37 | try: | 251 | try: |
38 | return (int(lines[0]), lines[1:]) | 252 | return (int(lines[0]), lines[1:]) |
39 | except ValueError: | 253 | except ValueError: |
40 | raise ParseError("expected a timed-block, but timestamp '%s' is not an integer" % lines[0]) | 254 | raise ParseError("expected a timed-block, but timestamp '%s' is not an integer" % lines[0]) |
41 | blocks = file.read().split('\n\n') | 255 | blocks = file.read().decode('utf-8').split('\n\n') |
42 | return [parse(block) for block in blocks if block.strip()] | 256 | return [parse(block) for block in blocks if block.strip() and not block.endswith(' not running\n')] |
43 | 257 | ||
44 | def _parse_proc_ps_log(file): | 258 | def _parse_proc_ps_log(writer, file): |
45 | """ | 259 | """ |
46 | * See proc(5) for details. | 260 | * See proc(5) for details. |
47 | * | 261 | * |
48 | * {pid, comm, state, ppid, pgrp, session, tty_nr, tpgid, flags, minflt, cminflt, majflt, cmajflt, utime, stime, | 262 | * {pid, comm, state, ppid, pgrp, session, tty_nr, tpgid, flags, minflt, cminflt, majflt, cmajflt, utime, stime, |
49 | * cutime, cstime, priority, nice, 0, itrealvalue, starttime, vsize, rss, rlim, startcode, endcode, startstack, | 263 | * cutime, cstime, priority, nice, 0, itrealvalue, starttime, vsize, rss, rlim, startcode, endcode, startstack, |
50 | * kstkesp, kstkeip} | 264 | * kstkesp, kstkeip} |
51 | """ | 265 | """ |
52 | processMap = {} | 266 | processMap = {} |
53 | ltime = 0 | 267 | ltime = 0 |
54 | timed_blocks = _parse_timed_blocks(file) | 268 | timed_blocks = _parse_timed_blocks(file) |
55 | for time, lines in timed_blocks: | 269 | for time, lines in timed_blocks: |
56 | for line in lines: | 270 | for line in lines: |
57 | tokens = line.split(' ') | 271 | if not line: continue |
58 | 272 | tokens = line.split(' ') | |
59 | offset = [index for index, token in enumerate(tokens[1:]) if token.endswith(')')][0] | 273 | if len(tokens) < 21: |
60 | pid, cmd, state, ppid = int(tokens[0]), ' '.join(tokens[1:2+offset]), tokens[2+offset], int(tokens[3+offset]) | 274 | continue |
61 | userCpu, sysCpu, stime= int(tokens[13+offset]), int(tokens[14+offset]), int(tokens[21+offset]) | 275 | |
62 | 276 | offset = [index for index, token in enumerate(tokens[1:]) if token[-1] == ')'][0] | |
63 | if processMap.has_key(pid): | 277 | pid, cmd, state, ppid = int(tokens[0]), ' '.join(tokens[1:2+offset]), tokens[2+offset], int(tokens[3+offset]) |
64 | process = processMap[pid] | 278 | userCpu, sysCpu, stime = int(tokens[13+offset]), int(tokens[14+offset]), int(tokens[21+offset]) |
65 | process.cmd = cmd.replace('(', '').replace(')', '') # why rename after latest name?? | 279 | |
66 | else: | 280 | # magic fixed point-ness ... |
67 | process = Process(pid, cmd, ppid, min(time, stime)) | 281 | pid *= 1000 |
68 | processMap[pid] = process | 282 | ppid *= 1000 |
69 | 283 | if pid in processMap: | |
70 | if process.last_user_cpu_time is not None and process.last_sys_cpu_time is not None and ltime is not None: | 284 | process = processMap[pid] |
71 | userCpuLoad, sysCpuLoad = process.calc_load(userCpu, sysCpu, time - ltime) | 285 | process.cmd = cmd.strip('()') # why rename after latest name?? |
72 | cpuSample = CPUSample('null', userCpuLoad, sysCpuLoad, 0.0) | 286 | else: |
73 | process.samples.append(ProcessSample(time, state, cpuSample)) | 287 | process = Process(writer, pid, cmd.strip('()'), ppid, min(time, stime)) |
74 | 288 | processMap[pid] = process | |
75 | process.last_user_cpu_time = userCpu | 289 | |
76 | process.last_sys_cpu_time = sysCpu | 290 | if process.last_user_cpu_time is not None and process.last_sys_cpu_time is not None and ltime is not None: |
77 | ltime = time | 291 | userCpuLoad, sysCpuLoad = process.calc_load(userCpu, sysCpu, max(1, time - ltime)) |
78 | 292 | cpuSample = CPUSample('null', userCpuLoad, sysCpuLoad, 0.0) | |
79 | startTime = timed_blocks[0][0] | 293 | process.samples.append(ProcessSample(time, state, cpuSample)) |
80 | avgSampleLength = (ltime - startTime)/(len(timed_blocks)-1) | 294 | |
81 | 295 | process.last_user_cpu_time = userCpu | |
82 | for process in processMap.values(): | 296 | process.last_sys_cpu_time = sysCpu |
83 | process.set_parent(processMap) | 297 | ltime = time |
84 | 298 | ||
85 | for process in processMap.values(): | 299 | if len (timed_blocks) < 2: |
86 | process.calc_stats(avgSampleLength) | 300 | return None |
87 | 301 | ||
88 | return ProcessStats(processMap.values(), avgSampleLength, startTime, ltime) | 302 | startTime = timed_blocks[0][0] |
89 | 303 | avgSampleLength = (ltime - startTime)/(len (timed_blocks) - 1) | |
304 | |||
305 | return ProcessStats (writer, processMap, len (timed_blocks), avgSampleLength, startTime, ltime) | ||
306 | |||
307 | def _parse_taskstats_log(writer, file): | ||
308 | """ | ||
309 | * See bootchart-collector.c for details. | ||
310 | * | ||
311 | * { pid, ppid, comm, cpu_run_real_total, blkio_delay_total, swapin_delay_total } | ||
312 | * | ||
313 | """ | ||
314 | processMap = {} | ||
315 | pidRewrites = {} | ||
316 | ltime = None | ||
317 | timed_blocks = _parse_timed_blocks(file) | ||
318 | for time, lines in timed_blocks: | ||
319 | # we have no 'stime' from taskstats, so prep 'init' | ||
320 | if ltime is None: | ||
321 | process = Process(writer, 1, '[init]', 0, 0) | ||
322 | processMap[1000] = process | ||
323 | ltime = time | ||
324 | # continue | ||
325 | for line in lines: | ||
326 | if not line: continue | ||
327 | tokens = line.split(' ') | ||
328 | if len(tokens) != 6: | ||
329 | continue | ||
330 | |||
331 | opid, ppid, cmd = int(tokens[0]), int(tokens[1]), tokens[2] | ||
332 | cpu_ns, blkio_delay_ns, swapin_delay_ns = long(tokens[-3]), long(tokens[-2]), long(tokens[-1]), | ||
333 | |||
334 | # make space for trees of pids | ||
335 | opid *= 1000 | ||
336 | ppid *= 1000 | ||
337 | |||
338 | # when the process name changes, we re-write the pid. | ||
339 | if opid in pidRewrites: | ||
340 | pid = pidRewrites[opid] | ||
341 | else: | ||
342 | pid = opid | ||
343 | |||
344 | cmd = cmd.strip('(').strip(')') | ||
345 | if pid in processMap: | ||
346 | process = processMap[pid] | ||
347 | if process.cmd != cmd: | ||
348 | pid += 1 | ||
349 | pidRewrites[opid] = pid | ||
350 | # print "process mutation ! '%s' vs '%s' pid %s -> pid %s\n" % (process.cmd, cmd, opid, pid) | ||
351 | process = process.split (writer, pid, cmd, ppid, time) | ||
352 | processMap[pid] = process | ||
353 | else: | ||
354 | process.cmd = cmd; | ||
355 | else: | ||
356 | process = Process(writer, pid, cmd, ppid, time) | ||
357 | processMap[pid] = process | ||
358 | |||
359 | delta_cpu_ns = (float) (cpu_ns - process.last_cpu_ns) | ||
360 | delta_blkio_delay_ns = (float) (blkio_delay_ns - process.last_blkio_delay_ns) | ||
361 | delta_swapin_delay_ns = (float) (swapin_delay_ns - process.last_swapin_delay_ns) | ||
362 | |||
363 | # make up some state data ... | ||
364 | if delta_cpu_ns > 0: | ||
365 | state = "R" | ||
366 | elif delta_blkio_delay_ns + delta_swapin_delay_ns > 0: | ||
367 | state = "D" | ||
368 | else: | ||
369 | state = "S" | ||
370 | |||
371 | # retain the ns timing information into a CPUSample - that tries | ||
372 | # with the old-style to be a %age of CPU used in this time-slice. | ||
373 | if delta_cpu_ns + delta_blkio_delay_ns + delta_swapin_delay_ns > 0: | ||
374 | # print "proc %s cpu_ns %g delta_cpu %g" % (cmd, cpu_ns, delta_cpu_ns) | ||
375 | cpuSample = CPUSample('null', delta_cpu_ns, 0.0, | ||
376 | delta_blkio_delay_ns, | ||
377 | delta_swapin_delay_ns) | ||
378 | process.samples.append(ProcessSample(time, state, cpuSample)) | ||
379 | |||
380 | process.last_cpu_ns = cpu_ns | ||
381 | process.last_blkio_delay_ns = blkio_delay_ns | ||
382 | process.last_swapin_delay_ns = swapin_delay_ns | ||
383 | ltime = time | ||
384 | |||
385 | if len (timed_blocks) < 2: | ||
386 | return None | ||
387 | |||
388 | startTime = timed_blocks[0][0] | ||
389 | avgSampleLength = (ltime - startTime)/(len(timed_blocks)-1) | ||
390 | |||
391 | return ProcessStats (writer, processMap, len (timed_blocks), avgSampleLength, startTime, ltime) | ||
392 | |||
90 | def _parse_proc_stat_log(file): | 393 | def _parse_proc_stat_log(file): |
91 | samples = [] | 394 | samples = [] |
92 | ltimes = None | 395 | ltimes = None |
93 | for time, lines in _parse_timed_blocks(file): | 396 | for time, lines in _parse_timed_blocks(file): |
94 | # CPU times {user, nice, system, idle, io_wait, irq, softirq} | 397 | # skip emtpy lines |
95 | tokens = lines[0].split(); | 398 | if not lines: |
96 | times = [ int(token) for token in tokens[1:] ] | 399 | continue |
97 | if ltimes: | 400 | # CPU times {user, nice, system, idle, io_wait, irq, softirq} |
98 | user = float((times[0] + times[1]) - (ltimes[0] + ltimes[1])) | 401 | tokens = lines[0].split() |
99 | system = float((times[2] + times[5] + times[6]) - (ltimes[2] + ltimes[5] + ltimes[6])) | 402 | times = [ int(token) for token in tokens[1:] ] |
100 | idle = float(times[3] - ltimes[3]) | 403 | if ltimes: |
101 | iowait = float(times[4] - ltimes[4]) | 404 | user = float((times[0] + times[1]) - (ltimes[0] + ltimes[1])) |
102 | 405 | system = float((times[2] + times[5] + times[6]) - (ltimes[2] + ltimes[5] + ltimes[6])) | |
103 | aSum = max(user + system + idle + iowait, 1) | 406 | idle = float(times[3] - ltimes[3]) |
104 | samples.append( CPUSample(time, user/aSum, system/aSum, iowait/aSum) ) | 407 | iowait = float(times[4] - ltimes[4]) |
105 | 408 | ||
106 | ltimes = times | 409 | aSum = max(user + system + idle + iowait, 1) |
107 | # skip the rest of statistics lines | 410 | samples.append( CPUSample(time, user/aSum, system/aSum, iowait/aSum) ) |
108 | return samples | 411 | |
109 | 412 | ltimes = times | |
110 | 413 | # skip the rest of statistics lines | |
414 | return samples | ||
415 | |||
111 | def _parse_proc_disk_stat_log(file, numCpu): | 416 | def _parse_proc_disk_stat_log(file, numCpu): |
112 | """ | 417 | """ |
113 | Parse file for disk stats, but only look at the whole disks, eg. sda, | 418 | Parse file for disk stats, but only look at the whole device, eg. sda, |
114 | not sda1, sda2 etc. The format of relevant lines should be: | 419 | not sda1, sda2 etc. The format of relevant lines should be: |
115 | {major minor name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq} | 420 | {major minor name rio rmerge rsect ruse wio wmerge wsect wuse running use aveq} |
116 | """ | 421 | """ |
117 | DISK_REGEX = 'hd.$|sd.$' | 422 | disk_regex_re = re.compile ('^([hsv]d.|mtdblock\d|mmcblk\d|cciss/c\d+d\d+.*)$') |
118 | 423 | ||
119 | def is_relevant_line(line): | 424 | # this gets called an awful lot. |
120 | return len(line.split()) == 14 and re.match(DISK_REGEX, line.split()[2]) | 425 | def is_relevant_line(linetokens): |
121 | 426 | if len(linetokens) != 14: | |
122 | disk_stat_samples = [] | 427 | return False |
123 | 428 | disk = linetokens[2] | |
124 | for time, lines in _parse_timed_blocks(file): | 429 | return disk_regex_re.match(disk) |
125 | sample = DiskStatSample(time) | 430 | |
126 | relevant_tokens = [line.split() for line in lines if is_relevant_line(line)] | 431 | disk_stat_samples = [] |
127 | 432 | ||
128 | for tokens in relevant_tokens: | 433 | for time, lines in _parse_timed_blocks(file): |
129 | disk, rsect, wsect, use = tokens[2], int(tokens[5]), int(tokens[9]), int(tokens[12]) | 434 | sample = DiskStatSample(time) |
130 | sample.add_diskdata([rsect, wsect, use]) | 435 | relevant_tokens = [linetokens for linetokens in map (lambda x: x.split(),lines) if is_relevant_line(linetokens)] |
131 | 436 | ||
132 | disk_stat_samples.append(sample) | 437 | for tokens in relevant_tokens: |
133 | 438 | disk, rsect, wsect, use = tokens[2], int(tokens[5]), int(tokens[9]), int(tokens[12]) | |
134 | disk_stats = [] | 439 | sample.add_diskdata([rsect, wsect, use]) |
135 | for sample1, sample2 in zip(disk_stat_samples[:-1], disk_stat_samples[1:]): | 440 | |
136 | interval = sample1.time - sample2.time | 441 | disk_stat_samples.append(sample) |
137 | sums = [ a - b for a, b in zip(sample1.diskdata, sample2.diskdata) ] | 442 | |
138 | readTput = sums[0] / 2.0 * 100.0 / interval | 443 | disk_stats = [] |
139 | writeTput = sums[1] / 2.0 * 100.0 / interval | 444 | for sample1, sample2 in zip(disk_stat_samples[:-1], disk_stat_samples[1:]): |
140 | util = float( sums[2] ) / 10 / interval / numCpu | 445 | interval = sample1.time - sample2.time |
141 | util = max(0.0, min(1.0, util)) | 446 | if interval == 0: |
142 | disk_stats.append(DiskSample(sample2.time, readTput, writeTput, util)) | 447 | interval = 1 |
143 | 448 | sums = [ a - b for a, b in zip(sample1.diskdata, sample2.diskdata) ] | |
144 | return disk_stats | 449 | readTput = sums[0] / 2.0 * 100.0 / interval |
145 | 450 | writeTput = sums[1] / 2.0 * 100.0 / interval | |
146 | 451 | util = float( sums[2] ) / 10 / interval / numCpu | |
452 | util = max(0.0, min(1.0, util)) | ||
453 | disk_stats.append(DiskSample(sample2.time, readTput, writeTput, util)) | ||
454 | |||
455 | return disk_stats | ||
456 | |||
457 | def _parse_proc_meminfo_log(file): | ||
458 | """ | ||
459 | Parse file for global memory statistics. | ||
460 | The format of relevant lines should be: ^key: value( unit)? | ||
461 | """ | ||
462 | used_values = ('MemTotal', 'MemFree', 'Buffers', 'Cached', 'SwapTotal', 'SwapFree',) | ||
463 | |||
464 | mem_stats = [] | ||
465 | meminfo_re = re.compile(r'([^ \t:]+):\s*(\d+).*') | ||
466 | |||
467 | for time, lines in _parse_timed_blocks(file): | ||
468 | sample = MemSample(time) | ||
469 | |||
470 | for line in lines: | ||
471 | match = meminfo_re.match(line) | ||
472 | if not match: | ||
473 | raise ParseError("Invalid meminfo line \"%s\"" % match.groups(0)) | ||
474 | sample.add_value(match.group(1), int(match.group(2))) | ||
475 | |||
476 | if sample.valid(): | ||
477 | mem_stats.append(sample) | ||
478 | |||
479 | return mem_stats | ||
480 | |||
481 | # if we boot the kernel with: initcall_debug printk.time=1 we can | ||
482 | # get all manner of interesting data from the dmesg output | ||
483 | # We turn this into a pseudo-process tree: each event is | ||
484 | # characterised by a | ||
485 | # we don't try to detect a "kernel finished" state - since the kernel | ||
486 | # continues to do interesting things after init is called. | ||
487 | # | ||
488 | # sample input: | ||
489 | # [ 0.000000] ACPI: FACP 3f4fc000 000F4 (v04 INTEL Napa 00000001 MSFT 01000013) | ||
490 | # ... | ||
491 | # [ 0.039993] calling migration_init+0x0/0x6b @ 1 | ||
492 | # [ 0.039993] initcall migration_init+0x0/0x6b returned 1 after 0 usecs | ||
493 | def _parse_dmesg(writer, file): | ||
494 | timestamp_re = re.compile ("^\[\s*(\d+\.\d+)\s*]\s+(.*)$") | ||
495 | split_re = re.compile ("^(\S+)\s+([\S\+_-]+) (.*)$") | ||
496 | processMap = {} | ||
497 | idx = 0 | ||
498 | inc = 1.0 / 1000000 | ||
499 | kernel = Process(writer, idx, "k-boot", 0, 0.1) | ||
500 | processMap['k-boot'] = kernel | ||
501 | base_ts = False | ||
502 | max_ts = 0 | ||
503 | for line in file.read().decode('utf-8').split('\n'): | ||
504 | t = timestamp_re.match (line) | ||
505 | if t is None: | ||
506 | # print "duff timestamp " + line | ||
507 | continue | ||
508 | |||
509 | time_ms = float (t.group(1)) * 1000 | ||
510 | # looks like we may have a huge diff after the clock | ||
511 | # has been set up. This could lead to huge graph: | ||
512 | # so huge we will be killed by the OOM. | ||
513 | # So instead of using the plain timestamp we will | ||
514 | # use a delta to first one and skip the first one | ||
515 | # for convenience | ||
516 | if max_ts == 0 and not base_ts and time_ms > 1000: | ||
517 | base_ts = time_ms | ||
518 | continue | ||
519 | max_ts = max(time_ms, max_ts) | ||
520 | if base_ts: | ||
521 | # print "fscked clock: used %f instead of %f" % (time_ms - base_ts, time_ms) | ||
522 | time_ms -= base_ts | ||
523 | m = split_re.match (t.group(2)) | ||
524 | |||
525 | if m is None: | ||
526 | continue | ||
527 | # print "match: '%s'" % (m.group(1)) | ||
528 | type = m.group(1) | ||
529 | func = m.group(2) | ||
530 | rest = m.group(3) | ||
531 | |||
532 | if t.group(2).startswith ('Write protecting the') or \ | ||
533 | t.group(2).startswith ('Freeing unused kernel memory'): | ||
534 | kernel.duration = time_ms / 10 | ||
535 | continue | ||
536 | |||
537 | # print "foo: '%s' '%s' '%s'" % (type, func, rest) | ||
538 | if type == "calling": | ||
539 | ppid = kernel.pid | ||
540 | p = re.match ("\@ (\d+)", rest) | ||
541 | if p is not None: | ||
542 | ppid = float (p.group(1)) // 1000 | ||
543 | # print "match: '%s' ('%g') at '%s'" % (func, ppid, time_ms) | ||
544 | name = func.split ('+', 1) [0] | ||
545 | idx += inc | ||
546 | processMap[func] = Process(writer, ppid + idx, name, ppid, time_ms / 10) | ||
547 | elif type == "initcall": | ||
548 | # print "finished: '%s' at '%s'" % (func, time_ms) | ||
549 | if func in processMap: | ||
550 | process = processMap[func] | ||
551 | process.duration = (time_ms / 10) - process.start_time | ||
552 | else: | ||
553 | print("corrupted init call for %s" % (func)) | ||
554 | |||
555 | elif type == "async_waiting" or type == "async_continuing": | ||
556 | continue # ignore | ||
557 | |||
558 | return processMap.values() | ||
559 | |||
560 | # | ||
561 | # Parse binary pacct accounting file output if we have one | ||
562 | # cf. /usr/include/linux/acct.h | ||
563 | # | ||
564 | def _parse_pacct(writer, file): | ||
565 | # read LE int32 | ||
566 | def _read_le_int32(file): | ||
567 | byts = file.read(4) | ||
568 | return (ord(byts[0])) | (ord(byts[1]) << 8) | \ | ||
569 | (ord(byts[2]) << 16) | (ord(byts[3]) << 24) | ||
570 | |||
571 | parent_map = {} | ||
572 | parent_map[0] = 0 | ||
573 | while file.read(1) != "": # ignore flags | ||
574 | ver = file.read(1) | ||
575 | if ord(ver) < 3: | ||
576 | print("Invalid version 0x%x" % (ord(ver))) | ||
577 | return None | ||
578 | |||
579 | file.seek (14, 1) # user, group etc. | ||
580 | pid = _read_le_int32 (file) | ||
581 | ppid = _read_le_int32 (file) | ||
582 | # print "Parent of %d is %d" % (pid, ppid) | ||
583 | parent_map[pid] = ppid | ||
584 | file.seek (4 + 4 + 16, 1) # timings | ||
585 | file.seek (16, 1) # acct_comm | ||
586 | return parent_map | ||
587 | |||
588 | def _parse_paternity_log(writer, file): | ||
589 | parent_map = {} | ||
590 | parent_map[0] = 0 | ||
591 | for line in file.read().decode('utf-8').split('\n'): | ||
592 | if not line: | ||
593 | continue | ||
594 | elems = line.split(' ') # <Child> <Parent> | ||
595 | if len (elems) >= 2: | ||
596 | # print "paternity of %d is %d" % (int(elems[0]), int(elems[1])) | ||
597 | parent_map[int(elems[0])] = int(elems[1]) | ||
598 | else: | ||
599 | print("Odd paternity line '%s'" % (line)) | ||
600 | return parent_map | ||
601 | |||
602 | def _parse_cmdline_log(writer, file): | ||
603 | cmdLines = {} | ||
604 | for block in file.read().decode('utf-8').split('\n\n'): | ||
605 | lines = block.split('\n') | ||
606 | if len (lines) >= 3: | ||
607 | # print "Lines '%s'" % (lines[0]) | ||
608 | pid = int (lines[0]) | ||
609 | values = {} | ||
610 | values['exe'] = lines[1].lstrip(':') | ||
611 | args = lines[2].lstrip(':').split('\0') | ||
612 | args.pop() | ||
613 | values['args'] = args | ||
614 | cmdLines[pid] = values | ||
615 | return cmdLines | ||
616 | |||
147 | def get_num_cpus(headers): | 617 | def get_num_cpus(headers): |
148 | """Get the number of CPUs from the system.cpu header property. As the | 618 | """Get the number of CPUs from the system.cpu header property. As the |
149 | CPU utilization graphs are relative, the number of CPUs currently makes | 619 | CPU utilization graphs are relative, the number of CPUs currently makes |
150 | no difference.""" | 620 | no difference.""" |
151 | if headers is None: | 621 | if headers is None: |
152 | return 1 | 622 | return 1 |
623 | if headers.get("system.cpu.num"): | ||
624 | return max (int (headers.get("system.cpu.num")), 1) | ||
153 | cpu_model = headers.get("system.cpu") | 625 | cpu_model = headers.get("system.cpu") |
154 | if cpu_model is None: | 626 | if cpu_model is None: |
155 | return 1 | 627 | return 1 |
156 | mat = re.match(".*\\((\\d+)\\)", cpu_model) | 628 | mat = re.match(".*\\((\\d+)\\)", cpu_model) |
157 | if mat is None: | 629 | if mat is None: |
158 | return 1 | 630 | return 1 |
159 | return int(mat.group(1)) | 631 | return max (int(mat.group(1)), 1) |
160 | |||
161 | class ParserState: | ||
162 | def __init__(self): | ||
163 | self.processes = {} | ||
164 | self.start = {} | ||
165 | self.end = {} | ||
166 | 632 | ||
167 | def valid(self): | 633 | def _do_parse(writer, state, filename, file, mintime): |
168 | return len(self.processes) != 0 | 634 | writer.info("parsing '%s'" % filename) |
169 | 635 | t1 = clock() | |
170 | |||
171 | _relevant_files = set(["header", "proc_diskstats.log", "proc_ps.log", "proc_stat.log"]) | ||
172 | |||
173 | def _do_parse(state, filename, file, mintime): | ||
174 | #print filename | ||
175 | #writer.status("parsing '%s'" % filename) | ||
176 | paths = filename.split("/") | 636 | paths = filename.split("/") |
177 | task = paths[-1] | 637 | task = paths[-1] |
178 | pn = paths[-2] | 638 | pn = paths[-2] |
@@ -194,44 +654,49 @@ def _do_parse(state, filename, file, mintime): | |||
194 | state.end[end] = [] | 654 | state.end[end] = [] |
195 | if k not in state.end[end]: | 655 | if k not in state.end[end]: |
196 | state.end[end].append(pn + ":" + task) | 656 | state.end[end].append(pn + ":" + task) |
657 | t2 = clock() | ||
658 | writer.info(" %s seconds" % str(t2-t1)) | ||
197 | return state | 659 | return state |
198 | 660 | ||
199 | def parse_file(state, filename, mintime): | 661 | def parse_file(writer, state, filename, mintime): |
662 | if state.filename is None: | ||
663 | state.filename = filename | ||
200 | basename = os.path.basename(filename) | 664 | basename = os.path.basename(filename) |
201 | with open(filename, "rb") as file: | 665 | with open(filename, "rb") as file: |
202 | return _do_parse(state, filename, file, mintime) | 666 | return _do_parse(writer, state, filename, file, mintime) |
203 | 667 | ||
204 | def parse_paths(state, paths, mintime): | 668 | def parse_paths(writer, state, paths, mintime): |
205 | for path in paths: | 669 | for path in paths: |
206 | root,extension = os.path.splitext(path) | 670 | if state.filename is None: |
671 | state.filename = path | ||
672 | root, extension = os.path.splitext(path) | ||
207 | if not(os.path.exists(path)): | 673 | if not(os.path.exists(path)): |
208 | print "warning: path '%s' does not exist, ignoring." % path | 674 | writer.warn("warning: path '%s' does not exist, ignoring." % path) |
209 | continue | 675 | continue |
676 | #state.filename = path | ||
210 | if os.path.isdir(path): | 677 | if os.path.isdir(path): |
211 | files = [ f for f in [os.path.join(path, f) for f in os.listdir(path)] ] | 678 | files = [ f for f in [os.path.join(path, f) for f in os.listdir(path)] ] |
212 | files.sort() | 679 | files.sort() |
213 | state = parse_paths(state, files, mintime) | 680 | state = parse_paths(writer, state, files, mintime) |
214 | elif extension in [".tar", ".tgz", ".tar.gz"]: | 681 | elif extension in [".tar", ".tgz", ".gz"]: |
682 | if extension == ".gz": | ||
683 | root, extension = os.path.splitext(root) | ||
684 | if extension != ".tar": | ||
685 | writer.warn("warning: can only handle zipped tar files, not zipped '%s'-files; ignoring" % extension) | ||
686 | continue | ||
215 | tf = None | 687 | tf = None |
216 | try: | 688 | try: |
689 | writer.status("parsing '%s'" % path) | ||
217 | tf = tarfile.open(path, 'r:*') | 690 | tf = tarfile.open(path, 'r:*') |
218 | for name in tf.getnames(): | 691 | for name in tf.getnames(): |
219 | state = _do_parse(state, name, tf.extractfile(name)) | 692 | state = _do_parse(writer, state, name, tf.extractfile(name)) |
220 | except tarfile.ReadError, error: | 693 | except tarfile.ReadError as error: |
221 | raise ParseError("error: could not read tarfile '%s': %s." % (path, error)) | 694 | raise ParseError("error: could not read tarfile '%s': %s." % (path, error)) |
222 | finally: | 695 | finally: |
223 | if tf != None: | 696 | if tf != None: |
224 | tf.close() | 697 | tf.close() |
225 | else: | 698 | else: |
226 | state = parse_file(state, path, mintime) | 699 | state = parse_file(writer, state, path, mintime) |
227 | return state | ||
228 | |||
229 | def parse(paths, prune, mintime): | ||
230 | state = parse_paths(ParserState(), paths, mintime) | ||
231 | if not state.valid(): | ||
232 | raise ParseError("empty state: '%s' does not contain a valid bootchart" % ", ".join(paths)) | ||
233 | #monitored_app = state.headers.get("profile.process") | ||
234 | #proc_tree = ProcessTree(state.ps_stats, monitored_app, prune) | ||
235 | return state | 700 | return state |
236 | 701 | ||
237 | def split_res(res, n): | 702 | def split_res(res, n): |
diff --git a/scripts/pybootchartgui/pybootchartgui/process_tree.py b/scripts/pybootchartgui/pybootchartgui/process_tree.py index bde29ebda8..cf88110b1c 100644 --- a/scripts/pybootchartgui/pybootchartgui/process_tree.py +++ b/scripts/pybootchartgui/pybootchartgui/process_tree.py | |||
@@ -1,3 +1,18 @@ | |||
1 | # This file is part of pybootchartgui. | ||
2 | |||
3 | # pybootchartgui is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 3 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | |||
8 | # pybootchartgui is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | |||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
1 | class ProcessTree: | 16 | class ProcessTree: |
2 | """ProcessTree encapsulates a process tree. The tree is built from log files | 17 | """ProcessTree encapsulates a process tree. The tree is built from log files |
3 | retrieved during the boot process. When building the process tree, it is | 18 | retrieved during the boot process. When building the process tree, it is |
@@ -19,55 +34,61 @@ class ProcessTree: | |||
19 | are merged together. | 34 | are merged together. |
20 | 35 | ||
21 | """ | 36 | """ |
22 | LOGGER_PROC = 'bootchartd' | 37 | LOGGER_PROC = 'bootchart-colle' |
23 | EXPLODER_PROCESSES = set(['hwup']) | 38 | EXPLODER_PROCESSES = set(['hwup']) |
24 | 39 | ||
25 | def __init__(self, psstats, monitoredApp, prune, for_testing = False): | 40 | def __init__(self, writer, kernel, psstats, sample_period, |
41 | monitoredApp, prune, idle, taskstats, | ||
42 | accurate_parentage, for_testing = False): | ||
43 | self.writer = writer | ||
26 | self.process_tree = [] | 44 | self.process_tree = [] |
27 | self.psstats = psstats | 45 | self.taskstats = taskstats |
28 | self.process_list = sorted(psstats.process_list, key = lambda p: p.pid) | 46 | if psstats is None: |
29 | self.sample_period = psstats.sample_period | 47 | process_list = kernel |
30 | 48 | elif kernel is None: | |
31 | self.build() | 49 | process_list = psstats.process_map.values() |
32 | self.update_ppids_for_daemons(self.process_list) | 50 | else: |
51 | process_list = list(kernel) + list(psstats.process_map.values()) | ||
52 | self.process_list = sorted(process_list, key = lambda p: p.pid) | ||
53 | self.sample_period = sample_period | ||
54 | |||
55 | self.build() | ||
56 | if not accurate_parentage: | ||
57 | self.update_ppids_for_daemons(self.process_list) | ||
33 | 58 | ||
34 | self.start_time = self.get_start_time(self.process_tree) | 59 | self.start_time = self.get_start_time(self.process_tree) |
35 | self.end_time = self.get_end_time(self.process_tree) | 60 | self.end_time = self.get_end_time(self.process_tree) |
36 | self.duration = self.end_time - self.start_time | 61 | self.duration = self.end_time - self.start_time |
62 | self.idle = idle | ||
37 | 63 | ||
38 | if for_testing: | 64 | if for_testing: |
39 | return | 65 | return |
40 | 66 | ||
41 | # print 'proc_tree before prune: num_proc=%i, duration=%i' % (self.num_nodes(self.process_list), self.duration) | 67 | removed = self.merge_logger(self.process_tree, self.LOGGER_PROC, monitoredApp, False) |
42 | 68 | writer.status("merged %i logger processes" % removed) | |
43 | removed = self.merge_logger(self.process_tree, self.LOGGER_PROC, monitoredApp, False) | ||
44 | print "Merged %i logger processes" % removed | ||
45 | 69 | ||
46 | if prune: | 70 | if prune: |
47 | removed = self.prune(self.process_tree, None) | 71 | p_processes = self.prune(self.process_tree, None) |
48 | print "Pruned %i processes" % removed | 72 | p_exploders = self.merge_exploders(self.process_tree, self.EXPLODER_PROCESSES) |
49 | removed = self.merge_exploders(self.process_tree, self.EXPLODER_PROCESSES) | 73 | p_threads = self.merge_siblings(self.process_tree) |
50 | print "Pruned %i exploders" % removed | 74 | p_runs = self.merge_runs(self.process_tree) |
51 | removed = self.merge_siblings(self.process_tree) | 75 | writer.status("pruned %i process, %i exploders, %i threads, and %i runs" % (p_processes, p_exploders, p_threads, p_runs)) |
52 | print "Pruned %i threads" % removed | ||
53 | removed = self.merge_runs(self.process_tree) | ||
54 | print "Pruned %i runs" % removed | ||
55 | 76 | ||
56 | self.sort(self.process_tree) | 77 | self.sort(self.process_tree) |
57 | 78 | ||
58 | self.start_time = self.get_start_time(self.process_tree) | 79 | self.start_time = self.get_start_time(self.process_tree) |
59 | self.end_time = self.get_end_time(self.process_tree) | 80 | self.end_time = self.get_end_time(self.process_tree) |
60 | self.duration = self.end_time - self.start_time | 81 | self.duration = self.end_time - self.start_time |
61 | 82 | ||
62 | self.num_proc = self.num_nodes(self.process_tree) | 83 | self.num_proc = self.num_nodes(self.process_tree) |
63 | 84 | ||
64 | def build(self): | 85 | def build(self): |
65 | """Build the process tree from the list of top samples.""" | 86 | """Build the process tree from the list of top samples.""" |
66 | self.process_tree = [] | 87 | self.process_tree = [] |
67 | for proc in self.process_list: | 88 | for proc in self.process_list: |
68 | if not proc.parent: | 89 | if not proc.parent: |
69 | self.process_tree.append(proc) | 90 | self.process_tree.append(proc) |
70 | else: | 91 | else: |
71 | proc.parent.child_list.append(proc) | 92 | proc.parent.child_list.append(proc) |
72 | 93 | ||
73 | def sort(self, process_subtree): | 94 | def sort(self, process_subtree): |
@@ -85,11 +106,11 @@ class ProcessTree: | |||
85 | 106 | ||
86 | def get_start_time(self, process_subtree): | 107 | def get_start_time(self, process_subtree): |
87 | """Returns the start time of the process subtree. This is the start | 108 | """Returns the start time of the process subtree. This is the start |
88 | time of the earliest process. | 109 | time of the earliest process. |
89 | 110 | ||
90 | """ | 111 | """ |
91 | if not process_subtree: | 112 | if not process_subtree: |
92 | return 100000000; | 113 | return 100000000 |
93 | return min( [min(proc.start_time, self.get_start_time(proc.child_list)) for proc in process_subtree] ) | 114 | return min( [min(proc.start_time, self.get_start_time(proc.child_list)) for proc in process_subtree] ) |
94 | 115 | ||
95 | def get_end_time(self, process_subtree): | 116 | def get_end_time(self, process_subtree): |
@@ -98,13 +119,13 @@ class ProcessTree: | |||
98 | 119 | ||
99 | """ | 120 | """ |
100 | if not process_subtree: | 121 | if not process_subtree: |
101 | return -100000000; | 122 | return -100000000 |
102 | return max( [max(proc.start_time + proc.duration, self.get_end_time(proc.child_list)) for proc in process_subtree] ) | 123 | return max( [max(proc.start_time + proc.duration, self.get_end_time(proc.child_list)) for proc in process_subtree] ) |
103 | 124 | ||
104 | def get_max_pid(self, process_subtree): | 125 | def get_max_pid(self, process_subtree): |
105 | """Returns the max PID found in the process tree.""" | 126 | """Returns the max PID found in the process tree.""" |
106 | if not process_subtree: | 127 | if not process_subtree: |
107 | return -100000000; | 128 | return -100000000 |
108 | return max( [max(proc.pid, self.get_max_pid(proc.child_list)) for proc in process_subtree] ) | 129 | return max( [max(proc.pid, self.get_max_pid(proc.child_list)) for proc in process_subtree] ) |
109 | 130 | ||
110 | def update_ppids_for_daemons(self, process_list): | 131 | def update_ppids_for_daemons(self, process_list): |
@@ -118,29 +139,29 @@ class ProcessTree: | |||
118 | rcendpid = -1 | 139 | rcendpid = -1 |
119 | rcproc = None | 140 | rcproc = None |
120 | for p in process_list: | 141 | for p in process_list: |
121 | if p.cmd == "rc" and p.ppid == 1: | 142 | if p.cmd == "rc" and p.ppid // 1000 == 1: |
122 | rcproc = p | 143 | rcproc = p |
123 | rcstartpid = p.pid | 144 | rcstartpid = p.pid |
124 | rcendpid = self.get_max_pid(p.child_list) | 145 | rcendpid = self.get_max_pid(p.child_list) |
125 | if rcstartpid != -1 and rcendpid != -1: | 146 | if rcstartpid != -1 and rcendpid != -1: |
126 | for p in process_list: | 147 | for p in process_list: |
127 | if p.pid > rcstartpid and p.pid < rcendpid and p.ppid == 1: | 148 | if p.pid > rcstartpid and p.pid < rcendpid and p.ppid // 1000 == 1: |
128 | p.ppid = rcstartpid | 149 | p.ppid = rcstartpid |
129 | p.parent = rcproc | 150 | p.parent = rcproc |
130 | for p in process_list: | 151 | for p in process_list: |
131 | p.child_list = [] | 152 | p.child_list = [] |
132 | self.build() | 153 | self.build() |
133 | 154 | ||
134 | def prune(self, process_subtree, parent): | 155 | def prune(self, process_subtree, parent): |
135 | """Prunes the process tree by removing idle processes and processes | 156 | """Prunes the process tree by removing idle processes and processes |
136 | that only live for the duration of a single top sample. Sibling | 157 | that only live for the duration of a single top sample. Sibling |
137 | processes with the same command line (i.e. threads) are merged | 158 | processes with the same command line (i.e. threads) are merged |
138 | together. This filters out sleepy background processes, short-lived | 159 | together. This filters out sleepy background processes, short-lived |
139 | processes and bootcharts' analysis tools. | 160 | processes and bootcharts' analysis tools. |
140 | """ | 161 | """ |
141 | def is_idle_background_process_without_children(p): | 162 | def is_idle_background_process_without_children(p): |
142 | process_end = p.start_time + p.duration | 163 | process_end = p.start_time + p.duration |
143 | return not p.active and \ | 164 | return not p.active and \ |
144 | process_end >= self.start_time + self.duration and \ | 165 | process_end >= self.start_time + self.duration and \ |
145 | p.start_time > self.start_time and \ | 166 | p.start_time > self.start_time and \ |
146 | p.duration > 0.9 * self.duration and \ | 167 | p.duration > 0.9 * self.duration and \ |
@@ -175,8 +196,8 @@ class ProcessTree: | |||
175 | 196 | ||
176 | def merge_logger(self, process_subtree, logger_proc, monitored_app, app_tree): | 197 | def merge_logger(self, process_subtree, logger_proc, monitored_app, app_tree): |
177 | """Merges the logger's process subtree. The logger will typically | 198 | """Merges the logger's process subtree. The logger will typically |
178 | spawn lots of sleep and cat processes, thus polluting the | 199 | spawn lots of sleep and cat processes, thus polluting the |
179 | process tree. | 200 | process tree. |
180 | 201 | ||
181 | """ | 202 | """ |
182 | num_removed = 0 | 203 | num_removed = 0 |
@@ -185,7 +206,7 @@ class ProcessTree: | |||
185 | if logger_proc == p.cmd and not app_tree: | 206 | if logger_proc == p.cmd and not app_tree: |
186 | is_app_tree = True | 207 | is_app_tree = True |
187 | num_removed += self.merge_logger(p.child_list, logger_proc, monitored_app, is_app_tree) | 208 | num_removed += self.merge_logger(p.child_list, logger_proc, monitored_app, is_app_tree) |
188 | # don't remove the logger itself | 209 | # don't remove the logger itself |
189 | continue | 210 | continue |
190 | 211 | ||
191 | if app_tree and monitored_app != None and monitored_app == p.cmd: | 212 | if app_tree and monitored_app != None and monitored_app == p.cmd: |
@@ -193,7 +214,7 @@ class ProcessTree: | |||
193 | 214 | ||
194 | if is_app_tree: | 215 | if is_app_tree: |
195 | for child in p.child_list: | 216 | for child in p.child_list: |
196 | self.__merge_processes(p, child) | 217 | self.merge_processes(p, child) |
197 | num_removed += 1 | 218 | num_removed += 1 |
198 | p.child_list = [] | 219 | p.child_list = [] |
199 | else: | 220 | else: |
@@ -202,7 +223,7 @@ class ProcessTree: | |||
202 | 223 | ||
203 | def merge_exploders(self, process_subtree, processes): | 224 | def merge_exploders(self, process_subtree, processes): |
204 | """Merges specific process subtrees (used for processes which usually | 225 | """Merges specific process subtrees (used for processes which usually |
205 | spawn huge meaningless process trees). | 226 | spawn huge meaningless process trees). |
206 | 227 | ||
207 | """ | 228 | """ |
208 | num_removed = 0 | 229 | num_removed = 0 |
@@ -210,7 +231,7 @@ class ProcessTree: | |||
210 | if processes in processes and len(p.child_list) > 0: | 231 | if processes in processes and len(p.child_list) > 0: |
211 | subtreemap = self.getProcessMap(p.child_list) | 232 | subtreemap = self.getProcessMap(p.child_list) |
212 | for child in subtreemap.values(): | 233 | for child in subtreemap.values(): |
213 | self.__merge_processes(p, child) | 234 | self.merge_processes(p, child) |
214 | num_removed += len(subtreemap) | 235 | num_removed += len(subtreemap) |
215 | p.child_list = [] | 236 | p.child_list = [] |
216 | p.cmd += " (+)" | 237 | p.cmd += " (+)" |
@@ -218,10 +239,10 @@ class ProcessTree: | |||
218 | num_removed += self.merge_exploders(p.child_list, processes) | 239 | num_removed += self.merge_exploders(p.child_list, processes) |
219 | return num_removed | 240 | return num_removed |
220 | 241 | ||
221 | def merge_siblings(self,process_subtree): | 242 | def merge_siblings(self, process_subtree): |
222 | """Merges thread processes. Sibling processes with the same command | 243 | """Merges thread processes. Sibling processes with the same command |
223 | line are merged together. | 244 | line are merged together. |
224 | 245 | ||
225 | """ | 246 | """ |
226 | num_removed = 0 | 247 | num_removed = 0 |
227 | idx = 0 | 248 | idx = 0 |
@@ -233,7 +254,7 @@ class ProcessTree: | |||
233 | idx -= 1 | 254 | idx -= 1 |
234 | num_removed += 1 | 255 | num_removed += 1 |
235 | p.child_list.extend(nextp.child_list) | 256 | p.child_list.extend(nextp.child_list) |
236 | self.__merge_processes(p, nextp) | 257 | self.merge_processes(p, nextp) |
237 | num_removed += self.merge_siblings(p.child_list) | 258 | num_removed += self.merge_siblings(p.child_list) |
238 | idx += 1 | 259 | idx += 1 |
239 | if len(process_subtree) > 0: | 260 | if len(process_subtree) > 0: |
@@ -243,7 +264,7 @@ class ProcessTree: | |||
243 | 264 | ||
244 | def merge_runs(self, process_subtree): | 265 | def merge_runs(self, process_subtree): |
245 | """Merges process runs. Single child processes which share the same | 266 | """Merges process runs. Single child processes which share the same |
246 | command line with the parent are merged. | 267 | command line with the parent are merged. |
247 | 268 | ||
248 | """ | 269 | """ |
249 | num_removed = 0 | 270 | num_removed = 0 |
@@ -253,16 +274,17 @@ class ProcessTree: | |||
253 | if len(p.child_list) == 1 and p.child_list[0].cmd == p.cmd: | 274 | if len(p.child_list) == 1 and p.child_list[0].cmd == p.cmd: |
254 | child = p.child_list[0] | 275 | child = p.child_list[0] |
255 | p.child_list = list(child.child_list) | 276 | p.child_list = list(child.child_list) |
256 | self.__merge_processes(p, child) | 277 | self.merge_processes(p, child) |
257 | num_removed += 1 | 278 | num_removed += 1 |
258 | continue | 279 | continue |
259 | num_removed += self.merge_runs(p.child_list) | 280 | num_removed += self.merge_runs(p.child_list) |
260 | idx += 1 | 281 | idx += 1 |
261 | return num_removed | 282 | return num_removed |
262 | 283 | ||
263 | def __merge_processes(self, p1, p2): | 284 | def merge_processes(self, p1, p2): |
264 | """Merges two process samples.""" | 285 | """Merges two process' samples.""" |
265 | p1.samples.extend(p2.samples) | 286 | p1.samples.extend(p2.samples) |
287 | p1.samples.sort( key = lambda p: p.time ) | ||
266 | p1time = p1.start_time | 288 | p1time = p1.start_time |
267 | p2time = p2.start_time | 289 | p2time = p2.start_time |
268 | p1.start_time = min(p1time, p2time) | 290 | p1.start_time = min(p1time, p2time) |
diff --git a/scripts/pybootchartgui/pybootchartgui/samples.py b/scripts/pybootchartgui/pybootchartgui/samples.py index c94b30d032..015d743aa0 100644 --- a/scripts/pybootchartgui/pybootchartgui/samples.py +++ b/scripts/pybootchartgui/pybootchartgui/samples.py | |||
@@ -1,93 +1,151 @@ | |||
1 | # This file is part of pybootchartgui. | ||
2 | |||
3 | # pybootchartgui is free software: you can redistribute it and/or modify | ||
4 | # it under the terms of the GNU General Public License as published by | ||
5 | # the Free Software Foundation, either version 3 of the License, or | ||
6 | # (at your option) any later version. | ||
7 | |||
8 | # pybootchartgui is distributed in the hope that it will be useful, | ||
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | # GNU General Public License for more details. | ||
12 | |||
13 | # You should have received a copy of the GNU General Public License | ||
14 | # along with pybootchartgui. If not, see <http://www.gnu.org/licenses/>. | ||
15 | |||
16 | |||
1 | class DiskStatSample: | 17 | class DiskStatSample: |
2 | def __init__(self, time): | 18 | def __init__(self, time): |
3 | self.time = time | 19 | self.time = time |
4 | self.diskdata = [0, 0, 0] | 20 | self.diskdata = [0, 0, 0] |
5 | def add_diskdata(self, new_diskdata): | 21 | def add_diskdata(self, new_diskdata): |
6 | self.diskdata = [ a + b for a, b in zip(self.diskdata, new_diskdata) ] | 22 | self.diskdata = [ a + b for a, b in zip(self.diskdata, new_diskdata) ] |
7 | 23 | ||
8 | class CPUSample: | 24 | class CPUSample: |
9 | def __init__(self, time, user, sys, io): | 25 | def __init__(self, time, user, sys, io = 0.0, swap = 0.0): |
10 | self.time = time | 26 | self.time = time |
11 | self.user = user | 27 | self.user = user |
12 | self.sys = sys | 28 | self.sys = sys |
13 | self.io = io | 29 | self.io = io |
14 | 30 | self.swap = swap | |
15 | def __str__(self): | 31 | |
16 | return str(self.time) + "\t" + str(self.user) + "\t" + str(self.sys) + "\t" + str(self.io); | 32 | @property |
17 | 33 | def cpu(self): | |
34 | return self.user + self.sys | ||
35 | |||
36 | def __str__(self): | ||
37 | return str(self.time) + "\t" + str(self.user) + "\t" + \ | ||
38 | str(self.sys) + "\t" + str(self.io) + "\t" + str (self.swap) | ||
39 | |||
40 | class MemSample: | ||
41 | used_values = ('MemTotal', 'MemFree', 'Buffers', 'Cached', 'SwapTotal', 'SwapFree',) | ||
42 | |||
43 | def __init__(self, time): | ||
44 | self.time = time | ||
45 | self.records = {} | ||
46 | |||
47 | def add_value(self, name, value): | ||
48 | if name in MemSample.used_values: | ||
49 | self.records[name] = value | ||
50 | |||
51 | def valid(self): | ||
52 | keys = self.records.keys() | ||
53 | # discard incomplete samples | ||
54 | return [v for v in MemSample.used_values if v not in keys] == [] | ||
55 | |||
18 | class ProcessSample: | 56 | class ProcessSample: |
19 | def __init__(self, time, state, cpu_sample): | 57 | def __init__(self, time, state, cpu_sample): |
20 | self.time = time | 58 | self.time = time |
21 | self.state = state | 59 | self.state = state |
22 | self.cpu_sample = cpu_sample | 60 | self.cpu_sample = cpu_sample |
23 | 61 | ||
24 | def __str__(self): | 62 | def __str__(self): |
25 | return str(self.time) + "\t" + str(self.state) + "\t" + str(self.cpu_sample); | 63 | return str(self.time) + "\t" + str(self.state) + "\t" + str(self.cpu_sample) |
26 | 64 | ||
27 | class ProcessStats: | 65 | class ProcessStats: |
28 | def __init__(self, process_list, sample_period, start_time, end_time): | 66 | def __init__(self, writer, process_map, sample_count, sample_period, start_time, end_time): |
29 | self.process_list = process_list | 67 | self.process_map = process_map |
30 | self.sample_period = sample_period | 68 | self.sample_count = sample_count |
31 | self.start_time = start_time | 69 | self.sample_period = sample_period |
32 | self.end_time = end_time | 70 | self.start_time = start_time |
33 | 71 | self.end_time = end_time | |
34 | class Process: | 72 | writer.info ("%d samples, avg. sample length %f" % (self.sample_count, self.sample_period)) |
35 | def __init__(self, pid, cmd, ppid, start_time): | 73 | writer.info ("process list size: %d" % len (self.process_map.values())) |
36 | self.pid = pid | ||
37 | self.cmd = cmd.strip('(').strip(')') | ||
38 | self.ppid = ppid | ||
39 | self.start_time = start_time | ||
40 | self.samples = [] | ||
41 | self.parent = None | ||
42 | self.child_list = [] | ||
43 | |||
44 | self.duration = 0 | ||
45 | self.active = None | ||
46 | |||
47 | self.last_user_cpu_time = None | ||
48 | self.last_sys_cpu_time = None | ||
49 | |||
50 | def __str__(self): | ||
51 | return " ".join([str(self.pid), self.cmd, str(self.ppid), '[ ' + str(len(self.samples)) + ' samples ]' ]) | ||
52 | |||
53 | def calc_stats(self, samplePeriod): | ||
54 | if self.samples: | ||
55 | firstSample = self.samples[0] | ||
56 | lastSample = self.samples[-1] | ||
57 | self.start_time = min(firstSample.time, self.start_time) | ||
58 | self.duration = lastSample.time - self.start_time + samplePeriod | ||
59 | |||
60 | activeCount = sum( [1 for sample in self.samples if sample.cpu_sample and sample.cpu_sample.sys + sample.cpu_sample.user + sample.cpu_sample.io > 0.0] ) | ||
61 | activeCount = activeCount + sum( [1 for sample in self.samples if sample.state == 'D'] ) | ||
62 | self.active = (activeCount>2) | ||
63 | |||
64 | def calc_load(self, userCpu, sysCpu, interval): | ||
65 | |||
66 | userCpuLoad = float(userCpu - self.last_user_cpu_time) / interval | ||
67 | sysCpuLoad = float(sysCpu - self.last_sys_cpu_time) / interval | ||
68 | cpuLoad = userCpuLoad + sysCpuLoad | ||
69 | # normalize | ||
70 | if cpuLoad > 1.0: | ||
71 | userCpuLoad = userCpuLoad / cpuLoad; | ||
72 | sysCpuLoad = sysCpuLoad / cpuLoad; | ||
73 | return (userCpuLoad, sysCpuLoad) | ||
74 | |||
75 | def set_parent(self, processMap): | ||
76 | if self.ppid != None: | ||
77 | self.parent = processMap.get(self.ppid) | ||
78 | if self.parent == None and self.pid > 1: | ||
79 | print "warning: no parent for pid '%i' with ppid '%i'" % (self.pid,self.ppid) | ||
80 | def get_end_time(self): | ||
81 | return self.start_time + self.duration | ||
82 | 74 | ||
83 | class DiskSample: | 75 | class Process: |
84 | def __init__(self, time, read, write, util): | 76 | def __init__(self, writer, pid, cmd, ppid, start_time): |
85 | self.time = time | 77 | self.writer = writer |
86 | self.read = read | 78 | self.pid = pid |
87 | self.write = write | 79 | self.cmd = cmd |
88 | self.util = util | 80 | self.exe = cmd |
89 | self.tput = read + write | 81 | self.args = [] |
82 | self.ppid = ppid | ||
83 | self.start_time = start_time | ||
84 | self.duration = 0 | ||
85 | self.samples = [] | ||
86 | self.parent = None | ||
87 | self.child_list = [] | ||
88 | |||
89 | self.active = None | ||
90 | self.last_user_cpu_time = None | ||
91 | self.last_sys_cpu_time = None | ||
92 | |||
93 | self.last_cpu_ns = 0 | ||
94 | self.last_blkio_delay_ns = 0 | ||
95 | self.last_swapin_delay_ns = 0 | ||
96 | |||
97 | # split this process' run - triggered by a name change | ||
98 | def split(self, writer, pid, cmd, ppid, start_time): | ||
99 | split = Process (writer, pid, cmd, ppid, start_time) | ||
100 | |||
101 | split.last_cpu_ns = self.last_cpu_ns | ||
102 | split.last_blkio_delay_ns = self.last_blkio_delay_ns | ||
103 | split.last_swapin_delay_ns = self.last_swapin_delay_ns | ||
104 | |||
105 | return split | ||
106 | |||
107 | def __str__(self): | ||
108 | return " ".join([str(self.pid), self.cmd, str(self.ppid), '[ ' + str(len(self.samples)) + ' samples ]' ]) | ||
90 | 109 | ||
91 | def __str__(self): | 110 | def calc_stats(self, samplePeriod): |
92 | return "\t".join([str(self.time), str(self.read), str(self.write), str(self.util)]) | 111 | if self.samples: |
112 | firstSample = self.samples[0] | ||
113 | lastSample = self.samples[-1] | ||
114 | self.start_time = min(firstSample.time, self.start_time) | ||
115 | self.duration = lastSample.time - self.start_time + samplePeriod | ||
116 | |||
117 | activeCount = sum( [1 for sample in self.samples if sample.cpu_sample and sample.cpu_sample.sys + sample.cpu_sample.user + sample.cpu_sample.io > 0.0] ) | ||
118 | activeCount = activeCount + sum( [1 for sample in self.samples if sample.state == 'D'] ) | ||
119 | self.active = (activeCount>2) | ||
120 | |||
121 | def calc_load(self, userCpu, sysCpu, interval): | ||
122 | userCpuLoad = float(userCpu - self.last_user_cpu_time) / interval | ||
123 | sysCpuLoad = float(sysCpu - self.last_sys_cpu_time) / interval | ||
124 | cpuLoad = userCpuLoad + sysCpuLoad | ||
125 | # normalize | ||
126 | if cpuLoad > 1.0: | ||
127 | userCpuLoad = userCpuLoad / cpuLoad | ||
128 | sysCpuLoad = sysCpuLoad / cpuLoad | ||
129 | return (userCpuLoad, sysCpuLoad) | ||
130 | |||
131 | def set_parent(self, processMap): | ||
132 | if self.ppid != None: | ||
133 | self.parent = processMap.get (self.ppid) | ||
134 | if self.parent == None and self.pid // 1000 > 1 and \ | ||
135 | not (self.ppid == 2000 or self.pid == 2000): # kernel threads: ppid=2 | ||
136 | self.writer.warn("Missing CONFIG_PROC_EVENTS: no parent for pid '%i' ('%s') with ppid '%i'" \ | ||
137 | % (self.pid,self.cmd,self.ppid)) | ||
138 | |||
139 | def get_end_time(self): | ||
140 | return self.start_time + self.duration | ||
141 | |||
142 | class DiskSample: | ||
143 | def __init__(self, time, read, write, util): | ||
144 | self.time = time | ||
145 | self.read = read | ||
146 | self.write = write | ||
147 | self.util = util | ||
148 | self.tput = read + write | ||
93 | 149 | ||
150 | def __str__(self): | ||
151 | return "\t".join([str(self.time), str(self.read), str(self.write), str(self.util)]) | ||
diff --git a/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py b/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py index 574c2c7a2b..00fb3bf797 100644 --- a/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py +++ b/scripts/pybootchartgui/pybootchartgui/tests/parser_test.py | |||
@@ -4,90 +4,102 @@ import unittest | |||
4 | 4 | ||
5 | sys.path.insert(0, os.getcwd()) | 5 | sys.path.insert(0, os.getcwd()) |
6 | 6 | ||
7 | import parsing | 7 | import pybootchartgui.parsing as parsing |
8 | import pybootchartgui.main as main | ||
8 | 9 | ||
9 | debug = False | 10 | debug = False |
10 | 11 | ||
11 | def floatEq(f1, f2): | 12 | def floatEq(f1, f2): |
12 | return math.fabs(f1-f2) < 0.00001 | 13 | return math.fabs(f1-f2) < 0.00001 |
13 | 14 | ||
15 | bootchart_dir = os.path.join(os.path.dirname(sys.argv[0]), '../../examples/1/') | ||
16 | parser = main._mk_options_parser() | ||
17 | options, args = parser.parse_args(['--q', bootchart_dir]) | ||
18 | writer = main._mk_writer(options) | ||
19 | |||
14 | class TestBCParser(unittest.TestCase): | 20 | class TestBCParser(unittest.TestCase): |
15 | 21 | ||
16 | def setUp(self): | 22 | def setUp(self): |
17 | self.name = "My first unittest" | 23 | self.name = "My first unittest" |
18 | self.rootdir = '../examples/1' | 24 | self.rootdir = bootchart_dir |
19 | 25 | ||
20 | def mk_fname(self,f): | 26 | def mk_fname(self,f): |
21 | return os.path.join(self.rootdir, f) | 27 | return os.path.join(self.rootdir, f) |
22 | 28 | ||
23 | def testParseHeader(self): | 29 | def testParseHeader(self): |
24 | state = parsing.parse_file(parsing.ParserState(), self.mk_fname('header')) | 30 | trace = parsing.Trace(writer, args, options) |
31 | state = parsing.parse_file(writer, trace, self.mk_fname('header')) | ||
25 | self.assertEqual(6, len(state.headers)) | 32 | self.assertEqual(6, len(state.headers)) |
26 | self.assertEqual(2, parsing.get_num_cpus(state.headers)) | 33 | self.assertEqual(2, parsing.get_num_cpus(state.headers)) |
27 | 34 | ||
28 | def test_parseTimedBlocks(self): | 35 | def test_parseTimedBlocks(self): |
29 | state = parsing.parse_file(parsing.ParserState(), self.mk_fname('proc_diskstats.log')) | 36 | trace = parsing.Trace(writer, args, options) |
37 | state = parsing.parse_file(writer, trace, self.mk_fname('proc_diskstats.log')) | ||
30 | self.assertEqual(141, len(state.disk_stats)) | 38 | self.assertEqual(141, len(state.disk_stats)) |
31 | 39 | ||
32 | def testParseProcPsLog(self): | 40 | def testParseProcPsLog(self): |
33 | state = parsing.parse_file(parsing.ParserState(), self.mk_fname('proc_ps.log')) | 41 | trace = parsing.Trace(writer, args, options) |
42 | state = parsing.parse_file(writer, trace, self.mk_fname('proc_ps.log')) | ||
34 | samples = state.ps_stats | 43 | samples = state.ps_stats |
35 | processes = samples.process_list | 44 | processes = samples.process_map |
36 | sorted_processes = sorted(processes, key=lambda p: p.pid ) | 45 | sorted_processes = [processes[k] for k in sorted(processes.keys())] |
37 | 46 | ||
38 | for index, line in enumerate(open(self.mk_fname('extract2.proc_ps.log'))): | 47 | ps_data = open(self.mk_fname('extract2.proc_ps.log')) |
48 | for index, line in enumerate(ps_data): | ||
39 | tokens = line.split(); | 49 | tokens = line.split(); |
40 | process = sorted_processes[index] | 50 | process = sorted_processes[index] |
41 | if debug: | 51 | if debug: |
42 | print tokens[0:4] | 52 | print(tokens[0:4]) |
43 | print process.pid, process.cmd, process.ppid, len(process.samples) | 53 | print(process.pid / 1000, process.cmd, process.ppid, len(process.samples)) |
44 | print '-------------------' | 54 | print('-------------------') |
45 | 55 | ||
46 | self.assertEqual(tokens[0], str(process.pid)) | 56 | self.assertEqual(tokens[0], str(process.pid // 1000)) |
47 | self.assertEqual(tokens[1], str(process.cmd)) | 57 | self.assertEqual(tokens[1], str(process.cmd)) |
48 | self.assertEqual(tokens[2], str(process.ppid)) | 58 | self.assertEqual(tokens[2], str(process.ppid // 1000)) |
49 | self.assertEqual(tokens[3], str(len(process.samples))) | 59 | self.assertEqual(tokens[3], str(len(process.samples))) |
50 | 60 | ps_data.close() | |
51 | 61 | ||
52 | def testparseProcDiskStatLog(self): | 62 | def testparseProcDiskStatLog(self): |
53 | state_with_headers = parsing.parse_file(parsing.ParserState(), self.mk_fname('header')) | 63 | trace = parsing.Trace(writer, args, options) |
64 | state_with_headers = parsing.parse_file(writer, trace, self.mk_fname('header')) | ||
54 | state_with_headers.headers['system.cpu'] = 'xxx (2)' | 65 | state_with_headers.headers['system.cpu'] = 'xxx (2)' |
55 | samples = parsing.parse_file(state_with_headers, self.mk_fname('proc_diskstats.log')).disk_stats | 66 | samples = parsing.parse_file(writer, state_with_headers, self.mk_fname('proc_diskstats.log')).disk_stats |
56 | self.assertEqual(141, len(samples)) | 67 | self.assertEqual(141, len(samples)) |
57 | 68 | ||
58 | for index, line in enumerate(open(self.mk_fname('extract.proc_diskstats.log'))): | 69 | diskstats_data = open(self.mk_fname('extract.proc_diskstats.log')) |
70 | for index, line in enumerate(diskstats_data): | ||
59 | tokens = line.split('\t') | 71 | tokens = line.split('\t') |
60 | sample = samples[index] | 72 | sample = samples[index] |
61 | if debug: | 73 | if debug: |
62 | print line.rstrip(), | 74 | print(line.rstrip()) |
63 | print sample | 75 | print(sample) |
64 | print '-------------------' | 76 | print('-------------------') |
65 | 77 | ||
66 | self.assertEqual(tokens[0], str(sample.time)) | 78 | self.assertEqual(tokens[0], str(sample.time)) |
67 | self.assert_(floatEq(float(tokens[1]), sample.read)) | 79 | self.assert_(floatEq(float(tokens[1]), sample.read)) |
68 | self.assert_(floatEq(float(tokens[2]), sample.write)) | 80 | self.assert_(floatEq(float(tokens[2]), sample.write)) |
69 | self.assert_(floatEq(float(tokens[3]), sample.util)) | 81 | self.assert_(floatEq(float(tokens[3]), sample.util)) |
82 | diskstats_data.close() | ||
70 | 83 | ||
71 | def testparseProcStatLog(self): | 84 | def testparseProcStatLog(self): |
72 | samples = parsing.parse_file(parsing.ParserState(), self.mk_fname('proc_stat.log')).cpu_stats | 85 | trace = parsing.Trace(writer, args, options) |
86 | samples = parsing.parse_file(writer, trace, self.mk_fname('proc_stat.log')).cpu_stats | ||
73 | self.assertEqual(141, len(samples)) | 87 | self.assertEqual(141, len(samples)) |
74 | 88 | ||
75 | for index, line in enumerate(open(self.mk_fname('extract.proc_stat.log'))): | 89 | stat_data = open(self.mk_fname('extract.proc_stat.log')) |
90 | for index, line in enumerate(stat_data): | ||
76 | tokens = line.split('\t') | 91 | tokens = line.split('\t') |
77 | sample = samples[index] | 92 | sample = samples[index] |
78 | if debug: | 93 | if debug: |
79 | print line.rstrip() | 94 | print(line.rstrip()) |
80 | print sample | 95 | print(sample) |
81 | print '-------------------' | 96 | print('-------------------') |
82 | self.assert_(floatEq(float(tokens[0]), sample.time)) | 97 | self.assert_(floatEq(float(tokens[0]), sample.time)) |
83 | self.assert_(floatEq(float(tokens[1]), sample.user)) | 98 | self.assert_(floatEq(float(tokens[1]), sample.user)) |
84 | self.assert_(floatEq(float(tokens[2]), sample.sys)) | 99 | self.assert_(floatEq(float(tokens[2]), sample.sys)) |
85 | self.assert_(floatEq(float(tokens[3]), sample.io)) | 100 | self.assert_(floatEq(float(tokens[3]), sample.io)) |
86 | 101 | stat_data.close() | |
87 | def testParseLogDir(self): | 102 | |
88 | res = parsing.parse([self.rootdir], False) | ||
89 | self.assertEqual(4, len(res)) | ||
90 | |||
91 | if __name__ == '__main__': | 103 | if __name__ == '__main__': |
92 | unittest.main() | 104 | unittest.main() |
93 | 105 | ||
diff --git a/scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py b/scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py index 971e125eab..6f46a1c03d 100644 --- a/scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py +++ b/scripts/pybootchartgui/pybootchartgui/tests/process_tree_test.py | |||
@@ -4,16 +4,28 @@ import unittest | |||
4 | 4 | ||
5 | sys.path.insert(0, os.getcwd()) | 5 | sys.path.insert(0, os.getcwd()) |
6 | 6 | ||
7 | import parsing | 7 | import pybootchartgui.parsing as parsing |
8 | import process_tree | 8 | import pybootchartgui.process_tree as process_tree |
9 | import pybootchartgui.main as main | ||
10 | |||
11 | if sys.version_info >= (3, 0): | ||
12 | long = int | ||
9 | 13 | ||
10 | class TestProcessTree(unittest.TestCase): | 14 | class TestProcessTree(unittest.TestCase): |
11 | 15 | ||
12 | def setUp(self): | 16 | def setUp(self): |
13 | self.name = "Process tree unittest" | 17 | self.name = "Process tree unittest" |
14 | self.rootdir = '../examples/1' | 18 | self.rootdir = os.path.join(os.path.dirname(sys.argv[0]), '../../examples/1/') |
15 | self.ps_stats = parsing.parse_file(parsing.ParserState(), self.mk_fname('proc_ps.log')).ps_stats | 19 | |
16 | self.processtree = process_tree.ProcessTree(self.ps_stats, None, False, for_testing = True) | 20 | parser = main._mk_options_parser() |
21 | options, args = parser.parse_args(['--q', self.rootdir]) | ||
22 | writer = main._mk_writer(options) | ||
23 | trace = parsing.Trace(writer, args, options) | ||
24 | |||
25 | parsing.parse_file(writer, trace, self.mk_fname('proc_ps.log')) | ||
26 | trace.compile(writer) | ||
27 | self.processtree = process_tree.ProcessTree(writer, None, trace.ps_stats, \ | ||
28 | trace.ps_stats.sample_period, None, options.prune, None, None, False, for_testing = True) | ||
17 | 29 | ||
18 | def mk_fname(self,f): | 30 | def mk_fname(self,f): |
19 | return os.path.join(self.rootdir, f) | 31 | return os.path.join(self.rootdir, f) |
@@ -26,14 +38,16 @@ class TestProcessTree(unittest.TestCase): | |||
26 | return flattened | 38 | return flattened |
27 | 39 | ||
28 | def checkAgainstJavaExtract(self, filename, process_tree): | 40 | def checkAgainstJavaExtract(self, filename, process_tree): |
29 | for expected, actual in zip(open(filename), self.flatten(process_tree)): | 41 | test_data = open(filename) |
42 | for expected, actual in zip(test_data, self.flatten(process_tree)): | ||
30 | tokens = expected.split('\t') | 43 | tokens = expected.split('\t') |
31 | self.assertEqual(int(tokens[0]), actual.pid) | 44 | self.assertEqual(int(tokens[0]), actual.pid // 1000) |
32 | self.assertEqual(tokens[1], actual.cmd) | 45 | self.assertEqual(tokens[1], actual.cmd) |
33 | self.assertEqual(long(tokens[2]), 10 * actual.start_time) | 46 | self.assertEqual(long(tokens[2]), 10 * actual.start_time) |
34 | self.assert_(long(tokens[3]) - 10 * actual.duration < 5, "duration") | 47 | self.assert_(long(tokens[3]) - 10 * actual.duration < 5, "duration") |
35 | self.assertEqual(int(tokens[4]), len(actual.child_list)) | 48 | self.assertEqual(int(tokens[4]), len(actual.child_list)) |
36 | self.assertEqual(int(tokens[5]), len(actual.samples)) | 49 | self.assertEqual(int(tokens[5]), len(actual.samples)) |
50 | test_data.close() | ||
37 | 51 | ||
38 | def testBuild(self): | 52 | def testBuild(self): |
39 | process_tree = self.processtree.process_tree | 53 | process_tree = self.processtree.process_tree |