├── .gitignore
├── CONTRIBUTING.md
├── COPYING
├── README.md
├── aboutdialogue.cpp
├── aboutdialogue.h
├── aboutdialogue.ui
├── colourhelper.cpp
├── colourhelper.h
├── cputools.cpp
├── cputools.h
├── filesystemworker.cpp
├── filesystemworker.h
├── hashqstring.h
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── memoryconverter.cpp
├── memoryconverter.h
├── preferencesdialogue.cpp
├── preferencesdialogue.h
├── preferencesdialogue.ui
├── processinformationworker.cpp
├── processinformationworker.h
├── processpropertiesdialogue.cpp
├── processpropertiesdialogue.h
├── processpropertiesdialogue.ui
├── processtools.cpp
├── processtools.h
├── qcustomplot.cpp
├── qcustomplot.h
├── resourcesworker.cpp
├── resourcesworker.h
├── system-monitor.desktop
├── system-monitor.pro
├── tablememoryitem.h
├── tablenumberitem.h
├── workerthread.cpp
└── workerthread.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # C++ objects and libs
2 |
3 | *.slo
4 | *.lo
5 | *.o
6 | *.a
7 | *.la
8 | *.lai
9 | *.so
10 | *.dll
11 | *.dylib
12 |
13 | # Qt-es
14 |
15 | /.qmake.cache
16 | /.qmake.stash
17 | *.pro.user
18 | *.pro.user.*
19 | *.qbs.user
20 | *.qbs.user.*
21 | *.moc
22 | moc_*.cpp
23 | qrc_*.cpp
24 | ui_*.h
25 | Makefile*
26 | *build-*
27 |
28 | # QtCreator
29 |
30 | *.autosave
31 |
32 | # QtCtreator Qml
33 | *.qmlproject.user
34 | *.qmlproject.user.*
35 |
36 | # QtCtreator CMake
37 | CMakeLists.txt.user
38 |
39 | # ignore compiled program
40 | system-monitor
41 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions can be made to the project by forking and making a pull request to this repository
4 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
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.
21 |
22 | 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
24 | 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
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | 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
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
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 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
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.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
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
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU 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
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
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 |
625 | 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
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | 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
631 | state 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.
633 |
634 |
635 | Copyright (C)
636 |
637 | 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
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | 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
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # system-monitor
2 |
3 | Qt based replacement for the gnome system montior on Linux
4 |
5 | ## Compiling
6 |
7 | Qmake can be used to directly build the project as long as all dependancies are met.
8 |
9 | `qmake && make; make install`
10 |
11 | The program uses C++14 and pthreads, g++ is recommended.
12 |
13 | ## Dependancies
14 |
15 | Qt5 must be installed to use system monitor.
16 |
17 | ### Compiling
18 |
19 | Compiling depends on the following:
20 |
21 | * libprocps-dev
22 |
23 | ### Running
24 |
25 | Running the program depends on the following:
26 |
27 | * libprocps6
28 |
29 | ## References
30 |
31 | * QCustomPlot - [http://qcustomplot.com/](http://qcustomplot.com/)
32 |
33 | ## Contributing
34 |
35 | See [guide](CONTRIBUTING.md)
36 |
--------------------------------------------------------------------------------
/aboutdialogue.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #include "aboutdialogue.h"
19 | #include "ui_aboutdialogue.h"
20 | #include
21 |
22 | AboutDialogue::AboutDialogue(QWidget *parent) :
23 | QDialog(parent),
24 | ui(new Ui::AboutDialogue)
25 | {
26 | ui->setupUi(this);
27 |
28 | this->setWindowFlags(Qt::Window);
29 |
30 | QPushButton* closeButton = this->findChild("closeButton");
31 | connect(closeButton,SIGNAL(clicked(bool)),this,SLOT(close()));
32 |
33 | QLabel* versionLabel = this->findChild("versionLabel");
34 | QString version = QString::number(VERSION_MAJOR) + "." + QString::number(VERSION_MINOR) + "." + QString::number(VERSION_BUILD);
35 | versionLabel->setText(version);
36 |
37 | QIcon appIcon = QIcon::fromTheme("utilities-system-monitor",QIcon::fromTheme("application-x-executable"));
38 | QLabel* programIcon = this->findChild("programIcon");
39 | programIcon->setPixmap(appIcon.pixmap(appIcon.actualSize(QSize(128,128))));
40 | }
41 |
42 | AboutDialogue::~AboutDialogue()
43 | {
44 | delete ui;
45 | }
46 |
--------------------------------------------------------------------------------
/aboutdialogue.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #ifndef ABOUTDIALOGUE_H
19 | #define ABOUTDIALOGUE_H
20 |
21 | #include
22 |
23 | namespace Ui {
24 | class AboutDialogue;
25 | }
26 |
27 | class AboutDialogue : public QDialog
28 | {
29 | Q_OBJECT
30 |
31 | public:
32 | explicit AboutDialogue(QWidget *parent = 0);
33 | ~AboutDialogue();
34 |
35 | private:
36 | Ui::AboutDialogue *ui;
37 | };
38 |
39 | #endif // ABOUTDIALOGUE_H
40 |
--------------------------------------------------------------------------------
/aboutdialogue.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | AboutDialogue
4 |
5 |
6 |
7 | 0
8 | 0
9 | 340
10 | 330
11 |
12 |
13 |
14 | About System Monitor
15 |
16 |
17 | false
18 |
19 |
20 |
21 | QLayout::SetFixedSize
22 |
23 | -
24 |
25 |
-
26 |
27 |
28 |
29 | 10
30 | true
31 |
32 |
33 |
34 | <html><head/><body><p align="center"><span style=" font-style:normal;">Copyright © 2016 - 2017 Lily Rivers</span></p></body></html>
35 |
36 |
37 |
38 | -
39 |
40 |
-
41 |
42 |
43 | false
44 |
45 |
46 | Credits
47 |
48 |
49 |
50 | -
51 |
52 |
53 | false
54 |
55 |
56 | License
57 |
58 |
59 |
60 | -
61 |
62 |
63 | Qt::Horizontal
64 |
65 |
66 |
67 | 40
68 | 20
69 |
70 |
71 |
72 |
73 | -
74 |
75 |
76 |
77 | 0
78 | 0
79 |
80 |
81 |
82 | Close
83 |
84 |
85 | true
86 |
87 |
88 | true
89 |
90 |
91 | false
92 |
93 |
94 |
95 |
96 |
97 | -
98 |
99 |
100 | <html><head/><body><p align="center">VERSION</p></body></html>
101 |
102 |
103 | Qt::AlignCenter
104 |
105 |
106 |
107 | -
108 |
109 |
110 | Qt::Vertical
111 |
112 |
113 |
114 | 20
115 | 40
116 |
117 |
118 |
119 |
120 | -
121 |
122 |
123 | <html><head/><body><p align="center"><span style=" font-weight:600;">System Monitor</span></p></body></html>
124 |
125 |
126 |
127 | -
128 |
129 |
130 |
131 | 0
132 | 0
133 |
134 |
135 |
136 | <html><head/><body><p align="center">View current processes and monitor system state</p></body></html>
137 |
138 |
139 | true
140 |
141 |
142 |
143 | -
144 |
145 |
146 | Qt::Vertical
147 |
148 |
149 |
150 | 20
151 | 40
152 |
153 |
154 |
155 |
156 | -
157 |
158 |
159 |
160 |
161 |
162 | Qt::AlignCenter
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
--------------------------------------------------------------------------------
/colourhelper.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #include "colourhelper.h"
19 |
20 | namespace colourHelper {
21 |
22 | QColor createColourFromSettings(QSettings *settings, QString name, const int defaults[])
23 | {
24 | return QColor(settings->value(name+"_R",defaults[0]).toInt(),
25 | settings->value(name+"_G",defaults[1]).toInt(),
26 | settings->value(name+"_B",defaults[2]).toInt());
27 | }
28 |
29 | void saveColourToSettings(QSettings *settings, QString name, const QColor &colour)
30 | {
31 | settings->setValue(name+"_R", colour.red());
32 | settings->setValue(name+"_G", colour.green());
33 | settings->setValue(name+"_B", colour.blue());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/colourhelper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #ifndef COLOURHELPER_H
19 | #define COLOURHELPER_H
20 |
21 | #include
22 | #include
23 |
24 | namespace colourHelper {
25 | QColor createColourFromSettings(QSettings *settings, QString name, const int defaults[]);
26 | void saveColourToSettings(QSettings *settings, QString name, const QColor &colour);
27 | }
28 |
29 | #endif // COLOURHELPER_H
30 |
--------------------------------------------------------------------------------
/cputools.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include "cputools.h"
23 | namespace cpuTools {
24 |
25 | std::vector getCpuTimes()
26 | {
27 | std::vector times;
28 |
29 | // adapted from https://github.com/scaidermern/top-processes/blob/master/top_proc.c#L54
30 | FILE* file = fopen("/proc/stat", "r");
31 | if (file == NULL) {
32 | perror("Could not open stat file");
33 | return times;
34 | }
35 |
36 | char buffer[1024];
37 | memset(buffer,1,1024); // initialise the buffer with known data but not 0 (null) so that the next while loop still works
38 | // skip the first line
39 | while(buffer[0] != '\n' && buffer != NULL) {
40 | buffer[0] = (char)fgetc(file);
41 | }
42 |
43 | while(buffer != NULL) {
44 | unsigned long long user = 0, nice = 0, system = 0, idle = 0;
45 | // added between Linux 2.5.41 and 2.6.33, see man proc(5)
46 | unsigned long long iowait = 0, irq = 0, softirq = 0, steal = 0, guest = 0, guestnice = 0;
47 |
48 | char* ret = fgets(buffer, sizeof(buffer) - 1, file);
49 | if (ret == NULL) {
50 | perror("Could not read stat file");
51 | fclose(file);
52 | return times;
53 | } else if (strncmp(buffer, "cpu", 3)) {
54 | break; // we got all of the cpu lines
55 | }
56 |
57 | sscanf(buffer,
58 | "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu",
59 | &user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, &guest, &guestnice);
60 |
61 | // sum everything up (except guest and guestnice since they are already included
62 | // in user and nice, see http://unix.stackexchange.com/q/178045/20626)
63 |
64 | cpuStruct cpu = {idle + iowait, user + nice + system + irq + softirq + steal};
65 | times.push_back(cpu);
66 | }
67 |
68 | fclose(file);
69 | return times;
70 | }
71 |
72 | std::vector calculateCpuPercentages(std::vector now, std::vector prev)
73 | {
74 | std::vector times;
75 | if (now.size() != prev.size()) {
76 | return times;
77 | }
78 |
79 | for(unsigned int i=0; i getCpuTimes();
26 | std::vector calculateCpuPercentages(std::vector now, std::vector prev);
27 | }
28 |
29 | #endif // CPUTOOLS_H
30 |
--------------------------------------------------------------------------------
/filesystemworker.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #include "filesystemworker.h"
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include "tablememoryitem.h"
33 | #include "tablenumberitem.h"
34 |
35 | fileSystemWorker::fileSystemWorker(QObject *parent, QSettings *settings)
36 | : QObject(parent), workerThread()
37 | {
38 | QTabWidget* mainTabs = parent->findChild("tabWidgetMain");
39 | diskTable = mainTabs->findChild("tableFilesystem");
40 |
41 | connect(this,SIGNAL(updateTableData()),this,SLOT(updateTable()));
42 |
43 | createFilesystemView();
44 | timeSinceLastIOCheck = 0;
45 | lastEpochCount = std::chrono::system_clock::now().time_since_epoch();
46 |
47 | this->settings = settings;
48 | }
49 |
50 | /**
51 | * @brief fileSystemWorker::createFilesystemView Create the filesystem table
52 | */
53 | void fileSystemWorker::createFilesystemView()
54 | {
55 | diskTable->setColumnCount(7);
56 | diskTable->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
57 | //table->setHorizontalHeaderLabels(QString("HEADER 1;HEADER 2;HEADER 3").split(";"));
58 | diskTable->setHorizontalHeaderLabels(QString("Device;Directory;Type;Total;Available;Used;IO").split(";"));
59 | diskTable->verticalHeader()->setVisible(false);
60 | diskTable->setSelectionBehavior(QAbstractItemView::SelectRows);
61 | diskTable->resizeColumnsToContents();
62 | }
63 |
64 | /**
65 | * @brief fileSystemWorker::readMtabDisks Read the data from /etc/mtab and check it against
66 | * @return A vector of physical disks that exist. Only the name, mount point, and type are filled in
67 | */
68 | std::vector fileSystemWorker::readMtabDisks()
69 | {
70 | // mtab lists all of the mounted disks on the machine, need to check that they exist in /dev and are real devices to avoid listing
71 | // things like the proc and udev file systems
72 | QFile file("/etc/mtab");
73 | std::vector disks;
74 | if (file.open(QFile::ReadOnly)) {
75 | while(true) {
76 | QStringList tabParts = QString::fromLocal8Bit(file.readLine()).trimmed().split(" "); // read the next line
77 | if (tabParts.count() > 1) {
78 | // still some of the file left to read
79 | if (tabParts[0].contains("/dev/")) {
80 | // http://serverfault.com/questions/267609/how-to-understand-etc-mtab
81 | disk d;
82 | d.name=tabParts[0];
83 | d.mountPoint=tabParts[1];
84 | d.type=tabParts[2];
85 | disks.push_back(d);
86 | }
87 | } else {
88 | // EOF
89 | break;
90 | }
91 | }
92 | }
93 |
94 | return disks;
95 | }
96 |
97 | /**
98 | * @brief fileSystemWorker::fillDiskStructures Fill in any remaining data in each of the given disks
99 | * @param disks The list of disks to operate on
100 | */
101 | void fileSystemWorker::fillDiskStructures(std::vector &disks)
102 | {
103 | for(unsigned int i=0; igetUnit());
119 | disks[i].usedPercentage = disks[i].usedSize->getValue() / totalSizeCopy.getValue() * 100;
120 | } else {
121 | throw std::runtime_error(qPrintable("'" + disks[i].mountPoint + "'' failed statvfs!"));
122 | }
123 |
124 | // https://www.kernel.org/doc/Documentation/iostats.txt
125 | // check /sys/block// for the disks we found in mtab and then grab some extra data about them
126 | // some disks have are logical and have /dev/mapper/ names, these should be shown using /dev/mapper names as in GSM but the names
127 | // need to be resolved to be used as diskstats uses dm type names. The disks are symlinked to the correct paths
128 | QString name = disks[i].name;
129 | if (disks[i].name.contains("/dev/mapper")) {
130 | char buf[1024];
131 | size_t len;
132 | if ((len = readlink(qPrintable(name), buf, sizeof(buf)-1))) {
133 | buf[len] = '\0';
134 | }
135 | name = QString(buf);
136 | }
137 | name = QFileInfo(name).fileName();
138 |
139 | QString parent = QFileInfo(name).fileName();
140 | // /sys/block contains dm partitions, these should not be shown
141 | if (parent.section(QRegExp("\\d"),0,parent.size()) != "" && !parent.contains("dm")) {
142 | // this disk has a parent
143 | parent.remove(QRegExp("\\d"));
144 | } else {
145 | parent = "";
146 | }
147 |
148 | if (parent == name) {
149 | // this is actually a full disk partition, ignore the parent
150 | parent = "";
151 | }
152 |
153 | std::vector parts;
154 | QFile stat("/sys/block/"+(parent==""? "":parent+"/")+name+"/stat");
155 | if (stat.open(QFile::ReadOnly)) {
156 | QString s = stat.readLine();
157 | std::locale loc;
158 | for (int i = 0; i < s.size(); i++) {
159 | if (std::isspace(s.at(i).toLatin1(), loc)) {
160 | continue;
161 | }
162 |
163 | QString buf;
164 | for (int j = i; j < s.size(); j++, i++) {
165 | if (std::isspace(s.at(j).toLatin1(), loc)) {
166 | break;
167 | }
168 |
169 | buf += s.at(j);
170 | }
171 |
172 | parts.push_back(buf.toLong());
173 | }
174 |
175 | if (oldDisks.size() > 0) {
176 | disks[i].ioms = parts[9];
177 | if (timeSinceLastIOCheck > 0) {
178 | disks[i].io = 100.0L * (parts[9]-oldDisks[i].ioms) / timeSinceLastIOCheck;
179 | }
180 | /*if (disks[i].io > 100) {
181 | disks[i].io = 100;
182 | }
183 | if (disks[i].io < 0) {
184 | disks[i].io = 0;
185 | }*/
186 | } else {
187 | disks[i].io = 0;
188 | disks[i].ioms = parts[9];
189 | }
190 | }
191 | }
192 | }
193 |
194 | /**
195 | * @brief fileSystemWorker::updateTable Update the filesystem table
196 | */
197 | void fileSystemWorker::updateTable()
198 | {
199 | timeSinceLastIOCheck = std::chrono::duration_cast(
200 | std::chrono::system_clock::now().time_since_epoch() - lastEpochCount).count();
201 | lastEpochCount = std::chrono::system_clock::now().time_since_epoch();
202 |
203 | std::vector disks = readMtabDisks();
204 |
205 | fillDiskStructures(disks);
206 |
207 | // delete the objects we created with new before we assign to prevent leaks
208 | while(!oldDisks.empty()) {
209 | disk *workingDisk = &(oldDisks.back());
210 | delete workingDisk->freeSize;
211 | delete workingDisk->totalSize;
212 | delete workingDisk->usedSize;
213 | oldDisks.pop_back();
214 | }
215 | oldDisks = disks;
216 |
217 | diskTable->setUpdatesEnabled(false); // avoid inconsistant data
218 | diskTable->setSortingEnabled(false);
219 | diskTable->setRowCount(disks.size());
220 | unsigned int index = 0;
221 | for(auto &i:disks) {
222 | disk* p = &(i);
223 | if (p!=nullptr) {
224 | diskTable->setItem(index,0,new QTableWidgetItem(p->name));
225 | diskTable->setItem(index,1,new QTableWidgetItem(p->mountPoint));
226 | diskTable->setItem(index,2,new QTableWidgetItem(p->type));
227 | diskTable->setItem(index,3,new TableMemoryItem((*p->totalSize)));
228 | diskTable->setItem(index,4,new TableMemoryItem((*p->freeSize)));
229 | diskTable->setItem(index,5,new TableNumberItem(QString::number(p->usedPercentage) + QString::fromStdString("% (" +
230 | p->usedSize->to_string() + ")")));
231 | diskTable->setItem(index,6,new TableNumberItem(QString::number(p->io) + "%"));
232 | diskTable->showRow(index);
233 | }
234 | index++;
235 | }
236 | diskTable->setUpdatesEnabled(true);
237 | diskTable->setSortingEnabled(true);
238 | }
239 |
240 | /**
241 | * @brief fileSystemWorker::loop Run the loop for the thread
242 | */
243 | void fileSystemWorker::loop()
244 | {
245 | standard = memoryConverter::stringToStandard(settings->value("unit prefix standards", JEDEC).toString().toStdString());
246 | emit(updateTableData());
247 |
248 | std::this_thread::sleep_for(std::chrono::milliseconds(1000));
249 | }
250 |
251 |
--------------------------------------------------------------------------------
/filesystemworker.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #ifndef FILESYSTEMWORKER_H
19 | #define FILESYSTEMWORKER_H
20 | #include
21 | #include "workerthread.h"
22 | #include
23 | #include
24 | #include "memoryconverter.h"
25 | #include
26 |
27 | class fileSystemWorker : public QObject, public workerThread
28 | {
29 | Q_OBJECT
30 | public:
31 | explicit fileSystemWorker(QObject *parent, QSettings *settings);
32 |
33 | signals:
34 | void updateTableData();
35 |
36 | private slots:
37 | void updateTable();
38 |
39 | private:
40 | void loop();
41 | QTableWidget* diskTable;
42 | void createFilesystemView();
43 | struct disk {
44 | QString name;
45 | QString mountPoint;
46 | QString type;
47 | memoryConverter *freeSize;
48 | memoryConverter *totalSize;
49 | memoryConverter *usedSize;
50 | int usedPercentage;
51 | double io;
52 | unsigned long long ioms;
53 | };
54 | std::chrono::milliseconds::rep timeSinceLastIOCheck;
55 | std::chrono::nanoseconds lastEpochCount;
56 | std::vector oldDisks;
57 | std::vector readMtabDisks();
58 | void fillDiskStructures(std::vector &disks);
59 | QSettings *settings;
60 | unitStandard standard;
61 | };
62 |
63 | #endif // FILESYSTEMWORKER_H
64 |
--------------------------------------------------------------------------------
/hashqstring.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #ifndef HASHQSTRING_H
19 | #define HASHQSTRING_H
20 |
21 | #include
22 | #include
23 |
24 | namespace std {
25 | template<> struct hash
26 | {
27 | size_t operator()(const QString& k) const
28 | {
29 | return hash()(k.toStdString());
30 | }
31 | };
32 | }
33 |
34 | #endif // HASHQSTRING_H
35 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #include "mainwindow.h"
19 | #include
20 |
21 | int main(int argc, char *argv[])
22 | {
23 | QApplication a(argc, argv);
24 | MainWindow w;
25 | w.show();
26 |
27 | return a.exec();
28 | }
29 |
--------------------------------------------------------------------------------
/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #include "mainwindow.h"
19 | #include "ui_mainwindow.h"
20 | #include "aboutdialogue.h"
21 | #include "preferencesdialogue.h"
22 | #include
23 | #include "colourhelper.h"
24 | using namespace colourHelper;
25 |
26 | MainWindow::MainWindow(QWidget *parent) :
27 | QMainWindow(parent),
28 | ui(new Ui::MainWindow)
29 | {
30 | ui->setupUi(this);
31 |
32 | settings = new QSettings("system-monitor","system-monitor");
33 |
34 | QDataStream geometry(settings->value("mainWindowGeometry", this->geometry()).toByteArray());
35 | QRect geomRect;
36 | geometry >> geomRect;
37 | this->setGeometry(geomRect);
38 |
39 | processesThread = new processInformationWorker(this, settings);
40 | resourcesThread = new resourcesWorker(this, settings);
41 | filesystemThread = new fileSystemWorker(this, settings);
42 |
43 | processesThread->start();
44 | resourcesThread->start();
45 | filesystemThread->start();
46 |
47 | quitAction = this->findChild("actionQuit");
48 | connect(quitAction,SIGNAL(triggered(bool)),QApplication::instance(),SLOT(quit()));
49 |
50 | aboutAction = this->findChild("actionAbout");
51 | connect(aboutAction,SIGNAL(triggered(bool)),this,SLOT(showAboutWindow()));
52 |
53 | preferencesAction = this->findChild("actionPreferences");
54 | connect(preferencesAction,SIGNAL(triggered(bool)),this,SLOT(showPreferencesWindow()));
55 |
56 | mainTabs = findChild("tabWidgetMain");
57 | connect(mainTabs, SIGNAL(currentChanged(int)), this, SLOT(handleTabChange()));
58 |
59 | qRegisterMetaType("qcustomplotCpuVector");
60 | cpuPlot = reinterpret_cast(ui->tabResources->findChild("cpuPlot"));
61 | connect(resourcesThread,SIGNAL(updateCpuPlotSIG(const qcustomplotCpuVector&)),
62 | this,SLOT(updateCpuPlotSLO(const qcustomplotCpuVector&)));
63 | cpuInfoArea = ui->tabResources->findChild("cpuInfoArea");
64 |
65 | qRegisterMetaType("qcustomplotNetworkVector");
66 | networkPlot = reinterpret_cast(ui->tabResources->findChild("networkPlot"));
67 | connect(resourcesThread,SIGNAL(updateNetworkPlotSIG(const qcustomplotNetworkVector&)),
68 | this,SLOT(updateNetworkPlotSLO(qcustomplotNetworkVector)));
69 |
70 | handleTabChange();
71 | }
72 |
73 | MainWindow::~MainWindow()
74 | {
75 | delete ui;
76 | delete processesThread;
77 | delete resourcesThread;
78 | delete filesystemThread;
79 | delete mainTabs;
80 | delete settings;
81 | }
82 |
83 | void MainWindow::resizeEvent(QResizeEvent* event)
84 | {
85 | QMainWindow::resizeEvent(event);
86 |
87 | QByteArray data;
88 | QDataStream geometry(&data, QIODevice::WriteOnly);
89 | geometry << this->geometry();
90 | settings->setValue("mainWindowGeometry", data);
91 | }
92 |
93 | void MainWindow::updateCpuAreaInfo(const QVector &input)
94 | {
95 | static QVector cpuLabels;
96 | static QVector cpuColourButtons;
97 | #define colourNamesLen 4
98 | static const QString colourNames[] = {
99 | "orange","red","green","blue"
100 | };
101 |
102 | if (cpuInfoArea->count() == 0) {
103 | for(int i=0; isetFlat(true);
109 | cpuColourButton->setObjectName("CPU" + QString::number(i+1));
110 | cpuColourButtons.append(cpuColourButton);
111 | /// TODO: dangarous, across thread and parent may not be correct, move to another object. See below todo
112 | connect(cpuColourButton, SIGNAL(clicked(bool)), this->resourcesThread, SLOT(createColourDialogue()), Qt::UniqueConnection);
113 |
114 | QHBoxLayout *cpuLayout = new QHBoxLayout();
115 | cpuLayout->addWidget(cpuColourButton);
116 | cpuLayout->addWidget(cpuLabel);
117 |
118 | cpuInfoArea->addLayout(cpuLayout, i / 4, i % 4);
119 | cpuInfoArea->setAlignment(cpuLayout, Qt::AlignHCenter);
120 |
121 | /// TODO: horrible, make a class. Duplicated in resourcesworker
122 | QColor colour = QColor(colourNames[i % colourNamesLen]);
123 | colour = colour.toRgb();
124 | struct__intArrayHolder rgbColor;
125 | rgbColor.array[0] = colour.red();
126 | rgbColor.array[1] = colour.green();
127 | rgbColor.array[2] = colour.blue();
128 | this->defaultCpuColours["CPU" + QString::number(i+1)] = rgbColor;
129 | }
130 | return;
131 | }
132 |
133 | for(int i=0; isetText("CPU" + QString::number(i+1) + " "
135 | + QString::number(memoryConverter::roundDouble(input[i], 1)) + "%");
136 |
137 | QPixmap cpuColour = QPixmap(cpuColourButtons[i]->width(), cpuColourButtons[i]->height());
138 | cpuColour.fill(createColourFromSettings(settings, cpuColourButtons[i]->objectName(),
139 | this->defaultCpuColours[cpuColourButtons[i]->objectName()].array));
140 | cpuColourButtons[i]->setIcon(QIcon(cpuColour));
141 | }
142 | }
143 |
144 | QPair>, qcustomplotCpuVector> MainWindow::generateSpline(QString name, QVector &x, const qcustomplotCpuVector &y, bool setMax)
145 | {
146 | /// TODO stub
147 | int size = y.size();
148 | QVector> xs;
149 | for(unsigned int i=0; i < size; i++) {
150 | xs.push_back(x);
151 | }
152 | return QPair>, qcustomplotCpuVector>(xs, y);
153 | }
154 |
155 | void MainWindow::updateCpuPlotSLO(const qcustomplotCpuVector &input)
156 | {
157 | QVector x(60); // initialize with entries 60..0
158 | for (int i=59; i>0; --i)
159 | {
160 | x[i] = i;
161 | }
162 |
163 | const qcustomplotCpuVector *values = &input;
164 |
165 | static bool previouslyPlotted = false;
166 | int size = values->count();//values->size();
167 | if (size == 0) {
168 | return;
169 | }
170 |
171 | QVector> splineXValues;
172 | bool smooth = settings->value("smoothGraphs", false).toBool();
173 | QPair>, qcustomplotCpuVector> data;
174 | if(smooth) {
175 | data = generateSpline("cpu", x, *values, true);
176 | if (!data.second.empty() && !data.second.at(0).empty()) {
177 | values = &data.second;
178 | x = data.first.at(0);
179 | }
180 | splineXValues = data.first;
181 | }
182 |
183 | QVector lastValues;
184 | for(int i=0; idefaultCpuColours[colName].array);
194 |
195 | if (!previouslyPlotted) {
196 | cpuPlot->addGraph();
197 | } else {
198 | cpuPlot->graph(i)->data()->clear();
199 | cpuPlot->graph(i)->setPen(QPen(QColor(cpuColour)));
200 | }
201 |
202 | cpuPlot->graph(i)->setData(x, values->at(i));
203 |
204 | if (settings->value("draw cpu area stacked",false).toBool()) {
205 | cpuPlot->graph(i)->setBrush(QBrush(cpuColour));
206 | } else {
207 | cpuPlot->graph(i)->setBrush(QBrush());
208 | }
209 | }
210 | previouslyPlotted = true;
211 |
212 | if (smooth) {
213 | cpuPlot->xAxis->setRange(0, x.last() + 1);
214 | } else {
215 | cpuPlot->xAxis->setRange(0, values->at(0).size());
216 | }
217 | cpuPlot->yAxis->setRange(0, 100);
218 | cpuPlot->replot();
219 | }
220 |
221 | void MainWindow::updateNetworkPlotSLO(const qcustomplotNetworkVector &values)
222 | {
223 | const memoryConverter *sendingMax = nullptr, *recievingMax = nullptr;
224 |
225 | // find max value to scale all other values by
226 | for(unsigned int i=0; i<2; i++) {
227 | for(int j=0; j> scaled, *plotting = &scaled;
253 |
254 | for(unsigned int i=0; i<2; i++) {
255 | QVector scaledValuesTemp;
256 | for(int j=0; j x(60); // initialize with entries 60..0
265 | for (int i=59; i>0; --i)
266 | {
267 | x[i] = i;
268 | }
269 |
270 | QVector> splineXValues;
271 | bool smooth = settings->value("smoothGraphs", false).toBool();
272 | QPair>, qcustomplotCpuVector> data;
273 | if(smooth) {
274 | data = generateSpline("network", x, *plotting);
275 | if (!data.second.empty() && !data.second.at(0).empty()) {
276 | plotting = &data.second;
277 | x = data.first.at(0);
278 | }
279 | splineXValues = data.first;
280 | }
281 |
282 | QString colours[] = {
283 | "networkRecievingColourButton",
284 | "networkSendingColourButton"
285 | };
286 | for(unsigned int i=0; i<2; i++) {
287 | networkPlot->addGraph();
288 | networkPlot->graph(i)->setPen(QPen(colourHelper::createColourFromSettings(settings, colours[i],
289 | resourcesThread->getColourDefaults()[colours[i]].array)));
290 | networkPlot->graph(i)->setData(x, plotting->at(i));
291 | }
292 |
293 | if (smooth) {
294 | networkPlot->xAxis->setRange(0, x.last() + 1);
295 | } else {
296 | networkPlot->xAxis->setRange(0, plotting->at(0).size());
297 | }
298 | networkPlot->yAxis->setRange(0, scaler.getValue() + 1);
299 | networkPlot->yAxis->setLabel(QString::fromStdString(scaler.getUnitAsString()));
300 | networkPlot->replot();
301 | }
302 |
303 | /**
304 | * @brief MainWindow::handleTabChange Handle when the tab is changed, pause the other threads
305 | */
306 | void MainWindow::handleTabChange()
307 | {
308 | unsigned int index = mainTabs->currentIndex();
309 | processesThread->setPaused(true);
310 | if (!settings->value("resourcesKeepThreadRunning", true).toBool()) {
311 | resourcesThread->setPaused(true);
312 | } else {
313 | resourcesThread->setPaused(false);
314 | }
315 | filesystemThread->setPaused(true);
316 | switch(index) {
317 | case 0:
318 | processesThread->setPaused(false);
319 | break;
320 |
321 | case 1:
322 | resourcesThread->setPaused(false);
323 | break;
324 |
325 | case 2:
326 | filesystemThread->setPaused(false);
327 | break;
328 | }
329 | }
330 |
331 | /**
332 | * @brief MainWindow::showAboutWindow Show the about dialogue without blocking the main thread
333 | */
334 | void MainWindow::showAboutWindow()
335 | {
336 | AboutDialogue* about = new AboutDialogue(this);
337 | //about->show();
338 | about->exec();
339 | }
340 |
341 | /**
342 | * @brief MainWindow::showPreferencesWindow Show the preferences dialogue
343 | */
344 | void MainWindow::showPreferencesWindow()
345 | {
346 | PreferencesDialogue* pref = new PreferencesDialogue(this, settings);
347 | pref->exec();
348 | }
349 |
--------------------------------------------------------------------------------
/mainwindow.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #ifndef MAINWINDOW_H
19 | #define MAINWINDOW_H
20 |
21 | #include
22 | #include "processinformationworker.h"
23 | #include "resourcesworker.h"
24 | #include "filesystemworker.h"
25 | #include
26 | #include "qcustomplot.h"
27 | #include
28 | #include
29 |
30 | namespace Ui {
31 | class MainWindow;
32 | }
33 |
34 | class MainWindow : public QMainWindow
35 | {
36 | Q_OBJECT
37 |
38 | public:
39 | Ui::MainWindow *ui;
40 | explicit MainWindow(QWidget *parent = 0);
41 | ~MainWindow();
42 |
43 | protected:
44 | void resizeEvent(QResizeEvent *event) override;
45 |
46 | public slots:
47 | void updateCpuPlotSLO(const qcustomplotCpuVector &input);
48 | void updateNetworkPlotSLO(const qcustomplotNetworkVector &values);
49 |
50 | private slots:
51 | void handleTabChange();
52 | void showAboutWindow();
53 | void showPreferencesWindow();
54 |
55 | private:
56 | processInformationWorker* processesThread;
57 | resourcesWorker* resourcesThread;
58 | fileSystemWorker* filesystemThread;
59 | QTabWidget* mainTabs;
60 | QAction *quitAction, *aboutAction, *preferencesAction;
61 | QCustomPlot *cpuPlot, *networkPlot;
62 | QSettings *settings;
63 | QGridLayout *cpuInfoArea;
64 | void updateCpuAreaInfo(const QVector &input);
65 | QHash defaultCpuColours; /// TODO: use qcolor?
66 | QPair>, qcustomplotCpuVector> generateSpline(QString name, QVector &x, const QVector> &y, bool setMax = false);
67 | };
68 |
69 | #endif // MAINWINDOW_H
70 |
--------------------------------------------------------------------------------
/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 943
10 | 605
11 |
12 |
13 |
14 |
15 | 0
16 | 0
17 |
18 |
19 |
20 | System Monitor
21 |
22 |
23 |
24 | -
25 |
26 |
27 | true
28 |
29 |
30 | 1
31 |
32 |
33 |
34 |
35 | 0
36 | 0
37 |
38 |
39 |
40 | Processes
41 |
42 |
43 |
-
44 |
45 |
-
46 |
47 |
48 | Search
49 |
50 |
51 | true
52 |
53 |
54 |
55 | -
56 |
57 |
58 | true
59 |
60 |
61 | Only me
62 |
63 |
64 |
65 |
66 |
67 | -
68 |
69 |
70 | QFrame::NoFrame
71 |
72 |
73 | Qt::ScrollBarAlwaysOn
74 |
75 |
76 | Qt::ScrollBarAsNeeded
77 |
78 |
79 | false
80 |
81 |
82 | QAbstractItemView::NoEditTriggers
83 |
84 |
85 | QAbstractItemView::SingleSelection
86 |
87 |
88 | QAbstractItemView::SelectRows
89 |
90 |
91 | false
92 |
93 |
94 | true
95 |
96 |
97 | true
98 |
99 |
100 | true
101 |
102 |
103 | false
104 |
105 |
106 |
107 | -
108 |
109 |
110 | TextLabel
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | Resources
119 |
120 |
121 | -
122 |
123 |
124 | Qt::Vertical
125 |
126 |
127 | QSizePolicy::Maximum
128 |
129 |
130 |
131 | 20
132 | 20
133 |
134 |
135 |
136 |
137 | -
138 |
139 |
140 | QLayout::SetMinimumSize
141 |
142 |
-
143 |
144 |
145 | Network History
146 |
147 |
148 |
149 | -
150 |
151 |
152 |
153 | 0
154 | 0
155 |
156 |
157 |
158 |
159 | 0
160 | 100
161 |
162 |
163 |
164 |
165 | -
166 |
167 |
-
168 |
169 |
-
170 |
171 |
172 |
173 | 50
174 | 16777215
175 |
176 |
177 |
178 |
179 |
180 |
181 | true
182 |
183 |
184 |
185 | -
186 |
187 |
-
188 |
189 |
190 | Recieving
191 |
192 |
193 |
194 | -
195 |
196 |
197 | Total Recieved
198 |
199 |
200 |
201 |
202 |
203 | -
204 |
205 |
-
206 |
207 |
208 | TextLabel
209 |
210 |
211 |
212 | -
213 |
214 |
215 | TextLabel
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 | -
224 |
225 |
-
226 |
227 |
228 |
229 | 50
230 | 16777215
231 |
232 |
233 |
234 |
235 |
236 |
237 | true
238 |
239 |
240 |
241 | -
242 |
243 |
-
244 |
245 |
246 | Sending
247 |
248 |
249 |
250 | -
251 |
252 |
253 | Total Sent
254 |
255 |
256 |
257 |
258 |
259 | -
260 |
261 |
-
262 |
263 |
264 | TextLabel
265 |
266 |
267 |
268 | -
269 |
270 |
271 | TextLabel
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 | -
284 |
285 |
286 | QLayout::SetMinimumSize
287 |
288 |
-
289 |
290 |
-
291 |
292 |
293 |
294 | 49
295 | 22
296 |
297 |
298 |
299 | Swap
300 |
301 |
302 |
303 | -
304 |
305 |
306 | 24
307 |
308 |
309 |
310 |
311 |
312 | -
313 |
314 |
315 | TextLabel
316 |
317 |
318 |
319 |
320 |
321 | -
322 |
323 |
324 | Qt::Vertical
325 |
326 |
327 | QSizePolicy::Maximum
328 |
329 |
330 |
331 | 20
332 | 20
333 |
334 |
335 |
336 |
337 | -
338 |
339 |
340 | QLayout::SetMinimumSize
341 |
342 |
-
343 |
344 |
-
345 |
346 |
347 | Memory
348 |
349 |
350 |
351 | -
352 |
353 |
354 | 24
355 |
356 |
357 |
358 |
359 |
360 | -
361 |
362 |
363 |
364 | 0
365 | 0
366 |
367 |
368 |
369 | TextLabel
370 |
371 |
372 | -1
373 |
374 |
375 |
376 |
377 |
378 | -
379 |
380 |
381 | QLayout::SetMinimumSize
382 |
383 |
-
384 |
385 |
386 | CPU History
387 |
388 |
389 |
390 | -
391 |
392 |
393 |
394 | 0
395 | 0
396 |
397 |
398 |
399 |
400 | 0
401 | 100
402 |
403 |
404 |
405 |
406 | -
407 |
408 |
409 | QLayout::SetMinAndMaxSize
410 |
411 |
-
412 |
413 |
414 | Qt::Horizontal
415 |
416 |
417 | QSizePolicy::Fixed
418 |
419 |
420 |
421 | 40
422 | 20
423 |
424 |
425 |
426 |
427 | -
428 |
429 |
430 | QLayout::SetNoConstraint
431 |
432 |
433 |
434 | -
435 |
436 |
437 | Qt::Horizontal
438 |
439 |
440 | QSizePolicy::Fixed
441 |
442 |
443 |
444 | 40
445 | 20
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 | File Systems
459 |
460 |
461 | -
462 |
463 |
464 |
465 | 0
466 | 0
467 |
468 |
469 |
470 | Qt::ScrollBarAlwaysOn
471 |
472 |
473 | Qt::ScrollBarAlwaysOn
474 |
475 |
476 | QAbstractScrollArea::AdjustIgnored
477 |
478 |
479 | QAbstractItemView::NoEditTriggers
480 |
481 |
482 | QAbstractItemView::NoSelection
483 |
484 |
485 | QAbstractItemView::SelectItems
486 |
487 |
488 | true
489 |
490 |
491 | false
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
520 |
521 |
522 | About
523 |
524 |
525 |
526 |
527 | Quit
528 |
529 |
530 |
531 |
532 | Preferences
533 |
534 |
535 |
536 |
537 |
538 |
539 | QCustomPlot
540 | QWidget
541 |
542 | 1
543 |
544 |
545 |
546 |
547 |
548 |
--------------------------------------------------------------------------------
/memoryconverter.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #include "memoryconverter.h"
19 | #include
20 | #include
21 |
22 | /**
23 | * @brief memoryConverter::memoryConverter Constructor taking standard enum value
24 | * @param value The value of the memory to represent
25 | * @param unit The unit the value is in
26 | * @param standard The standard to show the units for
27 | */
28 | memoryConverter::memoryConverter(double value, memoryUnit unit,
29 | unitStandard standard)
30 | {
31 | memoryConverter::memoryEntry converted = fitMemoryValueToUnit(value, unit, getStandardKbSize(standard));
32 | this->memoryValue = converted.id;
33 | this->unit = converted.unit;
34 | this->standard = standard;
35 | }
36 |
37 | /**
38 | * @brief memoryConverter::memoryConverter Constructor taking string standard name
39 | * @param value The value of the memory to represent
40 | * @param unit The unit the memory is in
41 | * @param standard The standard to show the unit for
42 | */
43 | memoryConverter::memoryConverter(double value, memoryUnit unit, std::string standard) :
44 | memoryConverter(value, unit, memoryConverter::stringToStandard(standard))
45 | {
46 | ;
47 | }
48 |
49 | /**
50 | * @brief memoryConverter::memoryConverter Copy ctor
51 | * @param other The other converter
52 | */
53 | memoryConverter::memoryConverter(const memoryConverter &other)
54 | {
55 | this->memoryValue = other.getValue();
56 | this->unit = other.getUnit();
57 | this->standard = other.getStandard();
58 | }
59 |
60 | /**
61 | * @brief memoryConverter::operator= Assignment operator
62 | * @param other The other converter
63 | * @return this
64 | */
65 | memoryConverter& memoryConverter::operator=(const memoryConverter& other)
66 | {
67 | this->memoryValue = other.getValue();
68 | this->unit = other.getUnit();
69 | this->standard = other.getStandard();
70 | return *this;
71 | }
72 |
73 | /**
74 | * @brief memoryConverter::operator< Comparison operator
75 | * @param other The other converter
76 | * @return if this < other
77 | */
78 | bool memoryConverter::operator<(const memoryConverter &other) const
79 | {
80 | memoryUnit otherUnit = other.unit;
81 | double otherValue = other.memoryValue;
82 |
83 | if (((int)unit) < ((int)otherUnit)) { return true; }
84 | if (((int)unit) > ((int)otherUnit)) { return false; }
85 | // must be equal, return the bigger of the 2 values
86 |
87 | return memoryValue < otherValue;
88 | }
89 |
90 | /**
91 | * @brief memoryConverter::getValue Get the value of the converter
92 | * @return The memory value
93 | */
94 | double memoryConverter::getValue() const
95 | {
96 | return memoryValue;
97 | }
98 |
99 | /**
100 | * @brief memoryConverter::getUnit Get the units
101 | * @return The unit the memory has
102 | */
103 | memoryUnit memoryConverter::getUnit() const
104 | {
105 | return unit;
106 | }
107 |
108 | /**
109 | * @brief memoryConverter::getStandard Get the standard the unit uses
110 | * @return The standard used
111 | */
112 | unitStandard memoryConverter::getStandard() const
113 | {
114 | return standard;
115 | }
116 |
117 | /**
118 | * @brief memoryConverter::getStandardKbSize Get the number of bytes in a kb based on the standard
119 | * @param standard The standard used
120 | * @return The number of bytes in a kb
121 | */
122 | int memoryConverter::getStandardKbSize(unitStandard standard)
123 | {
124 | switch(standard) {
125 | case IEC:
126 | case JEDEC:
127 | return 1024;
128 | case SI:
129 | return 1000;
130 | }
131 | return 1;
132 | }
133 |
134 | /**
135 | * @brief memoryConverter::getStandardUnit Get the string representation of a unit based on the standard
136 | * @param standard The standard to use
137 | * @param unit The unit to represent
138 | * @return The string of the representation
139 | */
140 | std::string memoryConverter::getStandardUnit(unitStandard standard, memoryUnit unit)
141 | {
142 | static std::string IEC_units[] = {
143 | "B", "KiB", "MiB", "GiB", "TiB"
144 | };
145 |
146 | static std::string JEDEC_units[] = {
147 | "B", "KB", "MB", "GB", "TB"
148 | };
149 |
150 | static std::string SI_units[] = {
151 | "B", "kB", "MB", "GB", "TB"
152 | };
153 |
154 | // converting this enum into an int causes sigsegv so use the lookup map instead
155 | int pos = 0;
156 | for(; pos kb) {
197 | // too big for the unit it's in
198 | memory /= kb;
199 | unit = nextMemoryUnit(unit);
200 | }
201 | }
202 | return {memory, unit};
203 | }
204 |
205 | /**
206 | * @brief nextMemoryUnit Find the unit which is next after the given unit
207 | * @param unit The unit to find the next unit from
208 | * @return The next unit to the given unit or the given unit if there is no other unit
209 | */
210 | memoryUnit memoryConverter::nextMemoryUnit(memoryUnit unit)
211 | {
212 | for(int i = 0; i memoryLookupLength-1) {
215 | break;
216 | }
217 | return memoryLookup[i+1].unit;
218 | }
219 | }
220 | return unit;
221 | }
222 |
223 | /**
224 | * @brief prevMemoryUnit Find the previous unit which is before the given unit
225 | * @param unit The unit to find the previous unit from
226 | * @return The previous unit or the current unit if there is no previous
227 | */
228 | memoryUnit memoryConverter::prevMemoryUnit(memoryUnit unit)
229 | {
230 | for(int i = 0; iunit - (int)newUnit;
244 | if (mulTimes == 0) {
245 | return;
246 | }
247 |
248 | if (mulTimes < 0) {
249 | this->memoryValue = this->memoryValue / (getStandardKbSize(standard) * abs(mulTimes));
250 | } else {
251 | this->memoryValue = this->memoryValue * (getStandardKbSize(standard) * mulTimes);
252 | }
253 |
254 | this->unit = newUnit;
255 | }
256 |
257 | /**
258 | * @brief memoryConverter::to_string Convert to a string in the format [value] [unit] where value is rounded down to 1 dp
259 | * @return The string representation of the memory
260 | */
261 | std::string memoryConverter::to_string()
262 | {
263 | std::string buffer;
264 | buffer += dbl2str(roundDouble(this->memoryValue, 1));
265 | buffer += " " + getStandardUnit(this->standard, this->unit);
266 | return buffer;
267 | }
268 |
269 | /**
270 | * @brief memoryConverter::getUnitAsString Convert the unit to the standard specific representation and return it as a string
271 | * @return A string for the unit represented in the standard that the memory converter is using
272 | */
273 | std::string memoryConverter::getUnitAsString()
274 | {
275 | return getStandardUnit(this->standard, this->unit);
276 | }
277 |
278 | /**
279 | * @brief memoryConverter::operator std::string @see to_string
280 | */
281 | memoryConverter::operator std::string()
282 | {
283 | return to_string();
284 | }
285 |
286 | /**
287 | * @brief truncateDouble Truncate the decimal precision of a double precision floating point number
288 | * @param input The double to truncate
289 | * @param prec The precision to use
290 | * @return The truncated double
291 | */
292 | double memoryConverter::truncateDouble(double input, unsigned int prec)
293 | {
294 | return std::floor(std::pow(10, prec) * input) / std::pow(10, prec);
295 | }
296 |
297 | /**
298 | * @brief roundDouble Round a double without completely removing trailing decimal places
299 | * @param input The double to round
300 | * @param prec The number of places to round to
301 | * @return The rounded double
302 | */
303 | double memoryConverter::roundDouble(double input, unsigned int prec)
304 | {
305 | return std::roundf(std::pow(10, prec) * input) / std::pow(10, prec);
306 | }
307 |
308 | /* from http://stackoverflow.com/questions/15165502/double-to-string-without-scientific-notation-or-trailing-zeros-efficiently
309 | * User https://stackoverflow.com/users/13005/steve-jessop has given this snippet under a
310 | * "a non-exclusive perpetual license to use, distribute and modify them, and to distribute modifications,
311 | * under any license or none, with or without attribution."
312 | /**
313 | * @brief dbl2str Convert a double to a string while discarding trailing 0's produced from just casting. Taken from SO!
314 | * @param d The double to convert to a string
315 | * @return A string representation of the double
316 | */
317 | std::string memoryConverter::dbl2str(double d)
318 | {
319 | size_t len = std::snprintf(0, 0, "%.10f", d);
320 | std::string s(len+1, 0);
321 | // technically non-portable, see below
322 | std::snprintf(&s[0], len+1, "%.10f", d);
323 | // remove nul terminator
324 | s.pop_back();
325 | // remove trailing zeros
326 | s.erase(s.find_last_not_of('0') + 1, std::string::npos);
327 | // remove trailing point
328 | if(s.back() == '.') {
329 | s.pop_back();
330 | }
331 | return s;
332 | }
333 |
--------------------------------------------------------------------------------
/memoryconverter.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #ifndef MEMORYUNIT_H
19 | #define MEMORYUNIT_H
20 |
21 | #include
22 |
23 | enum memoryUnit {b = 0, kb, mb, gb, tb};
24 | enum unitStandard {
25 | IEC, JEDEC, SI
26 | };
27 |
28 | class memoryConverter
29 | {
30 | public:
31 | memoryConverter(double value, memoryUnit unit, unitStandard standard);
32 | memoryConverter(double value, memoryUnit unit, std::string standard);
33 | memoryConverter() {
34 | memoryValue = 0;
35 | unit = b;
36 | standard = JEDEC;
37 | }
38 | memoryConverter(const memoryConverter &other);
39 | memoryConverter& operator=(const memoryConverter& other);
40 | bool operator <(const memoryConverter &other) const;
41 | operator std::string();
42 | void convertTo(memoryUnit newUnit);
43 | static unitStandard stringToStandard(std::string standard) {
44 | if (standard == "IEC") {
45 | return IEC;
46 | } else if (standard == "JEDEC") {
47 | return JEDEC;
48 | } else if (standard == "SI") {
49 | return SI;
50 | }
51 | return JEDEC;
52 | }
53 | static double truncateDouble(double input, unsigned int prec);
54 | static double roundDouble(double input, unsigned int prec);
55 | static std::string dbl2str(double d);
56 | double getValue() const;
57 | memoryUnit getUnit() const;
58 | std::string getUnitAsString();
59 | unitStandard getStandard() const;
60 | std::string to_string();
61 |
62 | private:
63 | double memoryValue;
64 | memoryUnit unit;
65 | unitStandard standard;
66 | struct memoryEntry {
67 | double id;
68 | memoryUnit unit;
69 | };
70 | int getStandardKbSize(unitStandard standard);
71 | std::string getStandardUnit(unitStandard standard, memoryUnit unit);
72 | memoryEntry fitMemoryValueToUnit(double memory, memoryUnit unit, int kb);
73 | #define memoryLookupLength 5
74 | const memoryEntry memoryLookup[memoryLookupLength] = {
75 | {0, memoryUnit::b},
76 | {1, memoryUnit::kb},
77 | {2, memoryUnit::mb},
78 | {3, memoryUnit::gb},
79 | {4, memoryUnit::tb}
80 | };
81 | memoryUnit nextMemoryUnit(memoryUnit unit);
82 | memoryUnit prevMemoryUnit(memoryUnit unit);
83 | };
84 |
85 | #endif // MEMORYUNIT_H
86 |
--------------------------------------------------------------------------------
/preferencesdialogue.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #include "preferencesdialogue.h"
19 | #include "ui_preferencesdialogue.h"
20 | #include
21 | #include
22 |
23 | PreferencesDialogue::PreferencesDialogue(QWidget *parent, QSettings *settings) :
24 | QDialog(parent),
25 | ui(new Ui::PreferencesDialogue)
26 | {
27 | ui->setupUi(this);
28 | this->settings = settings;
29 |
30 | this->setWindowFlags(Qt::Window);
31 |
32 | QCheckBox *divideByCpuCheckbox = this->findChild("divideByCpuCheckbox");
33 | connect(divideByCpuCheckbox,SIGNAL(clicked(bool)),this,SLOT(toggleDivideCpuCheckbox(bool)));
34 | divideByCpuCheckbox->setChecked(settings->value("divide process cpu by cpu count", false).toBool());
35 |
36 | QDoubleSpinBox *updateIntervalProcessesSpinner = this->findChild("updateIntervalProcessesSpinner");
37 | connect(updateIntervalProcessesSpinner,SIGNAL(valueChanged(double)),this,SLOT(updateProcessesIntervalSpinner(double)));
38 | updateIntervalProcessesSpinner->setValue(settings->value("processes update interval", 1.0).toDouble());
39 |
40 | QDoubleSpinBox *updateIntervalResourcesSpinner = this->findChild("updateIntervalResourcesSpinner");
41 | connect(updateIntervalResourcesSpinner,SIGNAL(valueChanged(double)),this,SLOT(updateResourcesIntervalSpinner(double)));
42 | updateIntervalResourcesSpinner->setValue(settings->value("resources update interval", 1.0).toDouble());
43 |
44 | IECStandard = this->findChild("IECButton");
45 | connect(IECStandard,SIGNAL(toggled(bool)),this,SLOT(updateStandardsRadioButton()));
46 | JEDECStandard = this->findChild("JEDECButton");
47 | connect(JEDECStandard,SIGNAL(toggled(bool)),this,SLOT(updateStandardsRadioButton()));
48 | SIStandard = this->findChild("SIButton");
49 | connect(SIStandard,SIGNAL(toggled(bool)),this,SLOT(updateStandardsRadioButton()));
50 | checkStandardsRadioButtonBasedOnSettingValue();
51 |
52 | QCheckBox* stackedCpuCheckbox = this->findChild("stackedCpuCheckbox");
53 | connect(stackedCpuCheckbox,SIGNAL(clicked(bool)),this,SLOT(toggleStackedCpuCheckbox(bool)));
54 | stackedCpuCheckbox->setChecked(settings->value("draw cpu area stacked", false).toBool());
55 |
56 | std::vector processColShowCheckboxes = {
57 | this->findChild("processSharedCheckbox"),
58 | this->findChild("processNiceCheckbox"),
59 | this->findChild("processStartedCheckbox"),
60 | this->findChild("processUserCheckbox"),
61 | this->findChild("processPidCheckbox"),
62 | this->findChild("processResidentMemoryCheckbox"),
63 | this->findChild("processCpuTimeCheckbox"),
64 | this->findChild("processMemoryCheckbox"),
65 | this->findChild("processCpuCheckbox"),
66 | this->findChild("processCommandlineCheckbox"),
67 | this->findChild("processStatusCheckbox"),
68 | this->findChild("processVirtualMemoryCheckbox"),
69 | this->findChild("processNameCheckbox")
70 | };
71 |
72 | QSignalMapper *signalMapper = new QSignalMapper(this);
73 | connect(signalMapper,SIGNAL(mapped(QWidget*)),this,SLOT(toggleProcessCheckbox(QWidget*)));
74 |
75 | for(unsigned int i=0; i defaultCheckboxes = {
80 | "processNameCheckbox", "processUserCheckbox", "processCpuCheckbox",
81 | "processPidCheckbox", "processMemoryCheckbox"
82 | };
83 | for(unsigned int j=0; jproperty("objectName").toString()) {
85 | isDefaulted = true;
86 | break;
87 | }
88 | }
89 |
90 | currentCheckbox->setChecked(settings->value(currentCheckbox->property("objectName").toString(),isDefaulted).toBool());
91 | signalMapper->setMapping(currentCheckbox, currentCheckbox);
92 | connect(currentCheckbox, SIGNAL(clicked()), signalMapper, SLOT(map()));
93 | }
94 |
95 | QCheckBox* runResourcesThreadInBackgroundCheckbox = this->findChild("resourcesKeepThreadRunning");
96 | connect(runResourcesThreadInBackgroundCheckbox,SIGNAL(clicked(bool)),this,SLOT(toggleResourcesBackgroundCheckbox(bool)));
97 | runResourcesThreadInBackgroundCheckbox->setChecked(settings->value("resourcesKeepThreadRunning", true).toBool());
98 |
99 | QCheckBox* cachedMemoryIsUsed = this->findChild("cachedMemoryIsUsed");
100 | connect(cachedMemoryIsUsed,SIGNAL(clicked(bool)),this,SLOT(toggleCachedIsUsedCheckbox(bool)));
101 | cachedMemoryIsUsed->setChecked(settings->value("cachedMemoryIsUsed", false).toBool());
102 |
103 | QCheckBox* smoothGraphs = this->findChild("smoothGraphs");
104 | connect(smoothGraphs,SIGNAL(clicked(bool)),this,SLOT(toggleSmoothGraphsCheckbox(bool)));
105 | smoothGraphs->setChecked(settings->value("smoothGraphs", false).toBool());
106 | }
107 |
108 | PreferencesDialogue::~PreferencesDialogue()
109 | {
110 | delete ui;
111 | }
112 |
113 | void PreferencesDialogue::toggleDivideCpuCheckbox(bool checked)
114 | {
115 | settings->setValue("divide process cpu by cpu count",checked);
116 | }
117 |
118 | void PreferencesDialogue::toggleStackedCpuCheckbox(bool checked)
119 | {
120 | settings->setValue("draw cpu area stacked",checked);
121 | }
122 |
123 | void PreferencesDialogue::updateProcessesIntervalSpinner(double value)
124 | {
125 | settings->setValue("processes update interval", value);
126 | }
127 |
128 | void PreferencesDialogue::updateResourcesIntervalSpinner(double value)
129 | {
130 | settings->setValue("resources update interval", value);
131 | }
132 |
133 | void PreferencesDialogue::updateStandardsRadioButton()
134 | {
135 | const QString settingName = "unit prefix standards";
136 | // find out which radio button is pressed and write the setting to the file
137 | if (IECStandard->isChecked()) {
138 | settings->setValue(settingName, "IEC");
139 | } else if (JEDECStandard->isChecked()) {
140 | settings->setValue(settingName, "JEDEC");
141 | } else if (SIStandard->isChecked()) { // check even though there are only 3!
142 | settings->setValue(settingName, "SI");
143 | }
144 | }
145 |
146 | void PreferencesDialogue::checkStandardsRadioButtonBasedOnSettingValue()
147 | {
148 | const QString settingName = "unit prefix standards";
149 | // find if the setting is set to the correct name and then set the radio buttons
150 | const QString value = settings->value(settingName, "JEDEC").toString();
151 | if (value == "IEC") {
152 | IECStandard->setChecked(true);
153 | } else if (value == "JEDEC") {
154 | JEDECStandard->setChecked(true);
155 | } else if (value == "SI") {
156 | SIStandard->setChecked(true);
157 | }
158 | }
159 |
160 | void PreferencesDialogue::toggleProcessCheckbox(QWidget* checkbox)
161 | {
162 | QCheckBox* changingCheckbox = (QCheckBox*)checkbox;
163 | settings->setValue(changingCheckbox->property("objectName").toString(),changingCheckbox->isChecked());
164 | }
165 |
166 | void PreferencesDialogue::toggleResourcesBackgroundCheckbox(bool checked)
167 | {
168 | settings->setValue("resourcesKeepThreadRunning", checked);
169 | }
170 |
171 | void PreferencesDialogue::toggleCachedIsUsedCheckbox(bool checked)
172 | {
173 | settings->setValue("cachedMemoryIsUsed", checked);
174 | }
175 |
176 | void PreferencesDialogue::toggleSmoothGraphsCheckbox(bool checked)
177 | {
178 | settings->setValue("smoothGraphs", checked);
179 | }
180 |
--------------------------------------------------------------------------------
/preferencesdialogue.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #ifndef PREFERENCESDIALOG_H
19 | #define PREFERENCESDIALOG_H
20 |
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 |
27 | namespace Ui {
28 | class PreferencesDialogue;
29 | }
30 |
31 | class PreferencesDialogue : public QDialog
32 | {
33 | Q_OBJECT
34 |
35 | public:
36 | explicit PreferencesDialogue(QWidget *parent, QSettings *settings);
37 | ~PreferencesDialogue();
38 |
39 | public slots:
40 | void toggleDivideCpuCheckbox(bool checked);
41 | void updateProcessesIntervalSpinner(double value);
42 | void updateStandardsRadioButton();
43 | void toggleStackedCpuCheckbox(bool checked);
44 | void updateResourcesIntervalSpinner(double value);
45 | void toggleProcessCheckbox(QWidget* checkbox);
46 | void toggleResourcesBackgroundCheckbox(bool checked);
47 | void toggleCachedIsUsedCheckbox(bool checked);
48 | void toggleSmoothGraphsCheckbox(bool checked);
49 |
50 | private:
51 | Ui::PreferencesDialogue *ui;
52 | QSettings *settings;
53 | QRadioButton *IECStandard, *JEDECStandard, *SIStandard;
54 | void checkStandardsRadioButtonBasedOnSettingValue();
55 | };
56 |
57 | #endif // PREFERENCESDIALOG_H
58 |
--------------------------------------------------------------------------------
/preferencesdialogue.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | PreferencesDialogue
4 |
5 |
6 |
7 | 0
8 | 0
9 | 380
10 | 320
11 |
12 |
13 |
14 | Qt::NoContextMenu
15 |
16 |
17 | System monitor preferences
18 |
19 |
20 | -
21 |
22 |
23 | 0
24 |
25 |
26 |
27 | Processes
28 |
29 |
30 |
-
31 |
32 |
-
33 |
34 |
35 | QLayout::SetNoConstraint
36 |
37 |
-
38 |
39 |
40 | Update interval in seconds:
41 |
42 |
43 |
44 | -
45 |
46 |
47 | 0.250000000000000
48 |
49 |
50 | 0.250000000000000
51 |
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 | 75
61 | true
62 |
63 |
64 |
65 | Behaviour
66 |
67 |
68 |
69 | -
70 |
71 |
72 | Divide CPU usage by CPU count
73 |
74 |
75 |
76 |
77 |
78 | -
79 |
80 |
-
81 |
82 |
83 |
84 | 75
85 | true
86 |
87 |
88 |
89 | Information Fields
90 |
91 |
92 |
93 | -
94 |
95 |
96 | Process information shown in list:
97 |
98 |
99 |
100 | -
101 |
102 |
103 | true
104 |
105 |
106 |
107 |
108 | 0
109 | 0
110 | 320
111 | 391
112 |
113 |
114 |
115 |
-
116 |
117 |
-
118 |
119 |
120 | Process Name
121 |
122 |
123 |
124 | -
125 |
126 |
127 | User
128 |
129 |
130 |
131 | -
132 |
133 |
134 | Status
135 |
136 |
137 |
138 | -
139 |
140 |
141 | Virtual Memory
142 |
143 |
144 |
145 | -
146 |
147 |
148 | Resident Memory
149 |
150 |
151 |
152 | -
153 |
154 |
155 | Shared Memory
156 |
157 |
158 |
159 | -
160 |
161 |
162 | % CPU
163 |
164 |
165 |
166 | -
167 |
168 |
169 | CPU Time
170 |
171 |
172 |
173 | -
174 |
175 |
176 | Started
177 |
178 |
179 |
180 | -
181 |
182 |
183 | Nice
184 |
185 |
186 |
187 | -
188 |
189 |
190 | PID
191 |
192 |
193 |
194 | -
195 |
196 |
197 | Command Line
198 |
199 |
200 |
201 | -
202 |
203 |
204 | Memory
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 | Resources
221 |
222 |
223 | -
224 |
225 |
-
226 |
227 |
228 |
229 | 75
230 | true
231 |
232 |
233 |
234 | Graphs
235 |
236 |
237 |
238 | -
239 |
240 |
-
241 |
242 |
243 | Update interval in seconds:
244 |
245 |
246 |
247 | -
248 |
249 |
250 | 0.250000000000000
251 |
252 |
253 | 0.250000000000000
254 |
255 |
256 |
257 |
258 |
259 | -
260 |
261 |
262 | Draw CPU chart as stacked area chart
263 |
264 |
265 |
266 | -
267 |
268 |
269 | Smooth graphs
270 |
271 |
272 |
273 | -
274 |
275 |
276 | Run resources monitor in background
277 |
278 |
279 |
280 | -
281 |
282 |
283 | Include cached memory in used
284 |
285 |
286 |
287 |
288 |
289 | -
290 |
291 |
292 | Qt::Vertical
293 |
294 |
295 |
296 | 20
297 | 40
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 | File Systems
307 |
308 |
309 | -
310 |
311 |
-
312 |
313 |
314 |
315 | 75
316 | true
317 |
318 |
319 |
320 | Behaviour
321 |
322 |
323 |
324 | -
325 |
326 |
-
327 |
328 |
329 | Update interval in seconds:
330 |
331 |
332 |
333 | -
334 |
335 |
336 |
337 |
338 | -
339 |
340 |
341 | CheckBox
342 |
343 |
344 |
345 |
346 |
347 | -
348 |
349 |
-
350 |
351 |
352 |
353 | 75
354 | true
355 |
356 |
357 |
358 | Information Fields
359 |
360 |
361 |
362 | -
363 |
364 |
365 | File system information shown in list:
366 |
367 |
368 |
369 | -
370 |
371 |
372 | true
373 |
374 |
375 |
376 |
377 | 0
378 | 0
379 | 320
380 | 188
381 |
382 |
383 |
384 |
-
385 |
386 |
-
387 |
388 |
389 | CheckBox
390 |
391 |
392 |
393 | -
394 |
395 |
396 | CheckBox
397 |
398 |
399 |
400 | -
401 |
402 |
403 | CheckBox
404 |
405 |
406 |
407 | -
408 |
409 |
410 | CheckBox
411 |
412 |
413 |
414 | -
415 |
416 |
417 | CheckBox
418 |
419 |
420 |
421 | -
422 |
423 |
424 | CheckBox
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 | true
441 |
442 |
443 | General
444 |
445 |
446 | -
447 |
448 |
-
449 |
450 |
-
451 |
452 |
453 | IEC (KiB = 1024 bytes)
454 |
455 |
456 |
457 | -
458 |
459 |
460 | JEDEC (KB = 1024 bytes)
461 |
462 |
463 |
464 | -
465 |
466 |
467 | SI (kB = 1000 bytes)
468 |
469 |
470 |
471 |
472 |
473 | -
474 |
475 |
476 | Unit Standards:
477 |
478 |
479 |
480 | -
481 |
482 |
483 |
484 | 75
485 | true
486 |
487 |
488 |
489 | General
490 |
491 |
492 |
493 |
494 |
495 | -
496 |
497 |
498 | Qt::Vertical
499 |
500 |
501 |
502 | 20
503 | 40
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
--------------------------------------------------------------------------------
/processinformationworker.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #include "processinformationworker.h"
19 | #include
20 | #include
21 | #include "tablenumberitem.h"
22 | #include
23 | #include
24 | #include
25 | #include "tablememoryitem.h"
26 | #include "processpropertiesdialogue.h"
27 | #include "processtools.h"
28 | #include
29 | #include
30 | #include "memoryconverter.h"
31 | using namespace processTools;
32 |
33 | processInformationWorker::processInformationWorker(QObject *parent, QSettings *settings) :
34 | QObject(parent), workerThread() {
35 | mainWindow = parent;
36 | QTabWidget* mainTabs = parent->findChild("tabWidgetMain");
37 | processesTable = mainTabs->findChild("tableProcesses");
38 |
39 | loadAverage = parent->findChild("loadAvgLabel");
40 | connect(this,SIGNAL(updateLoadAverage(QString)),loadAverage,SLOT(setText(QString)));
41 |
42 | totalCpuTime = 0;
43 | selectedRowInfoID = 0;
44 |
45 | QAction* actionStop = new QAction("Stop",processesTable);
46 | connect(actionStop,SIGNAL(triggered(bool)),SLOT(handleProcessStop()));
47 |
48 | QAction* actionKill = new QAction("Kill",processesTable);
49 | connect(actionKill, SIGNAL(triggered(bool)),SLOT(handleProcessKill()));
50 |
51 | QAction* actionProperties = new QAction("Properties",processesTable);
52 | connect(actionProperties,SIGNAL(triggered(bool)),this,SLOT(showProcessProperties()));
53 | connect(processesTable,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(showProcessProperties()));
54 |
55 | QList rightClickActions;
56 | rightClickActions.push_back(actionStop);
57 | rightClickActions.push_back(actionKill);
58 | rightClickActions.push_back(actionProperties);
59 |
60 | processesTable->setContextMenuPolicy(Qt::ActionsContextMenu);
61 | processesTable->addActions(rightClickActions);
62 |
63 | filterCheckbox = mainTabs->findChild("processesFilterCheckbox");
64 | connect(filterCheckbox, SIGNAL(toggled(bool)), this, SLOT(filterCheckboxToggled(bool)));
65 | searchField = mainTabs->findChild("processesSearchField");
66 |
67 | connect(searchField,SIGNAL(textChanged(QString)),this,SLOT(filterProcesses(QString)));
68 | connect(this,SIGNAL(signalFilterProcesses(QString)),this,SLOT(filterProcesses(QString)));
69 | // set a function to run when a row is selected
70 | connect(processesTable->selectionModel(),SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
71 | this,SLOT(changeCurrentTableRowSelection(QModelIndex)));
72 |
73 | connect(this,SIGNAL(updateTableData()),SLOT(updateTable()));
74 | createProcessesView();
75 |
76 | this->settings = settings;
77 |
78 | filterCheckbox->setChecked(this->settings->value("processesFilterCheckbox", true).toBool());
79 | }
80 |
81 | /**
82 | * @brief processInformationWorker::showProcessProperties
83 | * Show the process' properties window. Do not block main thread
84 | */
85 | void processInformationWorker::showProcessProperties()
86 | {
87 | processPropertiesDialogue* properties = new processPropertiesDialogue((QWidget*)mainWindow, selectedRowInfoID, settings);
88 | properties->show();
89 | properties->exec();
90 | }
91 |
92 | void processInformationWorker::filterCheckboxToggled(bool checked)
93 | {
94 | this->settings->setValue("processesFilterCheckbox", checked);
95 | }
96 |
97 | /**
98 | * @brief processInformationWorker::changeCurrentTableRowSelection Select a row in the table of processes and remember its position
99 | * @param current The selection model for the current selection
100 | */
101 | void processInformationWorker::changeCurrentTableRowSelection(QModelIndex current)
102 | {
103 | // remember the tid so we can get the correct row again when we update the table
104 | selectedRowInfoID = processesTable->item(current.row(),3)->text().toInt();
105 | }
106 |
107 | /**
108 | * @brief processInformationWorker::createProcessesView construct the process table with properly resized row heights
109 | */
110 | void processInformationWorker::createProcessesView()
111 | {
112 | processesTable->setColumnCount(5);
113 | processesTable->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
114 | processesTable->setHorizontalHeaderLabels(QString("Process Name;User;% CPU;PID;Memory;").split(";"));
115 | processesTable->verticalHeader()->setVisible(false);
116 | processesTable->setSelectionBehavior(QAbstractItemView::SelectRows);
117 | processesTable->resizeColumnsToContents();
118 | }
119 |
120 | /**
121 | * @brief processInformationWorker::handleProcessStop Function to run when the user selects stop as an option for a process
122 | */
123 | void processInformationWorker::handleProcessStop()
124 | {
125 | /// TODO: ask for privilage escalation when controlling other users' processes
126 | int row = processesTable->currentIndex().row();
127 | // get PID
128 | int pid = processesTable->item(row,3)->text().toInt();
129 |
130 | QMessageBox::StandardButton reply;
131 | std::string info = "Are you sure you want to stop "+processesTable->item(row,0)->text().toStdString();
132 | reply = QMessageBox::question(processesTable, "Info", QString::fromStdString(info),
133 | QMessageBox::Yes|QMessageBox::No);
134 |
135 | if (reply == QMessageBox::Yes) {
136 | // attempt to send signal
137 | if (kill(pid,SIGTERM)!=0) {
138 | if (errno==EPERM) {
139 | // show a dialogue that we did not have permission to SIGTERM pid
140 | QMessageBox::information(processesTable, "Error",
141 | "Could not send signal, permission denied!", QMessageBox::Ok);
142 | }
143 | }
144 | }
145 | }
146 |
147 | /**
148 | * @brief processInformationWorker::handleProcessKill Function to run when the user selects stop as an option for a process
149 | */
150 | void processInformationWorker::handleProcessKill()
151 | {
152 | /// TODO: ask for privilage escalation when controlling other users' processes
153 | int row = processesTable->currentIndex().row();
154 | // get PID
155 | int pid = processesTable->item(row,3)->text().toInt();
156 |
157 | QMessageBox::StandardButton reply;
158 | std::string info = "Are you sure you want to kill "+processesTable->item(row,0)->text().toStdString();
159 | reply = QMessageBox::question(processesTable, "Info", QString::fromStdString(info),
160 | QMessageBox::Yes|QMessageBox::No);
161 |
162 | if (reply == QMessageBox::Yes) {
163 | // attempt to send signal
164 | if (kill(pid,SIGKILL)!=0) {
165 | if (errno==EPERM) {
166 | // show a dialogue that we did not have permission to SIGKILL pid
167 | QMessageBox::information(processesTable, "Error",
168 | "Could not send signal, permission denied!", QMessageBox::Ok);
169 | }
170 | }
171 | }
172 | }
173 |
174 | /**
175 | * @brief processInformationWorker::shouldHideProcess Return if the current row should be hidden when updating the table based on if
176 | * the user has selected to only show processes that they own
177 | * @param pid The pid of the process
178 | * @return True if the process is not owned by the user and they only want to show their processes
179 | */
180 | bool processInformationWorker::shouldHideProcess(unsigned int pid)
181 | {
182 | if (filterCheckbox->checkState() == Qt::CheckState::Checked) {
183 | // if the filter checkbox is checked, we need to make sure that the
184 | // user who owns the process is the same as the user running us
185 | return (pid != geteuid());
186 | }
187 | return false;
188 | }
189 |
190 | /**
191 | * @brief processInformationWorker::filterProcesses Hide all processes which do not match the search term
192 | * @param filter The search term to use
193 | */
194 | void processInformationWorker::filterProcesses(QString filter)
195 | {
196 | filter = filter.toLower();
197 | // loop over the table and hide items which do not match the search term given
198 | // only check col 0 (process name)
199 | for(int i = 0; i < processesTable->rowCount(); i++)
200 | {
201 | // check if the row is already hidden, if so, skip it
202 | /// TODO: find a better fix for this, can't check using QTableWidget
203 | /// so just check the PID manually
204 | if (!shouldHideProcess(getpwnam(processesTable->item(i,1)->text().toStdString().c_str())->pw_uid)) {
205 | QTableWidgetItem* name = processesTable->item(i,0); // process name
206 | QTableWidgetItem* pid = processesTable->item(i, 3);
207 | bool nameContains = name->text().toLower().contains(filter);
208 | bool cmdLineContains = getProcessCmdline(pid->text().toInt()).toLower().contains(filter);
209 | processesTable->setRowHidden(i, (!nameContains && !cmdLineContains));
210 | }
211 | }
212 | }
213 |
214 | /**
215 | * @brief processInformationWorker::updateTable
216 | * Read the list of open processes and list them in the process table
217 | */
218 | void processInformationWorker::updateTable() {
219 | // from http://codingrelic.geekhold.com/2011/02/listing-processes-with-libproc.html
220 | PROCTAB* proc = openproc(PROC_FILLMEM | PROC_FILLSTAT | PROC_FILLSTATUS | PROC_FILLUSR | PROC_FILLCOM);
221 | // proc_info must be static! https://gitlab.com/procps-ng/procps/issues/33
222 | static proc_t proc_info;
223 | memset(&proc_info, 0, sizeof(proc_t));
224 |
225 | storedProcType processes;
226 | while (readproc(proc, &proc_info) != NULL) {
227 | processes[proc_info.tid]=proc_info;
228 | }
229 | closeproc(proc);
230 |
231 | // fill in cpu%
232 | if (prevProcs.size()>0) {
233 | // we have previous proc info
234 | for(auto &newItr:processes) {
235 | auto prevItr = prevProcs[newItr.first];
236 | newItr.second.pcpu = (unsigned int)calculateCPUPercentage(&prevItr, &newItr.second, totalCpuTime);
237 | }
238 | }
239 | // update the cpu time for next loop
240 | totalCpuTime = getTotalCpuTime();
241 |
242 | processesTable->setUpdatesEnabled(false); // avoid inconsistant data
243 | processesTable->setSortingEnabled(false);
244 | processesTable->setRowCount(processes.size());
245 | unsigned int index = 0;
246 | for(auto &i:processes) {
247 | proc_t* p = (&i.second);
248 | QString processName = getProcessName(p);
249 | QTableWidgetItem* processNameTableItem = new QTableWidgetItem(processName);
250 | processNameTableItem->setToolTip(getProcessCmdline(p->tid));
251 | processNameTableItem->setIcon(getProcessIconFromName(processName,processIconCache));
252 | processesTable->setItem(index,0,processNameTableItem);
253 | QString user = p->euser;
254 | processesTable->setItem(index,1,new QTableWidgetItem(user));
255 | //std::cout << p->pcpu << std::endl;
256 | QString cpu = QString::number(settings->value("divide process cpu by cpu count",false).toBool()? p->pcpu/smp_num_cpus:p->pcpu);
257 | processesTable->setItem(index,2,new TableNumberItem(cpu));
258 | QString id = QString::number(p->tid);
259 | processesTable->setItem(index,3,new TableNumberItem(id));
260 | // gnome-system-monitor measures memory as RSS - shared
261 | // shared memory is only given as # pages, sysconf(_SC_PAGES) is in bytes
262 | // so do, (#pages RSS - #pages Share) * _SC_PAGES
263 | memoryConverter memory = memoryConverter((p->resident - p->share)*sysconf(_SC_PAGESIZE),memoryUnit::b,
264 | settings->value("unit prefix standards",JEDEC).toString().toStdString());
265 | processesTable->setItem(index,4,new TableMemoryItem(memory));
266 | processesTable->showRow(index);
267 |
268 | if (shouldHideProcess(p->euid)) {
269 | // hide this row
270 | processesTable->hideRow(index);
271 | }
272 |
273 | // update the row selection to reflect the row that was previously selected
274 | if (selectedRowInfoID>0) {
275 | if (selectedRowInfoID == p->tid) {
276 | // this is the same process
277 | processesTable->selectRow(index);
278 | }
279 | }
280 |
281 | index++;
282 | }
283 |
284 | processesTable->setUpdatesEnabled(true);
285 | processesTable->setSortingEnabled(true);
286 | emit(signalFilterProcesses(searchField->text()));
287 |
288 | // keep processes we've read for cpu calculations next cycle
289 | prevProcs = processes;
290 | }
291 |
292 | /**
293 | * @brief processInformationWorker::loop
294 | * Run the loop for this thread
295 | */
296 | void processInformationWorker::loop()
297 | {
298 | emit(updateTableData());
299 | // get the load average
300 | double load[3];
301 | getloadavg(load,3);
302 | // work out how overloaded the system was in the last minute based on CPU alone
303 | // yes, linux uses more than just CPU in the load calculations
304 | double overload = load[0] - smp_num_cpus;
305 | QString avg = "Load averages for the last 1, 5, 15 minutes: " + QString::number(load[0])
306 | + ", " + QString::number(load[1]) + ", " + QString::number(load[2])
307 | + (overload<0? "":"\nOverloaded by " + QString::number(overload*100) + "% in the last minute!");
308 | emit(updateLoadAverage(avg));
309 | if (settings->value("processes update interval",1.0).toDouble() < 0.25) {
310 | settings->setValue("processes update interval",0.25);
311 | }
312 | std::this_thread::sleep_for(std::chrono::duration(
313 | settings->value("processes update interval",1.0).toDouble() * 1000));
314 | }
315 |
316 |
--------------------------------------------------------------------------------
/processinformationworker.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Lily Rivers (VioletDarkKitty)
3 | *
4 | * This program is free software; you can redistribute it and/or
5 | * modify it under the terms of the GNU General Public License
6 | * as published by the Free Software Foundation; version 3
7 | * of the License only.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program; if not, write to the Free Software
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 | */
18 | #ifndef PROCESSINFORMATIONWORKER_H
19 | #define PROCESSINFORMATIONWORKER_H
20 | #include
21 | #include
22 | #include