├── .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 | 502 | 503 | 504 | 0 505 | 0 506 | 943 507 | 23 508 | 509 | 510 | 511 | 512 | System Monitor 513 | 514 | 515 | 516 | 517 | 518 | 519 | 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 |
qcustomplot.h
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 23 | #include "workerthread.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "hashqstring.h" 33 | 34 | class processInformationWorker : public QObject, public workerThread 35 | { 36 | typedef std::map storedProcType; 37 | Q_OBJECT 38 | public: 39 | explicit processInformationWorker(QObject *parent, QSettings *settings); 40 | 41 | private slots: 42 | void handleProcessStop(); 43 | void handleProcessKill(); 44 | void updateTable(); 45 | void filterProcesses(QString filter); 46 | void changeCurrentTableRowSelection(QModelIndex current); 47 | void showProcessProperties(); 48 | void filterCheckboxToggled(bool checked); 49 | 50 | signals: 51 | void updateTableData(); 52 | void signalFilterProcesses(QString filter); 53 | void updateLoadAverage(QString value); 54 | 55 | private: 56 | void loop(); 57 | QObject* mainWindow; 58 | QTableWidget* processesTable; 59 | void createProcessesView(); 60 | QCheckBox* filterCheckbox; 61 | QLineEdit* searchField; 62 | bool shouldHideProcess(unsigned int pid); 63 | storedProcType prevProcs; 64 | unsigned long long totalCpuTime; 65 | int selectedRowInfoID; 66 | QLabel* loadAverage; 67 | std::unordered_map processIconCache; 68 | QSettings *settings; 69 | }; 70 | 71 | #endif // PROCESSINFORMATIONWORKER_H 72 | -------------------------------------------------------------------------------- /processpropertiesdialogue.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 "processpropertiesdialogue.h" 19 | #include "ui_processpropertiesdialogue.h" 20 | 21 | processPropertiesDialogue::processPropertiesDialogue(QWidget *parent, pid_t pid, QSettings *settings) : 22 | QDialog(parent), 23 | ui(new Ui::processPropertiesDialogue) 24 | { 25 | ui->setupUi(this); 26 | 27 | this->settings = settings; 28 | 29 | processID = pid; 30 | before = NULL; 31 | cpuTime = 0; 32 | 33 | // store the information about constructing the table as a vector of pairs of labels and functions which fill in that label's data 34 | #define MARKUSED(X) ((void)(&(X))) // stop g++ complaining 35 | #define varg(x,y) std::make_pair(x,[this](proc_t* p)->QTableWidgetItem*{MARKUSED(p); y;}) // macro used to reduce the amount of typing in the vector initialisation 36 | // add the actions to the vector 37 | propertiesTableData = { 38 | varg("Process Name",return new QTableWidgetItem(getProcessName(p));), 39 | varg("User",return new QTableWidgetItem(QString(p->euser) + " (" + QString::number(p->euid) + ")");), 40 | varg("Status",return new QTableWidgetItem(getProcessStatus(p));), 41 | varg("Memory",return new TableMemoryItem(memoryConverter((p->resident - p->share)*sysconf(_SC_PAGESIZE),memoryUnit::b,standard));), 42 | varg("Virtual Memory",return new TableMemoryItem(memoryConverter(p->vm_size,memoryUnit::kb,standard));), 43 | varg("Resident Memory",return new TableMemoryItem(memoryConverter(p->vm_rss,memoryUnit::kb,standard));), 44 | varg("Shared Memory",return new TableMemoryItem(memoryConverter(p->share*sysconf(_SC_PAGESIZE),memoryUnit::b,standard));), 45 | varg("CPU",return new TableNumberItem(processPropertiesDialogue::getCpuPercentage(p));), 46 | varg("CPU Time",{unsigned long long s = (p->stime + p->cstime + p->utime + p->cutime)/(float)sysconf(_SC_CLK_TCK); 47 | unsigned long long m = s/60; s = s%60; return new TableNumberItem((QString::number(m)+":"+QString::number(s)));}), 48 | varg("Started",return new QTableWidgetItem(getProcessStartDate(p->start_time));), 49 | varg("Nice",return new TableNumberItem(QString::number(p->nice));), 50 | varg("Priority",return new TableNumberItem(QString::number(p->priority));), 51 | varg("PID",return new TableNumberItem(QString::number(p->tgid));), 52 | varg("Command Line",return new QTableWidgetItem(getProcessCmdline(p->tgid));) 53 | }; 54 | 55 | processInfoTable = this->findChild("processInfoTable"); 56 | processInfoTable->verticalHeader()->setHidden(true); 57 | processInfoTable->horizontalHeader()->setHidden(true); 58 | processInfoTable->setSelectionBehavior(QAbstractItemView::SelectRows); 59 | 60 | processInfoTable->setRowCount(propertiesTableData.size()); 61 | processInfoTable->setColumnCount(2); 62 | // set the labels for the table using the stored data 63 | for(unsigned int i=0; isetItem(i,0,new QTableWidgetItem(propertiesTableData.at(i).first)); 65 | } 66 | 67 | connect(this, SIGNAL(updateTable()), this, SLOT(updateTableData())); 68 | connect(parent,SIGNAL(destroyed(QObject*)),this,SLOT(deleteLater())); 69 | 70 | // hide minimise and maximise buttons 71 | setWindowFlags(Qt::Tool | Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint); 72 | 73 | this->start(); 74 | } 75 | 76 | processPropertiesDialogue::~processPropertiesDialogue() 77 | { 78 | delete ui; 79 | } 80 | 81 | /** 82 | * @brief processPropertiesDialogue::updateTableData 83 | * Update the process' properties table 84 | */ 85 | void processPropertiesDialogue::updateTableData() 86 | { 87 | PROCTAB *tab = openproc(PROC_PID | PROC_FILLMEM | PROC_FILLSTAT | PROC_FILLSTATUS | PROC_FILLUSR | PROC_FILLNS); 88 | proc_t* p; // Don't fill the proc_t struct with any info 89 | 90 | tab->pids = (pid_t*)malloc(sizeof(pid_t)*2); // PROCTAB should clean this up when closeproc is called 91 | tab->pids[0] = processID; 92 | tab->pids[1] = 0; // The array should be 0 terminated 93 | 94 | processInfoTable->setUpdatesEnabled(false); 95 | if ((p=readproc(tab,NULL))==NULL) { 96 | // The process is dead 97 | // GSM shows N/A for some fields in a dead process 98 | processInfoTable->setItem(processStatus,1,new QTableWidgetItem("Dead")); 99 | } else { 100 | QString procName = getProcessName(p); 101 | // set the window title 102 | QString title = procName + " (" + "PID " + QString::number(p->tid) + ")"; 103 | this->setWindowTitle(title); 104 | // run the function from the propertiesTableData for each row 105 | for(unsigned int i=0; isetItem(i,1,propertiesTableData.at(i).second(p)); 107 | } 108 | } 109 | processInfoTable->resizeColumnsToContents(); 110 | processInfoTable->setUpdatesEnabled(true); 111 | 112 | closeproc(tab); 113 | } 114 | 115 | /** 116 | * @brief processPropertiesDialogue::getCpuPercentage Calculate the cpu % for the process 117 | * @param p The proc_t structure for the process to use 118 | * @return The string containing the process' cpu % 119 | */ 120 | QString processPropertiesDialogue::getCpuPercentage(proc_t* p) 121 | { 122 | QString cpuPercentage; 123 | if (before==NULL) { 124 | cpuPercentage = "0%"; 125 | } else { 126 | cpuPercentage = QString::number((unsigned int)calculateCPUPercentage(before,p,cpuTime)) + "%"; 127 | free(before); 128 | } 129 | before = p; 130 | cpuTime = getTotalCpuTime(); 131 | return cpuPercentage; 132 | } 133 | 134 | /** 135 | * @brief processPropertiesDialogue::loop 136 | * Run the loop for this thread 137 | */ 138 | void processPropertiesDialogue::loop() 139 | { 140 | standard = memoryConverter::stringToStandard(settings->value("unit prefix standards",JEDEC).toString().toStdString()); 141 | emit(updateTable()); 142 | std::this_thread::sleep_for(std::chrono::milliseconds(1000)); 143 | } 144 | -------------------------------------------------------------------------------- /processpropertiesdialogue.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 PROCESSPROPERTIESDIALOGUE_H 19 | #define PROCESSPROPERTIESDIALOGUE_H 20 | 21 | #include 22 | #include 23 | #include "workerthread.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "processtools.h" 29 | #include "tablememoryitem.h" 30 | #include "tablenumberitem.h" 31 | #include "memoryconverter.h" 32 | #include 33 | using namespace processTools; 34 | 35 | namespace Ui { 36 | class processPropertiesDialogue; 37 | } 38 | 39 | class processPropertiesDialogue : public QDialog, public workerThread 40 | { 41 | Q_OBJECT 42 | 43 | public: 44 | explicit processPropertiesDialogue(QWidget *parent, pid_t pid, QSettings *settings); 45 | ~processPropertiesDialogue(); 46 | 47 | signals: 48 | void updateTable(); 49 | 50 | private slots: 51 | void updateTableData(); 52 | 53 | private: 54 | Ui::processPropertiesDialogue *ui; 55 | QSettings *settings; 56 | pid_t processID; 57 | void loop(); 58 | QTableWidget* processInfoTable; 59 | enum { 60 | processName=0, processUser, processStatus, processMemory, processVirtual, 61 | processResident, processShared, processCPU, processCPUTime, processStarted, 62 | processNice, processPriority, processPID, processCmdLine, processLastItem 63 | } processPropertiesTableValue; 64 | QString getCpuPercentage(proc_t* p); 65 | std::vector>> propertiesTableData; 66 | proc_t* before; 67 | double cpuTime; 68 | unitStandard standard; 69 | }; 70 | 71 | #endif // PROCESSPROPERTIESDIALOGUE_H 72 | -------------------------------------------------------------------------------- /processpropertiesdialogue.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | processPropertiesDialogue 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | QAbstractItemView::NoEditTriggers 21 | 22 | 23 | false 24 | 25 | 26 | Qt::NoPen 27 | 28 | 29 | true 30 | 31 | 32 | true 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /processtools.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 "processtools.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 "hashqstring.h" 31 | 32 | namespace processTools { 33 | /* from http://stackoverflow.com/questions/24581908/c-lstat-on-proc-pid-exe 34 | * User explicitly gave allowences for using this code via email 35 | */ 36 | /** 37 | * @brief exe_of Obtain the executable path a process is running 38 | * @param pid: Process ID 39 | * @param sizeptr: If specified, the allocated size is saved here 40 | * @param lenptr: If specified, the path length is saved here 41 | * @return the dynamically allocated pointer to the path, or NULL with errno set if an error occurs. 42 | */ 43 | char* exe_of(const pid_t pid, size_t *const sizeptr, size_t *const lenptr) 44 | { 45 | char *exe_path = NULL; 46 | size_t exe_size = 1024; 47 | ssize_t exe_used; 48 | char path_buf[64]; 49 | unsigned int path_len; 50 | 51 | path_len = snprintf(path_buf, sizeof path_buf, "/proc/%ld/exe", (long)pid); 52 | if (path_len < 1 || path_len >= sizeof path_buf) { 53 | errno = ENOMEM; 54 | return NULL; 55 | } 56 | 57 | while (1) { 58 | 59 | exe_path = (char*)malloc(exe_size); 60 | if (!exe_path) { 61 | errno = ENOMEM; 62 | return NULL; 63 | } 64 | 65 | exe_used = readlink(path_buf, exe_path, exe_size - 1); 66 | if (exe_used == (ssize_t)-1) { 67 | free(exe_path); 68 | return NULL; 69 | } 70 | 71 | if (exe_used < (ssize_t)1) { 72 | /* Race condition? */ 73 | errno = ENOENT; 74 | free(exe_path); 75 | return NULL; 76 | } 77 | 78 | if (exe_used < (ssize_t)(exe_size - 1)) 79 | break; 80 | 81 | free(exe_path); 82 | exe_size += 1024; 83 | } 84 | 85 | /* Try reallocating the exe_path to minimum size. 86 | * This is optional, and can even fail without 87 | * any bad effects. */ 88 | { 89 | char *temp; 90 | 91 | temp = (char*)realloc(exe_path, exe_used + 1); 92 | if (temp) { 93 | exe_path = temp; 94 | exe_size = exe_used + 1; 95 | } 96 | } 97 | 98 | if (sizeptr) 99 | *sizeptr = exe_size; 100 | 101 | if (lenptr) 102 | *lenptr = exe_used; 103 | 104 | exe_path[exe_used] = '\0'; 105 | return exe_path; 106 | } 107 | 108 | /** 109 | * @brief explode Explode a string based on 110 | * @param s The string to explode 111 | * @param c The seperator to use 112 | * @return A vector of the exploded string 113 | */ 114 | const std::vector explode(const std::string& s, const char& c) 115 | { 116 | std::string buff{""}; 117 | std::vector v; 118 | 119 | for(auto n:s) 120 | { 121 | if(n != c) buff+=n; else 122 | if(n == c && buff != "") { v.push_back(buff); buff = ""; } 123 | } 124 | if(buff != "") v.push_back(buff); 125 | 126 | return v; 127 | } 128 | 129 | /** 130 | * @brief getProcessNameFromCmdLine Get the name of the process from its PID 131 | * @param pid the pid of the process to get the name for 132 | * @return The name of the process 133 | */ 134 | QString getProcessNameFromCmdLine(const pid_t pid) 135 | { 136 | std::string cmdline = getProcessCmdline(pid).toStdString(); 137 | 138 | if (cmdline.size()<1) { 139 | return ""; 140 | } 141 | 142 | // maintain linux paths 143 | std::replace(cmdline.begin(),cmdline.end(),'\\','/'); 144 | 145 | auto args = explode(cmdline,' '); 146 | QString name = QFileInfo(QString::fromStdString(args[0])).fileName(); 147 | // replace the name of some processes with their first argument, eg, python, php, ruby etc 148 | // QString does not support hash 149 | static std::unordered_set nameMap({"python", "python2", "python3", "ruby", "php", "perl"}); 150 | auto pos = nameMap.find(name); 151 | if (pos != nameMap.end()) { 152 | return QFileInfo(QString::fromStdString(args[1])).fileName(); 153 | } else { 154 | return name; 155 | } 156 | } 157 | 158 | /** 159 | * @brief getProcessCmdline Get the command line that the process was executed with from its PID 160 | * @param pid The pid of the process to get 161 | * @return The command line that the process was run from 162 | */ 163 | QString getProcessCmdline(pid_t pid) 164 | { 165 | std::string temp; 166 | try { 167 | std::fstream fs; 168 | fs.open("/proc/"+std::to_string((long)pid)+"/cmdline", std::fstream::in); 169 | std::getline(fs,temp); 170 | fs.close(); 171 | } catch(std::ifstream::failure e) { 172 | return "FAILED TO READ PROC"; 173 | } 174 | 175 | // change \0 to ' ' 176 | std::replace(temp.begin(),temp.end(),'\0',' '); 177 | 178 | if (temp.size()<1) { 179 | return ""; 180 | } 181 | return QString::fromStdString(temp); 182 | } 183 | 184 | /** 185 | * @brief getProcessName Get the name of the process from a proc_t 186 | * @param p The proc_t structure to use for getting the name of the process 187 | * @return 188 | */ 189 | QString getProcessName(proc_t* p) 190 | { 191 | QString processName = "ERROR"; 192 | char* temp = NULL;//exe_of(p->tid,NULL,NULL); 193 | // if exe_of fails here, it will be because permission is denied 194 | if (temp!=NULL) { 195 | processName = QFileInfo(temp).fileName(); 196 | free(temp); 197 | } else { 198 | // next try to read from /proc/*//*cmdline 199 | processName = getProcessNameFromCmdLine(p->tid); 200 | if (processName=="") { 201 | // fallback on /proc/*//*stat program name value 202 | // bad because it is limited to 16 chars 203 | processName = p->cmd; 204 | } 205 | } 206 | return processName; 207 | } 208 | 209 | /** 210 | * @brief getTotalCpuTime Read the data from /proc/stat and get the total time the cpu has been busy 211 | * @return The total cpu time 212 | */ 213 | unsigned long long getTotalCpuTime() 214 | { 215 | // from https://github.com/scaidermern/top-processes/blob/master/top_proc.c#L54 216 | FILE* file = fopen("/proc/stat", "r"); 217 | if (file == NULL) { 218 | perror("Could not open stat file"); 219 | return 0; 220 | } 221 | 222 | char buffer[1024]; 223 | unsigned long long user = 0, nice = 0, system = 0, idle = 0; 224 | // added between Linux 2.5.41 and 2.6.33, see man proc(5) 225 | unsigned long long iowait = 0, irq = 0, softirq = 0, steal = 0, guest = 0, guestnice = 0; 226 | 227 | char* ret = fgets(buffer, sizeof(buffer) - 1, file); 228 | if (ret == NULL) { 229 | perror("Could not read stat file"); 230 | fclose(file); 231 | return 0; 232 | } 233 | fclose(file); 234 | 235 | sscanf(buffer, 236 | "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", 237 | &user, &nice, &system, &idle, &iowait, &irq, &softirq, &steal, &guest, &guestnice); 238 | 239 | // sum everything up (except guest and guestnice since they are already included 240 | // in user and nice, see http://unix.stackexchange.com/q/178045/20626) 241 | return user + nice + system + idle + iowait + irq + softirq + steal; 242 | } 243 | 244 | /** 245 | * @brief calculateCPUPercentage 246 | * @param before - old proc_t of the process 247 | * @param after - new proc_t of the process 248 | * @param cpuTime - the last total cpu time measurement 249 | * @return The cpu percentage of the process 250 | */ 251 | double calculateCPUPercentage(const proc_t* before, const proc_t* after, const unsigned long long &cpuTime) 252 | { 253 | double cpuTimeA = getTotalCpuTime() - cpuTime; 254 | unsigned long long processcpuTime = ((after->utime + after->stime) 255 | - (before->utime + before->stime)); 256 | /// TODO: GSM has an option to divide by # cpus 257 | return (processcpuTime / cpuTimeA) * 100.0 * sysconf(_SC_NPROCESSORS_CONF); 258 | } 259 | 260 | /** 261 | * @brief getProcessStartDate Convert a timestamp into a date in the form that is used in the current locale 262 | * @param start_time The timestamp 263 | * @return A date string 264 | */ 265 | QString getProcessStartDate(unsigned long long start_time) 266 | { 267 | __time_t time = getbtime() + start_time/Hertz; 268 | struct tm *tm = localtime(&time); 269 | char date[255]; 270 | strftime(date, sizeof(date), "%Ex %ER", tm); 271 | return QString(date); 272 | } 273 | 274 | /** 275 | * @brief getProcessStatus Get the status of a process as a long string from its proc_t 276 | * @param p The proc_t structure of the process 277 | * @return The long string form of the process status 278 | */ 279 | QString getProcessStatus(proc_t* p) 280 | { 281 | switch(p->state) { 282 | case 'S': 283 | return "Sleeping"; 284 | break; 285 | 286 | case 'R': 287 | return "Running"; 288 | break; 289 | 290 | case 'Z': 291 | return "Zombie"; 292 | break; 293 | 294 | case 'D': 295 | return "Uninterruptible Sleep"; 296 | break; 297 | 298 | case 'T': 299 | return "Stopped"; 300 | break; 301 | 302 | default: 303 | return "Unknown state: '" + QString(p->state) + "'"; 304 | } 305 | } 306 | 307 | /** 308 | * @brief getProcessIconFromName Get the icon for a process given its name 309 | * @param procname The name of the process 310 | * @return The process' icon or the default executable icon if none was found 311 | */ 312 | QIcon getProcessIconFromName(QString procName, std::unordered_map &processIconMapCache) 313 | { 314 | // check we havent already got the icon in the cache 315 | auto pos = processIconMapCache.find(procName); 316 | if (pos != processIconMapCache.end()) { 317 | return pos->second; 318 | } 319 | 320 | // apply some corrections to the process name 321 | // ie, sh should look for terminal icons, not anything containing sh 322 | static std::map procNameCorrections({ 323 | {"sh","terminal"}, {"bash","terminal"}, {"dconf-service", "dconf"}, {"gconfd-2", "dconf"}, {"deja-dup-monitor", "deja-dup"} 324 | }); 325 | auto procPos = procNameCorrections.find(procName); 326 | if (procPos != procNameCorrections.end()) { 327 | procName = procPos->second; 328 | } 329 | 330 | // search /usr/share/applications for the desktop file that corresponds to the proc and get its icon 331 | QDirIterator dir("/usr/share/applications", QDirIterator::Subdirectories); 332 | QString desktopFile; 333 | QIcon defaultExecutableIcon = QIcon::fromTheme("application-x-executable"); 334 | while(dir.hasNext()) { 335 | if (dir.fileInfo().suffix() == "desktop") { 336 | if (dir.fileName().toLower().contains(procName.toLower())) { 337 | desktopFile = dir.filePath(); 338 | break; 339 | } 340 | } 341 | dir.next(); 342 | } 343 | 344 | if (desktopFile.size() == 0) { 345 | return defaultExecutableIcon; 346 | } 347 | 348 | QIcon icon = defaultExecutableIcon; 349 | QString iconName; 350 | QFile in(desktopFile); 351 | in.open(QIODevice::ReadOnly); 352 | while(!in.atEnd()) { 353 | iconName = in.readLine().trimmed(); 354 | if (iconName.startsWith("Icon=")) { 355 | iconName.remove(0,5); // remove the first 5 chars 356 | } else { 357 | continue; 358 | } 359 | 360 | if (iconName.contains("/")) { 361 | // this is probably a path to the file, use that instead of the theme icon name 362 | icon = QIcon(iconName); 363 | } else { 364 | icon = QIcon::fromTheme(iconName,defaultExecutableIcon); 365 | break; 366 | } 367 | } 368 | in.close(); 369 | 370 | processIconMapCache[procName] = icon; 371 | return icon; 372 | } 373 | } 374 | -------------------------------------------------------------------------------- /processtools.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 PROCESSTOOLS 19 | #define PROCESSTOOLS 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace processTools { 26 | QString getProcessName(proc_t* p); 27 | double calculateCPUPercentage(const proc_t* before, const proc_t* after, const unsigned long long &cpuTime); 28 | QString getProcessCmdline(pid_t pid); 29 | QString getProcessStartDate(unsigned long long start_time); 30 | QString getProcessStatus(proc_t* p); 31 | unsigned long long getTotalCpuTime(); 32 | QIcon getProcessIconFromName(QString procName, std::unordered_map &processIconMapCache); 33 | } 34 | 35 | #endif // PROCESSTOOLS 36 | 37 | -------------------------------------------------------------------------------- /resourcesworker.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 "resourcesworker.h" 19 | #include 20 | #include 21 | #include 22 | #include "cputools.h" 23 | #include "memoryconverter.h" 24 | #include 25 | #include "colourhelper.h" 26 | using namespace cpuTools; 27 | using namespace colourHelper; 28 | 29 | resourcesWorker::resourcesWorker(QObject *parent, QSettings *settings) 30 | : QObject(parent), workerThread() 31 | { 32 | memoryBar = parent->findChild("memoryBar"); 33 | memoryLabel = parent->findChild("memoryLabel"); 34 | swapBar = parent->findChild("swapBar"); 35 | swapLabel = parent->findChild("swapLabel"); 36 | 37 | networkRecievingLabel = parent->findChild("networkRecievingLabel"); 38 | networkRecievingTotalLabel = parent->findChild("networkTotalRecievedLabel"); 39 | networkRecievingColourButton = parent->findChild("networkRecievingColourButton"); 40 | networkSendingLabel = parent->findChild("networkSendingLabel"); 41 | networkSendingTotalLabel = parent->findChild("networkTotalSentLabel"); 42 | networkSendingColourButton = parent->findChild("networkSendingColourButton"); 43 | 44 | connect(this,SIGNAL(updateMemoryBar(int)),memoryBar,SLOT(setValue(int))); 45 | connect(this,SIGNAL(updateMemoryText(QString)),memoryLabel,SLOT(setText(QString))); 46 | connect(this,SIGNAL(updateSwapBar(int)),swapBar,SLOT(setValue(int))); 47 | connect(this,SIGNAL(updateSwapText(QString)),swapLabel,SLOT(setText(QString))); 48 | 49 | connect(this,SIGNAL(updateNetworkRecieving(QString)),networkRecievingLabel,SLOT(setText(QString))); 50 | connect(this,SIGNAL(updateNetworkRecievingTotal(QString)),networkRecievingTotalLabel,SLOT(setText(QString))); 51 | connect(networkRecievingColourButton, SIGNAL(clicked(bool)), this, SLOT(createColourDialogue()), Qt::UniqueConnection); 52 | connect(this,SIGNAL(updateNetworkSending(QString)),networkSendingLabel,SLOT(setText(QString))); 53 | connect(this,SIGNAL(updateNetworkSendingTotal(QString)),networkSendingTotalLabel,SLOT(setText(QString))); 54 | connect(networkSendingColourButton, SIGNAL(clicked(bool)), this, SLOT(createColourDialogue()), Qt::UniqueConnection); 55 | 56 | /// TODO: this is horrible 57 | struct__intArrayHolder defaultRecieving; 58 | memset(&defaultRecieving, 0, sizeof(struct__intArrayHolder)); 59 | defaultRecieving.array[2] = 255; 60 | struct__intArrayHolder defaultSending; 61 | memset(&defaultSending, 0, sizeof(struct__intArrayHolder)); 62 | defaultSending.array[0] = 255; 63 | defaultColours[networkRecievingColourButton->objectName()] = defaultRecieving; 64 | defaultColours[networkSendingColourButton->objectName()] = defaultSending; 65 | 66 | this->settings = settings; 67 | } 68 | 69 | resourcesWorker::~resourcesWorker() 70 | { 71 | 72 | } 73 | 74 | void resourcesWorker::updateCpu() 75 | { 76 | std::vector cpuTimes = getCpuTimes(); 77 | if (prevCpuTimes.size() != 0) { 78 | std::vector cpuPercentages = calculateCpuPercentages(cpuTimes, prevCpuTimes); 79 | 80 | /*for(unsigned int i=0; i> plottingData = QVector>(); 92 | 93 | // The data is arranged in vectors but each vector has points that are intended 94 | // for multiple plots on multi core machines. 95 | // Seperate out the data by reading the number of doubles in the initial vector 96 | if (cpuPlotData.size() == 0) { 97 | return; // obviously we cant read the initial vector if it is blank 98 | } 99 | 100 | for(unsigned int i=0; i headingVector; 102 | headingVector.push_back(cpuPlotData.at(0).at(i)); 103 | plottingData.push_back(headingVector); 104 | } 105 | 106 | // now that the initial qvectors are filled, we can append the rest of the data 107 | for(unsigned int i=1; i0; j--) { 116 | plottingData[i].push_front((double)0); 117 | } 118 | } 119 | 120 | emit(updateCpuPlotSIG(plottingData)); 121 | } 122 | 123 | void resourcesWorker::createColourDialogue() 124 | { 125 | QColor defaultColour = colourHelper::createColourFromSettings(settings, sender()->objectName(), defaultColours[sender()->objectName()].array); 126 | QColor newColour = QColorDialog::getColor(defaultColour, (QWidget*) this->parent()); 127 | if (newColour.isValid()) { 128 | colourHelper::saveColourToSettings(settings, sender()->objectName(), newColour); 129 | } 130 | } 131 | 132 | /** 133 | * @brief resourcesWorker::updateMemory Calculate the used memory and emit signals 134 | */ 135 | void resourcesWorker::updateMemory() 136 | { 137 | memoryConverter mainUsed; 138 | // GSM includes cached/buffered memory in the used memory but excludes shared memory 139 | if (settings->value("cachedMemoryIsUsed", false).toBool()) { 140 | mainUsed = memoryConverter(kb_main_used + kb_main_buffers + kb_main_cached - kb_main_shared,memoryUnit::kb,standard); 141 | } else { 142 | mainUsed = memoryConverter(kb_main_used,memoryUnit::kb,standard); 143 | } 144 | 145 | memoryConverter mainTotal = memoryConverter(kb_main_total,memoryUnit::kb,standard); 146 | 147 | memoryConverter mainUsedCopy = mainUsed; 148 | mainUsedCopy.convertTo(mainTotal.getUnit()); 149 | double memory = (mainUsedCopy.getValue() / mainTotal.getValue()) * 100; 150 | emit(updateMemoryBar(memory)); 151 | std::string memPercent = memoryConverter::dbl2str(memoryConverter::truncateDouble(memoryConverter::roundDouble(memory, 1),1)); 152 | 153 | std::string memoryText = mainUsed.to_string() + " (" + memPercent + "%) of " + mainTotal.to_string(); 154 | emit(updateMemoryText(QString::fromStdString(memoryText))); 155 | } 156 | 157 | /** 158 | * @brief resourcesWorker::updateSwap Calculate used swap and emit the appropriate signals 159 | * If there is no swap, display 0 160 | */ 161 | void resourcesWorker::updateSwap() 162 | { 163 | if (kb_swap_total > 0.0) { 164 | // swap is active 165 | double swap = ((double)kb_swap_used / kb_swap_total) * 100; 166 | emit(updateSwapBar(swap)); 167 | 168 | memoryConverter swapUsed = memoryConverter(kb_swap_used,memoryUnit::kb,standard); 169 | memoryConverter swapTotal = memoryConverter(kb_swap_total,memoryUnit::kb,standard); 170 | 171 | // cleanup the swap values 172 | std::string swapPercent = memoryConverter::dbl2str(memoryConverter::truncateDouble(memoryConverter::roundDouble(swap, 1),1)); 173 | 174 | std::string swapText = swapUsed.to_string() + " (" + swapPercent + "%) of " + swapTotal.to_string(); 175 | emit(updateSwapText(QString::fromStdString(swapText))); 176 | } else { 177 | // there is no swap 178 | emit(updateSwapBar(0)); 179 | emit(updateSwapText("Not Available")); 180 | } 181 | } 182 | 183 | /** 184 | * @brief resourcesWorker::updateNetwork Search for network interfaces and total their sending and recieving bytes for display 185 | * and then display them 186 | */ 187 | void resourcesWorker::updateNetwork() 188 | { 189 | static long long lastSentBytes = 0, lastRecievedBytes = 0; 190 | long long totalSentBytes = 0, totalRecievedBytes = 0; 191 | 192 | // search in /sys/class/net for interfaces and total their bytes 193 | // ignore lo as this could look like an idle disconnected system is still sending data 194 | /// TODO: have an option to include lo traffic 195 | 196 | QDirIterator dirIt("/sys/class/net",QDirIterator::NoIteratorFlags); 197 | while (dirIt.hasNext()) { 198 | dirIt.next(); 199 | 200 | if (dirIt.fileName() == "." || dirIt.fileName() == "..") { 201 | continue; 202 | } 203 | 204 | // follow symbolic links to check for folders that link to ../../devices/virtual/[name] as these are not true interfaces, lo is also virtual 205 | QFileInfo fInfo = QFileInfo(dirIt.filePath()); 206 | QString path = fInfo.canonicalFilePath(); 207 | 208 | if (path.contains("/devices/virtual/net/")) { 209 | continue; 210 | } 211 | 212 | // total bytes from this folder 213 | QFile sending(QString(path + "/statistics/tx_bytes")); 214 | sending.open(QIODevice::ReadOnly); 215 | //qDebug() << "tx " << dirIt.fileName() << sending.readLine(); 216 | totalSentBytes += QString(sending.readLine()).toLongLong(); 217 | QFile recieving(QString(path + "/statistics/rx_bytes")); 218 | recieving.open(QIODevice::ReadOnly); 219 | totalRecievedBytes += QString(recieving.readLine()).toLongLong(); 220 | } 221 | 222 | long long sentSinceLastCheck = totalSentBytes - lastSentBytes; 223 | long long recievedSinceLastCheck = totalRecievedBytes - lastRecievedBytes; 224 | 225 | // used to scale the per second measurements to actually be for one second 226 | double waitDuration = settings->value("resources update interval",1.0).toDouble(); 227 | 228 | memoryConverter sending = memoryConverter(sentSinceLastCheck / waitDuration,memoryUnit::b,standard); 229 | emit(updateNetworkSending(QString::fromStdString(sending.to_string())+"/s")); 230 | 231 | memoryConverter recieving = memoryConverter(recievedSinceLastCheck / waitDuration,memoryUnit::b,standard); 232 | emit(updateNetworkRecieving(QString::fromStdString(recieving.to_string())+"/s")); 233 | 234 | memoryConverter sent = memoryConverter(totalSentBytes,memoryUnit::b,standard); 235 | emit(updateNetworkSendingTotal(QString::fromStdString(sent.to_string()))); 236 | 237 | memoryConverter recieved = memoryConverter(totalRecievedBytes,memoryUnit::b,standard); 238 | emit(updateNetworkRecievingTotal(QString::fromStdString(recieved.to_string()))); 239 | 240 | // prepare the data for plotting 241 | // this qvector is of 2 elements, the first being recieving and the second sending 242 | static QVector> plottingData = QVector>(); 243 | 244 | if (plottingData.empty()) { 245 | // fill with initial data 246 | for(int i=0; i<2; i++) { 247 | plottingData.push_back(QVector()); 248 | for(unsigned int j=0; j<60; j++) { 249 | plottingData[i].push_back(memoryConverter(0,memoryUnit::b,standard)); 250 | } 251 | } 252 | } 253 | 254 | if (lastSentBytes != 0) { 255 | plottingData[0].pop_front(); 256 | plottingData[0].push_back(recieving); 257 | plottingData[1].pop_front(); 258 | plottingData[1].push_back(sending); 259 | 260 | emit(updateNetworkPlotSIG(plottingData)); 261 | } 262 | 263 | lastSentBytes = totalSentBytes; 264 | lastRecievedBytes = totalRecievedBytes; 265 | 266 | QPixmap recievingColour = QPixmap(networkRecievingColourButton->width(), networkRecievingColourButton->height()); 267 | recievingColour.fill(createColourFromSettings(settings, networkRecievingColourButton->objectName(), 268 | defaultColours[networkRecievingColourButton->objectName()].array)); 269 | networkRecievingColourButton->setIcon(QIcon(recievingColour)); 270 | 271 | QPixmap sendingColour = QPixmap(networkSendingColourButton->width(), networkSendingColourButton->height()); 272 | sendingColour.fill(createColourFromSettings(settings, networkSendingColourButton->objectName(), 273 | defaultColours[networkSendingColourButton->objectName()].array)); 274 | networkSendingColourButton->setIcon(QIcon(sendingColour)); 275 | } 276 | 277 | /** 278 | * @brief resourcesWorker::loop Loop this threads execution 279 | */ 280 | void resourcesWorker::loop() 281 | { 282 | clock_t begin = clock(); 283 | 284 | if (settings->value("resources update interval",1.0).toDouble() < 0.25) { 285 | settings->setValue("resources update interval",0.25); 286 | } 287 | 288 | meminfo(); // have procps read the memory 289 | //std::cout << kb_main_used << "/" << kb_main_total << std::endl; 290 | //std::cout << memory << "%" << std::endl; 291 | 292 | standard = memoryConverter::stringToStandard(settings->value("unit prefix standards", JEDEC).toString().toStdString()); 293 | 294 | updateCpu(); 295 | updateMemory(); 296 | updateSwap(); 297 | updateNetwork(); 298 | 299 | // only wait for enough time to fill the interval as some time has been used for calculations 300 | clock_t end = clock(); 301 | double elapsedSecs = double(end - begin) / CLOCKS_PER_SEC; 302 | 303 | double waitTime = settings->value("resources update interval",1.0).toDouble() - elapsedSecs; 304 | 305 | if (waitTime >= 0) { 306 | std::this_thread::sleep_for(std::chrono::duration(waitTime* 1000)); 307 | } 308 | } 309 | -------------------------------------------------------------------------------- /resourcesworker.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 RESOURCESWORKER_H 19 | #define RESOURCESWORKER_H 20 | #include 21 | #include "workerthread.h" 22 | #include 23 | #include 24 | #include "qcustomplot.h" 25 | #include 26 | #include 27 | #include "cputools.h" 28 | #include 29 | #include 30 | #include "memoryconverter.h" 31 | #include 32 | 33 | typedef QVector> qcustomplotCpuVector; 34 | typedef QVector> qcustomplotNetworkVector; 35 | 36 | // qhash wont take an array as a value for some reason, ptr not working 37 | struct struct__intArrayHolder { 38 | int array[3]; 39 | }; 40 | 41 | class resourcesWorker : public QObject, public workerThread 42 | { 43 | Q_OBJECT 44 | public: 45 | explicit resourcesWorker(QObject *parent, QSettings *settings); 46 | const QHash getColourDefaults() { 47 | return defaultColours; 48 | } 49 | 50 | ~resourcesWorker(); 51 | signals: 52 | void updateMemoryBar(int value); 53 | void updateMemoryText(QString value); 54 | void updateSwapBar(int value); 55 | void updateSwapText(QString value); 56 | void updateCpuPlotSIG(const qcustomplotCpuVector &values); 57 | void updateNetworkRecieving(QString value); 58 | void updateNetworkRecievingTotal(QString value); 59 | void updateNetworkSending(QString value); 60 | void updateNetworkSendingTotal(QString value); 61 | void updateNetworkPlotSIG(const qcustomplotNetworkVector &values); 62 | private: 63 | void loop(); 64 | QProgressBar *memoryBar, *swapBar; 65 | QLabel *memoryLabel, *swapLabel; 66 | void updateMemory(); 67 | void updateSwap(); 68 | void updateCpu(); 69 | std::vector prevCpuTimes; 70 | std::deque> cpuPlotData; 71 | QSettings *settings; 72 | unitStandard standard; 73 | QLabel *networkRecievingLabel, *networkRecievingTotalLabel, *networkSendingLabel, *networkSendingTotalLabel; 74 | void updateNetwork(); 75 | QPushButton *networkRecievingColourButton, *networkSendingColourButton; 76 | QHash defaultColours; 77 | public slots: 78 | void createColourDialogue(); 79 | }; 80 | 81 | #endif // RESOURCESWORKER_H 82 | -------------------------------------------------------------------------------- /system-monitor.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Version=1.0 3 | Name=System Monitor 4 | Comment=View current processes and monitor system state 5 | Type=Application 6 | Icon=utilities-system-monitor 7 | Terminal=false 8 | Exec=system-monitor 9 | Categories=Utility 10 | Keywords=Monitor;System;Process;CPU;Memory;Network;History;Usage;Performance;Task;Manager; 11 | -------------------------------------------------------------------------------- /system-monitor.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2016-08-08T12:24:53 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui printsupport 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = system-monitor 12 | TEMPLATE = app 13 | 14 | target.path = /usr/bin 15 | 16 | desktop.path = /usr/share/applications 17 | desktop.files += system-monitor.desktop 18 | 19 | INSTALLS += target desktop 20 | 21 | #icon.path = utilities-system-monitor 22 | #icon.files += system-monitor.png 23 | 24 | VERSION_MAJOR = 0 25 | VERSION_MINOR = 0 26 | VERSION_BUILD = 121 27 | 28 | DEFINES += "VERSION_MAJOR=$$VERSION_MAJOR"\ 29 | "VERSION_MINOR=$$VERSION_MINOR"\ 30 | "VERSION_BUILD=$$VERSION_BUILD" 31 | 32 | #Target version 33 | VERSION = $${VERSION_MAJOR}.$${VERSION_MINOR}.$${VERSION_BUILD} 34 | 35 | SOURCES += main.cpp\ 36 | mainwindow.cpp \ 37 | processinformationworker.cpp \ 38 | workerthread.cpp \ 39 | resourcesworker.cpp \ 40 | filesystemworker.cpp \ 41 | processpropertiesdialogue.cpp \ 42 | processtools.cpp \ 43 | aboutdialogue.cpp \ 44 | qcustomplot.cpp \ 45 | cputools.cpp \ 46 | preferencesdialogue.cpp \ 47 | memoryconverter.cpp \ 48 | colourhelper.cpp 49 | 50 | HEADERS += mainwindow.h \ 51 | processinformationworker.h \ 52 | tablenumberitem.h \ 53 | workerthread.h \ 54 | resourcesworker.h \ 55 | tablememoryitem.h \ 56 | filesystemworker.h \ 57 | processpropertiesdialogue.h \ 58 | processtools.h \ 59 | aboutdialogue.h \ 60 | qcustomplot.h \ 61 | cputools.h \ 62 | preferencesdialogue.h \ 63 | hashqstring.h \ 64 | memoryconverter.h \ 65 | colourhelper.h 66 | 67 | FORMS += mainwindow.ui \ 68 | processpropertiesdialogue.ui \ 69 | aboutdialogue.ui \ 70 | preferencesdialogue.ui 71 | 72 | QMAKE_CXXFLAGS += -std=c++14 -Wall 73 | LIBS += -L"libprocps6" -lprocps -lstdc++fs 74 | 75 | DISTFILES += \ 76 | system-monitor.desktop 77 | -------------------------------------------------------------------------------- /tablememoryitem.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 TABLEMEMORYITEM_H 19 | #define TABLEMEMORYITEM_H 20 | #include 21 | #include "memoryconverter.h" 22 | 23 | class TableMemoryItem : public QTableWidgetItem 24 | { 25 | public: 26 | TableMemoryItem(memoryConverter memory) 27 | :QTableWidgetItem(calculateTxt(&memory)) 28 | { 29 | this->memory = memory; 30 | } 31 | 32 | bool operator <(const QTableWidgetItem &other) const 33 | { 34 | // return true if other is greater than this 35 | if (other.text() == "N/A") { return false; } 36 | const TableMemoryItem& otherMemoryItem = dynamic_cast(other); 37 | 38 | return memory < otherMemoryItem.memory; 39 | } 40 | protected: 41 | memoryConverter memory; 42 | private: 43 | static QString calculateTxt(memoryConverter *memory) { 44 | if (memory->getValue() > 0.0) { 45 | return QString::fromStdString(memory->to_string()); 46 | } 47 | return "N/A"; 48 | } 49 | }; 50 | 51 | #endif // TABLEMEMORYITEM_H 52 | 53 | -------------------------------------------------------------------------------- /tablenumberitem.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 TABLENUMBERITEM_H 19 | #define TABLENUMBERITEM_H 20 | 21 | // from http://stackoverflow.com/questions/7848683/how-to-sort-datas-in-qtablewidget 22 | 23 | class TableNumberItem : public QTableWidgetItem 24 | { 25 | public: 26 | TableNumberItem(const QString txt = QString("0")) 27 | :QTableWidgetItem(txt) 28 | { 29 | } 30 | bool operator <(const QTableWidgetItem &other) const 31 | { 32 | QString str1 = text(); 33 | QString str2 = other.text(); 34 | 35 | /*if (str1[0] == '$' || str1[0] == '€') { 36 | str1.remove(0, 1); 37 | str2.remove(0, 1); // we assume both items have the same format 38 | }*/ 39 | 40 | if (str1[str1.length() - 1] == '%') { 41 | str1.chop(1); 42 | str2.chop(1); // this works for "N%" and for "N %" formatted strings 43 | } 44 | 45 | return str1.toDouble() < str2.toDouble(); 46 | } 47 | }; 48 | 49 | #endif // TABLENUMBERITEM_H 50 | -------------------------------------------------------------------------------- /workerthread.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 "workerthread.h" 19 | 20 | workerThread::workerThread() 21 | { 22 | shouldQuit = false; 23 | shouldPause = false; 24 | workerThreadThread = nullptr; 25 | } 26 | 27 | workerThread::~workerThread() 28 | { 29 | // wait for the thread to exit gracefully! 30 | quit(); 31 | while(running()) { 32 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 33 | } 34 | } 35 | 36 | /** 37 | * @brief workerThread::start Start the thread 38 | */ 39 | void workerThread::start() 40 | { 41 | if (workerThreadThread!=nullptr) { 42 | throw std::exception(); 43 | } 44 | 45 | workerThreadThread = new std::thread( 46 | &workerThread::run,this); 47 | workerThreadThread->detach(); 48 | } 49 | 50 | /** 51 | * @brief workerThread::quit Mark the thread as quiting 52 | * The thread may take some time to exit after this is done, please wait until running shows false 53 | */ 54 | void workerThread::quit() 55 | { 56 | shouldQuit = true; 57 | shouldPause = false; 58 | } 59 | 60 | /** 61 | * @brief workerThread::running Return if the thread is running and not going to pause next loop 62 | * @return If the thread is running 63 | */ 64 | bool workerThread::running() 65 | { 66 | return (workerThreadThread!=nullptr) && !shouldPause; 67 | } 68 | 69 | /** 70 | * @brief workerThread::setPaused Set the pause state for the thread 71 | * @param pause If the thread should be paused when it next loops 72 | */ 73 | void workerThread::setPaused(bool pause) 74 | { 75 | shouldPause = pause; 76 | } 77 | 78 | /** 79 | * @brief workerThread::run Begin looping this thread 80 | * Extended classes are expected to have a loop function to run 81 | * Blocking functions should be kept to a minimum in derived threads as quit will only set flags not throw 82 | */ 83 | void workerThread::run() 84 | { 85 | try { 86 | while(1) { 87 | loop(); 88 | 89 | while(shouldPause) { 90 | std::this_thread::sleep_for(std::chrono::milliseconds(1)); 91 | } 92 | 93 | if (shouldQuit) { 94 | /// TODO: Use a better exception, other functions may throw 95 | throw std::exception(); 96 | } 97 | } 98 | } catch (std::exception &e) { 99 | shouldQuit = false; 100 | delete workerThreadThread; 101 | workerThreadThread = nullptr; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /workerthread.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 WORKERTHREAD_H 19 | #define WORKERTHREAD_H 20 | #include 21 | 22 | class workerThread 23 | { 24 | public: 25 | workerThread(); 26 | virtual ~workerThread(); 27 | void quit(); 28 | void start(); 29 | bool running(); 30 | void setPaused(bool pause); 31 | private: 32 | bool shouldQuit; 33 | bool shouldPause; 34 | void run(); 35 | virtual void loop(){} 36 | std::thread* workerThreadThread; 37 | }; 38 | 39 | #endif // WORKERTHREAD_H 40 | --------------------------------------------------------------------------------