pax_global_header00006660000000000000000000000064134156705610014522gustar00rootroot0000000000000052 comment=115469860b6765df636c58955e79aee4b983cefd nvtop-1.0.0/000077500000000000000000000000001341567056100126665ustar00rootroot00000000000000nvtop-1.0.0/.gitignore000066400000000000000000000000231341567056100146510ustar00rootroot00000000000000*.o *ctags build/* nvtop-1.0.0/CMakeLists.txt000066400000000000000000000116621341567056100154340ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.1) #///////////////////////////////////////////////////////////////////# # PROJECT # #///////////////////////////////////////////////////////////////////# project(nvtop VERSION 1.0.0 LANGUAGES C) set(default_build_type "Release") # Default build type if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to '${default_build_type}' as none was specified.") set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE) endif() set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) #///////////////////////////////////////////////////////////////////# # DEPENDENCIES # #///////////////////////////////////////////////////////////////////# if(NVML_RETRIEVE_HEADER_ONLINE) file(DOWNLOAD "https://raw.githubusercontent.com/NVIDIA/nvidia-settings/master/src/nvml.h" ${PROJECT_BINARY_DIR}/include/nvml.h) endif() list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_CURRENT_SOURCE_DIR}/cmake) find_package(NVML REQUIRED) add_library(nvml INTERFACE IMPORTED) set_property(TARGET nvml PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NVML_INCLUDE_DIRS}) set_property(TARGET nvml PROPERTY INTERFACE_LINK_LIBRARIES ${NVML_LIBRARIES}) set(CURSES_NEED_NCURSES TRUE) # Try to find ncurses with unicode support first set(CURSES_NEED_WIDE TRUE) find_package(Curses QUIET) if (NOT CURSE_FOUND) # Fallback to regular ncurses library, which may also support unicode! set(CURSES_NEED_WIDE FALSE) find_package(Curses REQUIRED) endif() add_library(ncurses INTERFACE IMPORTED) set_property(TARGET ncurses PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CURSES_INCLUDE_DIRS}) set_property(TARGET ncurses PROPERTY INTERFACE_LINK_LIBRARIES ${CURSES_LIBRARIES}) #///////////////////////////////////////////////////////////////////# # COMPILATION OPTIONS # #///////////////////////////////////////////////////////////////////# # Use full RPATH on build tree set(CMAKE_SKIP_BUILD_RPATH FALSE) # Do not build with install RPATH set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) # Set the RPATH when install set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # Only set RPATH if the installation directory is not a system directory LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) if("${isSystemDir}" STREQUAL "-1") set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") else() set(CMAKE_INSTALL_RPATH "") endif() add_subdirectory(src) #///////////////////////////////////////////////////////////////////# # INSTALL # #///////////////////////////////////////////////////////////////////# configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/manpage/nvtop.in" "${CMAKE_CURRENT_BINARY_DIR}/manpage/nvtop" IMMEDIATE @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/manpage/nvtop" DESTINATION share/man/man1/ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ RENAME nvtop.1) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) #///////////////////////////////////////////////////////////////////# # PACKAGING # #///////////////////////////////////////////////////////////////////# #set(CPACK_PACKAGE_NAME "nvtop") #set(CPACK_PACKAGE_VENDOR "Maxime Schmitt") #set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "NVIDIA GPU monitoring tool") #set(CPACK_PACKAGE_DESCRIPTION #"Nvtop is a htop-like monitoring tool for NVIDIA GPUs. It can print GPUs information such as GPU and memory usage, temperature and active processes.") #set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/README.markdown") #set(CPACK_PACKAGE_EXECUTABLES "nvtop") #set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) #set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) #set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) #set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "x86-64") #set(CPACK_DEBIAN_PACKAGE_DEPENDS "") #set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Maxime Schmitt ") #set(CPACK_DEBIAN_PACKAGE_SECTION "Utilities") #set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") #set(CPACK_RPM_PACKAGE_ARCHITECTURE "amd64") #set(CPACK_RPM_PACKAGE_RELEASE 1) #set(CPACK_RPM_PACKAGE_LICENSE "GPL3+") #set(CPACK_RPM_PACKAGE_REQUIRES "") #set(CPACK_GENERATOR "TGZ;TBZ2") #list(APPEND CPACK_GENERATOR "DEB") # .deb package build #list(APPEND CPACK_GENERATOR "RPM") # .rpm package build #set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2;ZIP") #set(CPACK_SOURCE_IGNORE_FILES #.git* #/.*build.* #) #include(CPack) nvtop-1.0.0/COPYING000066400000000000000000001045131341567056100137250ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . nvtop-1.0.0/LICENSE000077700000000000000000000000001341567056100147212COPYINGustar00rootroot00000000000000nvtop-1.0.0/README.markdown000066400000000000000000000101251341567056100153660ustar00rootroot00000000000000NVTOP ===== What is NVTOP? -------------- Nvtop stands for NVidia TOP, a (h)top like task monitor for NVIDIA GPUs. It can handle multiple GPUs and print information about them in a htop familiar way. Because a picture is worth a thousand words: ![NVTOP interface](/screenshot/NVTOP_ex1.png) Table of Contents ----------------- 1. [NVTOP Options and Interactive Commands](#nvtop-options-and-interactive-commands) 1. [GPU Support](#gpu-support) 1. [Build](#build) 1. [Ubuntu / Debian](#ubuntu--debian) 1. [Fedora / RedHat / CentOS](#fedora--redhat--centos) 1. [OpenSUSE](#opensuse) 1. [Arch Linux](#arch-linux) 1. [NVTOP Build](#nvtop-build) 1. [Troubleshoot](#troubleshoot) 1. [License](#license) NVTOP Options and Interactive Commands -------------------------------------- NVTOP comes with a manpage! ```bash man nvtop ``` For quick command line arguments help ```bash nvtop -h nvtop --help ``` GPU Support ----------- The *NVML library* does not support some of the queries for GPUs coming before the Kepler microarchitecture. Anything starting at GeForce 600, GeForce 800M and successor should work fine. For more information about supported GPUs please take a look at the [NVML documentation](http://docs.nvidia.com/deploy/nvml-api/nvml-api-reference.html#nvml-api-reference). Build ----- Two libraries are required: * The *NVIDIA Management Library* (*NVML*) which comes with the GPU driver. * This queries the GPU for information. * The *ncurses* library driving the user interface. * This makes the screen look beautiful. ## Distribution Specific Installation Process ### Ubuntu / Debian - NVIDIA drivers (see [Ubuntu Wiki](https://help.ubuntu.com/community/BinaryDriverHowto/Nvidia) or [Ubuntu PPA](https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa) or [Debian Wiki](https://wiki.debian.org/NvidiaGraphicsDrivers#NVIDIA_Proprietary_Driver)) - CMake, ncurses and git ```bash sudo apt install cmake libncurses5-dev libncursesw5-dev git ``` - NVTOP - Follow the [NVTOP Build](#nvtop-build) ### Fedora / RedHat / CentOS - NVIDIA drivers, **CUDA required for nvml libraries** (see [RPM Fusion](https://rpmfusion.org/Howto/NVIDIA)) - CMake, ncurses and git ```bash sudo dnf install cmake ncurses-devel git ``` - NVTOP - Follow the [NVTOP Build](#nvtop-build) ### OpenSUSE - NVIDIA drivers (see [SUSE Support Database](https://en.opensuse.org/SDB:NVIDIA_drivers)) - CMake, ncurses and git ```bash sudo zypper install cmake ncurses-devel git ``` - NVTOP - Follow the [NVTOP Build](#nvtop-build) ### Arch Linux - NVIDIA drivers (see [Arch Linux wiki](https://wiki.archlinux.org/index.php/NVIDIA)) - CMake, ncurses and git ```bash sudo pacman -S cmake ncurses git ``` - NVTOP - The `nvtop` AUR package - Follow the [NVTOP Build](#nvtop-build) ## NVTOP Build ```bash git clone https://github.com/Syllo/nvtop.git mkdir -p nvtop/build && cd nvtop/build cmake .. # If it errors with "Could NOT find NVML (missing: NVML_INCLUDE_DIRS)" # try the following command instead, otherwise skip to the build with make. cmake .. -DNVML_RETRIEVE_HEADER_ONLINE=True make make install # You may need sufficient permission for that (root) ``` The build system supports multiple build type (e.g. -DCMAKE_BUILD_TYPE=RelWithDebInfo): * Release: Binary without debug information * RelWithDebInfo: Binary with debug information * Debug: Compile with warning flags and address/undefined sanitizers enabled (for development purposes) Troubleshoot ------------ - The plot looks bad - Verify that you installed the wide character version of the NCurses library (libncurses**w**5-dev for Debian / Ubuntu), clean the build directory and restart the build process - If you are using Putty, you should consider adding ``export NCURSES_NO_UTF8_ACS=1`` to your shell initialization script (e.g. ``~/.bashrc``) or execute nvtop as follows: ``NCURSES_NO_UTF8_ACS=1 nvtop`` License ------- Nvtop is licensed under the GPLV3 license or any later version. You will find a copy of the license inside the COPYING file of the repository or at the gnu website <[www.gnu.org/licenses/](http://www.gnu.org/licenses/)>. nvtop-1.0.0/TODO000066400000000000000000000002021341567056100133500ustar00rootroot00000000000000What is in the pipeline: - Add scrollable lists. - Add mouse selection with ncurses. - Add nouveau driver support if possible. nvtop-1.0.0/cmake/000077500000000000000000000000001341567056100137465ustar00rootroot00000000000000nvtop-1.0.0/cmake/cmake_uninstall.cmake.in000066400000000000000000000020241341567056100205240ustar00rootroot00000000000000if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) string(REGEX REPLACE "\n" ";" files "${files}") foreach(file ${files}) message(STATUS "Uninstalling $ENV{DESTDIR}${file}") if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") exec_program( "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" OUTPUT_VARIABLE rm_out RETURN_VALUE rm_retval) if(NOT "${rm_retval}" STREQUAL 0) message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") endif(NOT "${rm_retval}" STREQUAL 0) else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") message(STATUS "File $ENV{DESTDIR}${file} does not exist.") endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") endforeach(file) nvtop-1.0.0/cmake/compile-flags-helpers.cmake000066400000000000000000000053251341567056100211370ustar00rootroot00000000000000function(add_compiler_option_to_target_type TARGET BUILDTYPE VISIBILITY OPTIONS) include(CheckCCompilerFlag) list(APPEND OPTIONS ${ARGN}) foreach(COMPILE_OPTION IN LISTS OPTIONS) string(REPLACE "=" "-" COMPILE_OPTION_NAME "${COMPILE_OPTION}") check_c_compiler_flag(${COMPILE_OPTION} "compiler_has${COMPILE_OPTION_NAME}") if (${compiler_has${COMPILE_OPTION_NAME}}) target_compile_options(${TARGET} ${VISIBILITY} $<$:${COMPILE_OPTION}>) endif() endforeach() endfunction() function(add_compiler_option_to_all_but_target_type TARGET BUILDTYPE VISIBILITY OPTIONS) include(CheckCCompilerFlag) list(APPEND OPTIONS ${ARGN}) foreach(COMPILE_OPTION IN LISTS OPTIONS) string(REPLACE "=" "-" COMPILE_OPTION_NAME "${COMPILE_OPTION}") check_c_compiler_flag(${COMPILE_OPTION} "compiler_has${COMPILE_OPTION_NAME}") if (${compiler_has${COMPILE_OPTION_NAME}}) target_compile_options(${TARGET} ${VISIBILITY} $<$>:${COMPILE_OPTION}>) endif() endforeach() endfunction() function(add_linker_option_to_target_type TARGET BUILDTYPE VISIBILITY OPTIONS) include(CheckCCompilerFlag) list(APPEND OPTIONS ${ARGN}) foreach(LINK_OPTION IN LISTS OPTIONS) string(REPLACE "," "_" LINK_OPTION_NAME "${LINK_OPTION}") check_c_compiler_flag(${LINK_OPTION} "linker_has${LINK_OPTION_NAME}") if (${linker_has${LINK_OPTION_NAME}}) target_link_libraries(${TARGET} ${VISIBILITY} $<$:${LINK_OPTION}>) endif() endforeach() endfunction() function(add_linker_option_to_all_but_target_type TARGET BUILDTYPE VISIBILITY OPTIONS) include(CheckCCompilerFlag) list(APPEND OPTIONS ${ARGN}) foreach(LINK_OPTION IN LISTS OPTIONS) string(REPLACE "," "_" LINK_OPTION_NAME "${LINK_OPTION}") check_c_compiler_flag(${LINK_OPTION} "linker_has${LINK_OPTION_NAME}") if (${linker_has${LINK_OPTION_NAME}}) target_link_libraries(${TARGET} ${VISIBILITY} $<$>:${LINK_OPTION}>) endif() endforeach() endfunction() function(add_sanitizers_to_target TARGET BUILDTYPE VISIBILITY SANITIZERS) list(APPEND SANITIZERS ${ARGN}) foreach(SAN IN LISTS SANITIZERS) set(CMAKE_REQUIRED_FLAGS "-fsanitize=${SAN}") check_c_compiler_flag("-fsanitize=${SAN}" "sanitizer-${SAN}-available") unset(CMAKE_REQUIRED_FLAGS) if (${sanitizer-${SAN}-available}) list(APPEND AVAILABLE_SANITIZERS ${SAN}) endif() endforeach() foreach(SAN IN LISTS AVAILABLE_SANITIZERS) target_compile_options(${TARGET} ${VISIBILITY} $<$:-fsanitize=${SAN}>) target_link_libraries(${TARGET} ${VISIBILITY} $<$:-fsanitize=${SAN}>) endforeach() endfunction() nvtop-1.0.0/cmake/modules/000077500000000000000000000000001341567056100154165ustar00rootroot00000000000000nvtop-1.0.0/cmake/modules/FindCurses.cmake000066400000000000000000000203611341567056100204670ustar00rootroot00000000000000# Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. #.rst: # FindCurses # ---------- # # Find the curses or ncurses include file and library. # # Result Variables # ^^^^^^^^^^^^^^^^ # # This module defines the following variables: # # ``CURSES_FOUND`` # True if Curses is found. # ``CURSES_INCLUDE_DIRS`` # The include directories needed to use Curses. # ``CURSES_LIBRARIES`` # The libraries needed to use Curses. # ``CURSES_HAVE_CURSES_H`` # True if curses.h is available. # ``CURSES_HAVE_NCURSES_H`` # True if ncurses.h is available. # ``CURSES_HAVE_NCURSES_NCURSES_H`` # True if ``ncurses/ncurses.h`` is available. # ``CURSES_HAVE_NCURSES_CURSES_H`` # True if ``ncurses/curses.h`` is available. # # Set ``CURSES_NEED_NCURSES`` to ``TRUE`` before the # ``find_package(Curses)`` call if NCurses functionality is required. # Set ``CURSES_NEED_WIDE`` to ``TRUE`` before the # ``find_package(Curses)`` call if unicode functionality is required. # # Backward Compatibility # ^^^^^^^^^^^^^^^^^^^^^^ # # The following variable are provided for backward compatibility: # # ``CURSES_INCLUDE_DIR`` # Path to Curses include. Use ``CURSES_INCLUDE_DIRS`` instead. # ``CURSES_LIBRARY`` # Path to Curses library. Use ``CURSES_LIBRARIES`` instead. include(CheckLibraryExists) # we don't know anything about cursesw, so only ncurses # may be ncursesw if(NOT CURSES_NEED_WIDE) set(NCURSES_LIBRARY_NAME "ncurses") else() set(NCURSES_LIBRARY_NAME "ncursesw") # Also, if we are searchig fo wide curses - we are actually searching # for ncurses, we don't know about any other unicode version. set(CURSES_NEED_NCURSES TRUE) endif() find_library(CURSES_CURSES_LIBRARY NAMES curses ) find_library(CURSES_NCURSES_LIBRARY NAMES "${NCURSES_LIBRARY_NAME}" ) set(CURSES_USE_NCURSES FALSE) if(CURSES_NCURSES_LIBRARY AND ((NOT CURSES_CURSES_LIBRARY) OR CURSES_NEED_NCURSES)) set(CURSES_USE_NCURSES TRUE) endif() # http://cygwin.com/ml/cygwin-announce/2010-01/msg00002.html # cygwin ncurses stopped providing curses.h symlinks see above # message. Cygwin is an ncurses package, so force ncurses on # cygwin if the curses.h is missing if(CYGWIN) if (CURSES_NEED_WIDE) if(NOT EXISTS /usr/include/ncursesw/curses.h) set(CURSES_USE_NCURSES TRUE) endif() else() if(NOT EXISTS /usr/include/curses.h) set(CURSES_USE_NCURSES TRUE) endif() endif() endif() # Not sure the logic is correct here. # If NCurses is required, use the function wsyncup() to check if the library # has NCurses functionality (at least this is where it breaks on NetBSD). # If wsyncup is in curses, use this one. # If not, try to find ncurses and check if this has the symbol. # Once the ncurses library is found, search the ncurses.h header first, but # some web pages also say that even with ncurses there is not always a ncurses.h: # http://osdir.com/ml/gnome.apps.mc.devel/2002-06/msg00029.html # So at first try ncurses.h, if not found, try to find curses.h under the same # prefix as the library was found, if still not found, try curses.h with the # default search paths. if(CURSES_CURSES_LIBRARY AND CURSES_NEED_NCURSES) include(CMakePushCheckState) cmake_push_check_state() set(CMAKE_REQUIRED_QUIET ${Curses_FIND_QUIETLY}) CHECK_LIBRARY_EXISTS("${CURSES_CURSES_LIBRARY}" wsyncup "" CURSES_CURSES_HAS_WSYNCUP) if(CURSES_NCURSES_LIBRARY AND NOT CURSES_CURSES_HAS_WSYNCUP) CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}" wsyncup "" CURSES_NCURSES_HAS_WSYNCUP) if( CURSES_NCURSES_HAS_WSYNCUP) set(CURSES_USE_NCURSES TRUE) endif() endif() cmake_pop_check_state() endif() if(CURSES_USE_NCURSES) get_filename_component(_cursesLibDir "${CURSES_NCURSES_LIBRARY}" PATH) get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH) # Use CURSES_NCURSES_INCLUDE_PATH if set, for compatibility. if(CURSES_NCURSES_INCLUDE_PATH) if (CURSES_NEED_WIDE) find_path(CURSES_INCLUDE_PATH NAMES ncursesw/ncurses.h ncursesw/curses.h PATHS ${CURSES_NCURSES_INCLUDE_PATH} NO_DEFAULT_PATH ) else() find_path(CURSES_INCLUDE_PATH NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h PATHS ${CURSES_NCURSES_INCLUDE_PATH} NO_DEFAULT_PATH ) endif() endif() if (CURSES_NEED_WIDE) find_path(CURSES_INCLUDE_PATH NAMES ncursesw/ncurses.h ncursesw/curses.h HINTS "${_cursesParentDir}/include" ) else() find_path(CURSES_INCLUDE_PATH NAMES ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h HINTS "${_cursesParentDir}/include" ) endif() # Previous versions of FindCurses provided these values. if(NOT DEFINED CURSES_LIBRARY) set(CURSES_LIBRARY "${CURSES_NCURSES_LIBRARY}") endif() CHECK_LIBRARY_EXISTS("${CURSES_NCURSES_LIBRARY}" cbreak "" CURSES_NCURSES_HAS_CBREAK) if(NOT CURSES_NCURSES_HAS_CBREAK) find_library(CURSES_EXTRA_LIBRARY tinfo HINTS "${_cursesLibDir}") find_library(CURSES_EXTRA_LIBRARY tinfo ) endif() else() get_filename_component(_cursesLibDir "${CURSES_CURSES_LIBRARY}" PATH) get_filename_component(_cursesParentDir "${_cursesLibDir}" PATH) #We can't find anything with CURSES_NEED_WIDE because we know #only about ncursesw unicode curses version if(NOT CURSES_NEED_WIDE) find_path(CURSES_INCLUDE_PATH NAMES curses.h HINTS "${_cursesParentDir}/include" ) endif() # Previous versions of FindCurses provided these values. if(NOT DEFINED CURSES_CURSES_H_PATH) set(CURSES_CURSES_H_PATH "${CURSES_INCLUDE_PATH}") endif() if(NOT DEFINED CURSES_LIBRARY) set(CURSES_LIBRARY "${CURSES_CURSES_LIBRARY}") endif() endif() # Report whether each possible header name exists in the include directory. if(NOT DEFINED CURSES_HAVE_NCURSES_NCURSES_H) if(CURSES_NEED_WIDE) if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h") set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/ncurses.h") endif() elseif(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h") set(CURSES_HAVE_NCURSES_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses/ncurses.h") endif() if(NOT DEFINED CURSES_HAVE_NCURSES_NCURSES_H) set(CURSES_HAVE_NCURSES_NCURSES_H "CURSES_HAVE_NCURSES_NCURSES_H-NOTFOUND") endif() endif() if(NOT DEFINED CURSES_HAVE_NCURSES_CURSES_H) if(CURSES_NEED_WIDE) if(EXISTS "${CURSES_INCLUDE_PATH}/ncursesw/curses.h") set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncursesw/curses.h") endif() elseif(EXISTS "${CURSES_INCLUDE_PATH}/ncurses/curses.h") set(CURSES_HAVE_NCURSES_CURSES_H "${CURSES_INCLUDE_PATH}/ncurses/curses.h") endif() if(NOT DEFINED CURSES_HAVE_NCURSES_CURSES_H) set(CURSES_HAVE_NCURSES_CURSES_H "CURSES_HAVE_NCURSES_CURSES_H-NOTFOUND") endif() endif() if(NOT CURSES_NEED_WIDE) #ncursesw can't be found for this paths if(NOT DEFINED CURSES_HAVE_NCURSES_H) if(EXISTS "${CURSES_INCLUDE_PATH}/ncurses.h") set(CURSES_HAVE_NCURSES_H "${CURSES_INCLUDE_PATH}/ncurses.h") else() set(CURSES_HAVE_NCURSES_H "CURSES_HAVE_NCURSES_H-NOTFOUND") endif() endif() if(NOT DEFINED CURSES_HAVE_CURSES_H) if(EXISTS "${CURSES_INCLUDE_PATH}/curses.h") set(CURSES_HAVE_CURSES_H "${CURSES_INCLUDE_PATH}/curses.h") else() set(CURSES_HAVE_CURSES_H "CURSES_HAVE_CURSES_H-NOTFOUND") endif() endif() endif() find_library(CURSES_FORM_LIBRARY form HINTS "${_cursesLibDir}") find_library(CURSES_FORM_LIBRARY form ) # Previous versions of FindCurses provided these values. if(NOT DEFINED FORM_LIBRARY) set(FORM_LIBRARY "${CURSES_FORM_LIBRARY}") endif() # Need to provide the *_LIBRARIES set(CURSES_LIBRARIES ${CURSES_LIBRARY}) if(CURSES_EXTRA_LIBRARY) set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_EXTRA_LIBRARY}) endif() if(CURSES_FORM_LIBRARY) set(CURSES_LIBRARIES ${CURSES_LIBRARIES} ${CURSES_FORM_LIBRARY}) endif() # Provide the *_INCLUDE_DIRS result. set(CURSES_INCLUDE_DIRS ${CURSES_INCLUDE_PATH}) set(CURSES_INCLUDE_DIR ${CURSES_INCLUDE_PATH}) # compatibility include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Curses DEFAULT_MSG CURSES_LIBRARY CURSES_INCLUDE_PATH) mark_as_advanced( CURSES_INCLUDE_PATH CURSES_CURSES_LIBRARY CURSES_NCURSES_LIBRARY CURSES_EXTRA_LIBRARY CURSES_FORM_LIBRARY ) nvtop-1.0.0/cmake/modules/FindNVML.cmake000066400000000000000000000045211341567056100177770ustar00rootroot00000000000000# Version 1.2 # Public Domain # Written by Maxime SCHMITT #/////////////////////////////////////////////////////////////////////////////# # # # Search for Nvidia nvml library on the system # # Call with find_package(NVML) # # The module defines: # # - NVML_FOUND - If NVML was found # # - NVML_INCLUDE_DIRS - the NVML include directories # # - NVML_LIBRARIES - the NVML library directories # # - NVML_API_VERSION - the NVML api version # # # #/////////////////////////////////////////////////////////////////////////////# if (NVML_INCLUDE_DIRS AND NVML_LIBRARIES) set(NVML_FIND_QUIETLY TRUE) endif() # Headers file(GLOB nvml_header_path_hint /usr/include/nvidia*/include /usr/local/cuda*/include /opt/cuda*/include /usr/lib/*linux-gnu) find_path(NVML_INCLUDE_DIRS NAMES nvml.h PATHS ${nvml_header_path_hint} ${PROJECT_BINARY_DIR}/include) # library if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8") # 64bit file(GLOB nvml_lib_path_hint /usr/lib64/nvidia*/ /usr/lib/nvidia*/) else() # assume 32bit file(GLOB nvml_lib_path_hint /usr/lib32/nvidia*/ /usr/lib/nvidia*/) endif() find_library(NVML_LIBRARIES NAMES nvidia-ml libnvidia-ml.so.1 PATHS ${nvml_lib_path_hint}) # Version set(filename "${NVML_INCLUDE_DIRS}/nvml.h") if (EXISTS ${filename}) file(READ "${filename}" nvml_header) set(nvml_api_version_match "NVML_API_VERSION") string(REGEX REPLACE ".*#[ \t]*define[ \t]*${nvml_api_version_match}[ \t]*([0-9]+).*" "\\1" nvml_api_version "${nvml_header}") if (nvml_api_version STREQUAL nvml_header AND NOT quiet) message(AUTHOR_WARNING "Unable to find nvml api version") else() set(NVML_API_VERSION "${nvml_api_version}") endif() endif(EXISTS ${filename}) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(NVML FOUND_VAR NVML_FOUND REQUIRED_VARS NVML_INCLUDE_DIRS NVML_LIBRARIES VERSION_VAR NVML_API_VERSION) mark_as_advanced(NVML_INCLUDE_DIRS NVML_LIBRARIES NVML_API_VERSION) nvtop-1.0.0/cmake/optimization_flags.cmake000066400000000000000000000015161341567056100206550ustar00rootroot00000000000000set(ADDITIONAL_DEBUG_COMPILE_OPTIONS "-Wall" "-Wpedantic" "-Wextra" "-Waddress" "-Waggressive-loop-optimizations" "-Wcast-qual" "-Wcast-align" "-Wbad-function-cast" "-Wmissing-declarations" "-Wmissing-parameter-type" "-Wmissing-prototypes" "-Wnested-externs" "-Wold-style-declaration" "-Wold-style-definition" "-Wstrict-prototypes" "-Wpointer-sign" "-Wdouble-promotion" "-Wuninitialized" "-Winit-self" "-Wstrict-aliasing" "-Wsuggest-attribute=const" "-Wtrampolines" "-Wfloat-equal" "-Wshadow" "-Wunsafe-loop-optimizations" "-Wfloat-conversion" "-Wlogical-op" "-Wnormalized" "-Wdisabled-optimization" "-Whsa" "-Wconversion" "-Wunused-result" "-Werror=implicit-function-declaration" #"-Wpadded" CACHE INTERNAL "String" ) set(ADDITIONAL_RELEASE_LINK_OPTIONS "-Wl,-z,relro") nvtop-1.0.0/include/000077500000000000000000000000001341567056100143115ustar00rootroot00000000000000nvtop-1.0.0/include/nvtop/000077500000000000000000000000001341567056100154575ustar00rootroot00000000000000nvtop-1.0.0/include/nvtop/extract_gpuinfo.h000066400000000000000000000113751341567056100210400ustar00rootroot00000000000000/* * * Copyright (C) 2017 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #ifndef EXTRACT_GPUINFO_H_ #define EXTRACT_GPUINFO_H_ #include #include #include #include #include #define IS_VALID(x, y) ((y)[(x) / CHAR_BIT] & (1 << ((x) % CHAR_BIT))) #define SET_VALID(x, y) ((y)[(x) / CHAR_BIT] |= (1 << ((x) % CHAR_BIT))) #define RESET_VALID(x, y) ((y)[(x) / CHAR_BIT] &= ~(1 << ((x) % CHAR_BIT))) struct gpu_process { intmax_t pid; // Process ID char *process_name; // Process Name char *user_name; // Process User Name unsigned long long used_memory; // Memory used by process size_t cpu_memory_virt; size_t cpu_memory_res; double cpu_usage; }; enum dev_info_valid { device_name_valid = 0, gpu_clock_speed_valid, gpu_clock_speed_max_valid, mem_clock_speed_valid, mem_clock_speed_max_valid, gpu_util_rate_valid, mem_util_rate_valid, encoder_rate_valid, encoder_sampling_valid, decoder_rate_valid, decoder_sampling_valid, free_memory_valid, total_memory_valid, used_memory_valid, cur_pcie_link_gen_valid, max_pcie_link_gen_valid, cur_pcie_link_width_valid, max_pcie_link_width_valid, pcie_rx_valid, pcie_tx_valid, fan_speed_valid, gpu_temp_valid, gpu_temp_slowdown_valid, gpu_temp_shutdown_valid, power_draw_valid, power_draw_max_valid, valid_max_val, }; struct device_info { nvmlDevice_t device_handle; // Used to query device char device_name[NVML_DEVICE_NAME_BUFFER_SIZE]; // Device Name unsigned int gpu_clock_speed; // Device clock speed in MHz unsigned int gpu_clock_speed_max; // Maximum clock speed in MHz unsigned int mem_clock_speed; // Device clock speed in MHz unsigned int mem_clock_speed_max; // Maximum clock speed in MHz unsigned int gpu_util_rate; // GPU utilization rate in % unsigned int mem_util_rate; // MEM utilization rate in % unsigned int encoder_rate; // Encoder utilization rate in % unsigned int encoder_sampling; // Encoder sampling period in micro sec unsigned int decoder_rate; // Decoder utilization rate in % unsigned int decoder_sampling; // Decoder sampling period in micro sec unsigned long long free_memory; // Unallocated memory (bytes) unsigned long long total_memory; // Total memory (bytes) unsigned long long used_memory; // Allocated memory (bytes) unsigned int cur_pcie_link_gen; // PCIe link generation used unsigned int max_pcie_link_gen; // PCIe link generation max unsigned int cur_pcie_link_width; // PCIe line width used unsigned int max_pcie_link_width; // PCIe line width max unsigned int pcie_rx; // PCIe throughput in KB/s unsigned int pcie_tx; // PCIe throughput in KB/s unsigned int fan_speed; // Fan speed percentage unsigned int gpu_temp; // GPU temperature °c unsigned int gpu_temp_slowdown; // GPU temperature °c unsigned int gpu_temp_shutdown; // GPU temperature °c unsigned int power_draw; // Power usage in milliwatts unsigned int power_draw_max; // Max power usage in milliwatts unsigned int size_proc_buffers; // Number of Compute processes (Cuda) unsigned int num_compute_procs; // Number of Compute processes (Cuda) unsigned int num_graphical_procs; // Number of Graphical processes struct gpu_process *graphic_procs; // Graphical process info struct gpu_process *compute_procs; // Compute processes info nvmlProcessInfo_t *process_infos; // Internal use unsigned char valid[valid_max_val / CHAR_BIT + 1]; // Validity bits }; bool init_gpu_info_extraction(void); bool shutdown_gpu_info_extraction(void); unsigned int initialize_device_info(struct device_info **dev_info, size_t gpu_mask); void update_device_infos(unsigned int num_devs, struct device_info *dev_info); void clean_device_info(unsigned int num_devs, struct device_info *dev_info); void clean_pid_cache(void); #endif // EXTRACT_GPUINFO_H_ nvtop-1.0.0/include/nvtop/get_process_info.h000066400000000000000000000023731341567056100211650ustar00rootroot00000000000000/* * * Copyright (C) 2017 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #ifndef GET_PROCESS_INFO_H_ #define GET_PROCESS_INFO_H_ #include #include #include "nvtop/time.h" struct process_cpu_usage { double total_user_time; // Seconds double total_kernel_time; // Seconds size_t virtual_memory; // Bytes size_t resident_memory; // Bytes nvtop_time time; }; void get_username_from_pid(pid_t pid, char **buffer); void get_command_from_pid(pid_t pid, char **buffer); bool get_process_info(pid_t pid, struct process_cpu_usage *usage); #endif // GET_PROCESS_INFO_H_ nvtop-1.0.0/include/nvtop/interface.h000066400000000000000000000031201341567056100175640ustar00rootroot00000000000000/* * * Copyright (C) 2017-2018 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #ifndef INTERFACE_H_ #define INTERFACE_H_ #include "nvtop/extract_gpuinfo.h" struct nvtop_interface; void show_gpu_infos_ascii(unsigned int num_devices, struct device_info *dev_info); struct nvtop_interface * initialize_curses(unsigned int num_devices, unsigned int biggest_device_name, bool use_color, bool use_fahrenheit, bool show_per_gpu_plot, double encode_decode_hide_time, unsigned collect_interval); void clean_ncurses(struct nvtop_interface *interface); void draw_gpu_info_ncurses(struct device_info *dev_info, struct nvtop_interface *interface); void update_window_size_to_terminal_size(struct nvtop_interface *inter); void interface_key(int keyId, struct nvtop_interface *inter); bool is_escape_for_quit(struct nvtop_interface *inter); #endif // INTERFACE_H_ nvtop-1.0.0/include/nvtop/interface_layout_selection.h000066400000000000000000000014221341567056100232310ustar00rootroot00000000000000#ifndef INTERFACE_LAYOUT_SELECTION_H__ #define INTERFACE_LAYOUT_SELECTION_H__ #include struct layout_selection; enum plot_type { plot_gpu_max, plot_gpu_solo, plot_gpu_duo, }; struct window_position { unsigned posX, posY, sizeX, sizeY; }; char *layout_as_string(struct layout_selection *layout); void compute_sizes_from_layout( bool show_graphs, bool show_header, bool show_process, size_t num_devices, unsigned num_info_per_device, unsigned device_header_rows, unsigned device_header_cols, unsigned rows, unsigned cols, struct window_position *device_position, struct window_position *process_position, unsigned *num_plots, struct window_position **plot_positions, enum plot_type *plot_types); #endif // INTERFACE_LAYOUT_SELECTION_H__ nvtop-1.0.0/include/nvtop/plot.h000066400000000000000000000023531341567056100166110ustar00rootroot00000000000000/* * * Copyright (C) 2018 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #ifndef __PLOT_H_ #define __PLOT_H_ #include #include void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data, double min, double max, unsigned num_plots, const char *legend[]); void nvtop_bar_plot(WINDOW *win, size_t num_data, const double *data, double min, double max); void draw_rectangle(WINDOW *win, unsigned startX, unsigned startY, unsigned sizeX, unsigned sizeY); #endif // __PLOT_H_ nvtop-1.0.0/include/nvtop/time.h000066400000000000000000000044531341567056100165740ustar00rootroot00000000000000/* * * Copyright (C) 2018 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #ifndef NVTOP_TIME_H_ #define NVTOP_TIME_H_ #include #include #ifdef CLOCK_MONOTONIC_RAW #define NVTOP_CLOCK CLOCK_MONOTONIC_RAW #else #define NVTOP_CLOCK CLOCK_MONOTONIC #endif typedef struct timespec nvtop_time; inline void nvtop_get_current_time(nvtop_time *time) { clock_gettime(NVTOP_CLOCK, time); } inline double nvtop_difftime(nvtop_time t0, nvtop_time t1) { double secdiff = difftime(t1.tv_sec, t0.tv_sec); if (t1.tv_nsec < t0.tv_nsec) { long val = 1000000000l - t0.tv_nsec + t1.tv_nsec; secdiff += (double)val / 1e9 - 1.; } else { long val = t1.tv_nsec - t0.tv_nsec; secdiff += (double)val / 1e9; } return secdiff; } inline nvtop_time nvtop_hmns_to_time(unsigned hour, unsigned minutes, unsigned long nanosec) { nvtop_time t = {hour * 60 * 60 + 60 * minutes + nanosec / 1000000, nanosec % 1000000}; return t; } inline nvtop_time nvtop_substract_time(nvtop_time t0, nvtop_time t1) { nvtop_time t = t0.tv_nsec - t1.tv_nsec < 0 ? (nvtop_time){t0.tv_sec - t1.tv_sec - 1, t0.tv_nsec - t1.tv_nsec + 1000000} : (nvtop_time){t0.tv_sec - t1.tv_sec, t0.tv_nsec - t1.tv_nsec}; return t; } inline nvtop_time nvtop_add_time(nvtop_time t0, nvtop_time t1) { nvtop_time t = t0.tv_nsec + t1.tv_nsec > 1000000 ? (nvtop_time){t0.tv_sec + t1.tv_sec + 1, t0.tv_nsec + t1.tv_nsec - 1000000} : (nvtop_time){t0.tv_sec + t1.tv_sec, t0.tv_nsec + t1.tv_nsec}; return t; } #endif // NVTOP_TIME_H_ nvtop-1.0.0/include/nvtop/version.h.in000066400000000000000000000020631341567056100177230ustar00rootroot00000000000000/* * * Copyright (C) 2018 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #ifndef __NVTOP_VERSION_H_ #define __NVTOP_VERSION_H_ #define NVTOP_VERSION_MAJOR @nvtop_VERSION_MAJOR@ #define NVTOP_VERSION_MINOR @nvtop_VERSION_MINOR@ #define NVTOP_VERSION_PATCH @nvtop_VERSION_PATCH@ #define NVTOP_VERSION_STRING "@nvtop_VERSION_MAJOR@.@nvtop_VERSION_MINOR@.@nvtop_VERSION_PATCH@" #endif // __NVTOP_VERSION_H_ nvtop-1.0.0/include/uthash.h000066400000000000000000002303251341567056100157630ustar00rootroot00000000000000/* Copyright (c) 2003-2018, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef UTHASH_H #define UTHASH_H #define UTHASH_VERSION 2.0.2 #include /* memcmp, memset, strlen */ #include /* ptrdiff_t */ #include /* exit */ /* These macros use decltype or the earlier __typeof GNU extension. As decltype is only available in newer compilers (VS2010 or gcc 4.3+ when compiling c++ source) this code uses whatever method is needed or, for VS2008 where neither is available, uses casting workarounds. */ #if !defined(DECLTYPE) && !defined(NO_DECLTYPE) #if defined(_MSC_VER) /* MS compiler */ #if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */ #define DECLTYPE(x) (decltype(x)) #else /* VS2008 or older (or VS2010 in C mode) */ #define NO_DECLTYPE #endif #elif defined(__BORLANDC__) || defined(__ICCARM__) || defined(__LCC__) || defined(__WATCOMC__) #define NO_DECLTYPE #else /* GNU, Sun and other compilers */ #define DECLTYPE(x) (__typeof(x)) #endif #endif #ifdef NO_DECLTYPE #define DECLTYPE(x) #define DECLTYPE_ASSIGN(dst,src) \ do { \ char **_da_dst = (char**)(&(dst)); \ *_da_dst = (char*)(src); \ } while (0) #else #define DECLTYPE_ASSIGN(dst,src) \ do { \ (dst) = DECLTYPE(dst)(src); \ } while (0) #endif /* a number of the hash function use uint32_t which isn't defined on Pre VS2010 */ #if defined(_WIN32) #if defined(_MSC_VER) && _MSC_VER >= 1600 #include #elif defined(__WATCOMC__) || defined(__MINGW32__) || defined(__CYGWIN__) #include #else typedef unsigned int uint32_t; typedef unsigned char uint8_t; #endif #elif defined(__GNUC__) && !defined(__VXWORKS__) #include #else typedef unsigned int uint32_t; typedef unsigned char uint8_t; #endif #ifndef uthash_malloc #define uthash_malloc(sz) malloc(sz) /* malloc fcn */ #endif #ifndef uthash_free #define uthash_free(ptr,sz) free(ptr) /* free fcn */ #endif #ifndef uthash_bzero #define uthash_bzero(a,n) memset(a,'\0',n) #endif #ifndef uthash_memcmp #define uthash_memcmp(a,b,n) memcmp(a,b,n) #endif #ifndef uthash_strlen #define uthash_strlen(s) strlen(s) #endif #ifndef uthash_noexpand_fyi #define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */ #endif #ifndef uthash_expand_fyi #define uthash_expand_fyi(tbl) /* can be defined to log expands */ #endif #ifndef HASH_NONFATAL_OOM #define HASH_NONFATAL_OOM 0 #endif #if HASH_NONFATAL_OOM /* malloc failures can be recovered from */ #ifndef uthash_nonfatal_oom #define uthash_nonfatal_oom(obj) do {} while (0) /* non-fatal OOM error */ #endif #define HASH_RECORD_OOM(oomed) do { (oomed) = 1; } while (0) #define IF_HASH_NONFATAL_OOM(x) x #else /* malloc failures result in lost memory, hash tables are unusable */ #ifndef uthash_fatal #define uthash_fatal(msg) exit(-1) /* fatal OOM error */ #endif #define HASH_RECORD_OOM(oomed) uthash_fatal("out of memory") #define IF_HASH_NONFATAL_OOM(x) #endif /* initial number of buckets */ #define HASH_INITIAL_NUM_BUCKETS 32U /* initial number of buckets */ #define HASH_INITIAL_NUM_BUCKETS_LOG2 5U /* lg2 of initial number of buckets */ #define HASH_BKT_CAPACITY_THRESH 10U /* expand when bucket count reaches */ /* calculate the element whose hash handle address is hhp */ #define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho))) /* calculate the hash handle from element address elp */ #define HH_FROM_ELMT(tbl,elp) ((UT_hash_handle *)(((char*)(elp)) + ((tbl)->hho))) #define HASH_ROLLBACK_BKT(hh, head, itemptrhh) \ do { \ struct UT_hash_handle *_hd_hh_item = (itemptrhh); \ unsigned _hd_bkt; \ HASH_TO_BKT(_hd_hh_item->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \ (head)->hh.tbl->buckets[_hd_bkt].count++; \ _hd_hh_item->hh_next = NULL; \ _hd_hh_item->hh_prev = NULL; \ } while (0) #define HASH_VALUE(keyptr,keylen,hashv) \ do { \ HASH_FCN(keyptr, keylen, hashv); \ } while (0) #define HASH_FIND_BYHASHVALUE(hh,head,keyptr,keylen,hashval,out) \ do { \ (out) = NULL; \ if (head) { \ unsigned _hf_bkt; \ HASH_TO_BKT(hashval, (head)->hh.tbl->num_buckets, _hf_bkt); \ if (HASH_BLOOM_TEST((head)->hh.tbl, hashval) != 0) { \ HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], keyptr, keylen, hashval, out); \ } \ } \ } while (0) #define HASH_FIND(hh,head,keyptr,keylen,out) \ do { \ unsigned _hf_hashv; \ HASH_VALUE(keyptr, keylen, _hf_hashv); \ HASH_FIND_BYHASHVALUE(hh, head, keyptr, keylen, _hf_hashv, out); \ } while (0) #ifdef HASH_BLOOM #define HASH_BLOOM_BITLEN (1UL << HASH_BLOOM) #define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8UL) + (((HASH_BLOOM_BITLEN%8UL)!=0UL) ? 1UL : 0UL) #define HASH_BLOOM_MAKE(tbl,oomed) \ do { \ (tbl)->bloom_nbits = HASH_BLOOM; \ (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN); \ if (!(tbl)->bloom_bv) { \ HASH_RECORD_OOM(oomed); \ } else { \ uthash_bzero((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \ (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \ } \ } while (0) #define HASH_BLOOM_FREE(tbl) \ do { \ uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \ } while (0) #define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8U] |= (1U << ((idx)%8U))) #define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8U] & (1U << ((idx)%8U))) #define HASH_BLOOM_ADD(tbl,hashv) \ HASH_BLOOM_BITSET((tbl)->bloom_bv, ((hashv) & (uint32_t)((1UL << (tbl)->bloom_nbits) - 1U))) #define HASH_BLOOM_TEST(tbl,hashv) \ HASH_BLOOM_BITTEST((tbl)->bloom_bv, ((hashv) & (uint32_t)((1UL << (tbl)->bloom_nbits) - 1U))) #else #define HASH_BLOOM_MAKE(tbl,oomed) #define HASH_BLOOM_FREE(tbl) #define HASH_BLOOM_ADD(tbl,hashv) #define HASH_BLOOM_TEST(tbl,hashv) (1) #define HASH_BLOOM_BYTELEN 0U #endif #define HASH_MAKE_TABLE(hh,head,oomed) \ do { \ (head)->hh.tbl = (UT_hash_table*)uthash_malloc(sizeof(UT_hash_table)); \ if (!(head)->hh.tbl) { \ HASH_RECORD_OOM(oomed); \ } else { \ uthash_bzero((head)->hh.tbl, sizeof(UT_hash_table)); \ (head)->hh.tbl->tail = &((head)->hh); \ (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \ (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head); \ (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc( \ HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket)); \ (head)->hh.tbl->signature = HASH_SIGNATURE; \ if (!(head)->hh.tbl->buckets) { \ HASH_RECORD_OOM(oomed); \ uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ } else { \ uthash_bzero((head)->hh.tbl->buckets, \ HASH_INITIAL_NUM_BUCKETS * sizeof(struct UT_hash_bucket)); \ HASH_BLOOM_MAKE((head)->hh.tbl, oomed); \ IF_HASH_NONFATAL_OOM( \ if (oomed) { \ uthash_free((head)->hh.tbl->buckets, \ HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ } \ ) \ } \ } \ } while (0) #define HASH_REPLACE_BYHASHVALUE_INORDER(hh,head,fieldname,keylen_in,hashval,add,replaced,cmpfcn) \ do { \ (replaced) = NULL; \ HASH_FIND_BYHASHVALUE(hh, head, &((add)->fieldname), keylen_in, hashval, replaced); \ if (replaced) { \ HASH_DELETE(hh, head, replaced); \ } \ HASH_ADD_KEYPTR_BYHASHVALUE_INORDER(hh, head, &((add)->fieldname), keylen_in, hashval, add, cmpfcn); \ } while (0) #define HASH_REPLACE_BYHASHVALUE(hh,head,fieldname,keylen_in,hashval,add,replaced) \ do { \ (replaced) = NULL; \ HASH_FIND_BYHASHVALUE(hh, head, &((add)->fieldname), keylen_in, hashval, replaced); \ if (replaced) { \ HASH_DELETE(hh, head, replaced); \ } \ HASH_ADD_KEYPTR_BYHASHVALUE(hh, head, &((add)->fieldname), keylen_in, hashval, add); \ } while (0) #define HASH_REPLACE(hh,head,fieldname,keylen_in,add,replaced) \ do { \ unsigned _hr_hashv; \ HASH_VALUE(&((add)->fieldname), keylen_in, _hr_hashv); \ HASH_REPLACE_BYHASHVALUE(hh, head, fieldname, keylen_in, _hr_hashv, add, replaced); \ } while (0) #define HASH_REPLACE_INORDER(hh,head,fieldname,keylen_in,add,replaced,cmpfcn) \ do { \ unsigned _hr_hashv; \ HASH_VALUE(&((add)->fieldname), keylen_in, _hr_hashv); \ HASH_REPLACE_BYHASHVALUE_INORDER(hh, head, fieldname, keylen_in, _hr_hashv, add, replaced, cmpfcn); \ } while (0) #define HASH_APPEND_LIST(hh, head, add) \ do { \ (add)->hh.next = NULL; \ (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail); \ (head)->hh.tbl->tail->next = (add); \ (head)->hh.tbl->tail = &((add)->hh); \ } while (0) #define HASH_AKBI_INNER_LOOP(hh,head,add,cmpfcn) \ do { \ do { \ if (cmpfcn(DECLTYPE(head)(_hs_iter), add) > 0) { \ break; \ } \ } while ((_hs_iter = HH_FROM_ELMT((head)->hh.tbl, _hs_iter)->next)); \ } while (0) #ifdef NO_DECLTYPE #undef HASH_AKBI_INNER_LOOP #define HASH_AKBI_INNER_LOOP(hh,head,add,cmpfcn) \ do { \ char *_hs_saved_head = (char*)(head); \ do { \ DECLTYPE_ASSIGN(head, _hs_iter); \ if (cmpfcn(head, add) > 0) { \ DECLTYPE_ASSIGN(head, _hs_saved_head); \ break; \ } \ DECLTYPE_ASSIGN(head, _hs_saved_head); \ } while ((_hs_iter = HH_FROM_ELMT((head)->hh.tbl, _hs_iter)->next)); \ } while (0) #endif #if HASH_NONFATAL_OOM #define HASH_ADD_TO_TABLE(hh,head,keyptr,keylen_in,hashval,add,oomed) \ do { \ if (!(oomed)) { \ unsigned _ha_bkt; \ (head)->hh.tbl->num_items++; \ HASH_TO_BKT(hashval, (head)->hh.tbl->num_buckets, _ha_bkt); \ HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt], hh, &(add)->hh, oomed); \ if (oomed) { \ HASH_ROLLBACK_BKT(hh, head, &(add)->hh); \ HASH_DELETE_HH(hh, head, &(add)->hh); \ (add)->hh.tbl = NULL; \ uthash_nonfatal_oom(add); \ } else { \ HASH_BLOOM_ADD((head)->hh.tbl, hashval); \ HASH_EMIT_KEY(hh, head, keyptr, keylen_in); \ } \ } else { \ (add)->hh.tbl = NULL; \ uthash_nonfatal_oom(add); \ } \ } while (0) #else #define HASH_ADD_TO_TABLE(hh,head,keyptr,keylen_in,hashval,add,oomed) \ do { \ unsigned _ha_bkt; \ (head)->hh.tbl->num_items++; \ HASH_TO_BKT(hashval, (head)->hh.tbl->num_buckets, _ha_bkt); \ HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt], hh, &(add)->hh, oomed); \ HASH_BLOOM_ADD((head)->hh.tbl, hashval); \ HASH_EMIT_KEY(hh, head, keyptr, keylen_in); \ } while (0) #endif #define HASH_ADD_KEYPTR_BYHASHVALUE_INORDER(hh,head,keyptr,keylen_in,hashval,add,cmpfcn) \ do { \ IF_HASH_NONFATAL_OOM( int _ha_oomed = 0; ) \ (add)->hh.hashv = (hashval); \ (add)->hh.key = (char*) (keyptr); \ (add)->hh.keylen = (unsigned) (keylen_in); \ if (!(head)) { \ (add)->hh.next = NULL; \ (add)->hh.prev = NULL; \ HASH_MAKE_TABLE(hh, add, _ha_oomed); \ IF_HASH_NONFATAL_OOM( if (!_ha_oomed) { ) \ (head) = (add); \ IF_HASH_NONFATAL_OOM( } ) \ } else { \ void *_hs_iter = (head); \ (add)->hh.tbl = (head)->hh.tbl; \ HASH_AKBI_INNER_LOOP(hh, head, add, cmpfcn); \ if (_hs_iter) { \ (add)->hh.next = _hs_iter; \ if (((add)->hh.prev = HH_FROM_ELMT((head)->hh.tbl, _hs_iter)->prev)) { \ HH_FROM_ELMT((head)->hh.tbl, (add)->hh.prev)->next = (add); \ } else { \ (head) = (add); \ } \ HH_FROM_ELMT((head)->hh.tbl, _hs_iter)->prev = (add); \ } else { \ HASH_APPEND_LIST(hh, head, add); \ } \ } \ HASH_ADD_TO_TABLE(hh, head, keyptr, keylen_in, hashval, add, _ha_oomed); \ HASH_FSCK(hh, head, "HASH_ADD_KEYPTR_BYHASHVALUE_INORDER"); \ } while (0) #define HASH_ADD_KEYPTR_INORDER(hh,head,keyptr,keylen_in,add,cmpfcn) \ do { \ unsigned _hs_hashv; \ HASH_VALUE(keyptr, keylen_in, _hs_hashv); \ HASH_ADD_KEYPTR_BYHASHVALUE_INORDER(hh, head, keyptr, keylen_in, _hs_hashv, add, cmpfcn); \ } while (0) #define HASH_ADD_BYHASHVALUE_INORDER(hh,head,fieldname,keylen_in,hashval,add,cmpfcn) \ HASH_ADD_KEYPTR_BYHASHVALUE_INORDER(hh, head, &((add)->fieldname), keylen_in, hashval, add, cmpfcn) #define HASH_ADD_INORDER(hh,head,fieldname,keylen_in,add,cmpfcn) \ HASH_ADD_KEYPTR_INORDER(hh, head, &((add)->fieldname), keylen_in, add, cmpfcn) #define HASH_ADD_KEYPTR_BYHASHVALUE(hh,head,keyptr,keylen_in,hashval,add) \ do { \ IF_HASH_NONFATAL_OOM( int _ha_oomed = 0; ) \ (add)->hh.hashv = (hashval); \ (add)->hh.key = (char*) (keyptr); \ (add)->hh.keylen = (unsigned) (keylen_in); \ if (!(head)) { \ (add)->hh.next = NULL; \ (add)->hh.prev = NULL; \ HASH_MAKE_TABLE(hh, add, _ha_oomed); \ IF_HASH_NONFATAL_OOM( if (!_ha_oomed) { ) \ (head) = (add); \ IF_HASH_NONFATAL_OOM( } ) \ } else { \ (add)->hh.tbl = (head)->hh.tbl; \ HASH_APPEND_LIST(hh, head, add); \ } \ HASH_ADD_TO_TABLE(hh, head, keyptr, keylen_in, hashval, add, _ha_oomed); \ HASH_FSCK(hh, head, "HASH_ADD_KEYPTR_BYHASHVALUE"); \ } while (0) #define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add) \ do { \ unsigned _ha_hashv; \ HASH_VALUE(keyptr, keylen_in, _ha_hashv); \ HASH_ADD_KEYPTR_BYHASHVALUE(hh, head, keyptr, keylen_in, _ha_hashv, add); \ } while (0) #define HASH_ADD_BYHASHVALUE(hh,head,fieldname,keylen_in,hashval,add) \ HASH_ADD_KEYPTR_BYHASHVALUE(hh, head, &((add)->fieldname), keylen_in, hashval, add) #define HASH_ADD(hh,head,fieldname,keylen_in,add) \ HASH_ADD_KEYPTR(hh, head, &((add)->fieldname), keylen_in, add) #define HASH_TO_BKT(hashv,num_bkts,bkt) \ do { \ bkt = ((hashv) & ((num_bkts) - 1U)); \ } while (0) /* delete "delptr" from the hash table. * "the usual" patch-up process for the app-order doubly-linked-list. * The use of _hd_hh_del below deserves special explanation. * These used to be expressed using (delptr) but that led to a bug * if someone used the same symbol for the head and deletee, like * HASH_DELETE(hh,users,users); * We want that to work, but by changing the head (users) below * we were forfeiting our ability to further refer to the deletee (users) * in the patch-up process. Solution: use scratch space to * copy the deletee pointer, then the latter references are via that * scratch pointer rather than through the repointed (users) symbol. */ #define HASH_DELETE(hh,head,delptr) \ HASH_DELETE_HH(hh, head, &(delptr)->hh) #define HASH_DELETE_HH(hh,head,delptrhh) \ do { \ struct UT_hash_handle *_hd_hh_del = (delptrhh); \ if ((_hd_hh_del->prev == NULL) && (_hd_hh_del->next == NULL)) { \ HASH_BLOOM_FREE((head)->hh.tbl); \ uthash_free((head)->hh.tbl->buckets, \ (head)->hh.tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ (head) = NULL; \ } else { \ unsigned _hd_bkt; \ if (_hd_hh_del == (head)->hh.tbl->tail) { \ (head)->hh.tbl->tail = HH_FROM_ELMT((head)->hh.tbl, _hd_hh_del->prev); \ } \ if (_hd_hh_del->prev != NULL) { \ HH_FROM_ELMT((head)->hh.tbl, _hd_hh_del->prev)->next = _hd_hh_del->next; \ } else { \ DECLTYPE_ASSIGN(head, _hd_hh_del->next); \ } \ if (_hd_hh_del->next != NULL) { \ HH_FROM_ELMT((head)->hh.tbl, _hd_hh_del->next)->prev = _hd_hh_del->prev; \ } \ HASH_TO_BKT(_hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \ HASH_DEL_IN_BKT((head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del); \ (head)->hh.tbl->num_items--; \ } \ HASH_FSCK(hh, head, "HASH_DELETE_HH"); \ } while (0) /* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */ #define HASH_FIND_STR(head,findstr,out) \ do { \ unsigned _uthash_hfstr_keylen = (unsigned)uthash_strlen(findstr); \ HASH_FIND(hh, head, findstr, _uthash_hfstr_keylen, out); \ } while (0) #define HASH_ADD_STR(head,strfield,add) \ do { \ unsigned _uthash_hastr_keylen = (unsigned)uthash_strlen((add)->strfield); \ HASH_ADD(hh, head, strfield[0], _uthash_hastr_keylen, add); \ } while (0) #define HASH_REPLACE_STR(head,strfield,add,replaced) \ do { \ unsigned _uthash_hrstr_keylen = (unsigned)uthash_strlen((add)->strfield); \ HASH_REPLACE(hh, head, strfield[0], _uthash_hrstr_keylen, add, replaced); \ } while (0) #define HASH_FIND_INT(head,findint,out) \ HASH_FIND(hh,head,findint,sizeof(int),out) #define HASH_ADD_INT(head,intfield,add) \ HASH_ADD(hh,head,intfield,sizeof(int),add) #define HASH_REPLACE_INT(head,intfield,add,replaced) \ HASH_REPLACE(hh,head,intfield,sizeof(int),add,replaced) #define HASH_FIND_PTR(head,findptr,out) \ HASH_FIND(hh,head,findptr,sizeof(void *),out) #define HASH_ADD_PTR(head,ptrfield,add) \ HASH_ADD(hh,head,ptrfield,sizeof(void *),add) #define HASH_REPLACE_PTR(head,ptrfield,add,replaced) \ HASH_REPLACE(hh,head,ptrfield,sizeof(void *),add,replaced) #define HASH_DEL(head,delptr) \ HASH_DELETE(hh,head,delptr) /* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined. * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined. */ #ifdef HASH_DEBUG #define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0) #define HASH_FSCK(hh,head,where) \ do { \ struct UT_hash_handle *_thh; \ if (head) { \ unsigned _bkt_i; \ unsigned _count = 0; \ char *_prev; \ for (_bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; ++_bkt_i) { \ unsigned _bkt_count = 0; \ _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head; \ _prev = NULL; \ while (_thh) { \ if (_prev != (char*)(_thh->hh_prev)) { \ HASH_OOPS("%s: invalid hh_prev %p, actual %p\n", \ (where), (void*)_thh->hh_prev, (void*)_prev); \ } \ _bkt_count++; \ _prev = (char*)(_thh); \ _thh = _thh->hh_next; \ } \ _count += _bkt_count; \ if ((head)->hh.tbl->buckets[_bkt_i].count != _bkt_count) { \ HASH_OOPS("%s: invalid bucket count %u, actual %u\n", \ (where), (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count); \ } \ } \ if (_count != (head)->hh.tbl->num_items) { \ HASH_OOPS("%s: invalid hh item count %u, actual %u\n", \ (where), (head)->hh.tbl->num_items, _count); \ } \ _count = 0; \ _prev = NULL; \ _thh = &(head)->hh; \ while (_thh) { \ _count++; \ if (_prev != (char*)_thh->prev) { \ HASH_OOPS("%s: invalid prev %p, actual %p\n", \ (where), (void*)_thh->prev, (void*)_prev); \ } \ _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh); \ _thh = (_thh->next ? HH_FROM_ELMT((head)->hh.tbl, _thh->next) : NULL); \ } \ if (_count != (head)->hh.tbl->num_items) { \ HASH_OOPS("%s: invalid app item count %u, actual %u\n", \ (where), (head)->hh.tbl->num_items, _count); \ } \ } \ } while (0) #else #define HASH_FSCK(hh,head,where) #endif /* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to * the descriptor to which this macro is defined for tuning the hash function. * The app can #include to get the prototype for write(2). */ #ifdef HASH_EMIT_KEYS #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) \ do { \ unsigned _klen = fieldlen; \ write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \ write(HASH_EMIT_KEYS, keyptr, (unsigned long)fieldlen); \ } while (0) #else #define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) #endif /* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */ #ifdef HASH_FUNCTION #define HASH_FCN HASH_FUNCTION #else #define HASH_FCN HASH_JEN #endif /* The Bernstein hash function, used in Perl prior to v5.6. Note (x<<5+x)=x*33. */ #define HASH_BER(key,keylen,hashv) \ do { \ unsigned _hb_keylen = (unsigned)keylen; \ const unsigned char *_hb_key = (const unsigned char*)(key); \ (hashv) = 0; \ while (_hb_keylen-- != 0U) { \ (hashv) = (((hashv) << 5) + (hashv)) + *_hb_key++; \ } \ } while (0) /* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */ #define HASH_SAX(key,keylen,hashv) \ do { \ unsigned _sx_i; \ const unsigned char *_hs_key = (const unsigned char*)(key); \ hashv = 0; \ for (_sx_i=0; _sx_i < keylen; _sx_i++) { \ hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \ } \ } while (0) /* FNV-1a variation */ #define HASH_FNV(key,keylen,hashv) \ do { \ unsigned _fn_i; \ const unsigned char *_hf_key = (const unsigned char*)(key); \ (hashv) = 2166136261U; \ for (_fn_i=0; _fn_i < keylen; _fn_i++) { \ hashv = hashv ^ _hf_key[_fn_i]; \ hashv = hashv * 16777619U; \ } \ } while (0) #define HASH_OAT(key,keylen,hashv) \ do { \ unsigned _ho_i; \ const unsigned char *_ho_key=(const unsigned char*)(key); \ hashv = 0; \ for(_ho_i=0; _ho_i < keylen; _ho_i++) { \ hashv += _ho_key[_ho_i]; \ hashv += (hashv << 10); \ hashv ^= (hashv >> 6); \ } \ hashv += (hashv << 3); \ hashv ^= (hashv >> 11); \ hashv += (hashv << 15); \ } while (0) #define HASH_JEN_MIX(a,b,c) \ do { \ a -= b; a -= c; a ^= ( c >> 13 ); \ b -= c; b -= a; b ^= ( a << 8 ); \ c -= a; c -= b; c ^= ( b >> 13 ); \ a -= b; a -= c; a ^= ( c >> 12 ); \ b -= c; b -= a; b ^= ( a << 16 ); \ c -= a; c -= b; c ^= ( b >> 5 ); \ a -= b; a -= c; a ^= ( c >> 3 ); \ b -= c; b -= a; b ^= ( a << 10 ); \ c -= a; c -= b; c ^= ( b >> 15 ); \ } while (0) #define HASH_JEN(key,keylen,hashv) \ do { \ unsigned _hj_i,_hj_j,_hj_k; \ unsigned const char *_hj_key=(unsigned const char*)(key); \ hashv = 0xfeedbeefu; \ _hj_i = _hj_j = 0x9e3779b9u; \ _hj_k = (unsigned)(keylen); \ while (_hj_k >= 12U) { \ _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \ + ( (unsigned)_hj_key[2] << 16 ) \ + ( (unsigned)_hj_key[3] << 24 ) ); \ _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) \ + ( (unsigned)_hj_key[6] << 16 ) \ + ( (unsigned)_hj_key[7] << 24 ) ); \ hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) \ + ( (unsigned)_hj_key[10] << 16 ) \ + ( (unsigned)_hj_key[11] << 24 ) ); \ \ HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ \ _hj_key += 12; \ _hj_k -= 12U; \ } \ hashv += (unsigned)(keylen); \ switch ( _hj_k ) { \ case 11: hashv += ( (unsigned)_hj_key[10] << 24 ); /* FALLTHROUGH */ \ case 10: hashv += ( (unsigned)_hj_key[9] << 16 ); /* FALLTHROUGH */ \ case 9: hashv += ( (unsigned)_hj_key[8] << 8 ); /* FALLTHROUGH */ \ case 8: _hj_j += ( (unsigned)_hj_key[7] << 24 ); /* FALLTHROUGH */ \ case 7: _hj_j += ( (unsigned)_hj_key[6] << 16 ); /* FALLTHROUGH */ \ case 6: _hj_j += ( (unsigned)_hj_key[5] << 8 ); /* FALLTHROUGH */ \ case 5: _hj_j += _hj_key[4]; /* FALLTHROUGH */ \ case 4: _hj_i += ( (unsigned)_hj_key[3] << 24 ); /* FALLTHROUGH */ \ case 3: _hj_i += ( (unsigned)_hj_key[2] << 16 ); /* FALLTHROUGH */ \ case 2: _hj_i += ( (unsigned)_hj_key[1] << 8 ); /* FALLTHROUGH */ \ case 1: _hj_i += _hj_key[0]; \ } \ HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ } while (0) /* The Paul Hsieh hash function */ #undef get16bits #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) #define get16bits(d) (*((const uint16_t *) (d))) #endif #if !defined (get16bits) #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \ +(uint32_t)(((const uint8_t *)(d))[0]) ) #endif #define HASH_SFH(key,keylen,hashv) \ do { \ unsigned const char *_sfh_key=(unsigned const char*)(key); \ uint32_t _sfh_tmp, _sfh_len = (uint32_t)keylen; \ \ unsigned _sfh_rem = _sfh_len & 3U; \ _sfh_len >>= 2; \ hashv = 0xcafebabeu; \ \ /* Main loop */ \ for (;_sfh_len > 0U; _sfh_len--) { \ hashv += get16bits (_sfh_key); \ _sfh_tmp = ((uint32_t)(get16bits (_sfh_key+2)) << 11) ^ hashv; \ hashv = (hashv << 16) ^ _sfh_tmp; \ _sfh_key += 2U*sizeof (uint16_t); \ hashv += hashv >> 11; \ } \ \ /* Handle end cases */ \ switch (_sfh_rem) { \ case 3: hashv += get16bits (_sfh_key); \ hashv ^= hashv << 16; \ hashv ^= (uint32_t)(_sfh_key[sizeof (uint16_t)]) << 18; \ hashv += hashv >> 11; \ break; \ case 2: hashv += get16bits (_sfh_key); \ hashv ^= hashv << 11; \ hashv += hashv >> 17; \ break; \ case 1: hashv += *_sfh_key; \ hashv ^= hashv << 10; \ hashv += hashv >> 1; \ } \ \ /* Force "avalanching" of final 127 bits */ \ hashv ^= hashv << 3; \ hashv += hashv >> 5; \ hashv ^= hashv << 4; \ hashv += hashv >> 17; \ hashv ^= hashv << 25; \ hashv += hashv >> 6; \ } while (0) #ifdef HASH_USING_NO_STRICT_ALIASING /* The MurmurHash exploits some CPU's (x86,x86_64) tolerance for unaligned reads. * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error. * MurmurHash uses the faster approach only on CPU's where we know it's safe. * * Note the preprocessor built-in defines can be emitted using: * * gcc -m64 -dM -E - < /dev/null (on gcc) * cc -## a.c (where a.c is a simple test file) (Sun Studio) */ #if (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86)) #define MUR_GETBLOCK(p,i) p[i] #else /* non intel */ #define MUR_PLUS0_ALIGNED(p) (((unsigned long)p & 3UL) == 0UL) #define MUR_PLUS1_ALIGNED(p) (((unsigned long)p & 3UL) == 1UL) #define MUR_PLUS2_ALIGNED(p) (((unsigned long)p & 3UL) == 2UL) #define MUR_PLUS3_ALIGNED(p) (((unsigned long)p & 3UL) == 3UL) #define WP(p) ((uint32_t*)((unsigned long)(p) & ~3UL)) #if (defined(__BIG_ENDIAN__) || defined(SPARC) || defined(__ppc__) || defined(__ppc64__)) #define MUR_THREE_ONE(p) ((((*WP(p))&0x00ffffff) << 8) | (((*(WP(p)+1))&0xff000000) >> 24)) #define MUR_TWO_TWO(p) ((((*WP(p))&0x0000ffff) <<16) | (((*(WP(p)+1))&0xffff0000) >> 16)) #define MUR_ONE_THREE(p) ((((*WP(p))&0x000000ff) <<24) | (((*(WP(p)+1))&0xffffff00) >> 8)) #else /* assume little endian non-intel */ #define MUR_THREE_ONE(p) ((((*WP(p))&0xffffff00) >> 8) | (((*(WP(p)+1))&0x000000ff) << 24)) #define MUR_TWO_TWO(p) ((((*WP(p))&0xffff0000) >>16) | (((*(WP(p)+1))&0x0000ffff) << 16)) #define MUR_ONE_THREE(p) ((((*WP(p))&0xff000000) >>24) | (((*(WP(p)+1))&0x00ffffff) << 8)) #endif #define MUR_GETBLOCK(p,i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) : \ (MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : \ (MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) : \ MUR_ONE_THREE(p)))) #endif #define MUR_ROTL32(x,r) (((x) << (r)) | ((x) >> (32 - (r)))) #define MUR_FMIX(_h) \ do { \ _h ^= _h >> 16; \ _h *= 0x85ebca6bu; \ _h ^= _h >> 13; \ _h *= 0xc2b2ae35u; \ _h ^= _h >> 16; \ } while (0) #define HASH_MUR(key,keylen,hashv) \ do { \ const uint8_t *_mur_data = (const uint8_t*)(key); \ const int _mur_nblocks = (int)(keylen) / 4; \ uint32_t _mur_h1 = 0xf88D5353u; \ uint32_t _mur_c1 = 0xcc9e2d51u; \ uint32_t _mur_c2 = 0x1b873593u; \ uint32_t _mur_k1 = 0; \ const uint8_t *_mur_tail; \ const uint32_t *_mur_blocks = (const uint32_t*)(_mur_data+(_mur_nblocks*4)); \ int _mur_i; \ for (_mur_i = -_mur_nblocks; _mur_i != 0; _mur_i++) { \ _mur_k1 = MUR_GETBLOCK(_mur_blocks,_mur_i); \ _mur_k1 *= _mur_c1; \ _mur_k1 = MUR_ROTL32(_mur_k1,15); \ _mur_k1 *= _mur_c2; \ \ _mur_h1 ^= _mur_k1; \ _mur_h1 = MUR_ROTL32(_mur_h1,13); \ _mur_h1 = (_mur_h1*5U) + 0xe6546b64u; \ } \ _mur_tail = (const uint8_t*)(_mur_data + (_mur_nblocks*4)); \ _mur_k1=0; \ switch ((keylen) & 3U) { \ case 0: break; \ case 3: _mur_k1 ^= (uint32_t)_mur_tail[2] << 16; /* FALLTHROUGH */ \ case 2: _mur_k1 ^= (uint32_t)_mur_tail[1] << 8; /* FALLTHROUGH */ \ case 1: _mur_k1 ^= (uint32_t)_mur_tail[0]; \ _mur_k1 *= _mur_c1; \ _mur_k1 = MUR_ROTL32(_mur_k1,15); \ _mur_k1 *= _mur_c2; \ _mur_h1 ^= _mur_k1; \ } \ _mur_h1 ^= (uint32_t)(keylen); \ MUR_FMIX(_mur_h1); \ hashv = _mur_h1; \ } while (0) #endif /* HASH_USING_NO_STRICT_ALIASING */ /* iterate over items in a known bucket to find desired item */ #define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,hashval,out) \ do { \ if ((head).hh_head != NULL) { \ DECLTYPE_ASSIGN(out, ELMT_FROM_HH(tbl, (head).hh_head)); \ } else { \ (out) = NULL; \ } \ while ((out) != NULL) { \ if ((out)->hh.hashv == (hashval) && (out)->hh.keylen == (keylen_in)) { \ if (uthash_memcmp((out)->hh.key, keyptr, keylen_in) == 0) { \ break; \ } \ } \ if ((out)->hh.hh_next != NULL) { \ DECLTYPE_ASSIGN(out, ELMT_FROM_HH(tbl, (out)->hh.hh_next)); \ } else { \ (out) = NULL; \ } \ } \ } while (0) /* add an item to a bucket */ #define HASH_ADD_TO_BKT(head,hh,addhh,oomed) \ do { \ UT_hash_bucket *_ha_head = &(head); \ _ha_head->count++; \ (addhh)->hh_next = _ha_head->hh_head; \ (addhh)->hh_prev = NULL; \ if (_ha_head->hh_head != NULL) { \ _ha_head->hh_head->hh_prev = (addhh); \ } \ _ha_head->hh_head = (addhh); \ if ((_ha_head->count >= ((_ha_head->expand_mult + 1U) * HASH_BKT_CAPACITY_THRESH)) \ && !(addhh)->tbl->noexpand) { \ HASH_EXPAND_BUCKETS(addhh,(addhh)->tbl, oomed); \ IF_HASH_NONFATAL_OOM( \ if (oomed) { \ HASH_DEL_IN_BKT(head,addhh); \ } \ ) \ } \ } while (0) /* remove an item from a given bucket */ #define HASH_DEL_IN_BKT(head,delhh) \ do { \ UT_hash_bucket *_hd_head = &(head); \ _hd_head->count--; \ if (_hd_head->hh_head == (delhh)) { \ _hd_head->hh_head = (delhh)->hh_next; \ } \ if ((delhh)->hh_prev) { \ (delhh)->hh_prev->hh_next = (delhh)->hh_next; \ } \ if ((delhh)->hh_next) { \ (delhh)->hh_next->hh_prev = (delhh)->hh_prev; \ } \ } while (0) /* Bucket expansion has the effect of doubling the number of buckets * and redistributing the items into the new buckets. Ideally the * items will distribute more or less evenly into the new buckets * (the extent to which this is true is a measure of the quality of * the hash function as it applies to the key domain). * * With the items distributed into more buckets, the chain length * (item count) in each bucket is reduced. Thus by expanding buckets * the hash keeps a bound on the chain length. This bounded chain * length is the essence of how a hash provides constant time lookup. * * The calculation of tbl->ideal_chain_maxlen below deserves some * explanation. First, keep in mind that we're calculating the ideal * maximum chain length based on the *new* (doubled) bucket count. * In fractions this is just n/b (n=number of items,b=new num buckets). * Since the ideal chain length is an integer, we want to calculate * ceil(n/b). We don't depend on floating point arithmetic in this * hash, so to calculate ceil(n/b) with integers we could write * * ceil(n/b) = (n/b) + ((n%b)?1:0) * * and in fact a previous version of this hash did just that. * But now we have improved things a bit by recognizing that b is * always a power of two. We keep its base 2 log handy (call it lb), * so now we can write this with a bit shift and logical AND: * * ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0) * */ #define HASH_EXPAND_BUCKETS(hh,tbl,oomed) \ do { \ unsigned _he_bkt; \ unsigned _he_bkt_i; \ struct UT_hash_handle *_he_thh, *_he_hh_nxt; \ UT_hash_bucket *_he_new_buckets, *_he_newbkt; \ _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \ 2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \ if (!_he_new_buckets) { \ HASH_RECORD_OOM(oomed); \ } else { \ uthash_bzero(_he_new_buckets, \ 2UL * (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \ (tbl)->ideal_chain_maxlen = \ ((tbl)->num_items >> ((tbl)->log2_num_buckets+1U)) + \ ((((tbl)->num_items & (((tbl)->num_buckets*2U)-1U)) != 0U) ? 1U : 0U); \ (tbl)->nonideal_items = 0; \ for (_he_bkt_i = 0; _he_bkt_i < (tbl)->num_buckets; _he_bkt_i++) { \ _he_thh = (tbl)->buckets[ _he_bkt_i ].hh_head; \ while (_he_thh != NULL) { \ _he_hh_nxt = _he_thh->hh_next; \ HASH_TO_BKT(_he_thh->hashv, (tbl)->num_buckets * 2U, _he_bkt); \ _he_newbkt = &(_he_new_buckets[_he_bkt]); \ if (++(_he_newbkt->count) > (tbl)->ideal_chain_maxlen) { \ (tbl)->nonideal_items++; \ _he_newbkt->expand_mult = _he_newbkt->count / (tbl)->ideal_chain_maxlen; \ } \ _he_thh->hh_prev = NULL; \ _he_thh->hh_next = _he_newbkt->hh_head; \ if (_he_newbkt->hh_head != NULL) { \ _he_newbkt->hh_head->hh_prev = _he_thh; \ } \ _he_newbkt->hh_head = _he_thh; \ _he_thh = _he_hh_nxt; \ } \ } \ uthash_free((tbl)->buckets, (tbl)->num_buckets * sizeof(struct UT_hash_bucket)); \ (tbl)->num_buckets *= 2U; \ (tbl)->log2_num_buckets++; \ (tbl)->buckets = _he_new_buckets; \ (tbl)->ineff_expands = ((tbl)->nonideal_items > ((tbl)->num_items >> 1)) ? \ ((tbl)->ineff_expands+1U) : 0U; \ if ((tbl)->ineff_expands > 1U) { \ (tbl)->noexpand = 1; \ uthash_noexpand_fyi(tbl); \ } \ uthash_expand_fyi(tbl); \ } \ } while (0) /* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */ /* Note that HASH_SORT assumes the hash handle name to be hh. * HASH_SRT was added to allow the hash handle name to be passed in. */ #define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn) #define HASH_SRT(hh,head,cmpfcn) \ do { \ unsigned _hs_i; \ unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize; \ struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail; \ if (head != NULL) { \ _hs_insize = 1; \ _hs_looping = 1; \ _hs_list = &((head)->hh); \ while (_hs_looping != 0U) { \ _hs_p = _hs_list; \ _hs_list = NULL; \ _hs_tail = NULL; \ _hs_nmerges = 0; \ while (_hs_p != NULL) { \ _hs_nmerges++; \ _hs_q = _hs_p; \ _hs_psize = 0; \ for (_hs_i = 0; _hs_i < _hs_insize; ++_hs_i) { \ _hs_psize++; \ _hs_q = ((_hs_q->next != NULL) ? \ HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \ if (_hs_q == NULL) { \ break; \ } \ } \ _hs_qsize = _hs_insize; \ while ((_hs_psize != 0U) || ((_hs_qsize != 0U) && (_hs_q != NULL))) { \ if (_hs_psize == 0U) { \ _hs_e = _hs_q; \ _hs_q = ((_hs_q->next != NULL) ? \ HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \ _hs_qsize--; \ } else if ((_hs_qsize == 0U) || (_hs_q == NULL)) { \ _hs_e = _hs_p; \ if (_hs_p != NULL) { \ _hs_p = ((_hs_p->next != NULL) ? \ HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \ } \ _hs_psize--; \ } else if ((cmpfcn( \ DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_p)), \ DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_q)) \ )) <= 0) { \ _hs_e = _hs_p; \ if (_hs_p != NULL) { \ _hs_p = ((_hs_p->next != NULL) ? \ HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \ } \ _hs_psize--; \ } else { \ _hs_e = _hs_q; \ _hs_q = ((_hs_q->next != NULL) ? \ HH_FROM_ELMT((head)->hh.tbl, _hs_q->next) : NULL); \ _hs_qsize--; \ } \ if ( _hs_tail != NULL ) { \ _hs_tail->next = ((_hs_e != NULL) ? \ ELMT_FROM_HH((head)->hh.tbl, _hs_e) : NULL); \ } else { \ _hs_list = _hs_e; \ } \ if (_hs_e != NULL) { \ _hs_e->prev = ((_hs_tail != NULL) ? \ ELMT_FROM_HH((head)->hh.tbl, _hs_tail) : NULL); \ } \ _hs_tail = _hs_e; \ } \ _hs_p = _hs_q; \ } \ if (_hs_tail != NULL) { \ _hs_tail->next = NULL; \ } \ if (_hs_nmerges <= 1U) { \ _hs_looping = 0; \ (head)->hh.tbl->tail = _hs_tail; \ DECLTYPE_ASSIGN(head, ELMT_FROM_HH((head)->hh.tbl, _hs_list)); \ } \ _hs_insize *= 2U; \ } \ HASH_FSCK(hh, head, "HASH_SRT"); \ } \ } while (0) /* This function selects items from one hash into another hash. * The end result is that the selected items have dual presence * in both hashes. There is no copy of the items made; rather * they are added into the new hash through a secondary hash * hash handle that must be present in the structure. */ #define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \ do { \ unsigned _src_bkt, _dst_bkt; \ void *_last_elt = NULL, *_elt; \ UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL; \ ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst)); \ if ((src) != NULL) { \ for (_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) { \ for (_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head; \ _src_hh != NULL; \ _src_hh = _src_hh->hh_next) { \ _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh); \ if (cond(_elt)) { \ IF_HASH_NONFATAL_OOM( int _hs_oomed = 0; ) \ _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho); \ _dst_hh->key = _src_hh->key; \ _dst_hh->keylen = _src_hh->keylen; \ _dst_hh->hashv = _src_hh->hashv; \ _dst_hh->prev = _last_elt; \ _dst_hh->next = NULL; \ if (_last_elt_hh != NULL) { \ _last_elt_hh->next = _elt; \ } \ if ((dst) == NULL) { \ DECLTYPE_ASSIGN(dst, _elt); \ HASH_MAKE_TABLE(hh_dst, dst, _hs_oomed); \ IF_HASH_NONFATAL_OOM( \ if (_hs_oomed) { \ uthash_nonfatal_oom(_elt); \ (dst) = NULL; \ continue; \ } \ ) \ } else { \ _dst_hh->tbl = (dst)->hh_dst.tbl; \ } \ HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt); \ HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt], hh_dst, _dst_hh, _hs_oomed); \ (dst)->hh_dst.tbl->num_items++; \ IF_HASH_NONFATAL_OOM( \ if (_hs_oomed) { \ HASH_ROLLBACK_BKT(hh_dst, dst, _dst_hh); \ HASH_DELETE_HH(hh_dst, dst, _dst_hh); \ _dst_hh->tbl = NULL; \ uthash_nonfatal_oom(_elt); \ continue; \ } \ ) \ HASH_BLOOM_ADD(_dst_hh->tbl, _dst_hh->hashv); \ _last_elt = _elt; \ _last_elt_hh = _dst_hh; \ } \ } \ } \ } \ HASH_FSCK(hh_dst, dst, "HASH_SELECT"); \ } while (0) #define HASH_CLEAR(hh,head) \ do { \ if ((head) != NULL) { \ HASH_BLOOM_FREE((head)->hh.tbl); \ uthash_free((head)->hh.tbl->buckets, \ (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket)); \ uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ (head) = NULL; \ } \ } while (0) #define HASH_OVERHEAD(hh,head) \ (((head) != NULL) ? ( \ (size_t)(((head)->hh.tbl->num_items * sizeof(UT_hash_handle)) + \ ((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket)) + \ sizeof(UT_hash_table) + \ (HASH_BLOOM_BYTELEN))) : 0U) #ifdef NO_DECLTYPE #define HASH_ITER(hh,head,el,tmp) \ for(((el)=(head)), ((*(char**)(&(tmp)))=(char*)((head!=NULL)?(head)->hh.next:NULL)); \ (el) != NULL; ((el)=(tmp)), ((*(char**)(&(tmp)))=(char*)((tmp!=NULL)?(tmp)->hh.next:NULL))) #else #define HASH_ITER(hh,head,el,tmp) \ for(((el)=(head)), ((tmp)=DECLTYPE(el)((head!=NULL)?(head)->hh.next:NULL)); \ (el) != NULL; ((el)=(tmp)), ((tmp)=DECLTYPE(el)((tmp!=NULL)?(tmp)->hh.next:NULL))) #endif /* obtain a count of items in the hash */ #define HASH_COUNT(head) HASH_CNT(hh,head) #define HASH_CNT(hh,head) ((head != NULL)?((head)->hh.tbl->num_items):0U) typedef struct UT_hash_bucket { struct UT_hash_handle *hh_head; unsigned count; /* expand_mult is normally set to 0. In this situation, the max chain length * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If * the bucket's chain exceeds this length, bucket expansion is triggered). * However, setting expand_mult to a non-zero value delays bucket expansion * (that would be triggered by additions to this particular bucket) * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH. * (The multiplier is simply expand_mult+1). The whole idea of this * multiplier is to reduce bucket expansions, since they are expensive, in * situations where we know that a particular bucket tends to be overused. * It is better to let its chain length grow to a longer yet-still-bounded * value, than to do an O(n) bucket expansion too often. */ unsigned expand_mult; } UT_hash_bucket; /* random signature used only to find hash tables in external analysis */ #define HASH_SIGNATURE 0xa0111fe1u #define HASH_BLOOM_SIGNATURE 0xb12220f2u typedef struct UT_hash_table { UT_hash_bucket *buckets; unsigned num_buckets, log2_num_buckets; unsigned num_items; struct UT_hash_handle *tail; /* tail hh in app order, for fast append */ ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */ /* in an ideal situation (all buckets used equally), no bucket would have * more than ceil(#items/#buckets) items. that's the ideal chain length. */ unsigned ideal_chain_maxlen; /* nonideal_items is the number of items in the hash whose chain position * exceeds the ideal chain maxlen. these items pay the penalty for an uneven * hash distribution; reaching them in a chain traversal takes >ideal steps */ unsigned nonideal_items; /* ineffective expands occur when a bucket doubling was performed, but * afterward, more than half the items in the hash had nonideal chain * positions. If this happens on two consecutive expansions we inhibit any * further expansion, as it's not helping; this happens when the hash * function isn't a good fit for the key domain. When expansion is inhibited * the hash will still work, albeit no longer in constant time. */ unsigned ineff_expands, noexpand; uint32_t signature; /* used only to find hash tables in external analysis */ #ifdef HASH_BLOOM uint32_t bloom_sig; /* used only to test bloom exists in external analysis */ uint8_t *bloom_bv; uint8_t bloom_nbits; #endif } UT_hash_table; typedef struct UT_hash_handle { struct UT_hash_table *tbl; void *prev; /* prev element in app order */ void *next; /* next element in app order */ struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ struct UT_hash_handle *hh_next; /* next hh in bucket order */ void *key; /* ptr to enclosing struct's key */ unsigned keylen; /* enclosing struct's key len */ unsigned hashv; /* result of hash-fcn(key) */ } UT_hash_handle; #endif /* UTHASH_H */ nvtop-1.0.0/manpage/000077500000000000000000000000001341567056100142765ustar00rootroot00000000000000nvtop-1.0.0/manpage/nvtop.in000066400000000000000000000040661341567056100160020ustar00rootroot00000000000000.\" Manpage for nvtop .\" Contact maxime.schmitt91@gmail.com .TH nvtop 1 "January 2019" "Version @nvtop_VERSION_MAJOR@.@nvtop_VERSION_MINOR@.@nvtop_VERSION_PATCH@" "nvtop command" .SH NAME nvtop \- NVIDIA GPU top .SH SYNOPSIS .B nvtop \fR[\fB\-hv\fR] \fR[\fB\-si\fR \fIid1:id2:...\fR] \fR[\fB\-d\fR \fIdelay\fR] .SH DESCRIPTION nvtop is a ncurses\-based GPU status viewer for NVIDIA GPUs. .SH COMMAND\-LINE OPTIONS .TP .BR \-d ", " \-\-delay =\fIdelay\fR Delay between updates, in tenths of seconds (\fIdelay\fR * 0.1s). .TP .BR \-h ", " \-\-help Print the help and exit. .TP .BR \-s ", " \-\-gpu\-select =\fIid1:...\fR Colon separated list of GPU IDs to be monitored by nvtop. .TP .BR \-i ", " \-\-gpu\-ignore =\fIid1:...\fR Colon separated list of GPU IDs to be ignored by nvtop. .TP .BR \-C ", " \-\-no\-color Monochrome mode. .TP .BR \-N ", " \-\-no\-cache Disable the (process id, user name, command line) cache and query the system at each refresh. .TP .BR \-f ", " \-\-freedom\-unit Use fahrenheit as temperature scale. .TP .BR \-E ", " \-\-encode\-hide =\fIseconds\fR Modify the setting for the encode/decode auto-hide timer. Always visible if negative. Default to 30 seconds. .TP .BR \-p ", " \-\-no\-plot Show only one bar plot corresponding to the maximum of all GPUs. .TP .BR \-v ", " \-\-version Print the version and exit. .SH INTERACTIVE COMMANDS .TP The following commands are available while in nvtop: .TP .BR Up Select (highlight) the previous process. .TP .BR Down Select (highlight) the next process. .TP .BR Left\ /\ Right Scroll in the process row. .TP .BR + Sort increasingly. .TP .BR - Sort decreasingly. .TP .BR F1 "Kill" process: Select a signal to send to the highlighted process. .TP .BR F2 Sort: Select the field for sorting. The current sort field is highlighted inside the header bar. .TP .BR F3 ", " q ", " Esc Quit. .SH BUGS .TP .BR "Some fields are shown as N/A" Ask NVIDIA for better support of your hardware! .TP .BR "Compatibility issues" Does not work with nouveau driver stack and older NVIDIA GPU for the time being. .SH AUTHOR Written by Maxime Schmitt. nvtop-1.0.0/screenshot/000077500000000000000000000000001341567056100150435ustar00rootroot00000000000000nvtop-1.0.0/screenshot/NVTOP_ex1.png000066400000000000000000001147571341567056100172530ustar00rootroot00000000000000‰PNG  IHDR¼û`ã]zTXtRaw profile type exifxÚåšYv$¹rDÿ± -ó°ŒçhZ¾®!’¬âT¯_=ý©ØM&“ÀÝÜÜ H³ÿç¿ù/þ峉©ÔÜr¶ü‹-6ßyQíóïùél¼ßï¿1mx½ûá}sÆë¥ç§.y.³y??]çýôë†_ïï›2Ÿ¾¾ôúÃÛƒFö¼x]W_ þyß½~7íu_¿-çõ¿O¯÷^ÿü{,c%ž¼ñ;¸`ù^5J`¡†ÎwÇwœ×;×áõÝ;óþòSðjyþ)v¶¿®Cal~]?Åèõ¾KßÇîFè÷9ûžµѽÍéKìÎYõœý¬®ÇL¤²y-ê-„÷Bîm™¯Âÿ‰×å~5¾*Kœdl‘ÍÁ×4®9O´‹n¹îŽÛ÷çt“)F¿}á§÷“¸ë½Šo~Þ¤D}¹ãKharäÃ$k·ýû\Ü·Ýñ¦«Œ¼WzÇÃw|ù2ß½ù7_ï:GÐuNÁ$õîI°j˜†2§ï\EBÜyÅ4ÝøÞ/óžÖ_ÿ”Ø@Ó seÝŽç#¹_Ø 7Ïë’Æ>¥áÊz=€1vb2 ;:›]H.;[¼/ÎÇJ~:3÷!úA\J~9sÈM™äT¯±¹§¸{­Oþyj!)äPHM dŘÀO‰ õR4)¥œJª©¥žCŽ9åœKGõJ,©äRJ-­ôj¬©æZj­­öæ[€ÂRË­˜V[k½3hçÑ»;Wô>ü#Ž4ò(£Ž6ú>3Î4ó,³Î6ûò+,ÊåU̪«­¾ÝJ;î´ó.»î¶ûk'œxÒɧœzÚéïY{eõcÖܧÌý9kî•5e,Þëʯ¬ñv)op¢“¤œ‘1/Ê€öÊ™­.F¯Ì)g¶yŠ"y²æ’’³œ2Fãv>÷ž»_™ûcÞLŠÿVÞüO™3JÝÿEæŒR÷ÊÜ×¼}“µÕoG 7AªBÅÔ†±×FŽöôÂ8cÇ1)€}¶œ¨„Þ×Ò>VÞ,´KS0fTúIÙ%0éâR]L‹™j¢ïÓÔ$Y»¯Hˆ‰žŠŒ€‘±gj#¥:’-5ŸZ7ÜIP¥°oÛ§¨E–›U„†¸´z¤¯º©gBÄtGŠ„lJÒǾÈ|*¬Yjj¤®²“ëAGí…–R‰3’Œ`7?½úC޵hÖ£6fÌìVdHsÊuv`a΄?g˜ph>RÛRÌÈR !ùÒH– Æäc³».§©‡b)¿¢ÚSŸß5÷ÔNÜ ‹'̾?,¨®1k‘wÚ¤Në¡Û¤ð#$éZ%çfX{ËŸœT«¯= ƒ9RÄ5ø4¨„XÛÈð‰ÝÑÖQ K¯“u3Ç5 —Ò—†´ÏgCRŠlž'/.âö‹ó™ ‡Qæh /¤dÛîÒ<´®yð%iø LÚ ŒmE£ïrèæã©ªiÓSH=&(K‰_.R:Îvv.#Ž™‰¦d ËvgöRmè‡Ë J“ÜnJä䆩Ü#ë È:tf˜D\Ž&º78»XsÛ0£ëU2gO@9WECx»CK  ‘·­Æ…úô°í:ê6fZÍ·tKšWö‚ÌEMFµ;dÌ?¦Ýw6Ýݲo Ëa‚x€2gt$Êâ8õôð=Ï"3~ô8õ˜RoÓQ§Û°Æ²¼xxÌrÞN\ÏüC;¼SVi}î'3?'†¬åœ\êå/É#Ò& lÇ|Éñ+Ãýg,ã ÞG·oã›oh¶þ«…¼OãÎø™‡ùl_'Ã2îtx؇ ý ‡ù›x|ó7ñø.æoâñ]8LG!Õ}€ÕÒ˜H…5<|X‹ÛƒjÑ­6mZ\qVèüÃO[OÔU¦BíT{Á›$ªæÖQ7ðë)µ%mtré}ºÎž;{Œë為“†Q7bD*@÷:iÓL L)-­f–ÓrZäFïÁò bfJ1°ˆˆ̆ÌðVtw›žðQ@á‰S³A¡[±ôDp6”Iƒ¨s›j¤‹DÅHà¨Q–§ìuQ#Ü[¶'uThgœ V§è% ɉVÁ'¨½ËÈcöáY÷I_žCÝ“§óþ$ˆç¨É å$"¸4|»<÷ý]Üš+<%¤Çt~•“M™ë¬3òƒŠ§NíÜöÃP¯Ë"fAç~Ƨn~Š7æŸé#&ä]ú¤XÌ” ž¦!—r"mýPèÝÈ£Ò5Qôí™ÚÑN³ëˆºÐ1‰ÿ¸±_™)tq4)æ=BÑÄb/glG¤¯-° ¨%i­DP—vTJÓûwëÞǵXÌ¿Ž˜ù2Ïšüb§†êÊ¡q £*¾/;|?ó6æHû®ŠÉ ='玈.mKhfÊ©¯púFý–)ó l{V§+žTyÚßo0D¹ù8e· QWÅ…EE®ŒôˆA4¶ë)F3ÍÙ£åÝî¾!Â.<Ž]‡©{Ù¨p¼oFš ãàkÚtg{½B¡(‘ì@ Ý‘I”ü´t9ü‰ƒ÷ê„îÖL`ïð‘ËäzhÕLDË À†¨¯A´•U§Í! Ë£$ÊJ,,`žú‚GË „fÁÍ›ÉE.Û9k”›@3BÌÁM™ ðCY€,j.N Õôxa;þ_C» ÚÑBü׊0Dâ3P•UŽ"¡ÜÚ¼ãm'ò*sQõ` ~E…D—žt|L NþHBKF¬R*)A HQì>Q@ˆDK D6ÖÁcMw*ðt9°õ9ìÕ¼ÆGŒǶk¤,ðg“ÁI@à1¤~{ mþ½ÛÀ^Õfßo7Ý[¬5ßÝżï§ÁÌ?í LB-­ŽJo+â8d+Ø_|>ÆÏ- “!Õ“v|$Æ-;8UV¼á#‚LB1½YXÌ¡"}­8š©$oxc{´µáxœeó=Ÿì ÖÞT Î…MV*>še X¹Ó´¯šü·¸ °s³!á· ñ‡¸z ZÅ4oæ › Ñ2oa&~ذ;ÖØê£'¦‰c® ÌlmÈÞ ½[852AüÚÁÓðÈÍTüŒUb†¾E‹ tX@ÌâÒ6aè4µ—œ¼3ví7$ô2ͬ@ypk5Ž…ÚÙsœäѾÿ6$ u»å!K2úl~’HZ8òŒ|“„ÓýzÊA„DJÏ=I{N#GVveVœé´.e(ŠØQmõUÆënMˆüX@tÚM¹.J{¦.ñ ¬D.q%tMÜy ÁоQCá¬7£ŽNs£â¬@ íw§WHDÊxÉ·§S„’v¡ @vŠùQœóØ‘ëÐfð`’§²¼•¾hÏ”{4ª.¡+»)ÔÉ\·0s|¦G 5Dt$A}¨Ž«ð,À%4k¹mònwFAžNa‹ÚÞϤšºÒFG÷èmóИW¨Xí|Pô#»s£øëØm® mfµÚ™ƒ]pR^à#iE蘨sOsÀk6‹üìÒ—¯õøoíiÞýllà“.W%Q#Š¡ÉÒa÷v¹ŒB ø6/﵃ï:É1ª®Þé©ãÄNvQ´{ß “r]p ½øì'*¯˜‰ãøä-ïú–Ìos9Äcø8œ3ZÂeH¹S½…lª˜5Ĉ·Iå¨ð&˸—; LCŠjÅânD/©Ïœ´1ÕˆÜ0ý1O䞸IGÛµ©íÒ±×—}2z~Jã˜3)7Ô~ =jó/:L5‡»¦DÐHŠ£¶î¥á)ZGÜù¨ªi~†ØÏ1•š»ötP„U»5›…* C‡&mÚ£?B´WQÖ“nÐÃkï&ßï䦢¶iuÈH-Q¡TØn³N×è¥tEЦz0sÚôWÅžß¹CùžÏ> õl’¶—%ãx´ŒäŠ:Ÿ¢$|QžðoÇÐD¿ˆö6oä*mì™Ý³ù5½8榾éÓJèÑ ±—’ݶHÿ{îÛÜL×K÷4vßÓÖTÀ;vÝî†@Ãã¦üc¢àŒ°ÎÚ£d2U¡ù@AK,ì©T_ÞX‚`#êO†/Ô‹ ïxíuÁø›¶©¿NO› *?z&‰ˆÑ>dž¥"óÛ4È©À&‰™É˜\^%4Ö¶kx@±äȰö\N÷3¸@·Óg*˜¼*Ìu œ°CdÏ”oÑæDïAÈÔ‡è³6Jíƒ8B€ŠŒÓŠbi⮢Ŏø*­r ù ãJ®h¯äÊ¿8ëojÏà’Û£»®Ḭað~I’DKƒžº#N§Ç¥òî€&-u¯‰ªÙKb”¼âFÓXœèãÇj{£­[$".hË܇µ<Ò”LvüñÖ¶—Ó Ã–ðB—J±ÞtÓ#ýS®MFåèpÊ0·'åŸXì,bˆïÿIìÌOÁƒâuØ:ÆUm7³ô=ÀÖfPmÞÄ®s±Q,DÊTé*¯’!¯¬Þ=%švWëœÇ7êÜÏNßmÉ#Ø€¦jC´1ñ{uا>ô) ø9!¯Ú¤šÔÑÊ«faìŽú8]Ê_RiµF×®g¾þ>mq„â{zHüª@ó^‚=@\ÈYJÀ¡êœƒàX[ òº9ž…nmôc¤$³Ñdw¸e[C†ZÄ2r<èd:eÖÕQܺ±UÔà鯙îߊ ð&ÆoRŒfÇþàHD;*ÎÏ‚¾l•IÃj£7h¶÷€¦DÞ̹¦¤&f´ˆÒ&2"ž (3jÚ„9fë¨Z—ƒUTSÑ~Ï€ÞÏ)ÈÒy»™š‹:§Ê8ãâ ÖµjS x°Óqtfµ˜F¬Ã¬:}Ôèµ'¤¤Ã¾4<•„r,¨Sƒ‹¬©­×ŽtŠh°ÌpÂêÚ´žÒ‚ˆ)Žý`|”8…ýgï†ZhÓh÷ðP=‰Ö¹‰Ž<Çž(“ Ïe!uu˜£6iîVäâ–ô¹¶XH®¶ÕƳvÈ*b(—ñ[Sv™BÜ<]g²‡3­ö¤)ñÉâPV 4dõ5|q á þŽ?Ô÷bÕöý aØGlŒbÇì¯$‰ªÚŽâIMÍËyƒ‹¹»c¼»3xjÜ™ï‡z*Ý®¬$±°fOiÅ<࡯èÄwÌfSŲõaÆ .'dX×1 EÒNwÌ,¢ýV׌2‘ü< KçgwšYäBîÚˆ‚Æ}Á‰Æ8´Ó¶d&B´ª…su6C³ .5èÛê:¬¶úü ù܇‚â'Üx#Ñ´Áö¥/ŠpT¶OŸhF» (Tû7ÀP=>jІ!"Ù×¹µ¶dÑ Õá%tþñvòúi>¿ñ·?ÿ>(ôX¡›gúF´‹–é((®ª —F3ÝÏŸÑm€“™ú€˜ØÚ*Ї–f¡~7Š˜—ˆK±,þ~jÿÙw¢Wô¡Š‚Òu^š.˜ ÆT|^M{*°tÅ ÁOøÜÙôñ7fåJZ´` ÷tü"VûÒÜhò ’ÓGe—ŽÊèËC[²†þÑUƒZt÷,ä´ýwQ:²9Ú€}æªfZŸÆe½è9£zWÐ×z€T2÷еôI´Ûîšk‚5]Êqz §ÑŠ›‡‰ÍQ³œŸ:_GÏh/LÎòuûsPßn—AÏÇgKíڬג$ —©hwíQ{¦såçÔÑ;é,ŸGo^™îgT^CšÏc2e¬…>€"ûœq0Üíʵ›‡.Í£t€|Ny»k8éaóq°çOdA'¯IJQ¤9wW+g©Õ=kÏ]˜­íÊÏ߆³:qÑ Béãú0ŒÎ€SERÆ£m<‰ñŸ—ös8_Ѥ7Ò«ž‚9Í×XþZÞÛ€:Cz%Pù6”æC,\Þ2÷ ¦ùÍ«öÿ¼Àoòg^ ü1¢X©ú‡%¾gÐüžÂ'ƒ?ÅóÏà4¿£ó?§ùÿ 8¿YÚßÓÔŸ—ÖCÓq/þÈÊÄ­f«6‹‘‘yèÓq<µÃ Û0Õåmñj©Íü/žRº‹3ŒbKGDÿÿÿ ½§“ pHYsuu¹cQ2tIMEâ  ! 9¤JÚ IDATxÚìÝw|UþÿñÏܹ-½^r‘PbD)H$®ˆÆ‡ùYvWWDÁ/‘¢¢«¬ _1"‚¢EÅ¥è*»¢|­4é%b7!tBÊ­óûc †{oÂK^Ͻ99÷ÌÌ™33ï;™;#€ÓΚ™™ðöÛ¶yóbŸxÂØ­Û ½72''ôŠ+NqÌçž?{vüK/YÏ?¿½:#FŒØ¼yóš5k~øa½dÈ![¶l)((øâ‹/âââ¾+??¿¼¼¼´´´´´tìØ±?i7úÌÏ;ï¼SZZZ__èСÒÒÒ>úèŠ+®øüóÏõʹ¹¹<òH{MMŸ>=??¿õÇaÃ†íØ±cçÎ×^{­^2yòäÝ»wïÚµkÚ´iíÕ¹çž{Ö¬Y³iÓ¦œœœ€SQíK—ÚæÎµååE­£ÆÇÇ>ñ„íÿˆŸ3ǘ”$"¶ùó/NX²Ä6¾b±Ù©¦ÔYñ³^±½2-vZ„!Bu™}Ù|Û|ý_š9-ÓšùûÔ™9ᢋü1™L6l(..Þ»wïwÜÑÁä|zlРA[·n-//ÿàƒ‚œáA–Aï$¼3Ï6ïÛ+úÌ ¶ ~:öiý·£"F]~}Mù¯‹`êS⯸¸8<<¼õÇ~ýú9Ž}ûöΚ5KQ”Ö_)в}ûö„„„`áþèûçÛæ/NX¼$aÉ|ÛüÇcï̽À¡9úôðjËËSŒÆàß«vébˆŠ:¥É+ŠíÕWU»Ýk›?_1™Ö7nÜäÉ“ÛÆ©¢¢¢óÏ?_?4¶wðËÏÏOII9 }ØÞü<ðÀ­¹VD>ú裬¬¬3Î8#???$$$`S7ÞxãŽ;Z# Á`())éÕ«W×®]KKK-KbbâBBBŒFcaaajjªÖÖî¾ûîI“&µšãçÌÅjñEËàÁ"ûÌ3!—^*"†èhCl¬^3ìO ¿é¦¢æÙòú˜úˆH²19Ú­Šún»mëdZ3',þkø_;ÍŠ¢$&&ŠHlllEE…Íf‘¾}ûþûßÿþâ‹/æÎæßcŠ¢ìÝ»÷Ê+¯‘3Î8#øÐühÌ£"bW틇ÂDäñ˜ÇÓ-éñjüœø9fÅL;¬‹êSdLܲe‹ˆ¨ªºiÓ¦ßÿþ÷­¿ºüòËßzë­Õ ûÓ-·´þØÉ{Щ:þµsËOU•©o_±^pAüK/Å¿øbĘ1ú‘&èÕ"n½UÏUá7Þû¿ÿk:ô‡ìxæ™q3fÄ¿ðBìÓOëáÛ§q³gOouµš`:óLOi©éœs‚Y’Ë.»lïÞ½ß|óˆìرãÀ"rýõ×ïÚµkûöíÏ?ÿ|{o=zôÎ;wîÜyûí·ë%O=õÔ´iÓ>ûì³/¿ü2++KD2226lذuëÖÏ?ÿÜl6ÓrÀùñ7iÒ¤'Ÿ|rêÔ©>úhsssÀ:±±±£Fjý1--­¬¬¬W¯^»wï:thSSScc£ÕjµZ­§¶¶Ö¿Î ­¥Å™Ÿ¯víªÚíÆ„„æÕ«EÄ[Wç­© ü)ëxët eà~Ïþ|W¾ˆ”¸Kê¼u«mvlΰd(¢´;cšV^^."¡¡¡n·ÛårÅÇÇ¿öÚk<ðÀ\°råÊ¿ÿýïþ=Ö¿ÿÚÚÚ•+WŠÈÿû_éÙ³çÖ­[ÃÂÂ,Ë·ß~{öÙgwОŠZOmCy­áµá#F†üçá:5ç‘!1ú®¨»Ú{{0ë¿N0%ÌóYgµiÓ¦ž={¶–X,–Ç·–Lœ8ñÅ_Ô_ßrË-Û¶mÛ´iÓœ9s‚'ô ó8þ)doe¥Ñnw—”„ÿéOÕ“&iÍÍÑ÷ÝgNKslØqóÍ¢(¢i–ŒŒÆwÞ‘à ŠÇÓöÄ`ôßÿ^?k–sçNµKMÓ ÑÑ>í8·nõ ò11žÚZSÏžŠÅâ©­UÛ¹ÐÂG¯^½ Û–$$$<øàƒC† ihhX²dÉ¥—^úÉ'ŸˆÈš5kÜn·ˆüáhll|òÉ' àr¹¶lÙ²|ùòï¿ÿ^D~÷»ßýñt¹\¡¡¡Š¢,^¼xÔ¨Q_|ñE=4Mk¯åŽç' íÛ·ïܹ³OŸ>7ß|s{ufϞݣGÖív{EEÅ€ÂÂÂ***ºuë¶zõêÇ{¬¨¨HÓ´‡~¸²²2==ݧΉ}–ŠŒ´ôïßòå—Æ®]Ý¢iUbÚU{¹»Ü÷Ó‘bʳåé¯'×L—æ*pô3÷ëxö zôè1nܸººº'žxâ±Ç³Z­«W¯.**êÒ¥‹%''ïß¿ÿƒ>HLL\°`ÁsÏ=WTTôÒK/=óÌ3‡Z¸páîÝ»;˜\Wµk˜!¬ÂS¡'þïÝß'“ž¯ÿáÃR‰»$L kïíþë+˜:f³ù¸%íM±Go¼ñÆ7ÞXTTÔ¯_¿>}úäçç'%%-Z´hëÑU“’’·nÝ:ýÇÇ{lРAuuuñññÁz@hö=½g>çCTTÌ#ˆˆªÚlέ[ÝÅŦ³ÎÒš›½UUÞ†ÿ7ªv»æv;wîÏÁƒ"âßN€é)Š(Šæpȉ\¢(Š×ë‘©S§þÏÿüσ>xèÐ!›Í¶|ùr‰ŒŒlý»üE]´oß>ýõÅ_¼qãÆššùâ‹/ ¤‡æÿûß.—KDšššRRRœNç_|!"ÅÅÅ"2tèЀ-wüú-5[D$;,{‹cK™§ìú°ëóòNn}S§ººú¸%íMqÔ¨Q/½ôÒ›o¾©_¿«knnþàƒ.¼ðÂ?ü0<<<++ëþûïoýíM7Ý”™™yÍ5×|ýõ×guV£…Þtǹ¦Ù2hïڵ˵g¹_?5>^DÔÄDý a-ëÖYÒÓ-C†´ ÍÞúzµK—ÖÈ¥æ¾}EDíÒET5`;¾‘´¨È-Š¢:d<ã ×®]Á,ɪU«úôé£ñÎh4êñèøƒ~8%%¥k×®þïÚ¶m[FFF|||ddä…^¸yóæ€ñ×d2]pÁ"’œœl2™‚iÙ~üuéÒåŽ;îxòÉ'óòò®¸âŠ^½z³¤Û¶m³Û튢TUUsÎ9_~ùeQQÑàÁƒÃÃíVkFFƾ}ûüëœÜøð<è.-=òEÀ˜˜€—ʳN·8·$“ô/ª¢v<ѯ[¾Î°düU×®]õïq&&&žwÞyªªšL&‡Ãa³ÙúöíÛö[_?L}Ë–˜˜›Í¦Ÿ××/›™>}ú?þñ3f´^ÉÚžoZ¾q‹;Ý’eˆº2ôÊ%K>núx°e°]µë:¾Š·½u1vìØñG?Ÿø× ¦¤½)nذaüøñóçÏ7µù­ªª™™™úRn¹å–%K–8ŽÖßöîÝû›o¾yüñÇ#"" C0cƒÞ@¬™™ ï¼cËË‹}òIãÑk,ééñ/¼?gNÜsÏ©ö#ȘÇ‹}æ™cbxxxÜ³ÏÆ¿ô’eÐ 1¥¦ÆÍœÿÒK­_ ØŽoX?ï<[^ž-/ÏzÁíͤÏÝ3D$--mÛ¶m………Ÿ|òIïÞ½EäÊ+¯Üºuk~~þúõëõÿ»gŒ=z÷îÝùùù­·0{ê©§Æû…¶óÎ;oÓ¦M;wîlý" ËþüçG޽{Ƽyóî½÷^ýµ~äØÎܹsËËË].Wiié5×\#"ÙÙÙEEEÅÅÅ7Üpƒ^gòäÉ{öìyâ‰'Žœô«£ æîǬИ˜˜Ç·ÍŸÿÒKúýýo9Ì:íiìùbü‹ólóžŒ}Ò®Ú}n9w¡õÂLkæ=Q÷ˆHŒ!f©}iÀ»gœ}öÙÛ·o/+++))Ñ×׃>xýõ×÷ë×ï_ÿúל9sæÎ°Ç²²²6oÞœŸŸ¯wþ°aÃ>ûì3ýo +V¬¸îºëü§Õz÷ éoî?=núí‘·_vµ^rIÈ%÷Eß×úúªÐ«::#h]¼üòËúܶW'˜­÷‹˜3gÎO<ѯ_?§ÓY\\\TTôÆoèñضm›ÏEÀ+W®Ü±cGaaám·ÝÖÁ‚´½{½À¯ƒhF0:Í¿F¡¡¡_ýõþð9ö´gذao¿ý6ý@o: ÿ‡› cÇ}¸É¯T×®]çÍ›÷õ×_ÿßÿýŸþwü˜RSãgͲ½òJì´i†ˆ51Ѿt©mî\[^^dNŽˆ˜ÓÒb¦LÑ+G?ð€53³½¦¦OŸÞúd»ÝþÙgŸ•––îÙ³G¿eÉðáÃKr¹\¿ûÝïfΜYVV¦Í«¨¨(//ïꫯþ׿þ¥·ùú믷}fr"srº¼þº(ŠˆØòò¢î¼STÕ¾lÙÑ[8Ì7§¥¨Hcc£>‡ ,ÐK† ¶cÇŽ;w^{íµí•ø¼ëÇZ®èûïo{G‹˜Çf¹ü×i°c£·)þ…ø.ot‰™#"†CìÔXÛ|[üœxëï¬zˆˆˆW_}uÁ‚±Gï@—””ôñÇ÷Ýwùùù}úô Ørüœ9]ÞxCŸçÐË/× c¦L‰}úiýµ53ÓþŸÿ¨ "9aBHûÏ%9îú“É´k×®W^yED222V¬X‘››ÛA#{ÌúûßÇ¿ôRüœ9¡W\!"]ÞzKi½®ZQº,\T—šL6l(..Þ»w¯~Wÿ­ ƒ·+в}ûö„„ÿ_ùo_þ[e{ýÓVeeeHHHëäjÚy :¿Uí<ÜDU£ï»¯nútW~¾19YTUŽ>öB±Zãž}Ö2x°æv3o¼ñò£éG?ÜNž<ù«¯¾JMM]·nÝòåËýK>ú裤¤$‰ŠŠÚºuëºuëþò—¿ÔÖÖfdd8Ž€O¯ž÷ðaÓ™gj.—Öܬ—h.WåèÑ­¬çç_Ç_mm­>“:ƒÁ——wñÅ·´´¬_¿~åÊ•.—˧Äápø¼KoçÔ—«î™gD$ìO2„…5¼ñ†¾ƒY.ŸuêøöÛãOL‘èû¢ýãc£C?rÇåÃovîv»c§Ç:Ö;4·6zôèùóç:thüøñS§N‘Å‹¿úê«óçÏOHHPÕvoÕ\ýÀžò¸­˜ÍF»]s:•ÐP­©ID´ææK.9¼hÑ u‘Ï‹Èĉ÷îÝ«¿~衇n¸á†I“&¥§§oܸ±½v|z̵gOäøñÕwÝ¥9ñ/¾Ø²n§¢Â§/‚!2ÒÜ£yÜnwvvvyyyllì®]»–,Yâ¿tðöáÇoݺõÀó´Ïöåt:}¶Êöú§­ÂÂÂnݺéÒ´ÙlÁ?.€ßrh¶ èÙ¿ß•Ÿ/"î’QždÒZZœùùj×®îï¿f±±±£Fzë­·ôËËËËËËE¤  @Ó´ððpÿ’Ö“XþóŸ—-[æñxDä?ÿùÏÕW_íp8þóŸÿØÛ¹ð;ï¼£?ã-33³k×®ô¯ãX·Î𙩹\-ëÖ©11Û ¦Ž´´´²²²^½z………íÞ½{èС555>%«W¯öãµ\Áho¹ZשšÉFïa¯c£CDìê°c?kYÜß»½ ^™?þm·Ýv÷ÝwÏ™3GDÎ<óÌï¾ûNëðëG>eýïÿ™ç.]DÄÿüóW_}u%IIIÝ»wÿ¦Íº÷íÛg±XZ'ôÁè±R?©ëÓ§Ïĉÿûßw0uwy¹b2ÉÑv4—«òØçÿù×ñ×§OŸ²²²ÌÌÌeË–¥¤¤(Š¢(Jss³ÅbѯQö/ñ×»\>‚Y.ŸuT»^1÷7WM¬òòÆMslu¸‹Ü"bˆ1DŒ‰¨Z«×ª¯¯o{A¶Ëå r„Ô<ôPÛË3,ƒ5­\©µ´D´i­yõêÐ+¯ÔœÎà{ççûõë'"›6mt4‹oذa„ 999#FŒ˜6mZ{§™}z,dØ0ŸAâ)/7ÄNjǣ9F»ÝSQüL¦¦¦&''úé§~øáþýûnþî¸ãŽÙ³gŸè×qÿ:tÈ?4wïÞÝår577÷êÕ‹3ÍBó‘¿eð`iX°@ Åd’£Ws¶É_ni}›¢H‡>n+,,ìÝwßm{9©‰ˆŒ1âwÞi›´¦L™¢(ÊEí÷Ël6¿ùæ›cÆŒihhè`/\¨(йÿS©£_Ó¹víÚ’’’Þ½{ïß¿?11qÕªUaaa—\rIYYYuuµO‰ÿ»~Üå †Ïrù®Ó`2s×]êöôˆˆkËØÝè.r+V%æÁ˜Cóyö………½{÷n½ø!Hj\œ±[7ýû¦†˜ãÑ‹n]{÷“’Üû÷ß”OÏgff^xá…ùùùQQQV«µ¤¤äÀV«õ¹çž›2eÊ¢E‹fÏž½|ùòŸ¸Ží1om­!:ZmˆŠrîÞí­ª ¹è"×wßiÍÍæAƒš5Ò’’’­[·¦§§/[¶,àVà#<<<++ëþûï?¡-î¸ý³yófÿ58bĈ-[¶:thøðá/¼ð{O@§øò ç–-Ƥ$“~‹ƒv¾³å9pÀØ­›ªX,Ƥ$wp_ RUuáÂ…3fÌh½À׿¤54/:öË^õõõmÿlíï™gžyï½÷Ö¯_ßñ©?¾jüø¦÷ß·=+,"-_mÉÈržý{~ÆŒ½zõêÓ§Ï#<²dÉ’§Ÿ~úµ×^{ùå—{öìéõz³²²&L˜Toäç{öTãã QQæ¾}Û·»ËËMýú¹öísíÛgîß?È3Í]»vÕÿò˜˜xÞyç´·ø¸å–[–,Yâp8‚ßâ‚韀{þð‡?lܸñÛo¿½øâ‹9Ó èlŸiÖÜîÚ©S£ï¹G±X<4½ÿþ'•[CsUUÓûïÇÏš%ªÚüᇞv®Ýœ;wnvvv|||iiéwÞY^^ž••5xðà™3gŠÈe—]éS²k×®˜Íæ-[¶œÐÂÜu×]7nÔÿ••ä]±“É6¾þºá苎%''¿÷Þ{f³¹¾¾>''G¼'NüøãE¹÷Þ{õãSð]¿¨å ŠG^mˆyîÈà(Uµååé÷i6&'¢£ÕÄÄø9sDD±Zã_|Ñ2xpÀÐeÊ”ôôtŸšwß}÷¤I“Ú Íñ³g›RS={Æ¿ø¢š޽\€:íŒCBó/sløKLLÔ~™ššZ[[k6›M&SQQÑùçŸ/"ýúõÓ#²îòË/ë­·ôw8p $$Äh4¦¦¦l¼´´ô˜³í·ÜÁÈtBnb8г¿+?_DÜ%%Þ6÷mÕZZœùùj×®ô:Ûö1Úú³[Ÿd;Žu묙™ÖÌÌ–uëN¥~±cÃ_yyùW_}%"𦅇‡_vÙe{÷îÕ'¾cÇŽ´Vž8qâ‹/¾("MMMV«Õjµz<žÚÚÚ`f¦ƒ–8~hVívw;+1DFZú÷wÿ=}‡Ìž=»ªªªõÇ©S§.Z´Èl6)))wÜqÇ‚ "##Ûk£í)/· ," ˆÁ ˜L"⮨¨?¾M–qÿðlmE‡ÞD{n½õV«ÕúÜsÏM™2eÑ¢E³gÏ^¾|yï=¼p¡¢(æþýO±~EÂÂÂÞ}÷݉'îÝ»WD õ§…?üðêªZ, ÏÊʺÿþûõ·dddlÛ¶M?‡½aÆ!C†<…\VV&"k×®-))éÝ»wÀ–ðøL³sËcR’þE@QÕÀÁúÀc·nJh¨b±“’Üeeô&ÚóÚk¯½üòË={öôz½YYY&Lþ½ZS“·±ñÔëà—lìØ±ã~&WUuáÂ…3fÌX½zµ^²jÕª>}úè_×3|Ô¿å–[–,Yâp8ô‹ŠŠnµZ322öíÛçß²Íf³Ùl"Ò·oßää䢢¢€-|‰˜ IDATà/ðABs»k§N¾çÅbñ8Ðôþû?œTn ÍUUMï¿?k–¨jó‡zÚ¹Óܹs³³³ãããKKKï¼óÎ¥K—ŠÈž={RSSW¯^ýî±wÀ8!ŠÉd›?_Ýpô~íc#--M=úù<###++kðàÁ3gΑË.»l×®]W_}õ‚ ÂÂÂŠŠŠæÌ™£§aý$±nÛ¶m¯¾úê¦M›4M[²dÉúõëõò¶-'''¿÷Þ{f³¹¾¾>''§®®NDü[à'Ç-çp¢~Š{q˹߼aƽýöÛ¿º‘ øõ2ü¸Í544\wÝu<ÜÁÐ!qóÍ7×××3qBV­Zõ—¿üåW72~éL½M¦³L§^àä)§Þ„¦iô#~e9XQNëôÍøu9Ñk ËB3@hÍ¡ 4„fà·š§OŸžŸŸßúã°aÃvìØ±sçÎk¯½¶½à„DæätyýuQ±ååEÝy§^3eJìÓOë¯-ƒ·¾Ž5*üúë6eJMŸ5ËöÊ+±Ó¦""ÔÄDûÒ¥¶¹smyy‘99"bNK‹™2E¯ýÀÖÌÌ“žm£þ¿o¼ñòË/ÿ!J yyy_|qKKËúõëW®\ér¹|Jk'Ê{ø°éÌ35—KknÖK³Ùh·kN§ª559¾ý64;Û’žî..¶ R}×]ZQÕèûî«›>Ý•ŸoLNUwEEÕøñŠÕ÷ì³–Áƒ5·ûÇšç#gšcccGÕZš––VVVÖ«W¯ŒŒŒÝ»w:Ô¿„õ €“àX·Îš™iÍÌlY·N/1÷íë,(pîÞmIKÓK^{-|Ĉð‘#ÿóŸšÓé߈eà@Ïþý®ü|q—”xëêZ¥µ´8óóÕ®]Äy>šgÏž]UUÕZj·Û+** 0`À€ŠŠŠnݺù—°¾p\ÅÅÆädSJŠ»°ðHh8йm›sûvó Az‰»¤Äýý÷Ƥ¤–/¿ ؈j·»ËËÜÈHKÿþîï¿ÿñC³EQEinnv»ÝŠ¢,NŽ»¼ÜSU%š¦ÿh4ȹ}»sûvËÀGC±jêÝ[ 5DDH;U{ÄÈ‘]Þ|3äÒKEÄh·Ûòòârs›?ÿܹu«Ï;´£“; Æ€¥û÷ïOLL\µjUXXØ%—\RVVV]]íSÂÊÀÉ9¼p¡¢(æþýED‹3vë¦cÏcLJr—–†eg;¶lñ”•…]}C^ž žòrËàÁ"Ò°` ŠÉ$G¯in“ÍÝÒz¶WQÄã9é|¦yÛ¶mv»]Q”ªªªsÎ9çË/¿ô/aeàähMMÞÆFýµyàÀ¦O>©?¾jüø¦÷ß· dˆŠ ½òÊÆ%Kš>þØ2x°j·û·àܲŘ”dêÓGDôoÖ»uSBC‹Å˜”ä>…Ó¾GÎ4Ï;7;;;>>¾´´ôÎ;ï\ºtéĉ?þøcEQî½÷^ýFþ%À)² ÔòÍ7G¢ðöí¡YYêg4­Xámh‘ÆwÞ‰¸ùæºÜ\ߨív×N}Ï=ŠÅâ9p éý÷ÅïbOUUÓûïÇÏš%ªÚüᇞv®>]Náêà—Ÿ`y" @hÍ¡ 4 sÈù}äë#»è÷¹Èa»ó¢(½|Ê•1Oÿ¿Xýõàî–Ö×£2#®L;ªA–³ÏiÓÿ¥u3·7­“`dÍàt:ìðžÙÅäòhÍ®#·°0«Š=Òètk¡f¥É©}û½#»hzwKq{HË]ÿª²—G½ ²µÂy=¬þuÍøXWìÈìiuy´uÅ-1¡ªˆôíj.8àlviiÝ,ßµˆÈkß4Ü}IÔ÷5în8ìtkA¶sru‚Áå8­Šk\ɱÆ›©°Ò­— <üm¿sû~ç 3ÌzIIûûwR´ñË–àÛ1©JÞ›þÏ©¬sr:Å™fû²eŒNmUdgÓ àØôkßNéÃ_õ¾®¼ÞmR•Öȃ’,+·7µ¸µQ™z‰jÞñ&U•«¡¡Åd;.6柕×!4s€@XǦε҇¿Þ}݇EéßÕ,"qaj·hã”+cD$&Ôm,­sg÷ÛRê(«÷\?(,ïë†`Ú9•:„füâ495‘#'žaþ$¿é¥Ï‰Èÿü.bPwKƒÃ{e¿Ð¿ý«ºÉåý—ø;š*yŽÛN0Ó"4àWiÐG¾ü'"ÛËœYýBψQWìhjpxEäÍ7‰È]ULS&U™?Ò¦¿žÿMÃ/k95Mû…¯ þ €}‡¿½þ¡éŸÓ™`¹{@hÍ¡ 4„f€Ð šB3B3@hÍ¡ 4„f€Ð šø„æáÇ—år¹~÷»ß‰Hcc£^²`ÁÉÈÈX±bEnn.]€Îš?ú裤¤¤¤¤¤¾}û–••­[·NDjkkõ‘#GŠÈC=tà 7455¥§§Ókèt¡¹ÕŸÿüçeË–y<ÿzŠ¢hš¦ÿWDbccé;tÆÐ|ÓM7-^¼Xµoß¾7>\D¦NºhÑ"³Ù|ðàÁÜÜܱcÇÒwèt’’’¾ûî;EQô»uë&"™™™ŒŒŒÔ+<þøã<ð€ÏifýÜó/™}Ù2Ö/ö `þÆú‡>¤Nʼn&ØÎ41âwÞi}YY™ˆ¬]»¶¤¤¤wïÞ·ÞzkvvösÏ=×¥K—E‹]uÕUô5: cÛÐ|óÍ7ë¯m6›ˆTVVöíÛ799¹¨¨hóæÍ"’––æõz³²²V¬X±|ùrº(40Àl6oÙ²Eÿ199ù½÷Þ3›Íõõõ999uuuzùž={RSSW¯^ýî»ïÒwè\¡yÛ¶m}úôi-ݸqc÷îÝýk·´´dggÓkèTx" @hÍ¡ 4„f€Ð šB3B3@hÍ¡ 4„f€Ð ššB3@hÍ¡ 4„f€Ð €Ð šB3@hÍ¡ 4„f€Ð 0#]À˾lšÀqTdgÓ Ào —g„f€Ð šB3@hÍÀo=4766––––––.X°@/6lØŽ;vîÜyíµ×ŠHFFÆŠ+rssé2t6GnR[[›””ôC”6òòò.¾øâ–––õëׯ\¹ò¡‡ºá†&Mš”žž¾qãF:.4ûHKK+++ëÕ«WXXØîÝ»‡ª(ЦiúE$66¶¦¦†î@gpäòŒ¨¨¨}ûömܸqøðá"b·Û+** 0`À€ŠŠŠnݺM:uÑ¢Ef³ùàÁƒ¹¹¹cÇŽ¥ïÐI9ÓܧOŸ²²²ÌÌÌeË–¥¤¤(Š¢(Jss³ÅbQED6lØ0a„œœœ#FL›6ÓÌè<Žœi.++‘µk×–””ôîÝ{ÿþý‰‰‰«V­zÿý÷ÊÊÊn½õÖìììçž{®K—.‹-ºêª«è;tF±Ùl"RYYÙ·oßää䢢¢C‡ÙívEQªªªÎ9çœ/¿ürõêÕ"’––æõz³²²V¬X±|ùrº%4'''¿÷Þ{f³¹¾¾>''§®®ND&NœøñÇ+Šrï½÷:½öž={RSSW¯^ýî»ïÒwèD¡yãÆÝ»w÷ùŲeË–-[æSØÒÒ’M¯ Sቀ¡ 4„f€Ð šB3@hÍÍ¡ 4„f€Ð šB3@h@hÍ¡ 4¿FºüÙ—- ¦ZEv6}ü¼›!@h€ŸÓq1GtàgÜÓŒË3B3@hÍ¡ 4„fà7šívûgŸ}VZZºgÏžë®»NÿEccciiiiié‚ D$##cÅŠ¹¹¹t:chVeòäÉIIIW]uU^^žÙl‘ÚÚÚ¤¤¤¤¤¤‘#GŠÈC=tà 7455¥§§Ókèt¡¹¼¼ü«¯¾‘‚‚MÓÂÃÃýë)Š¢išþ_‰¥ïЉBs«Ë.»lçÎ555"µoß¾7>\D¦NºhÑ"³Ù|ðàÁÜÜܱcÇÒwè$Œ­¯Ÿþù«¯¾Zÿ±OŸ>eee™™™Ë–-KIIÙ°aÄ rrrFŒ1mÚ4=X@ç±lœ]q[Ö¼ÖBû²e"2ïýÛZK²_© ¯üÂ÷cc?Ö‘°°°¯¿þúü£ÿ¯6lØ0pàÀ[o½u„ ‘‘‘3fÌøè£®ºêªÖ ú¿dúQ ‚ß'ø×ñ?ØSŒ1à—3ƒÙGužý؉&X£ˆ¨ªºpáÂ3f¬^½Z/µÙl"RYYÙ·oßää䢢¢Í›7‹HZZš×ëÍÊÊZ±bÅòåËŽè Œ"’‘‘‘••5xðà™3gŠÈe—]úÞ{ï™Íæúúúœœœºº:½öž={RSSW¯^ýî»ïÒwèD¡yíÚµ&“ÉçÝ»w÷¯ÝÒÒ’M¯ Sቀ¡ 4„f€Ð šB3@h:+cç\ìÎó\u­nËš×úÚ¾l™ˆÌ{ÿ¶“¨pl¯}_‡Ÿ‡¦i¿ð9ÔG ;&íí~¬:ì[üø!4ƒqøëJ°\žšB3@hÍ¡ 4„f€Ð €Ð š€Ÿ€ñGlë—ö°ò۲浾Ö¿>ïýÛXåZ÷ ?…_ÚžwÀ¾®cÙÙj?–ýJÅÏ6mMÓ:íÑG#€±Æê¯Ñ‰&X.ÏÍ¡ 4„f€Ð š€Îš‡ ¶cÇŽ;w^{íµ"’‘‘±bÅŠÜÜ\º „fƒÁ———=lذ^xÁb±<ôÐC7ÜpCSSSzz:½€N%ðc´ÓÒÒÊÊÊzõê¶{÷î¡C‡*Š¢išþ_‰­©©¡ûÐ>Ól·Û+** 0`À€ŠŠŠnݺM:uÑ¢Ef³ùàÁƒ¹¹¹cÇŽ¥ïÐI>Ó¬(Š¢(ÍÍÍ‹EQÙ°aÄ rrrFŒ1mÚ´€§™;óãËtNì÷°ûu©ÈÎþ1›;÷Üs×®]›’’’––¶jÕª?þñ·Þzë„ "##g̘ñÑG]uÕU­•õ 6€_‹'Á †âââ3Ï<³[·neee‹E/OKK›>}ºªª|ð¡:4‹HvvvQQQqqñ 7ÜÐZhµZ—-[¶fÍš;3Р€ÎšÑ“Nc‚剀¡ 4„f€Ð šB3@h:+ãÒ Ï7Ÿ""öev:¢SšG´q]ªÈ®0Ð @ÇŒAÖó”{*'Tª]Tñˆeˆ%2'RD*GWz›½¢‰!ÔÿJ¼c³£~F½!Ú ÚÕȱ‘ÆnÆÓ¹$Î­ÎÆ¥1SbD¤nZõ"«5ÓÚ´¼©éý&Í­»cT\S¡Æ©ú[¢îŽÒŽ5—KŽv»b2Ùòò:®ãÛ¥FEŽý»ÄmL1" "b>Ǭ_ᣄ*"¢8CˆAkÒ‹âS""-ÿ×âØäM<•OÇfTãTýúr5NõÖy]û\æ~fŤ¨võ4_ú~òЬ_5deïA¯š žîEÑÚÄ\}⪘ÓÌæ4³Ö¬9w8~9ÏÜÏóhLË7-‡—Ž=7Ö¿‚š¨:¾uˆHÄÈñŠæÒôFÀ©ÿ¤¹Ù¢ˆv’kç·'üÆ5Msnß~ÒuT»ê.w·~@:²;¤y4ÿW«åë–Ø§c³R}_õ‘F Ç~¿6?É-盞*éÓé\5Au—¹µ&MshîR·±›ÑSéqîvŠˆæÐÜß»[o%õ|«űÑ UŸkv—º]ù.O°SglNJh¨!,ìTê¨]Tc’±ù“fñÖz=Õc£k¯Ë{È«5iÎNS¯ Æ³æÔ 1Ŭ¸ËÜîB·¸Ô1¥šÛšSó”{ÜenV¿|§”íZo9×¼º9þ•xq|ë¨S©&ª1SbÓi½&ñˆæÒ*G¹Š4bt„þÃL†ÿ%¼áKºÅ7l•˜‡cêfÔiMMPC³BýOúOýg_µ>Kj½ÐÚy†µærUŽ}tÙGù®è{£ëgÖ^xX U¢ŠVãÔˆ›"j¨M® S»µNÍ瘛–7UM¬2&­[ÝûÝÆ^Fÿ€zihÕ¸*c/cYü¼x"`gÆÛ≀ 0ž¡8ýjKþL°€öds¦p:¸‹Šj~øÐ<> â¤áÍ7kzÈUP@Wà¸N 4» «&N²Z° êöÛ«ï¾Û±~½^ràÏ®=ºrôèú3ô¹=8j”hšˆTŽSÿâ‹î’’×^[yÛm•·ÝvèÿÐåϧ€/YR5aBÕí·7¼ñ†ˆ¸öî­}≆×_®µª;ïôÖÕj‡mÇ[__sÿýGŒpîÚÕÞúÒZZ®Ó¶í8¾ý¶æÁtïë¯^²äçÝj‚Y®Ÿt‹ûÛ9õ©··Užž1vzÚ©¾çOUUÇ%·ÜüÙgÖ /Œ¼í¾t{Ü=I€ù t$ ø®†×^«?¾ƒ}Z°G´c÷~þÇÊ`Þå3?ŽM›ô®=ºâšk\ùùAö˜ÏÞÏ[[[óðÕ£GWßòõ×í­Ž;ÏÛ vÿÜfIý÷u'¹¤ÖŽÏ²·×Ï>"n¾9ôŠ+š?ýô¶˜öت3Fki9Í{ªão§¿E§rthÛc>G4cð{ÕºÜÜÈœKzú‘¶üK †˜G1ÄÄxªn¿Ý:t¨!*êWѹ®üüö"ZðýSÿ⋱S§*fsõ½÷ZÒÓ“É#¯ËÍž4ÉÔ§»¤D<žw)ÂþßÿS,–Ÿ«—/Wôçwß9Ö¯›5Kki©ùûß̓)F£!<Ü6þ1ŸØÂÃ]{÷*&“¢—¨gœ?k–x½Õ÷ÜãÌÏ7Ÿ}v€Ïy~íøïÜ›V¬°½úª¢ª•ãLJ\ziã;ïDßw_ãÒ¥®}ûL))/ˆcófSÏž†èèSì¶íÄ>óLÝ´i'·¾ZÛ± Ü´l™cãFcŽuëâfÍú™?pGEôrý[ÜÚÎižúO1Æ~ í·e­¥Å~=ÜžÄoh8ù¿«åÿþϱiÓ‰¶sܽ_€#cûLÿù± ¤Ï°ÖÔT5q¢)55¨²~{?ChhøM7™Ï>Û]VV3i’å¼óUõ=ZÁ̳o;FcûgŸ%õqrKê¿vÄëõYvc·nÇú‘Æ"#O–Å/=×:¢šÝ%%†ðpKzºˆ¨ññKDQ 11"¢9ŠªŠñt?àãð[oi« @Üî°?ÿÙ’žÞüÉ'K—ŠHhVVè•WŠˆO‰s۶Ë{ëëk&OE‰yôQÅz2÷3vââ<h--jR’k×.sZšÿñCíÚÕÔ§ˆ““ۛ级Ÿvïß/Š:lXèUWy«ÿö7SjªÖØhJM ÿë_ED¼Þú™3;vXÿ{ý>ć.lþôÓ°k®ÑS?½zhÎÍí6„…Å<ù¤òS®om­sÇëyç¹öíOE…©gOÅhTÂà 11®½{Æ_Ë!-k×*&“uÈOmí@\.Íé4XOòÆÒŠÅ¢X­šÓ)F£ †ðpMßrŽn?Þ†CDD{ooZ¾\ïdÍ鬺ãÛ¼y"RóÐCQwÞ©&&6úiãÒ¥ŠªšÎ:+rüø€kЧÀcÕo}‰Û]ûÔSî’ëDÜ|³ÿüˆHÄ­·ÖÏœiìÞ=|ÄÅlöÏç§å‹/Þ|S£1ü¯5ŸsÎñ?:ÕwÝe8Ðýý÷¦””ˆQ£N+˜åòé±€[\Ë_^¼X KZZĘ1§î#`;>c^s8l;Áœ¢8vô žÊJŸ©‹Áà¿UwŒµ|ñ…sûöÈ ô³ŒÆîÝC.½ÔgêAŽ1Ÿ:æ|æÙ×^¯¶mÇ„7¾÷^óªUjB‚ÖÜ|$[Ò¸t©sûvoMéÌ3]%%‘cƴ柭Àsð`ÛÐì³ÞýK‚Ü“øÎapG"ïáÃQwß]ÿÜsíïJ´ã?Ï>{¿GÆ ö™ÌOË—_ZÎ;O ÿ‘ÌÞÏeމc·n¢(Zs³»²Òçh¥¨èxž 11>í(ÇŸ€KÚÞ¾®í’wlø¯EQ|–=àÔý[%$Äýý÷šËàlW»©Èw)ü{£½£°»¬¬þÙg£|PMHðß?7Éøï‘nÝþ[îIìçÖ Ø‡?Ê1%àñËgZþû(Ÿ:'ëü{Ìÿˆlò¡í'úlûÔS¢ªšÃá=tèð?ÿ÷ ŠÑXu×]–óÎS,Ÿó€±TŽ­¿ëTR£ã**Ò5&ÆS] +*Œ>ï¶g‰ÈÉQããõ³­Ö¡CÅlö8ûä“jBB̓º‡U<••a×^yÇU·Ý¦ç§ðoó£9 ¯½7s¦¨jÕ¸qÁ¯SwEEÌuש±±•ãÆ…ßpƒætœÖq—˧Çü·8o]Ýáý+nút%$¤.7×¹u«éì³}¦î¿Ë °åúyMÄgÛ1žqF0Ëî³ *~»2ÿ©kN§ÿVyÜ1fÉÈhxóMÑ4Qdž aþ³ÿÔõdÌó¯Óñ:Õ{Õ§Ÿõ婨h^µ*î…¼ÕÕ•ãÆ,Kzºhš·®.lð`ǦMzkm[vnÙrhÞ<%$ÄÜ¿ÿ‘ Ùo½““}K‚Ø“œÿ#‘ÿ~#ôÊ+=w0´mÇžÍii>{¿öŽŒï3;˜Ÿæ5kZ“eÀ±ÑñÞ¯íYc÷WAÏÑJs8‚™gŸvÎ?û/iÀ}]Û% flè§¥|Ö²ÿ²ûL=àÓ™g*!!•·ÞyÛmÖ .*ù-…ooDG< {¨Ÿ93jÒ$5!¡½ýsÇI&à_<|¶no]]ÀíâD÷ó†¨(ß:--ûðÇ:¦³ìÖ—Ï>*`“Èu÷$þG´ Ï> ÎíÛã_xÁY=i’%-Í¿Dú¶W^ñõ3gZ32,çŸpÔÙNÀ9Æ=DÄ|î¹Î={ô­É·ÇUX(~²Ü]Rp<³ìÛ§víªïdõ¿rT5~¼vôz¡ø—_5.N‹Ó_xëê<••'·íì±cÎïÚå­¯¯}òIýﳞÊJÓÙgûL]µÛƒÙåùyŸm'`höYvÅhôÙÁ}þ?îVé?6«Õøÿۻ󸦮¼àçfOHXb‚)Z*bÑ S[´}ªEZ-Žã`ÑŽÚÖZ—aÚÒ_ç©…)δT´V«v;úÐÖÁ¥*#£PP”%, "˜²Ê–õ÷ÇÕ4ÍM R·™~Þø‚ãÍ÷ž{î¹7_NNî5J_YI …,™Œn^›½Ó‰‘3}Ìz³Ng·†ÌVµ‰cs¾ôÕÕ¼qã(.—íåEØÍ,¡s5B¥Ó±„Bsw7³†¼ dܲzµ¾ºúfÍ8瑩.›^pð€w»õa¾ xß°ÛlâèÔj›2ï~vßm"ª«m_å833^¿Î3ægS8¬ú†MdsG‡ÍÝ>˦ÖÖÎO?õx÷]ûïVNÔ™nŸÅ±W›v6\¾ÌõãÛoÓÙÝ&Ü1cØr¹áÚ5ËŸqf³YWZú³Á?q¢®¬ÌÑ­Á:×ÏÏ6‰¯ªâŽÅru½™*UVêÊÊÌ:KTÔ={ÚSRDÏ>k·gš{{ûΟÿéckËzÆýƒû›oê++{óó»Þ~[¶m›^ÇŒãèìôs¾(Ênœ®ƒù&°‡ ëJK“¼òŠ£þ̲—ôßÿ-Çbù(ÍúðéwÙ~ªÚO‰ÝûÙæ?8˜;w¸÷Aÿ1˼v:v;× ½ž`ïnjïªì¿"xì±Þ¼R'û†ÍÙ!f³Í±[[möÎ9ÒnSk+7  Ÿñmï6£cåèÊer{ýõŽO><ù¤m'´zÉ™ŒsW·“ã¡ßç¾ óìÜÙ÷ëc·»/›{”“õqþzïÿÍÙ§gp}}Í]]¦övb4jjØ ³ÄÔÒbll¤ûŸþâEúºº8£F髪Læîn]Y×ÏYb&1ݸñKöÅõõ5µµ³™ru5\¹Âµ7m”7a‚A£¹ùÕ`ß4ët,ŠÇ344jjè‘SK‹¾ºšºÒRîC9ìünn–O÷Ø^^fƒAW^N\xÇ¿thÍ%*J¾s§lÛ6É‚‚'ž ïþtMúΟ7߸Áõ÷7µ·›ÚÛé?¬×¯[á(‘ÈÎ4“I_Yiw ÓQœî£G-ßoeª¯®6÷öšu:}U[¡>ý´(2ÒØÔD(Êã½÷º¶{ =YYÂ'ž°Ìi£8³Ngêè0µ´êë-ÙܱcÅó盺»]ó6qnžWWÓÏ¿ac}¾è«ÆP[KŒÆ¾¢"ÞØ±Ì8¦ööîC‡\¢£E3fô?o¼vÍQþÙU0r¤¡¡ÁÔÖfîîÖWVÞÁ«ÉÉã²ÛbÖWwÌ]Yýõ#cc£©¥ÅùZYDZÛç¼vú¿íö„ÁÝ7˜}C0yrß¹s}gÎÐI³Ý;€“}ÌæO»u0ŽÍùâô•–šu:cc£¡¡Â,¹²X–?'˜çÝnOðN¬óÈÑ}£Ì8Ì2ï~ÌwF'ï™ö›1;[ÞÏ»ƒmɸû“©-%Ååùç-Ÿ¡3ß­œ©33³>Ìv¶{¤Ì{Í‘:Ó7˜g‡yìvÎŽ£»ÍÏÿ6vª{üü(˜­áè]˜ûÐC®Ë—wlÞLŒFgîÏÌ{¯3W·“ש“÷ùŸEþwì;²/Û{”ƒúÜîýÙQ‹Ù¼£9==ƒÍ–¼ürë{ï™ûúøaaôçk6%†+WÚÖ­3uvRl¶Ëï~Gúp±\]% ¶üïÿ³ÙeÎúÏhf !DôÜs-ï¾ËrqñX³fp_$åúê«-ù !Äõå—í¾™QŽÇ»ï¶mØ`îëc*ŠŒ´“Xvgdhcc9 …àÉ' W¯²GŒ`{zv}û­áòeÁ´iœaÃì~ðJL™ÒºfvåJÉË/óCBÜßz«cëV³^ÏruõøÛßîñ(tç§ŸêÊËYR)ý÷Ÿñúõ¶?¤¿á¶j•£ùî†Ë—¯¿ò !„7n=wÅöÃJq µµ–7cΨQÂéÓµ¯¿NQ”àñÇ-“5ÙÆ®^m‰<ö˜Ý½w=êñóÇ-¹Ì™óãë¯s|}-ÏÜèØ¹ÓØÜlÖéÄ11ŽF.™q!¢Èȶuën|óGBýžm}¾xœáÃo|û­¾²R0u*ý=Q›87¾þZôÜsô‡Y.óæuþãîo¿m·?Û Û»¾üòo½ÅV(ØÞÞ·ñ5'®¦‹b·Å¬¯8–››ëòå­ý+Ñë)‘Èýÿý?çûªÍ•kÓçéQ(ëkÇ™˜Ìk;v,³'ØìÝÉw\fß D"¶§§¹»›ž†awïNö1ÛÌÌ^Œcs¾Øžž¢§ŸÖ¾öÇÏ~Wc–8°$Ë[ó¼³½¼lJœº“¸¸ØÔÇÔÕeóN¤¯®fÞ7:>þ¸÷ìYSGÇõ%K$¯¾*`LbÆ!„0kèÌ{¥3˜õ1ÔÕƒÁÒÈÎô æÝO_YÙwþ¼¡¦¦óÓO !ý+gÄæ»Õ€uÖWUÙÄaÖ‡p8ÎÜç™÷:›#u¦o˜õzæÙ±{ç·ù“Þî4^¿NQßFÎgs&óì8zæÇ3æÆÿýŸxÁ‚ïÏvï½^ÝN^§î‹™o8jÃ;õž2à¾lîQŽês»y£³~G#„P„¯ƒ <¨L]]-o½5¸ÏIÁyºââîï¿wÿóŸÿËâÐBGŒFíoH?üð¶žù…k}ìF6^»ÖñÉ'loo×A=ãà® ñüãúª*×W_uò‹ÂwÖ¯öþüŸèÚìÙHšñÆÿånìÞÝWXHL&ጢˆ\;¸?’f€;Ÿ4£àîIIIQÓÏG#ÄËËëäÉ“¦²²rîܹtaWW—F£Ñh4»ví"„p¹Ü‚‚‚ºººªªªU«VýÚškúôéeeeååå¿ýíomàÉÝ4OöÉ òä(©DÀÜŽxljGŒÇ±-â:3PtïœyÞŸyæÍ-z½þ±[O«°îQ©©© ô"IµµµŸ~úé¸qãúúúª««kjj6mÚÔÏ*†\.·¢¢â“O>é¿V–m”Jeffæºuëœ9Š¢JKK‡:÷P*gâÈåòœœ­Vûøã[oššúšeÙ!±¸Ú²Æl¿õ™={¶Z­...–ÜZ¢Å:Žó˜qn÷¸úÜg111eee–G¡PL™2…ÐÚÚÊãñ!ÆæÝT¡PB¤Réµk×äwj±½ÿ,«¾¾ÞÏÏÏÛÛ[£Ñðo­ÚeÍ"Ÿ.Ê%„øH9îÂ;œ4{JØnƒù ³CGçÝÍÍ­®®ŽÍf3{TjjjYYYhhhpppii)4BØlvaa!Ýß슋‹KOOï?i¶Þfÿþýb±811qÒ¤INDDÄ×_ýË›Å&Îwß}g“4ûøøXÚªŸ¤Ù&ÎÞ½{Ÿøù*¯ÖqœÇŒ3¸ãºïõ¸GÉž£ÿJ¥‹­sjllÌÍÍ%„\¼xÑl6‹í=Ål6766BD"‘Á`Ð;X:kÑ¢E*•ª°°pÛ­oµ/Y²¤¼¼¼¼¼|åÊ•ÎWýý÷ßONN>yòdNNNdd$!$::º¢¢¢´´tãÆN•••›7oÎÊÊZ»ví Û188¸¡¡ÁÏÏO©T^¸pÁ&=¢=:‚µÝ¨nÒBê[ m=&BÈÂPñ¢É’fK×FI'äBÞyÆý£ßË6Ï“Í B\ø¬1ò·žv/Òã…I7›E‘ןrût|ÉonËÅ(ÅΖ>>ú§‡>äÉÝ0wÈæy²¤ç¥Ö]|Ls?ç}Þ¼y4ÌEIOOŠŠŠŠŠJOO·.çóùB¡ð†ƒÇ’{yy…‡‡gddôS%›m(Š2›Íô¿tMúymllìG}D÷ K"›íïïo·÷2û¡M»Ö¬Y“m}Ôééé—.]JJJ²[__ßìììiÓ¦mܸ1;;›¾™q¼.ìÆ±¹}}}KJJ\\\ø|þùóç~øá¶>÷ߨQ£,ã‚3fÌ8}ú4ýsggguuõ¹sçžyæË/^Ôét/½ô’£°—.]rww'„Èd2ú_F#•J%IMMÍÈ‘#OšO:ÅårétmèС–ÏvÓÒÒž¶·4†Ý¤Y¯×6Œ¢¨ªª*ñ`‘8sæÌ}ûö½ùæ› »víúÃþÀÜæ¹q¢åá¶O_*Nz^ÊfBŸCBdb6§þnˆ‡ˆåÂg¥/ó*aB’ž—ŽðàðØTú2¯‘R‡E}¾PÎãÜLˆ£'ŠŸwszEÈŽù# !ÄSÂfßýh»ç=;;û1«•D¬{Tjjêüùó322222æÌ™C4÷ööªÕê7nìܹÓÑŽ¾üòËW^y¥Ÿ‘f›m”JåÁƒ“’’FŒ±nݺwÞyÇÑ ýýýÏœ9cé̤٦÷2û!39Òo™Å$‹Ífóøñã9NQQQð­5·˜q233'L˜à(Žó×…u»×૯¾ºeË–?ü0..Înû<õ¸g8·µµB¡Ø¸qcTTýëØ±cÂÂÂ<èïïßÑÑA ðññù׿þuôèÑ«W¯2ƒäåå}ùå—™™™û÷ï'„;w®¥¥…rúôéË—/;YŸÐãšÝÝÝ3gΔËåôࢫ«ë§ŸRÞÐÐÐÐÐ@ÿàééycPëiSEQTOOŸÏw4—¢n®"üb¨dúÜé<¡î!„œ©í3š!¤Ï`&„L}H2‚O"—°¥"öµN£¶ËØÔi$„T]×û˹MÆ»—[ „¦N£‡Eÿ¯5/7¶Ád.oÔBš;÷ '1ÏûðáÃGŽ™——×Ï«ª««ù|¾ùÖêÊjµz„ B¡0333""âèÑ£6ÛÓ)xaaaHHˆ£˜Ìm V¬X±téÒ $''·8^ösÕªU[¶lé§Â6½—ÙŒÃÔØØ¨R©!Ç +))\œA\v¯Á;v=zT$M›6Íùö¹Çõx“f—½{÷ÆÆÆVUUYÒMBH~~~}}ýèÑ£‹ŠŠèòúúú’’’I“&´÷è… †……Í™3ç‡~3fŒuŠÙÏw¿ì¢Ótš^¯ÏÊʲ;ÄÛ?ƒÁ`ù™ÅäìÕ«W ÅñãÇ]\\žzê©{K½7v'ŽäBvídQ„{kÊD·ÞôSêéÉ}ÌWðÎÁÁ¼.jÝì[ͦ(:»4ÜJƒÍ柖uyÞ76ç}Á‚ß~û­¹ßj%&&Re“õôô9r$<<œ™4‡………‡‡«Õj777@P__o3™Áî6MMM`ýúõ‰‰‰{öìÙ²e‹ÝÙb±822òÏ·–13™L–i™¤nÓ{™ýçÖÙ±m‡~Z†þ/»qmüK® »× ‹‹ =U]"‘´··?€õ¸—œÍÙlöîÝ»7lØ••E—Èårúë><òˆOmm­··7ý¶B¡ ½xñ¢ÝP£GÎËË[³fD"a±X*•J©TÊd2WW×ððpKæ}»òóó§NJ\ùûû{{{ßËvT©T^^^EiµÚÀÀÀœœæ6ÅWtÃÝ9ôÍ—àq¨Ö“Î`æÎ-çpØ„"uaù˹l òæU5ëÕ¡½Çä)aÓ?_k7rXÔ½™žáè¼/X°`Ïž=ý¿¶½½½­­ÙÙÂÂÂì~à°aÃ??¿±cÇ&$$¤¥¥Y2æeË–-_¾ÜÑ6ŸþùÖ­[}}}M&SddäŠ+ìVfÑ¢Eiii}}}ô¯:N Èd2ooï   »½×™84­Vk3ªÚÜÜìããcùU¡Ps8œ3fÐÃóvã0ÙÄÄua÷LIIÙ¹sç† ,3³´úÜKGš·oß>{ölzráÿøÇÆÆÆÈÈȉ'¦¦¦Bf̘!‰öíÛÇãñÚÛÛ—.]ÚÖÖ¦P(¾ùæ©Tj0’““™ó¡i›6mòññ …‰‰‰&“I«ÕÆÇÇŸ>}š¢¨õë××××îHš››W¬X‘™™Éçó;::^xá…{ÙŽ&“)66öرcEÅÅÅÙM, &óG[ßüw>‡jê4.ïfnSѨ›$ÚkÛ|Úán›>}ú7ß|óßçAk$ÍwS||ü… ***’““-…\.·¢¢‚^wËåÔÕÕUUUY/ ö+1}úô²²²òòòßþö·Ž¶ ðänš'ûäyr”T"äsàxljGŒœY¾tŠëÌ@Ñý:ü””ëç¥tuui4F³k×.»í“ššÚÐÐ@?…·¶¶–^°¯¯¯ººº¦¦fÓ¦Mý<´Ûf_öU¥R™™™¹nÝ:g„¢¨ÒÒÒ¡C‡þ±ċŖ•­¥¦¦¾öÚk·UŸºº:g­t2òížSgZà×N¡P455 …B‡SSS@—ÇÅÅ¥§§ÓI3EQôêR©ôÚµkôSœ%X,V}}½ŸŸŸ···F£±¬…aÍ"Ÿ.ÓÏiö‘rÜ…w8iö”°Ý„¬ûrø111eeeÖé”F£é¿}RSSËÊÊBCCƒƒƒKKK餙~D›Í.,,œ2eŠ“û°¯îß¿_,'&&Nš4iÀc‰ˆˆøúë¯y›Xâ8Jš}||œ¹F¬ëãdÒìdäÛ=§¶<Às²çävÝÝÝ]]]@ ÆÖÖVBˆ——Wxx¸eq5³ÙÜØØH‰Dƒ^8—iÑ¢E*•ª°°pÛ¶mtÉ’%KÊËËËËËW®\é|Õßÿýäää“'OæääDFFB¢££+**JKK7nÜèd@PYY¹y󿬬¬µk׺ƒƒƒüüü”Jå… üqæ6Žà_m7ª›ô„úC[‰²0T¼h²äƒÙÒµQÒI#ù„wžqÿè÷²Íód³‚D„>kGŒü­§Ýß‹ôxaÒÍ„‰E‘ןrût|Éo$7¥øÃÙÒÇG ,»{È“»aîÍódIÏK9,ê®v#©TºxñâÛmŸôôô¨¨¨¨¨¨ôôtëù|¾P(t´žù€ûböUŠ¢Ìf3ý/¡Ÿ—ÇÆÆÒËgK²›M/àÂì½Ì~h‡>¢ôôôK—.YVcY³fMvvvttô€ýÐ:m̘1………¾¾¾UUU<.¤(Š~ü³ó‘-|}}KJJ\\\ø|þùóç~øa»í<`Ë!„¼øâ‹mmm­­­–Õ¾üòËW^y…i¦]¼xQ§Ó½ôÒKŽâ\ºtÉÝÝ"“Éè5T*•H$555#GŽt>i>uê—Ë¥Óô¡C‡K$BHZZÚÓO?ídÒ¬×ë‡ FQTUU•3ÃxvÍœ9sß¾}o¾ùfBB®]»ì®üÜ8ÑòpW›Â…¡â¤ç¥ôŠ}|E‘‰ÙtZœú»!"– Ÿ•¾Ìk¨„MIz^:ƒÃcSé˼FJ9õùB9s3!Žž(~vÜÍé!;bä÷fE@Ú¨Q£¬Ç ;;;«««Ï;÷Ì3ÏØmŸÔÔÔùóçgdddddÌ™3‡iîííU«Õ7nÜØ¹s§óû°¯*•ʃ&%%1bݺuï¼óŽ£úûûŸ9sÆÒ7˜I³MïeöCf±Xl6›ÇÏápŠŠŠ‚ƒƒéòøøxË,&GýÐ:!¤®®nܸqçÏŸ;v,!ä›o¾™8q¢B¡>|ø˜1c:ä|d¯¾úê–-[>üðø¸¸~ÚyÀ–øoÅqr;ooï„„ƒÁ››ûý÷ßÓ“, CBB¬· ðññù׿þuôèÑ«W¯2Cååå}ùå—™™™û÷ï'„;w®¥¥…rúôé»ë'ÛuàÀz<»»»{æÌ™r¹œövuuµY²¸ ôžžžŽ8ûGQEQ===|>ßÑd\Š"f3!„¼*™þ°ðg:O¨{!gjûŒ&Bé3˜ !S„ŒàS„È%l©ˆ}­Ó¨í26u !U×õþrnS‡ñÇnãå!¤©Óè!dÑÿkÍËm0™Ëu„fÆÿÞcÇŽmhh ;xð ¿¿¿£ö©®®æóùô0!D­VO˜0A(fffFDD0ד\_-((X±bÅÒ¥K,XœœLw6»V­ZµeË–~‚Ûô^f?´§±±Q¥RBŽ?VRRâ'2nð IDATd?dÖçСC{÷î¥3׳gφ„„ÌŸ?_(æääX§×·ÛÃwìØqôèQ‘H4mÚ4ܘœT*•*•J«Õ¶µµLž<9,,,<<\­Vÿío‹ŽŽ¶½«¯¯/))q4táÂ…k×® øá‡ètÓ:õ¼­ÚwttX~ÖëõYYYÓ¦M›6mZHHˆó‹0 †Ÿšƒ5È!Ù«W¯*ŠãÇ>|xèСtŽb£±ÃèåÊ&„ì:Û™¥îáÞš2Ñ­ÿi5æOîc¾‚5‡[Wlih5ÒíÁ¾Õ,lŠ¢³Kí4Øl&–*›ÍPÇ¢[ ??¿¾¾~ôèÑŽÚ'11qõêÕ6¯íéé9räHxxøàvÍì«/½ôÒìٳׯ_ïéé¹gÏžY³fÙ}¡X,ŽŒŒ´¬{g2™,Ò2Iݦ÷2û!3Ž Ë_柟0f?´gñâÅ&L „œ9sfâĉC† ‰D!!!gÏžu22“‹‹‹B¡pss£?«€A&͵µµ'N‹Å@©TVWWoذÁÏÏoìØ± iiiIIIÞÞÞôGØ …"44ôâÅ‹vC=://oÍš5‰„Åb©T*¥R)“É\]]ÃÃÃ‹ŠŠw$ùùùS§N¥˜ýýý½½½ïe;ªT*///Š¢´Zm```NNs›â+ºáîú‹€ŽæKð8TkIg0s猖s8lB‘º°üå\6‹yóªšõŽêÐÞcò”°éŸ¯µ9,ê^Nϰ&—Ëé/¢=òÈ#>>>µµµŽÚ§½½½­­Íæål6;,,Ìù!Ë–-[¾|¹£¾úùçŸoݺÕ×××d2EFFZæÙX´hQZZZ__ý«N§2™ÌÛÛ;((Ènïu&}Es8œ3fäååÑ…ÍÍÍ>>>ý3!¤  `ùòå_|ñ—Ë=þüO<¡Õj/_¾üÜsÏY’æ#3¥¤¤ìܹsÆ 6ó§àö’f•JõÙgŸ–””ìÝ»×òölÍÍÍmÿþý ùùùÉÉÉŽæ>nÚ´©¬¬L¥R%&&šL&­Vúôé³gÏ®_¿¾¾¾~pGÒÜܼbÅŠÌÌLµZ½{÷n¡Px/ÛÑd2ÅÆÆ;v,777..Î&Ñ¡Læ޶®œê¶#Fî+ãiìlSѨ3šÌ›çÉþ0Y|òb¯·‡ÒÜiœâ²å÷²ÜK½ mGuȽÔèÅû8Z2‚o&$åDÛÒ)’£eo<åF‘»ûEÀíÛ·çåå=Z£ÑÌ™3ÇÇÇçüùó×®]Û·oßÒ¥KÛÚÚœiBH```]]]uuuWW—£Ï löEÓƒ¯ýôÕÊÊÊ€€€¬¬¬Ã‡;ʼ­gçÓ©dQQÑöíÛÏ;g·÷:G­V¯^½º¦¦æðáÃ¥¥¥táwß}÷øã———GDD8‡öïÿ;???!!¡»»[§Ókùõĉwä¹Ô÷B||ü… ***’““é’’’’ÆÆÆ#GŽÐ%|ðAEEEaaáìÙ³mí3}úô²²²òòòßþö·Ž¶ ðänš'ûäyr”T"äsàxljGŒœY¾tŠëÌ@ÑÒÌž`S’ššÚÐÐ@?¹¶¶–^°¯¯¯ººº¦¦fÓ¦Mý<´;%%¥Ÿué¼¼¼Nž<©Ñh*++éA(•ÊÌÌÌuëÖ9SsŠ¢JKKéµ{~ K±XlYYÐZjjêk¯½öKê#—Ësrr´Z­ÝeÛï,ëõaÖç^Öà P(ššš„B!‡Ã©©©  W奿QD?ùÑGU©T<ÏÃÃC­Vóx¼_Oû°X¬úúz???oooFcY ÛE>] §ŸÓì#å¸ ïpÒì)a» YBk0{³$55µ¬¬,44488¸´´”Nš‹‹‹ !l6»°°pÊ”)vƒÇÄÄ”••õ“4+ úµ­­­<oÿþýb±811ÑÑ‚;Ö"""îÈã,q%Í>>>ôÓ¬a}èÌ=I³£úÜ›ÜÝdÏÉíº»»»ºº@ 0­­­AAA­­­‡"„\¹r…âççWRR¢ÓéZ[[¯]»¦T*í†Z´h‘J¥*,,ܶm]²dÉ’òòòòòò•+W:_õ÷ß?99ùäÉ“999‘‘‘„èè芊ŠÒÒÒ7:Ÿ TVVnÞ¼9++kíÚµƒnÇààà††???¥Ryá»)£#øWÛê&=!¤¾ÅÐÖc"„, /š,ù`¶tm”tÒH>!ägÜ?ú½ló<Ù¬ !Ä…ÏÚ#ëi÷÷"=^˜$¾yÚ(òúSnŸ./ùÍÍõÛb”âgK-°ìî!OC6Ï“%=/å°îécR˜=ÁnßHOOŠŠŠŠŠJOO·~9ŸÏ …ŽÖ3—J¥‹/îgï¹¹¹„‹/šÍf±XLQ”Ùl¦ÿ¥#ôóòØØXzë41;;›^¸‡Ù{™ýÐ&}Dééé—.]JJJ¢KÖ¬Y“=`?´Äqww¯©©Ù½{÷áÇÕß¾}¥¥¥%%%úÓŸì^qo½õÖ¡C‡èçOÿðᡡμŠþc櫯¾ª­­ýûßÿN— âŠøï÷â‹/¶µµµ¶¶Ò ªÍš5ëÀGŽ)..Ž‹‹#„<üðÃ.\pqq6lXKK‹£Y —.]rww'„Èd2ú_F#•J%IMMÍÈ‘#OšO:Åår !"‘hèСÅÅÅô"ÀiiiO?ý´“I³^¯6l=p.‹×83gÎÜ·oß›o¾™°k×®?üáÌmž'ZîjS¸0Tœô¼”^±Ï¡!21›N‹S7ÄCÄrá³Ò—y •° !IÏKGxpxl*}™×H)‡Ã¢>_(çqn&ÄÑÅÏŽ»9=ƒ"dGŒü~­Èì Ì’ÔÔÔùóçgdddddÌ™3‡iîííU«Õ7nÜØ¹sg?ñGÕÏH³ÅŒ3NŸ>MQ*•LJJ1bĺu묗|·áïïæÌKß`&Í6½—Ù™qÄb±Ùl?~<‡Ã)** ¦ËãããW­ZÕ?´Žãîîn4}}} !§N ¤ËmÆqé}ØlvQQ‘——³Îo½õÖŠ+V®\ù׿þ5**ê/ù‹3¯¢ÿZ~ä‘Gx<ÞåË—…B¡£+#Íð_‰ãävÞÞÞ þþþƒ!77÷ûï¿7™LO>ùdppðõë×Ïœ9sâĉ’’’mÛ¶åææ677ççç;Zd8//ïË/¿ÌÌÌÜ¿?!$((èܹsôbf§OŸ q~ýäèõzBHww÷Ì™3åryFF!ÄÕÕ•NœÑÐÐÐÐÐ@ÿàéééh€³EQÕÓÓÃçóMÆ¥(b6BÈ‹¡’é ÿq¦ó„º‡r¦¶Ïh"„>ƒ™2õ!AÈ>Eˆ\Â–ŠØ×:Ú.cS§‘Ru]ï/ç6uì6^n1Bš:Bý¿Ö¼ÜØ“¹¼QGifüïÝvᛞÀ,¡·¬®®æóùô0!D­VO˜0A(fffFDD=ztÐuP(7nŒŠŠ"„¬X±béÒ¥ ,HNN¶¬œÇ´jÕª-[¶ôÖ¦÷2û¡Ý8*•Šrüøñ°°°’’'û¡MFS[[KÑĉ+**˜qbbb"""(Š9r¤··÷µkטuîèè „ÐÃùnnnN¾êêÕ«ååå„ÚÚZ//¯Á]qÿ‰œT*•*•J«Õ¶µµLž<¹©©éÂ… uuu]]]ùùù<ò!dóæÍ&L˜1c†››ýîδpáµk×üðÃtºizÞVíé÷~š^¯ÏÊÊš6mÚ´iÓBBB-ÂÌd0ü´0µ£D@W¯^U(Ç?|øðСCéìÇFc‡ÑË•MÙu¶3KÝý5e¢[ÿÓjÌžÜÇ|k·®>ØÒÐj¤Ûƒ}«YØEg—†[i°ÙL,U¾•y>˜=ÁnßHLL\½zµÍk{zzŽ9>è½»¸¸ìÝ»766¶ªªŠòÒK/Íž={ýúõžžž{öì™5k–ÝW‰ÅâÈÈHË:|&“ÉÒ!-“Ômz/³2ãØ°ü…`þù cöCfçæ_¹l6ÛnœÐÐйsçFFFN›6M­VÓqìÖÙ‚Íf;ù*Ëâçf³™Íf;ºâÌŒŽh~ º&À]Mškkk'Nœ(‹R©¬®®...öððËå\.7$$¤¦¦†âããC™9s¦T*=þ¼ÝP£GÎËË[³fD"a±X*•J©TÊd2WW×ðð𢢢ÁI~~þÔ©Séá.ooï{ÙŽ*•ÊËË‹¢(­V˜““ÃܦøŠn¸;‡þ" £ù<ÕÚcÒÌÃÜ9£å›B¤.,9—Í"AÞ¼ªf½£:´÷˜<%lúçkíF‹º_Ó3ìö»}£½½½­­™Æ………9ÿ!dÙ²eË—/·¼|÷îÝ6lÈÊÊ¢K>ÿüó­[·úúúšL¦ÈÈHz~Ó¢E‹ÒÒÒ,©¡N§2™ÌÛÛ;((Ènïu&!D¡Ps8œ3fäååÑ…ÍÍÍt›8ÂŒãíí=iÒ$.—ûä“OÐ…Z­Ö2Ê+ ¯]»ÖÓÓ3f̘‰'Ò_ư΃{•£+κ>ŽJþk“f•JõÙgŸ–””ìÝ»÷ìÙ³ƒá7Þ8vìXiié±cÇè™—©©©Z­vݺuv'õÒ6mÚTVV¦R©M&“V«?}úôÙ³gׯ____?¸#inn^±bEff¦Z­Þ½{·P(¼—íh2™bcc;–››gèXLæ޶®œê¶#Fî+ãiìlSѨ3šÌ›çÉþ0Y|òb¯·‡ÒÜiœâ²å÷²ÜK½ mGuȽÔèÅû8Z2‚o&$åDÛÒ)’£eo<åFÝóõÒ™=Á™¾XWWW]]ÝÕÕå賂íÛ·çåå=Z£ÑÌ™3‡. ž0aý³R©ŒŒŒLMMÕh4Æ2÷·²²2 ++ëðáÃŽ2ïO>ùĺ$%%…þÂܹsçìö^'ã¨ÕêÕ«W×ÔÔ>|¸´´”.¤gú–——GDD8§®®îwÞ)--ýî»ï*++é­[·&$$”••ùúúæää †’’’¤¤¤]»v=ôÐCÎÔyp¯rtÅY×ÇQ ÀæÂgm›/C;ÜmÓ§Ow4¡â‰ãîîîÌ×4ï’fáÂ…ŠŠŠäädº$$$¤¤¤¤±±ñÈ‘#„gžyFs‹^¯ì±Ç~Uí3}úô²²²òòrGK!B<¹›æÉ>yAž%•ù8›Ú#g–/â:3Pô 4…——×É“'5Meeåܹs-å)))–Y¹©©© ôƒkkkéûúúª««kjj6mÚäè¡Ý¶3sïJ¥233sݺuÎTž¢¨ÒÒÒ¡C‡þÂF°Ä‹Å–•­¥¦¦¾öÚk·UŸºººA/Z ÷‚B¡hjj …§¦¦& €^ï÷ÙgŸ%·Öàµpss«««c³Ù¿žöa±Xõõõ~~~ÞÞÞƲ†56‹|º@N?§ÙGÊqÞá¤ÙSÂv²Þ2eÊBH@@@kk+ýÜߘ˜˜²²2뤹¬¬,44488¸´´”Nš‹‹‹ !l6»°°Ž0ˆvfî}ÿþýb±811qÒ¤IV>""â믿þå`‰ã(iöññ‘Ëå·U$Í÷-Ùsr»îîî®®.@ ŒFckkkPPPkkë¡C‡!W®\±ÞxÞ¼y4í¯Þ¼hÑ"•JUXX¸mÛ6ºdÉ’%åååååå+W®t¾êï¿ÿ~rròÉ“'srr"## !ÑÑÑ¥¥¥7nt2ˆ@ ¨¬¬Ü¼ysVVÖÚµkÝŽÁÁÁ ~~~J¥òÂ… ?þ8s›GGð¯¶ÕMzBH}‹¡­ÇDY*^4YòÁléÚ(餑|BÈ;ϸô{Ùæy²YA"Bˆ Ÿµ#FþÖÓîïEz¼0éfÂÄ¢ÈëO¹}º@¾ä7º$F)þp¶ôñÑËîòän˜;dó§¹±±177—rñâE³ÙLçyR©tñâÅÖ›¥§§GEEEEE¥§§[—óù|z…çÁµ3sïE™Ífú_º&ýT>66ö£>¢û†%ÙÍÎÎö÷÷·Û{™ýÐ&}Dééé—.]JJJ¢KÖ¬Y“=`?´ŽC3fLaa!ýÌc›½3ëÌŒlw_ÌkÇÑqÀ^|ñŶ¶¶ÖÖVzAµY³f8pàÈ‘#ÅÅÅqqqÖ[fgg÷37ãÒ¥Kîîî„™LFÿ«Ñh¤R©D"©©©9r¤óIó©S§¸\.!D$ :´¸¸X"‘BÒÒÒž~úi'“f½^?lØ0zà|ÐÃx3gÎÜ·oß›o¾™°k×.»ëw<7N´<ÜÕ¦pa¨8éy)½bŸCBdb6§þnˆ‡ˆåÂg¥/ó*aB’ž—ŽðàðØTú2¯‘R‡E}¾PÎãÜLˆ£'ŠŸwszEÈŽù}\6cƌӧO[~5j”õHóüùó322222æÌ™C4÷ööªÕê7nìܹsÐíÌÜ»R©räHËZÁLyyy_~ùeffæþýû !AAAçÎkii!„œ>}:$$Äùõ“8 ×ë !ÝÝÝ3gΔËå„WWWç—ímhhhhh ðôô´;À9 Š¢(ŠêééáóùŽ&ãR1› !äÅPÉô‡…ÿ8ÓyBÝC9SÛg4BHŸÁL™ú dŸ"D.aKEìkFm—±©ÓH©º®÷—s›:Œ?v/·!MF!‹þ_k^nlƒÉ\Þ¨#„4wïKßR(7nŒŠŠêg›êêj>ŸOBÔjõ„ „BafffDDÄÑ£GÑÎ̽¬X±béÒ¥ ,HNN¦;›]«V­Ú²eK?amz/³ÚÓØØ¨R©!Ç £¯gú!³>‡Ú»w¯õ›­÷.Œ|õêU›’G}ÔîµÃ<.€_-gG •J¥J¥Òjµmmm“'OnjjºpáB]]]WWW~~þ#++kÚ´iÓ¦M q´3“ÁðÓÂÔ,Ö ‡d¯^½ªP(Ž?~øðá¡C‡Ò‰Æ£—+›²ëlg–º‡{kÊD·þ§5Š<¹ù Ön]}°¥¡ÕH·ûV³°)ŠnVí4Øl&–*;nòûÀÅÅeïÞ½±±±UUUýl–˜˜¸zõj›Âžžž#GŽ„‡‡®™{饗fÏž½~ýzOOÏ={öÌš5Ëî«Äbqdd¤e>“Édé–ÉÓ6½—Ù™qlX. ›k„ÙíÆY¼xqDD„eÍp›½Û­33²M‰£kÇæ¸4¬¶¶vâĉôg»J¥²ººº¸¸ØÃÃC.—s¹ÜššKÒ¼gÏž~B=://oÍš5‰„Åb©T*¥R)“É\]]ÃÃÃ‹ŠŠw$ùùùS§N¥Éüýý½½½ïe;ªT*///Š¢´Zm```NNs›â+ºáîú‹€ŽæKð8TkIg0s猖s8lB‘º°üå\6‹yóªšõŽêÐÞcò”Üüòåµv#‡Eݯél6{÷îÝ6lÈÊÊêËööö¶¶6æËÃÂÂì~àਗ-[¶|ùrG{ÿüóÏ·nÝêëëk2™"##éùEL‹-JKKëëë£Õét@&“y{{Ùí½ÎÄ!„(Šàà`‡3cÆ Ë‡0ÍÍÍ>>>ý43!¤  `ùòå_|ñ=q†Ý:?à×Àg§g¨TªÏ>û¬°°Ðl6§¥¥={–òÆo;vL(8p€žy9~üxG?Á‘M›6ùøø…ÂÄÄD“ɤÕjãããOŸ>MQÔúõëëëëw$ÍÍÍ+V¬ÈÌÌäóù/¼ð½lG“É{ìØ1Š¢âââlšÁdþàhë›ÿãÎçPMÆÃåv>ò®hÔÍ mž'kì0œ¼ØëíÆ¹Òjlî4Î qéÁÉ®êmh3ðØöÇãs/õ¾éñq´ì³: ¯ô¥œh[îÊeS½¦„ŒVBîÝ@´R©ŒŒŒœ8qbjj*!dƌ۷oŸ={6=…ýü£ÝÖÕÕ™ÍæS§NÙý¬ÀQ;[žÖbwï„ÊÊÊ€€€¬¬¬½{÷ÚÝû²eËfΜi]’’’RTTT\\|îÜ9»½×É8jµzõêÕaaaÿüç?KKKéÂï¾ûîðáÃåååqqqÙÙÙÎÄ¡ýûßÿÎÏÏOHHøË_þÂü_fðkàpá³¶Í—¡î¶éÓ§;šPñI3À€('·ó:xðª÷µÙ³Qg¸7Y ­Ð¿›I³Z­nllÔh4fÙ²etaJJŠZ­¦îÍÏoKN&„³¹-9ùFZ]Þ±sg÷‘#ôϦöö–?ÿ¹yÁ]E…£’;ȦÎ^^^'OžÔh4•••sçÎ¥·éÎÈÐ._~}éÒÖ÷Þ»­àmkדén×™ËåÔÕÕUUU­ZµêfSçæjW®Ô._niX»¬[þ®Ö8–Ÿžxâ‰êêj˯111Ìt~ñ%‰££é_]žžâóo&ànnÒµkoæÖJî,ë:+ŠøøøÜÜÜ€€€3gÎdddº’šJñùúššÛЬW«‰Ù|·ëLQÔìÙ³¥RiEEEZZšéÆŽmÛ†lÚDñxÚ?þQ0y2K*µǺåïv~åNÏJ¥‹/¶)ì>rÄP_ï¶r%ýëÝ»[V¯îÍÉyޤ±±177—rñâE³Ù,‹MZ-ËÃÎ,¹£GÓ›õœ8¡]¹R»re÷¡C7âë¯;¿úªåÝw[þüç¾sçt*UËêÕ¦öö–øø–իͽ½w¯Îf³¹±±‘"‰ ƒ^¯×«ÕœQ£ØC†°$^` ®¬Ì¬Ó]õUzû–Õ«Ì–¿—uøúi¤9;;Û`0B¦NZ__¿eË–Q£FYoª¯®îÍÏ÷xï=ÂfÓ%â˜ËÏ÷…MéÂ3f”——·´´ }øasw÷qqüÐPÑôé,©ÔÔÑqãŸÿ²y3Åáhÿô'~h([.'„èÕjéûï6ÛÜ×GñùÒñã¯/YB—܃:_¼xqÔ¨Q¯8ä_ãIDAT½öZ[[›[k+ËÍíæ4nnÆ–»AlZž7~ü]­3’曦M›f==ƒÉl0¸ÅÆv~þ9?5õÉ̘uV(7nŒŠŠ"„P<Þ¿ÿ]WVÖ›Ÿ¯}ã ÙæÍ†Ë—9þþ,‰„ Ô×ÔÐI3òdúˆl&<Ü›:øøøüë_ÿ:zôh‡C¨ŸiB!xÜÆÓ3xcÇ ŸzŠãíÝ•žþS)Åxh3%w‡‹‹ËÞ½{ccc«ªªn±Ù¼à`×eËø>ª++s4å—%ÝßÓP___RR2iÒ$¶‡‡©­.4µ·³ÜÝ ë§sdÖëï}«Àm?rNòÊ+]û÷¯_¿ùz77csóÏ"ººš´ÚþKî6›½{÷î 6deeÑ%Æë×u.BÌ}}†Ë—ÙC†pFÒWU™::ÌÝݺ²2®ŸŸ£h”Hdºqãn×ÙÛÛÛßߟ¢P(BCC/^¼È 4\¹bÔjMííºŠ Þ¸q‡cÖéL¦–í)(v[þÞÔIóO¶oßž——7zôhF3gΜŸrS¹\ôÜsÛ·Ó¿ ¦LÑUThW®ì+,¤KD‘‘7ÒÒ´«V›š•Ü J¥222255•~ [`` 1›o|õÕõ—^Ò®ZÅ{ôQîØ±,WWÉÂ…-ÿû¿?ÆÅ¹Ì™ÃöôtMôÜsôWïê—êÜÜÜöïßßÐПŸŸœœ¬V«)Ïõ¥—ZÞ~ûúË/»<ÿ<ËÃâ2gί¿ÞþñÇ\Ëkí´ü=©3À¯V|@ëÜwöìo¾ñxï=z6ÜÇ,ŽƒVx0ñCC)@WV&øÍoÐ÷’æoüx4ü:ý^þµ†ŠŒd·IEND®B`‚nvtop-1.0.0/src/000077500000000000000000000000001341567056100134555ustar00rootroot00000000000000nvtop-1.0.0/src/CMakeLists.txt000066400000000000000000000015771341567056100162270ustar00rootroot00000000000000configure_file( "${PROJECT_SOURCE_DIR}/include/nvtop/version.h.in" "${PROJECT_BINARY_DIR}/include/nvtop/version.h" IMMEDIATE @ONLY) add_executable (nvtop nvtop.c interface.c interface_layout_selection.c get_process_info_linux.c extract_gpuinfo.c time.c plot.c) target_include_directories(nvtop PRIVATE ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include) set_property(TARGET nvtop PROPERTY C_STANDARD 11) target_link_libraries(nvtop PRIVATE nvml ncurses m) install (TARGETS nvtop RUNTIME DESTINATION bin) include(compile-flags-helpers) include(${PROJECT_SOURCE_DIR}/cmake/optimization_flags.cmake) add_compiler_option_to_target_type(nvtop Debug PRIVATE ${ADDITIONAL_DEBUG_COMPILE_OPTIONS}) add_linker_option_to_all_but_target_type(nvtop dummy PRIVATE ${ADDITIONAL_RELEASE_LINK_OPTIONS}) add_sanitizers_to_target(nvtop Debug PRIVATE address undefined) nvtop-1.0.0/src/extract_gpuinfo.c000066400000000000000000000470741341567056100170360ustar00rootroot00000000000000/* * * Copyright (C) 2017 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #include #include #include #include #include "nvtop/extract_gpuinfo.h" #include "nvtop/get_process_info.h" #include "uthash.h" #define HASH_FIND_PID(head, pidfield, out) \ HASH_FIND(hh, head, pidfield, sizeof(intmax_t), out) #define HASH_ADD_PID(head, pidfield, add) \ HASH_ADD(hh, head, pidfield, sizeof(intmax_t), add) #define HASH_REPLACE_PID(head, pidfield, replaced) \ HASH_REPLACE(hh, head, pidfield, sizeof(intmax_t), replaced) static bool nvml_initialized = false; bool init_gpu_info_extraction(void) { if (!nvml_initialized) { nvmlReturn_t retval = nvmlInit(); if (retval != NVML_SUCCESS) { fprintf(stderr, "Impossible to initialize nvidia nvml : %s\n", nvmlErrorString(retval)); return false; } nvml_initialized = true; } return true; } bool shutdown_gpu_info_extraction(void) { if (nvml_initialized) { nvmlReturn_t retval = nvmlShutdown(); if (retval != NVML_SUCCESS) { fprintf(stderr, "Impossible to shutdown nvidia nvml : %s\n", nvmlErrorString(retval)); return false; } nvml_initialized = false; } return true; } /** * Normaly those informations are not changing over time */ static void populate_static_device_infos(struct device_info *dev_info) { // GPU NAME nvmlReturn_t retval = nvmlDeviceGetName(dev_info->device_handle, dev_info->device_name, NVML_DEVICE_NAME_BUFFER_SIZE); SET_VALID(device_name_valid, dev_info->valid); if (retval != NVML_SUCCESS) { memcpy(dev_info->device_name, "UNKNOWN", strlen("UNKNOWN") + 1); RESET_VALID(device_name_valid, dev_info->valid); } // PCIe LINK GEN MAX retval = nvmlDeviceGetMaxPcieLinkGeneration(dev_info->device_handle, &dev_info->max_pcie_link_gen); SET_VALID(max_pcie_link_gen_valid, dev_info->valid); if (retval != NVML_SUCCESS) { dev_info->max_pcie_link_gen = 0; RESET_VALID(max_pcie_link_gen_valid, dev_info->valid); } // PCIe LINK WIDTH MAX retval = nvmlDeviceGetMaxPcieLinkWidth(dev_info->device_handle, &dev_info->max_pcie_link_width); SET_VALID(max_pcie_link_width_valid, dev_info->valid); if (retval != NVML_SUCCESS) { dev_info->max_pcie_link_width = 0; RESET_VALID(max_pcie_link_width_valid, dev_info->valid); } // GPU TEMP SHUTDOWN retval = nvmlDeviceGetTemperatureThreshold( dev_info->device_handle, NVML_TEMPERATURE_THRESHOLD_SHUTDOWN, &dev_info->gpu_temp_shutdown); SET_VALID(gpu_temp_shutdown_valid, dev_info->valid); if (retval != NVML_SUCCESS) { dev_info->gpu_temp_shutdown = 0; RESET_VALID(gpu_temp_shutdown_valid, dev_info->valid); } // GPU TEMP SLOWDOWN retval = nvmlDeviceGetTemperatureThreshold( dev_info->device_handle, NVML_TEMPERATURE_THRESHOLD_SLOWDOWN, &dev_info->gpu_temp_slowdown); SET_VALID(gpu_temp_slowdown_valid, dev_info->valid); if (retval != NVML_SUCCESS) { dev_info->gpu_temp_slowdown = 0; RESET_VALID(gpu_temp_slowdown_valid, dev_info->valid); } } struct pid_infos { intmax_t pid; char *process_name; char *user_name; double cpu_elapsed_time; nvtop_time last_measurement; UT_hash_handle hh; }; static struct pid_infos *saved_pid_infos = NULL; // Hash table saved pid info static struct pid_infos *current_used_infos = NULL; // Hash table saved pid info static void populate_infos(intmax_t pid, struct pid_infos *infos) { infos->pid = pid; get_command_from_pid((pid_t)pid, &infos->process_name); if (infos->process_name == NULL) { infos->process_name = malloc(4 * sizeof(*infos->process_name)); memcpy(infos->process_name, "N/A", 4); } get_username_from_pid((pid_t)pid, &infos->user_name); if (infos->user_name == NULL) { infos->user_name = malloc(4 * sizeof(*infos->user_name)); memcpy(infos->user_name, "N/A", 4); } struct process_cpu_usage cpu_usage; if (get_process_info((pid_t)pid, &cpu_usage)) { infos->cpu_elapsed_time = cpu_usage.total_kernel_time + cpu_usage.total_user_time; infos->last_measurement = cpu_usage.time; } else { infos->cpu_elapsed_time = -1.; } } static void update_gpu_process_from_process_info(unsigned int num_process, nvmlProcessInfo_t *p_info, struct gpu_process *gpu_proc_info) { for (unsigned int i = 0; i < num_process; ++i) { gpu_proc_info[i].pid = p_info[i].pid; struct pid_infos *infos; HASH_FIND_PID(saved_pid_infos, &gpu_proc_info[i].pid, infos); if (!infos) { HASH_FIND_PID(current_used_infos, &gpu_proc_info[i].pid, infos); if (!infos) { // getting information from the system infos = malloc(sizeof(*infos)); populate_infos(gpu_proc_info[i].pid, infos); HASH_ADD_PID(current_used_infos, pid, infos); } } else { HASH_DEL(saved_pid_infos, infos); HASH_ADD_PID(current_used_infos, pid, infos); } struct process_cpu_usage cpu_usage; if (get_process_info((pid_t)p_info[i].pid, &cpu_usage)) { if (infos->cpu_elapsed_time > -1.) { gpu_proc_info[i].cpu_usage = 100. * (cpu_usage.total_user_time + cpu_usage.total_kernel_time - infos->cpu_elapsed_time) / nvtop_difftime(infos->last_measurement, cpu_usage.time); } else { gpu_proc_info[i].cpu_usage = 0.; } gpu_proc_info[i].cpu_memory_virt = cpu_usage.virtual_memory; gpu_proc_info[i].cpu_memory_res = cpu_usage.resident_memory; infos->last_measurement = cpu_usage.time; infos->cpu_elapsed_time = cpu_usage.total_user_time + cpu_usage.total_kernel_time; } else { gpu_proc_info[i].cpu_memory_virt = 0; gpu_proc_info[i].cpu_memory_res = 0; gpu_proc_info[i].cpu_usage = 0.; infos->cpu_elapsed_time = -1.; } /*fprintf(stderr, "PID %d cpu usage %f virt %zu res %zu\n", * (int)p_info[i].pid,*/ /*gpu_proc_info[i].cpu_usage, gpu_proc_info[i].cpu_memory_virt,*/ /*gpu_proc_info[i].cpu_memory_res);*/ gpu_proc_info[i].process_name = infos->process_name; gpu_proc_info[i].user_name = infos->user_name; gpu_proc_info[i].used_memory = p_info[i].usedGpuMemory; } } static void update_graphical_process(struct device_info *dinfo) { nvmlReturn_t retval; unsigned int array_size; retry_querry_graphical: array_size = dinfo->size_proc_buffers; unsigned int prev_array_size = array_size; retval = nvmlDeviceGetGraphicsRunningProcesses( dinfo->device_handle, &array_size, dinfo->process_infos); if (retval != NVML_SUCCESS) { if (retval == NVML_ERROR_INSUFFICIENT_SIZE) { unsigned int new_size = prev_array_size * 2 > array_size * 2 ? prev_array_size * 2 : array_size * 2; dinfo->size_proc_buffers = new_size; dinfo->graphic_procs = realloc(dinfo->graphic_procs, new_size * sizeof(*dinfo->graphic_procs)); dinfo->compute_procs = realloc(dinfo->compute_procs, new_size * sizeof(*dinfo->compute_procs)); dinfo->process_infos = realloc(dinfo->process_infos, new_size * sizeof(*dinfo->process_infos)); goto retry_querry_graphical; } else { dinfo->num_graphical_procs = 0; } } else { dinfo->num_graphical_procs = array_size; } update_gpu_process_from_process_info( dinfo->num_graphical_procs, dinfo->process_infos, dinfo->graphic_procs); } static void update_compute_process(struct device_info *dinfo) { nvmlReturn_t retval; unsigned int array_size; retry_querry_compute: array_size = dinfo->size_proc_buffers; unsigned int prev_array_size = array_size; retval = nvmlDeviceGetComputeRunningProcesses( dinfo->device_handle, &array_size, dinfo->process_infos); if (retval != NVML_SUCCESS) { if (retval == NVML_ERROR_INSUFFICIENT_SIZE) { unsigned int new_size = prev_array_size * 2 > array_size * 2 ? prev_array_size * 2 : array_size * 2; dinfo->size_proc_buffers = new_size; dinfo->graphic_procs = realloc(dinfo->graphic_procs, new_size * sizeof(*dinfo->graphic_procs)); dinfo->compute_procs = realloc(dinfo->compute_procs, new_size * sizeof(*dinfo->compute_procs)); dinfo->process_infos = realloc(dinfo->process_infos, new_size * sizeof(*dinfo->process_infos)); goto retry_querry_compute; } else { dinfo->num_compute_procs = 0; } } else { dinfo->num_compute_procs = array_size; } update_gpu_process_from_process_info( dinfo->num_compute_procs, dinfo->process_infos, dinfo->compute_procs); } void update_device_infos(unsigned int num_devs, struct device_info *dev_info) { for (unsigned int i = 0; i < num_devs; ++i) { struct device_info *curr_dev_info = &dev_info[i]; // GPU CLK nvmlReturn_t retval = nvmlDeviceGetClockInfo( curr_dev_info->device_handle, NVML_CLOCK_GRAPHICS, &curr_dev_info->gpu_clock_speed); SET_VALID(gpu_clock_speed_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->gpu_clock_speed = 0; RESET_VALID(gpu_clock_speed_valid, curr_dev_info->valid); } // MEM CLK retval = nvmlDeviceGetClockInfo(curr_dev_info->device_handle, NVML_CLOCK_MEM, &curr_dev_info->mem_clock_speed); SET_VALID(mem_clock_speed_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->mem_clock_speed = 0; RESET_VALID(mem_clock_speed_valid, curr_dev_info->valid); } // GPU CLK MAX retval = nvmlDeviceGetMaxClockInfo(curr_dev_info->device_handle, NVML_CLOCK_GRAPHICS, &curr_dev_info->gpu_clock_speed_max); SET_VALID(gpu_clock_speed_max_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->gpu_clock_speed_max = 0; RESET_VALID(gpu_clock_speed_max_valid, curr_dev_info->valid); } // MEM CLK MAX retval = nvmlDeviceGetMaxClockInfo(curr_dev_info->device_handle, NVML_CLOCK_MEM, &curr_dev_info->mem_clock_speed_max); SET_VALID(mem_clock_speed_max_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->mem_clock_speed_max = 0; RESET_VALID(mem_clock_speed_max_valid, curr_dev_info->valid); } // GPU / MEM UTIL RATE nvmlUtilization_t util_rate; retval = nvmlDeviceGetUtilizationRates(curr_dev_info->device_handle, &util_rate); if (retval != NVML_SUCCESS) { curr_dev_info->gpu_util_rate = 0; curr_dev_info->mem_util_rate = 0; RESET_VALID(gpu_util_rate_valid, curr_dev_info->valid); RESET_VALID(mem_util_rate_valid, curr_dev_info->valid); } else { curr_dev_info->gpu_util_rate = util_rate.gpu; curr_dev_info->mem_util_rate = util_rate.memory; SET_VALID(gpu_util_rate_valid, curr_dev_info->valid); SET_VALID(mem_util_rate_valid, curr_dev_info->valid); } // FREE / TOTAL / USED MEMORY nvmlMemory_t meminfo; retval = nvmlDeviceGetMemoryInfo(curr_dev_info->device_handle, &meminfo); if (retval != NVML_SUCCESS) { curr_dev_info->free_memory = 0; curr_dev_info->total_memory = 0; curr_dev_info->used_memory = 0; RESET_VALID(free_memory_valid, curr_dev_info->valid); RESET_VALID(total_memory_valid, curr_dev_info->valid); RESET_VALID(used_memory_valid, curr_dev_info->valid); } else { curr_dev_info->free_memory = meminfo.free; curr_dev_info->total_memory = meminfo.total; curr_dev_info->used_memory = meminfo.used; SET_VALID(free_memory_valid, curr_dev_info->valid); SET_VALID(total_memory_valid, curr_dev_info->valid); SET_VALID(used_memory_valid, curr_dev_info->valid); } // PCIe LINK GEN retval = nvmlDeviceGetCurrPcieLinkGeneration( curr_dev_info->device_handle, &curr_dev_info->cur_pcie_link_gen); SET_VALID(cur_pcie_link_gen_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->cur_pcie_link_gen = 0; RESET_VALID(cur_pcie_link_gen_valid, curr_dev_info->valid); } // PCIe LINK WIDTH retval = nvmlDeviceGetCurrPcieLinkWidth( curr_dev_info->device_handle, &curr_dev_info->cur_pcie_link_width); SET_VALID(cur_pcie_link_width_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->cur_pcie_link_width = 0; RESET_VALID(cur_pcie_link_width_valid, curr_dev_info->valid); } // PCIe TX THROUGHPUT retval = nvmlDeviceGetPcieThroughput(curr_dev_info->device_handle, NVML_PCIE_UTIL_TX_BYTES, &curr_dev_info->pcie_tx); SET_VALID(pcie_tx_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->pcie_tx = 0; RESET_VALID(pcie_tx_valid, curr_dev_info->valid); } // PCIe RX THROUGHPUT retval = nvmlDeviceGetPcieThroughput(curr_dev_info->device_handle, NVML_PCIE_UTIL_RX_BYTES, &curr_dev_info->pcie_rx); SET_VALID(pcie_rx_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->pcie_rx = 0; RESET_VALID(pcie_rx_valid, curr_dev_info->valid); } // FAN SPEED retval = nvmlDeviceGetFanSpeed(curr_dev_info->device_handle, &curr_dev_info->fan_speed); SET_VALID(fan_speed_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->fan_speed = 0; RESET_VALID(fan_speed_valid, curr_dev_info->valid); } // GPU TEMP retval = nvmlDeviceGetTemperature(curr_dev_info->device_handle, NVML_TEMPERATURE_GPU, &curr_dev_info->gpu_temp); SET_VALID(gpu_temp_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->gpu_temp = 0; RESET_VALID(gpu_temp_valid, curr_dev_info->valid); } // POWER DRAW retval = nvmlDeviceGetPowerUsage(curr_dev_info->device_handle, &curr_dev_info->power_draw); SET_VALID(power_draw_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->power_draw = 0; RESET_VALID(power_draw_valid, curr_dev_info->valid); } // POWER MAX retval = nvmlDeviceGetEnforcedPowerLimit(curr_dev_info->device_handle, &curr_dev_info->power_draw_max); SET_VALID(power_draw_max_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->power_draw_max = 0; RESET_VALID(power_draw_max_valid, curr_dev_info->valid); } // Encoder infos retval = nvmlDeviceGetEncoderUtilization(curr_dev_info->device_handle, &curr_dev_info->encoder_rate, &curr_dev_info->encoder_sampling); SET_VALID(encoder_rate_valid, curr_dev_info->valid); SET_VALID(encoder_sampling_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->encoder_rate = 0; curr_dev_info->encoder_sampling = 0; RESET_VALID(encoder_rate_valid, curr_dev_info->valid); RESET_VALID(encoder_sampling_valid, curr_dev_info->valid); } // Decoder infos retval = nvmlDeviceGetDecoderUtilization(curr_dev_info->device_handle, &curr_dev_info->decoder_rate, &curr_dev_info->decoder_sampling); SET_VALID(decoder_rate_valid, curr_dev_info->valid); SET_VALID(decoder_sampling_valid, curr_dev_info->valid); if (retval != NVML_SUCCESS) { curr_dev_info->decoder_rate = 0; curr_dev_info->decoder_sampling = 0; RESET_VALID(decoder_rate_valid, curr_dev_info->valid); RESET_VALID(decoder_sampling_valid, curr_dev_info->valid); } // Process informations update_graphical_process(curr_dev_info); update_compute_process(curr_dev_info); } // Loop over devices // Now delete the (pid,username,command) cache entries that are not in use // anymore struct pid_infos *old_info, *tmp; HASH_ITER(hh, saved_pid_infos, old_info, tmp) { HASH_DEL(saved_pid_infos, old_info); free(old_info->process_name); free(old_info->user_name); free(old_info); } saved_pid_infos = current_used_infos; current_used_infos = NULL; } unsigned int initialize_device_info(struct device_info **dev_info, size_t gpu_mask) { unsigned int num_devices; nvmlReturn_t retval = nvmlDeviceGetCount(&num_devices); if (retval != NVML_SUCCESS) { fprintf(stderr, "Impossible to get the number of devices : %s\n", nvmlErrorString(retval)); return 0; } *dev_info = malloc(num_devices * sizeof(**dev_info)); struct device_info *devs = *dev_info; unsigned int num_queriable = 0; for (unsigned int i = 0; i < num_devices; ++i) { retval = nvmlDeviceGetHandleByIndex(i, &devs[num_queriable].device_handle); if (i < CHAR_BIT * sizeof(gpu_mask) && (gpu_mask & (1 << i)) == 0) continue; if (retval != NVML_SUCCESS) { if (retval == NVML_ERROR_NO_PERMISSION) { continue; } else { fprintf(stderr, "Impossible to get handle for device number %u : %s\n", i, nvmlErrorString(retval)); free(*dev_info); return 0; } } else { populate_static_device_infos(&devs[num_queriable]); #define DEF_PROC_NUM 25 devs[num_queriable].size_proc_buffers = DEF_PROC_NUM; devs[num_queriable].compute_procs = malloc(DEF_PROC_NUM * sizeof(*devs[num_queriable].compute_procs)); devs[num_queriable].graphic_procs = malloc(DEF_PROC_NUM * sizeof(*devs[num_queriable].graphic_procs)); devs[num_queriable].process_infos = malloc(DEF_PROC_NUM * sizeof(*devs[num_queriable].process_infos)); #undef DEF_PROC_NUM num_queriable += 1; } } return num_queriable; } void clean_pid_cache(void) { struct pid_infos *old_info, *tmp; // The current_used_infos should be NULL here assert(current_used_infos == NULL); HASH_ITER(hh, saved_pid_infos, old_info, tmp) { HASH_DEL(saved_pid_infos, old_info); free(old_info->process_name); free(old_info->user_name); free(old_info); } } void clean_device_info(unsigned int num_devs, struct device_info *dev_info) { for (unsigned int i = 0; i < num_devs; ++i) { free(dev_info[i].graphic_procs); free(dev_info[i].compute_procs); free(dev_info[i].process_infos); } free(dev_info); clean_pid_cache(); } nvtop-1.0.0/src/get_process_info_linux.c000066400000000000000000000150561341567056100203770ustar00rootroot00000000000000/* * * Copyright (C) 2017 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #include "nvtop/get_process_info.h" #include #include #include #include #include #include #include #include #define pid_path_size 1024 static char pid_path[pid_path_size]; void get_username_from_pid(pid_t pid, char **buffer) { int written = snprintf(pid_path, pid_path_size, "/proc/%" PRIdMAX, (intmax_t)pid); if (written == pid_path_size) { *buffer = NULL; return; } struct stat folder_stat; int starval = stat(pid_path, &folder_stat); if (starval == -1) { *buffer = NULL; return; } uid_t user_id = folder_stat.st_uid; struct passwd *user_info = getpwuid(user_id); if (user_info == NULL) { *buffer = NULL; return; } size_t namelen = strlen(user_info->pw_name) + 1; *buffer = malloc(namelen * sizeof(**buffer)); strncpy(*buffer, user_info->pw_name, namelen); } #define command_line_increment 32 void get_command_from_pid(pid_t pid, char **buffer) { int written = snprintf(pid_path, pid_path_size, "/proc/%" PRIdMAX "/cmdline", (intmax_t)pid); if (written == pid_path_size) { *buffer = NULL; return; } FILE *pid_file = fopen(pid_path, "r"); if (!pid_file) { *buffer = NULL; return; } size_t size_buffer = command_line_increment; *buffer = malloc(size_buffer); char *current_buffer = *buffer; size_t total_read = 0; do { size_t num_read = fread(current_buffer, 1, command_line_increment, pid_file); total_read += num_read; if (num_read == command_line_increment) { size_buffer += command_line_increment; *buffer = realloc(*buffer, size_buffer); current_buffer = &((*buffer)[total_read]); } } while (!feof(pid_file) && !ferror(pid_file)); if (ferror(pid_file)) { fclose(pid_file); free(*buffer); *buffer = NULL; return; } fclose(pid_file); for (size_t i = 0; total_read && i < total_read - 1; ++i) { if ((*buffer)[i] == '\0') (*buffer)[i] = ' '; } } /* * * From man 5 proc of /proc//stat * For clock ticks per second use sysconf(_SC_CLK_TCK) * * enum process_state { * process_running = 'R', * process_sleeping = 'S', * process_sleeping_disk = 'D', * process_zombie = 'Z', * process_stopped = 'T', * process_stopped_tracing = 't', * process_dead = 'X', * process_dead2 = 'x', * process_wake_kill = 'K', * process_waking = 'W', * process_parked = 'P', * }; * * struct stat_parse { * int process_id; * char *executable_filename; * enum process_state process_state; * int parent_pid; * int process_group_id; * int process_session_id; * int process_tty; * int foreground_process_group_id; * unsigned kernel_flag; * unsigned long num_minor_fault; * unsigned long num_minor_fault_children; * unsigned long num_major_fault; * unsigned long num_major_fault_children; * unsigned long user_time; // in clock ticks * unsigned long kernel_time; // in clock ticks * long children_user_time; // in clock ticks * long children_kernel_time; // in clock ticks * long process_priority; * long process_niceness; * long process_num_threads; * long next_sigalarm_time; * unsigned long long process_start_time; * unsigned long process_virt_mem_usage; * long process_resident_mem_usage; * long process_resident_mem_limit; * unsigned long process_text_address_start; * unsigned long process_text_address_end; * unsigned long process_stack_address_start; * unsigned long process_stack_address_current; * unsigned long process_instruction_pointer; * unsigned long process_signals; // Obsolete * unsigned long process_signals_blocked; // Obsolete * unsigned long process_signals_ignored; // Obsolete * unsigned long process_signals_caught; // Obsolete * unsigned long wait_channel_id; * unsigned long process_num_page_swapped; * unsigned long process_and_child_num_page_swapped; * int process_exit_signal_to_parent; * int process_processor; * unsigned process_real_time_priority; * unsigned policy; * long long unsigned total_io_delays; * long unsigned process_guest_time; * long process_children_guest_time; * unsigned long process_data_address_start; * unsigned long process_data_address_end; * unsigned long process_brk_start; * unsigned long process_arguments_address_start; * unsigned long process_arguments_address_end; * unsigned long process_env_vars_address_start; * unsigned long process_env_vars_address_end; * int thread_exit_code; * }; * */ bool get_process_info(pid_t pid, struct process_cpu_usage *usage) { double clock_ticks_per_second = sysconf(_SC_CLK_TCK); size_t page_size = (size_t)sysconf(_SC_PAGESIZE); int written = snprintf(pid_path, pid_path_size, "/proc/%" PRIdMAX "/stat", (intmax_t)pid); if (written == pid_path_size) { return false; } FILE *stat_file = fopen(pid_path, "r"); if (!stat_file) { return false; } nvtop_get_current_time(&usage->time); unsigned long total_user_time; // in clock_ticks unsigned long total_kernel_time; // in clock_ticks unsigned long virtual_memory; // In bytes long resident_memory; // In page number? int retval = fscanf(stat_file, "%*d %*[^)]) %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u " "%*u %lu %lu %*d %*d %*d %*d %*d %*d %*u %lu %ld", &total_user_time, &total_kernel_time, &virtual_memory, &resident_memory); fclose(stat_file); if (retval != 4) return false; usage->total_user_time = total_user_time / clock_ticks_per_second; usage->total_kernel_time = total_kernel_time / clock_ticks_per_second; usage->virtual_memory = virtual_memory; usage->resident_memory = (size_t)resident_memory * page_size; return true; } nvtop-1.0.0/src/interface.c000066400000000000000000001736171341567056100156000ustar00rootroot00000000000000/* * * Copyright (C) 2017-2018 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #include "nvtop/interface.h" #include "nvtop/interface_layout_selection.h" #include "nvtop/plot.h" #include "nvtop/time.h" #include #include #include #include #include #include #include #include #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) enum process_field { process_pid = 0, process_user, process_gpu_id, process_type, process_memory, process_cpu_usage, process_cpu_mem_usage, process_command, process_end, }; enum nvtop_option_window_state { nvtop_option_state_hidden, nvtop_option_state_kill, nvtop_option_state_sort_by, }; enum interface_color { cyan_color = 1, yellow_color, magenta_color, green_color, red_color, blue_color, }; struct device_window { char *device_name; WINDOW *name_win; // Name of the GPU WINDOW *gpu_util_enc_dec; WINDOW *gpu_util_no_enc_or_dec; WINDOW *gpu_util_no_enc_and_dec; WINDOW *mem_util_enc_dec; WINDOW *mem_util_no_enc_or_dec; WINDOW *mem_util_no_enc_and_dec; WINDOW *encode_util; WINDOW *decode_util; WINDOW *fan_speed; WINDOW *temperature; WINDOW *power_info; WINDOW *gpu_clock_info; WINDOW *mem_clock_info; WINDOW *pcie_info; nvtop_time last_decode_seen; nvtop_time last_encode_seen; }; struct all_gpu_processes { intmax_t pid; char *process_name; char *user_name; unsigned long long used_memory; double mem_percentage; double cpu_percent; size_t cpu_memory; unsigned int gpu_id; bool is_graphical; }; static const unsigned int option_window_size = 13; struct option_window { enum nvtop_option_window_state state; unsigned int selected_row; unsigned int offset; WINDOW *option_win; WINDOW *option_selection_window; }; struct process_window { unsigned int size_biggest_name; unsigned int size_processes_buffer; unsigned int num_processes; unsigned int offset; unsigned int offset_column; struct all_gpu_processes *all_process; WINDOW *process_win; WINDOW *process_with_option_win; unsigned int selected_row; enum process_field sort_criterion; bool sort_asc; struct option_window option_window; }; struct plot_window { enum plot_type type; /*nvtop_time max_data_retain_time;*/ /*nvtop_time time_between_data_collection;*/ /*nvtop_time last_time_collected;*/ size_t num_data; double *data; WINDOW *win; WINDOW *plot_window; size_t gpu_ids[2]; }; // Keep gpu information every 1 second for 10 minutes struct retained_data { unsigned collect_interval; size_t size_data_buffer; size_t num_collected_data; unsigned *gpu_util; unsigned *mem_util; nvtop_time last_collect; }; struct nvtop_interface { size_t num_devices; struct device_window *devices_win; struct process_window process; unsigned num_plots; struct plot_window *plots; bool use_fahrenheit; bool show_plot; double encode_decode_hide_time; struct retained_data past_data; }; enum device_field { device_name = 0, device_fan_speed, device_temperature, device_power, device_pcie, device_clock, device_count, }; static unsigned int sizeof_device_field[] = { [device_name] = 11, [device_fan_speed] = 8, [device_temperature] = 10, [device_power] = 15, [device_clock] = 11, [device_pcie] = 44, }; static unsigned int sizeof_process_field[] = { [process_pid] = 5, [process_user] = 4, [process_gpu_id] = 3, [process_type] = 7, [process_memory] = 13, // 8 for mem 5 for % [process_cpu_usage] = 6, [process_cpu_mem_usage] = 9, [process_command] = 0, }; static void alloc_device_window(unsigned int device_id, unsigned int start_row, unsigned int start_col, unsigned int totalcol, struct device_window *dwin) { const unsigned int spacer = 1; // Line 1 = Name | PCIe info dwin->name_win = newwin(1, sizeof_device_field[device_name], start_row, start_col); if (dwin->name_win == NULL) goto alloc_error; if (dwin->device_name != NULL) { wattron(dwin->name_win, COLOR_PAIR(cyan_color)); mvwprintw(dwin->name_win, 0, 0, "Device %-2u", device_id); wattroff(dwin->name_win, COLOR_PAIR(cyan_color)); wprintw(dwin->name_win, "[%s]", dwin->device_name); wnoutrefresh(dwin->name_win); } dwin->pcie_info = newwin(1, sizeof_device_field[device_pcie], start_row, start_col + spacer + sizeof_device_field[device_name]); if (dwin->pcie_info == NULL) goto alloc_error; // Line 2 = GPU clk | MEM clk | Temp | Fan | Power dwin->gpu_clock_info = newwin(1, sizeof_device_field[device_clock], start_row + 1, start_col); if (dwin->gpu_clock_info == NULL) goto alloc_error; dwin->mem_clock_info = newwin(1, sizeof_device_field[device_clock], start_row + 1, start_col + spacer + sizeof_device_field[device_clock]); if (dwin->mem_clock_info == NULL) goto alloc_error; dwin->temperature = newwin(1, sizeof_device_field[device_temperature], start_row + 1, start_col + spacer * 2 + sizeof_device_field[device_clock] * 2); if (dwin->temperature == NULL) goto alloc_error; dwin->fan_speed = newwin(1, sizeof_device_field[device_fan_speed], start_row + 1, start_col + spacer * 3 + sizeof_device_field[device_clock] * 2 + sizeof_device_field[device_temperature]); if (dwin->fan_speed == NULL) goto alloc_error; dwin->power_info = newwin(1, sizeof_device_field[device_power], start_row + 1, start_col + spacer * 4 + sizeof_device_field[device_clock] * 2 + sizeof_device_field[device_temperature] + sizeof_device_field[device_fan_speed]); if (dwin->power_info == NULL) goto alloc_error; // Line 3 = GPU used | MEM used | Encoder | Decoder int remaining_cols = totalcol - 3 * spacer; int size_gpu, size_mem, size_encode, size_decode; int quot, rem; quot = remaining_cols / 3; rem = remaining_cols % 3; size_gpu = size_mem = size_encode = quot; switch (rem) { case 2: if (size_encode % 2 == 1) size_encode += 1; else size_mem += 1; /* Falls through */ case 1: size_gpu += 1; break; } if (size_encode % 2 == 1) { size_mem += 1; size_encode -= 1; } if (size_encode / 2 < 14) { size_encode += 2; size_gpu -= 1; size_mem -= 1; } size_decode = size_encode / 2; if (size_encode % 2 == 1) size_encode += 1; size_encode /= 2; dwin->gpu_util_enc_dec = newwin(1, size_gpu, start_row + 2, start_col); if (dwin->gpu_util_enc_dec == NULL) goto alloc_error; dwin->mem_util_enc_dec = newwin(1, size_mem, start_row + 2, start_col + spacer + size_gpu); if (dwin->mem_util_enc_dec == NULL) goto alloc_error; dwin->encode_util = newwin(1, size_encode, start_row + 2, start_col + spacer * 2 + size_gpu + size_mem); if (dwin->encode_util == NULL) goto alloc_error; dwin->decode_util = newwin(1, size_decode, start_row + 2, start_col + spacer * 3 + size_gpu + size_mem + size_encode); if (dwin->decode_util == NULL) goto alloc_error; // For auto-hide encode / decode window dwin->gpu_util_no_enc_or_dec = newwin(1, size_gpu + size_encode / 2 + 1, start_row + 2, start_col); if (dwin->gpu_util_no_enc_or_dec == NULL) goto alloc_error; dwin->mem_util_no_enc_or_dec = newwin(1, size_mem + size_encode / 2, start_row + 2, start_col + spacer + size_gpu + size_encode / 2 + 1); if (dwin->mem_util_no_enc_or_dec == NULL) goto alloc_error; dwin->gpu_util_no_enc_and_dec = newwin(1, size_gpu + size_encode + 1, start_row + 2, start_col); if (dwin->gpu_util_no_enc_and_dec == NULL) goto alloc_error; dwin->mem_util_no_enc_and_dec = newwin(1, size_mem + size_encode + 1, start_row + 2, start_col + spacer + size_gpu + size_encode + 1); if (dwin->mem_util_no_enc_and_dec == NULL) goto alloc_error; return; alloc_error: endwin(); fprintf(stderr, "Error: Not enough columns to draw device information\n"); exit(EXIT_FAILURE); } static void free_device_windows(struct device_window *dwin) { delwin(dwin->name_win); delwin(dwin->gpu_util_enc_dec); delwin(dwin->mem_util_enc_dec); delwin(dwin->gpu_util_no_enc_or_dec); delwin(dwin->mem_util_no_enc_or_dec); delwin(dwin->gpu_util_no_enc_and_dec); delwin(dwin->mem_util_no_enc_and_dec); delwin(dwin->encode_util); delwin(dwin->decode_util); delwin(dwin->gpu_clock_info); delwin(dwin->mem_clock_info); delwin(dwin->power_info); delwin(dwin->temperature); delwin(dwin->fan_speed); delwin(dwin->pcie_info); } static void alloc_process_with_option(struct nvtop_interface *interface, unsigned posX, unsigned posY, unsigned sizeX, unsigned sizeY) { if (sizeY > 0) { interface->process.size_processes_buffer = sizeY > 50 ? sizeY : 50; interface->process.process_win = newwin(sizeY, sizeX, posY, posX); interface->process.process_with_option_win = newwin( sizeY, sizeX - option_window_size, posY, posX + option_window_size); } else { interface->process.option_window.state = nvtop_option_state_hidden; interface->process.process_win = NULL; interface->process.process_with_option_win = NULL; } } static void initialize_gpu_mem_plot(struct plot_window *plot, struct window_position *position) { unsigned rows = position->sizeY; unsigned cols = position->sizeX; cols -= 5; rows -= 2; cols = cols / 2 * 2; plot->plot_window = newwin(rows, cols, position->posY + 1, position->posX + 4); draw_rectangle(plot->win, 3, 0, cols + 2, rows + 2); mvwprintw(plot->win, 1 + rows * 3 / 4, 0, "25%%"); mvwprintw(plot->win, 1 + rows / 4, 0, "75%%"); mvwprintw(plot->win, 1 + rows / 2, 0, "50%%"); mvwprintw(plot->win, 1, 0, "100"); mvwprintw(plot->win, rows, 0, " 0%%"); plot->data = calloc(cols, sizeof(*plot->data)); plot->num_data = cols; } static void alloc_plot_window(struct nvtop_interface *interface, struct window_position *plot_positions, enum plot_type plot_type) { if (!plot_positions) { interface->plots = NULL; return; } interface->plots = malloc(interface->num_plots * sizeof(*interface->plots)); unsigned num_device_to_attribute; unsigned max_device_per_plot; switch (plot_type) { case plot_gpu_solo: num_device_to_attribute = interface->num_devices; max_device_per_plot = 1; break; case plot_gpu_duo: num_device_to_attribute = interface->num_devices; max_device_per_plot = 2; break; case plot_gpu_max: num_device_to_attribute = 1; max_device_per_plot = 1; break; } unsigned current_gpu_id = 0; for (size_t i = 0; i < interface->num_plots; ++i) { interface->plots[i].gpu_ids[0] = current_gpu_id++; if (num_device_to_attribute > 1 && max_device_per_plot > 1) { interface->plots[i].type = plot_gpu_duo; num_device_to_attribute -= 2; interface->plots[i].gpu_ids[1] = current_gpu_id++; } else { if (plot_type == plot_gpu_max) interface->plots[i].type = plot_gpu_max; else interface->plots[i].type = plot_gpu_solo; num_device_to_attribute -= 1; } interface->plots[i].win = newwin(plot_positions[i].sizeY, plot_positions[i].sizeX, plot_positions[i].posY, plot_positions[i].posX); initialize_gpu_mem_plot(&interface->plots[i], &plot_positions[i]); } } static unsigned device_length(void) { return max(sizeof_device_field[device_name] + sizeof_device_field[device_pcie] + 1, 2 * sizeof_device_field[device_clock] + sizeof_device_field[device_temperature] + sizeof_device_field[device_fan_speed] + sizeof_device_field[device_power] + 4); } static void initialize_all_windows(struct nvtop_interface *dwin) { int rows, cols; getmaxyx(stdscr, rows, cols); unsigned int num_devices = dwin->num_devices; struct window_position device_positions[num_devices]; struct window_position process_position; struct window_position *plot_positions = NULL; enum plot_type plot_type; compute_sizes_from_layout(dwin->show_plot, true, true, dwin->num_devices, 2, 3, device_length(), rows - 1, cols, device_positions, &process_position, &dwin->num_plots, &plot_positions, &plot_type); alloc_plot_window(dwin, plot_positions, plot_type); free(plot_positions); for (unsigned int i = 0; i < num_devices; ++i) { alloc_device_window(i, device_positions[i].posY, device_positions[i].posX, device_positions[i].sizeX, &dwin->devices_win[i]); } alloc_process_with_option(dwin, process_position.posX, process_position.posY, process_position.sizeX, process_position.sizeY); dwin->process.option_window.option_win = newwin(process_position.sizeY, option_window_size, process_position.posY, process_position.posX); dwin->process.option_window.option_selection_window = newwin(1, cols, rows - 1, 0); } static void delete_all_windows(struct nvtop_interface *dwin) { for (unsigned int i = 0; i < dwin->num_devices; ++i) { free_device_windows(&dwin->devices_win[i]); } delwin(dwin->process.process_win); delwin(dwin->process.process_with_option_win); dwin->process.process_win = NULL; dwin->process.process_with_option_win = NULL; delwin(dwin->process.option_window.option_selection_window); delwin(dwin->process.option_window.option_win); for (size_t i = 0; i < dwin->num_plots; ++i) { delwin(dwin->plots[i].win); free(dwin->plots[i].data); } free(dwin->plots); } void show_gpu_infos_ascii(unsigned int num_devices, struct device_info *dev_info) { for (unsigned int i = 0; i < num_devices; ++i) { printf("GPU %u: %s @ (%uMHz,%uMHz)," " Util. (%u%% , %u%%)," " FAN %u%%," " TEMP %u°c," " POWER %uW / %uW\n", i, dev_info[i].device_name, dev_info[i].gpu_clock_speed, dev_info[i].mem_clock_speed, dev_info[i].gpu_util_rate, dev_info[i].mem_util_rate, dev_info[i].fan_speed, dev_info[i].gpu_temp, dev_info[i].power_draw / 1000, dev_info[i].power_draw_max / 1000); } } static void initialize_colors(void) { start_color(); short background_color; #ifdef NCURSES_VERSION if (use_default_colors() == OK) background_color = -1; else background_color = COLOR_BLACK; #else background_color = COLOR_BLACK; #endif init_pair(cyan_color, COLOR_CYAN, background_color); init_pair(red_color, COLOR_RED, background_color); init_pair(green_color, COLOR_GREEN, background_color); init_pair(yellow_color, COLOR_YELLOW, background_color); init_pair(blue_color, COLOR_BLUE, background_color); init_pair(magenta_color, COLOR_MAGENTA, background_color); } struct nvtop_interface * initialize_curses(unsigned int num_devices, unsigned int biggest_device_name, bool use_color, bool use_fahrenheit, bool show_per_gpu_plot, double encode_decode_hide_time, unsigned collect_interval) { struct nvtop_interface *interface = calloc(1, sizeof(*interface)); interface->devices_win = calloc(num_devices, sizeof(*interface->devices_win)); interface->num_devices = num_devices; sizeof_device_field[device_name] = biggest_device_name + 11; initscr(); if (use_color && has_colors() == TRUE) { initialize_colors(); } cbreak(); noecho(); keypad(stdscr, TRUE); curs_set(0); interface->encode_decode_hide_time = encode_decode_hide_time < 0. ? 1e20 : encode_decode_hide_time; interface->show_plot = show_per_gpu_plot; interface->use_fahrenheit = use_fahrenheit; interface->process.offset = 0; interface->process.offset_column = 0; interface->process.option_window.offset = 0; interface->process.option_window.state = nvtop_option_state_hidden; interface->process.selected_row = 0; interface->process.sort_criterion = process_memory; interface->process.sort_asc = false; interface->process.size_processes_buffer = 50; interface->process.all_process = malloc(interface->process.size_processes_buffer * sizeof(*interface->process.all_process)); // Hide decode and encode if not active for more than some given seconds nvtop_time time_now, some_time_in_past; if (encode_decode_hide_time > 0.) some_time_in_past = nvtop_hmns_to_time( 0, (unsigned int)(encode_decode_hide_time / 60.) + 1, 0); else some_time_in_past = nvtop_hmns_to_time(0, 0, 0); nvtop_get_current_time(&time_now); some_time_in_past = nvtop_substract_time(time_now, some_time_in_past); interface->past_data.size_data_buffer = 10 * 60 * 1000; interface->past_data.num_collected_data = 0; interface->past_data.collect_interval = collect_interval > 1000 ? collect_interval : 1000; nvtop_get_current_time(&interface->past_data.last_collect); for (size_t i = 0; i < num_devices; ++i) { interface->devices_win[i].last_encode_seen = some_time_in_past; interface->devices_win[i].last_decode_seen = some_time_in_past; } interface->past_data.gpu_util = malloc( sizeof(unsigned[num_devices][interface->past_data.size_data_buffer])); interface->past_data.mem_util = malloc( sizeof(unsigned[num_devices][interface->past_data.size_data_buffer])); initialize_all_windows(interface); refresh(); return interface; } void clean_ncurses(struct nvtop_interface *interface) { endwin(); delete_all_windows(interface); for (unsigned int i = 0; i < interface->num_devices; ++i) free(interface->devices_win[i].device_name); free(interface->devices_win); free(interface->process.all_process); free(interface->past_data.gpu_util); free(interface->past_data.mem_util); free(interface); } static void draw_bare_percentage(WINDOW *win, const char *prelude, unsigned int new_percentage, const char inside_braces_right[1024]) { int rows, cols; getmaxyx(win, rows, cols); (void)rows; size_t size_prelude = strlen(prelude); wattron(win, COLOR_PAIR(cyan_color)); mvwprintw(win, 0, 0, "%s", prelude); wattroff(win, COLOR_PAIR(cyan_color)); waddch(win, '['); int curx, cury; curx = getcurx(win); cury = getcury(win); int between_sbraces = cols - size_prelude - 2; float usage = round((float)between_sbraces * new_percentage / 100.f); int represent_usage = (int)usage; whline(win, '|', (int)represent_usage); mvwhline(win, cury, curx + represent_usage, ' ', between_sbraces - represent_usage); mvwaddch(win, cury, curx + between_sbraces, ']'); unsigned int right_side_braces_space_required = strlen(inside_braces_right); wmove(win, cury, curx + between_sbraces - right_side_braces_space_required); wprintw(win, "%s", inside_braces_right); mvwchgat(win, cury, curx, represent_usage, 0, green_color, NULL); wnoutrefresh(win); } static const char *memory_prefix[] = {"B", "k", "M", "G", "T", "P"}; static void draw_temp_color(WINDOW *win, unsigned int temp, unsigned int temp_slowdown, bool celsius) { unsigned int temp_convert; if (celsius) temp_convert = temp; else temp_convert = (unsigned)(32 + nearbyint(temp * 1.8)); mvwprintw(win, 0, 0, "TEMP %3u", temp_convert); waddch(win, ACS_DEGREE); if (celsius) waddch(win, 'C'); else waddch(win, 'F'); if (temp >= temp_slowdown - 5) { if (temp >= temp_slowdown) mvwchgat(win, 0, 5, 3, 0, red_color, NULL); else mvwchgat(win, 0, 5, 3, 0, yellow_color, NULL); } else { mvwchgat(win, 0, 5, 3, 0, green_color, NULL); } mvwchgat(win, 0, 0, 4, 0, cyan_color, NULL); wnoutrefresh(win); } static void print_pcie_at_scale(WINDOW *win, unsigned int value) { int prefix_off; double val_d = value; for (prefix_off = 1; prefix_off < 5 && val_d >= 1000.; ++prefix_off) { val_d = val_d / 1000.; } if (val_d >= 100.) { wprintw(win, "%.1f", val_d); } else { if (val_d >= 10.) { wprintw(win, "%.2f", val_d); } else { wprintw(win, "%.3f", val_d); } } wprintw(win, " %sB/s", memory_prefix[prefix_off]); } static inline void werase_and_wnoutrefresh(WINDOW *w) { werase(w); wnoutrefresh(w); } static void draw_devices(struct device_info *dev_info, struct nvtop_interface *interface) { unsigned int num_devices = interface->num_devices; for (unsigned int i = 0; i < num_devices; ++i) { struct device_window *dev = &interface->devices_win[i]; struct device_info *dinfo = &dev_info[i]; if (dev->device_name == NULL) { size_t namelen = strlen(dinfo->device_name) + 1; dev->device_name = malloc(namelen); memcpy(dev->device_name, dinfo->device_name, namelen); wattron(dev->name_win, COLOR_PAIR(cyan_color)); mvwprintw(dev->name_win, 0, 0, "Device %-2u", i); wattroff(dev->name_win, COLOR_PAIR(cyan_color)); wprintw(dev->name_win, "[%s]", dev->device_name); wnoutrefresh(dev->name_win); } char buff[1024]; nvtop_time tnow; nvtop_get_current_time(&tnow); static bool has_encode_in_last_min = true; if (IS_VALID(encoder_rate_valid, dinfo->valid)) { if (dinfo->encoder_rate > 0) { if (!has_encode_in_last_min) { werase_and_wnoutrefresh(dev->gpu_util_no_enc_and_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_and_dec); werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec); } has_encode_in_last_min = true; dev->last_encode_seen = tnow; } else { if (nvtop_difftime(dev->last_encode_seen, tnow) > interface->encode_decode_hide_time) { if (has_encode_in_last_min) { werase_and_wnoutrefresh(dev->gpu_util_enc_dec); werase_and_wnoutrefresh(dev->mem_util_enc_dec); werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec); } has_encode_in_last_min = false; } } } else { has_encode_in_last_min = false; werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec); werase_and_wnoutrefresh(dev->gpu_util_enc_dec); werase_and_wnoutrefresh(dev->mem_util_enc_dec); werase_and_wnoutrefresh(dev->gpu_util_no_enc_and_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_and_dec); } static bool has_decode_in_last_min = true; if (IS_VALID(decoder_rate_valid, dinfo->valid)) { if (dinfo->decoder_rate > 0) { if (!has_decode_in_last_min) { werase_and_wnoutrefresh(dev->gpu_util_no_enc_and_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_and_dec); werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec); } has_decode_in_last_min = true; dev->last_decode_seen = tnow; } else { if (nvtop_difftime(dev->last_decode_seen, tnow) > interface->encode_decode_hide_time) { if (has_decode_in_last_min) { werase_and_wnoutrefresh(dev->gpu_util_enc_dec); werase_and_wnoutrefresh(dev->mem_util_enc_dec); werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec); } has_decode_in_last_min = false; } } } else { has_decode_in_last_min = false; werase_and_wnoutrefresh(dev->gpu_util_no_enc_or_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_or_dec); werase_and_wnoutrefresh(dev->gpu_util_enc_dec); werase_and_wnoutrefresh(dev->mem_util_enc_dec); werase_and_wnoutrefresh(dev->gpu_util_no_enc_and_dec); werase_and_wnoutrefresh(dev->mem_util_no_enc_and_dec); } WINDOW *gpu_util_win; WINDOW *mem_util_win; WINDOW *encode_win = dev->encode_util; WINDOW *decode_win = dev->decode_util; if (has_encode_in_last_min && has_decode_in_last_min) { gpu_util_win = dev->gpu_util_enc_dec; mem_util_win = dev->mem_util_enc_dec; } else { if (has_encode_in_last_min || has_decode_in_last_min) { if (has_encode_in_last_min) encode_win = dev->decode_util; gpu_util_win = dev->gpu_util_no_enc_or_dec; mem_util_win = dev->mem_util_no_enc_or_dec; } else { gpu_util_win = dev->gpu_util_no_enc_and_dec; mem_util_win = dev->mem_util_no_enc_and_dec; } } if (has_encode_in_last_min) { if (IS_VALID(encoder_rate_valid, dinfo->valid)) { snprintf(buff, 1024, "%u%%", dinfo->encoder_rate); draw_bare_percentage(encode_win, "ENC", dinfo->encoder_rate, buff); } } if (has_decode_in_last_min) { if (IS_VALID(decoder_rate_valid, dinfo->valid)) { snprintf(buff, 1024, "%u%%", dinfo->decoder_rate); draw_bare_percentage(decode_win, "DEC", dinfo->decoder_rate, buff); } } if (IS_VALID(gpu_util_rate_valid, dinfo->valid)) { snprintf(buff, 1024, "%u%%", dinfo->gpu_util_rate); draw_bare_percentage(gpu_util_win, "GPU", dinfo->gpu_util_rate, buff); } else { snprintf(buff, 1024, "N/A"); draw_bare_percentage(gpu_util_win, "GPU", 0, buff); } if (IS_VALID(total_memory_valid, dinfo->valid) && IS_VALID(used_memory_valid, dinfo->valid)) { double total_mem = dinfo->total_memory; double used_mem = dinfo->used_memory; size_t prefix_off; for (prefix_off = 0; prefix_off < 5 && total_mem >= 1000; ++prefix_off) { total_mem /= 1000; used_mem /= 1000; } snprintf(buff, 1024, "%.1f%s/%.1f%s", used_mem, memory_prefix[prefix_off], total_mem, memory_prefix[prefix_off]); draw_bare_percentage(mem_util_win, "MEM", (unsigned int)(100. * dinfo->used_memory / (double)dinfo->total_memory), buff); } else { snprintf(buff, 1024, "N/A"); draw_bare_percentage(mem_util_win, "MEM", 0, buff); } if (IS_VALID(gpu_temp_valid, dinfo->valid)) { if (!IS_VALID(gpu_temp_slowdown_valid, dinfo->valid)) dinfo->gpu_temp_slowdown = 0; draw_temp_color(dev->temperature, dinfo->gpu_temp, dinfo->gpu_temp_slowdown, !interface->use_fahrenheit); } else { mvwprintw(dev->temperature, 0, 0, "TEMP N/A"); waddch(dev->temperature, ACS_DEGREE); if (interface->use_fahrenheit) waddch(dev->temperature, 'F'); else waddch(dev->temperature, 'C'); wnoutrefresh(dev->temperature); } // FAN if (IS_VALID(fan_speed_valid, dinfo->valid)) mvwprintw(dev->fan_speed, 0, 0, "FAN %3u%%", dinfo->fan_speed); else mvwprintw(dev->fan_speed, 0, 0, "FAN N/A%%"); mvwchgat(dev->fan_speed, 0, 0, 3, 0, cyan_color, NULL); wnoutrefresh(dev->fan_speed); // GPU CLOCK werase(dev->gpu_clock_info); if (IS_VALID(gpu_clock_speed_valid, dinfo->valid)) mvwprintw(dev->gpu_clock_info, 0, 0, "GPU %uMHz", dinfo->gpu_clock_speed); else mvwprintw(dev->gpu_clock_info, 0, 0, "GPU N/A MHz"); mvwchgat(dev->gpu_clock_info, 0, 0, 3, 0, cyan_color, NULL); wnoutrefresh(dev->gpu_clock_info); // MEM CLOCK werase(dev->mem_clock_info); if (IS_VALID(mem_clock_speed_valid, dinfo->valid)) mvwprintw(dev->mem_clock_info, 0, 0, "MEM %uMHz", dinfo->mem_clock_speed); else mvwprintw(dev->mem_clock_info, 0, 0, "MEM N/A MHz"); mvwchgat(dev->mem_clock_info, 0, 0, 3, 0, cyan_color, NULL); wnoutrefresh(dev->mem_clock_info); // POWER werase(dev->power_info); if (IS_VALID(power_draw_valid, dinfo->valid) && IS_VALID(power_draw_max_valid, dinfo->valid)) mvwprintw(dev->power_info, 0, 0, "POW %3u / %3u W", dinfo->power_draw / 1000, dinfo->power_draw_max / 1000); else mvwprintw(dev->power_info, 0, 0, "POW N/A W"); mvwchgat(dev->power_info, 0, 0, 3, 0, cyan_color, NULL); wnoutrefresh(dev->power_info); // PICe throughput werase(dev->pcie_info); wattron(dev->pcie_info, COLOR_PAIR(cyan_color)); mvwprintw(dev->pcie_info, 0, 0, "PCIe "); wattroff(dev->pcie_info, COLOR_PAIR(cyan_color)); wattron(dev->pcie_info, COLOR_PAIR(magenta_color)); wprintw(dev->pcie_info, "GEN "); wattroff(dev->pcie_info, COLOR_PAIR(magenta_color)); if (IS_VALID(cur_pcie_link_gen_valid, dinfo->valid) && IS_VALID(cur_pcie_link_width_valid, dinfo->valid)) wprintw(dev->pcie_info, "%u@%2ux", dinfo->cur_pcie_link_gen, dinfo->cur_pcie_link_width); else wprintw(dev->pcie_info, "N/A"); wattron(dev->pcie_info, COLOR_PAIR(magenta_color)); wprintw(dev->pcie_info, " RX: "); wattroff(dev->pcie_info, COLOR_PAIR(magenta_color)); if (IS_VALID(pcie_rx_valid, dinfo->valid)) print_pcie_at_scale(dev->pcie_info, dinfo->pcie_rx); else wprintw(dev->pcie_info, "N/A"); wattron(dev->pcie_info, COLOR_PAIR(magenta_color)); wprintw(dev->pcie_info, " TX: "); wattroff(dev->pcie_info, COLOR_PAIR(magenta_color)); if (IS_VALID(pcie_tx_valid, dinfo->valid)) print_pcie_at_scale(dev->pcie_info, dinfo->pcie_tx); else wprintw(dev->pcie_info, "N/A"); wnoutrefresh(dev->pcie_info); } } static inline unsigned int max_val(unsigned int a, unsigned int b) { return a > b ? a : b; } static unsigned int copy_processes_for_processing(unsigned int num_devices, struct device_info *dev_info, struct nvtop_interface *interface) { unsigned int maximum_name_length = 0; unsigned int total_processes = 0; for (unsigned int i = 0; i < num_devices; ++i) { total_processes += dev_info[i].num_compute_procs + dev_info[i].num_graphical_procs; } while (total_processes > interface->process.size_processes_buffer) { interface->process.size_processes_buffer *= 2; interface->process.all_process = realloc(interface->process.all_process, interface->process.size_processes_buffer * sizeof(*interface->process.all_process)); } unsigned int offset = 0; for (unsigned int i = 0; i < num_devices; ++i) { for (unsigned int j = 0; j < dev_info[i].num_compute_procs; ++j) { interface->process.all_process[offset + j].is_graphical = false; interface->process.all_process[offset + j].gpu_id = i; interface->process.all_process[offset + j].pid = dev_info[i].compute_procs[j].pid; interface->process.all_process[offset + j].process_name = dev_info[i].compute_procs[j].process_name; interface->process.all_process[offset + j].user_name = dev_info[i].compute_procs[j].user_name; interface->process.all_process[offset + j].used_memory = dev_info[i].compute_procs[j].used_memory; maximum_name_length = max_val( maximum_name_length, strlen(dev_info[i].compute_procs[j].user_name)); interface->process.all_process[offset + j].mem_percentage = interface->process.all_process[offset + j].used_memory * 100. / (double)dev_info[i].total_memory; interface->process.all_process[offset + j].cpu_percent = dev_info[i].compute_procs[j].cpu_usage; interface->process.all_process[offset + j].cpu_memory = dev_info[i].compute_procs[j].cpu_memory_res; } offset += dev_info[i].num_compute_procs; for (unsigned int j = 0; j < dev_info[i].num_graphical_procs; ++j) { interface->process.all_process[offset + j].is_graphical = true; interface->process.all_process[offset + j].gpu_id = i; interface->process.all_process[offset + j].pid = dev_info[i].graphic_procs[j].pid; interface->process.all_process[offset + j].process_name = dev_info[i].graphic_procs[j].process_name; interface->process.all_process[offset + j].user_name = dev_info[i].graphic_procs[j].user_name; interface->process.all_process[offset + j].used_memory = dev_info[i].graphic_procs[j].used_memory; maximum_name_length = max_val( maximum_name_length, strlen(dev_info[i].graphic_procs[j].user_name)); interface->process.all_process[offset + j].mem_percentage = interface->process.all_process[offset + j].used_memory * 100. / (double)dev_info[i].total_memory; interface->process.all_process[offset + j].cpu_percent = dev_info[i].graphic_procs[j].cpu_usage; interface->process.all_process[offset + j].cpu_memory = dev_info[i].graphic_procs[j].cpu_memory_res; } offset += dev_info[i].num_graphical_procs; } interface->process.size_biggest_name = max_val(interface->process.size_biggest_name, maximum_name_length); return total_processes; } static int compare_pid_desc(const void *pp1, const void *pp2) { const struct all_gpu_processes *p1 = (const struct all_gpu_processes *)pp1; const struct all_gpu_processes *p2 = (const struct all_gpu_processes *)pp2; return -p1->pid + p2->pid; } static int compare_pid_asc(const void *pp1, const void *pp2) { return compare_pid_desc(pp2, pp1); } static int compare_username_desc(const void *pp1, const void *pp2) { const struct all_gpu_processes *p1 = (const struct all_gpu_processes *)pp1; const struct all_gpu_processes *p2 = (const struct all_gpu_processes *)pp2; return -strcmp(p1->user_name, p2->user_name); } static int compare_username_asc(const void *pp1, const void *pp2) { return compare_username_desc(pp2, pp1); } static int compare_process_name_desc(const void *pp1, const void *pp2) { const struct all_gpu_processes *p1 = (const struct all_gpu_processes *)pp1; const struct all_gpu_processes *p2 = (const struct all_gpu_processes *)pp2; return -strncmp(p1->process_name, p2->process_name, sizeof(p1->user_name)); } static int compare_process_name_asc(const void *pp1, const void *pp2) { return compare_process_name_desc(pp2, pp1); } static int compare_mem_usage_desc(const void *pp1, const void *pp2) { const struct all_gpu_processes *p1 = (const struct all_gpu_processes *)pp1; const struct all_gpu_processes *p2 = (const struct all_gpu_processes *)pp2; return -p1->used_memory + p2->used_memory; } static int compare_mem_usage_asc(const void *pp1, const void *pp2) { return compare_mem_usage_desc(pp2, pp1); } static int compare_cpu_usage_desc(const void *pp1, const void *pp2) { const struct all_gpu_processes *p1 = (const struct all_gpu_processes *)pp1; const struct all_gpu_processes *p2 = (const struct all_gpu_processes *)pp2; return p1->cpu_percent >= p2->cpu_percent ? -1 : 1; } static int compare_cpu_usage_asc(const void *pp1, const void *pp2) { return compare_cpu_usage_desc(pp2, pp1); } static int compare_cpu_mem_usage_desc(const void *pp1, const void *pp2) { const struct all_gpu_processes *p1 = (const struct all_gpu_processes *)pp1; const struct all_gpu_processes *p2 = (const struct all_gpu_processes *)pp2; return -(int)p1->cpu_memory + (int)p2->cpu_memory; } static int compare_cpu_mem_usage_asc(const void *pp1, const void *pp2) { return compare_cpu_mem_usage_desc(pp2, pp1); } static int compare_gpu_desc(const void *pp1, const void *pp2) { const struct all_gpu_processes *p1 = (const struct all_gpu_processes *)pp1; const struct all_gpu_processes *p2 = (const struct all_gpu_processes *)pp2; return -p1->gpu_id + p2->gpu_id; } static int compare_gpu_asc(const void *pp1, const void *pp2) { return -compare_gpu_desc(pp1, pp2); } static int compare_process_type_desc(const void *pp1, const void *pp2) { const struct all_gpu_processes *p1 = (const struct all_gpu_processes *)pp1; const struct all_gpu_processes *p2 = (const struct all_gpu_processes *)pp2; return p1->is_graphical != p2->is_graphical; } static int compare_process_type_asc(const void *pp1, const void *pp2) { return -compare_process_name_desc(pp1, pp2); } static void sort_process(struct all_gpu_processes *proc, unsigned int total_process, enum process_field criterion, bool asc_sort) { int (*sort_fun)(const void *, const void *); switch (criterion) { case process_pid: if (asc_sort) sort_fun = compare_pid_asc; else sort_fun = compare_pid_desc; break; case process_user: if (asc_sort) sort_fun = compare_username_asc; else sort_fun = compare_username_desc; break; case process_gpu_id: if (asc_sort) sort_fun = compare_gpu_asc; else sort_fun = compare_gpu_desc; break; case process_type: if (asc_sort) sort_fun = compare_process_type_asc; else sort_fun = compare_process_type_desc; break; case process_memory: if (asc_sort) sort_fun = compare_mem_usage_asc; else sort_fun = compare_mem_usage_desc; break; case process_command: if (asc_sort) sort_fun = compare_process_name_asc; else sort_fun = compare_process_name_desc; break; case process_cpu_usage: if (asc_sort) sort_fun = compare_cpu_usage_asc; else sort_fun = compare_cpu_usage_desc; break; case process_cpu_mem_usage: if (asc_sort) sort_fun = compare_cpu_mem_usage_asc; else sort_fun = compare_cpu_mem_usage_desc; break; case process_end: default: return; } qsort(proc, total_process, sizeof(*proc), sort_fun); } static const char *columnName[] = { "PID", "USER", "GPU", "TYPE", "GPU MEM", "CPU", "HOST MEM", "Command", }; static void update_selected_offset_with_window_size( unsigned int *selected_row, unsigned int *offset, unsigned int row_available_to_draw, unsigned int num_to_draw) { if (*selected_row > num_to_draw - 1) *selected_row = num_to_draw - 1; if (*offset > *selected_row) *offset = *selected_row; if (*offset + row_available_to_draw - 1 < *selected_row) *offset = *selected_row - row_available_to_draw + 1; while (row_available_to_draw > num_to_draw - *offset && *offset != 0) *offset -= 1; } #define process_buffer_line_size 8192 static char process_print_buffer[process_buffer_line_size]; static void set_attribute_between(WINDOW *win, int startY, int startX, int endX, attr_t attr, short pair) { int rows, cols; getmaxyx(win, rows, cols); (void)rows; if (startX >= cols || endX < 0) return; startX = startX < 0 ? 0 : startX; endX = endX > cols ? cols : endX; int size = endX - startX; mvwchgat(win, startY, startX, size, attr, pair, NULL); } static void print_processes_on_screen(unsigned int num_process, struct process_window *process) { WINDOW *win = process->option_window.state == nvtop_option_state_hidden ? process->process_win : process->process_with_option_win; struct all_gpu_processes *proc = process->all_process; werase(win); unsigned int rows, cols; getmaxyx(win, rows, cols); rows -= 1; update_selected_offset_with_window_size(&process->selected_row, &process->offset, rows, num_process); if (process->offset_column + cols >= process_buffer_line_size) process->offset_column = process_buffer_line_size - cols - 1; size_t special_row = process->selected_row; char pid_str[sizeof_process_field[process_pid] + 1]; char guid_str[sizeof_process_field[process_gpu_id] + 1]; char memory[sizeof_process_field[process_memory] + 1]; char cpu_percent[sizeof_process_field[process_cpu_usage] + 1]; char cpu_mem[sizeof_process_field[process_cpu_mem_usage] + 1]; unsigned int start_at_process = process->offset; unsigned int end_at_process = start_at_process + rows; int printed = 0; int column_sort_start = 0, column_sort_end = sizeof_process_field[0]; memset(process_print_buffer, 0, sizeof(process_print_buffer)); for (unsigned int i = 0; i < process_end; ++i) { if (i == process->sort_criterion) { column_sort_start = printed; column_sort_end = i == process_command ? process_buffer_line_size - 4 : column_sort_start + sizeof_process_field[i]; } printed += snprintf(&process_print_buffer[printed], process_buffer_line_size - printed, "%*s ", sizeof_process_field[i], columnName[i]); } mvwprintw(win, 0, 0, "%.*s", cols, &process_print_buffer[process->offset_column]); mvwchgat(win, 0, 0, -1, A_STANDOUT, green_color, NULL); set_attribute_between(win, 0, column_sort_start - (int)process->offset_column, column_sort_end - (int)process->offset_column, A_STANDOUT, cyan_color); int start_type = 0; for (unsigned int i = 0; i < process_type; ++i) { start_type += sizeof_process_field[i] + 1; } int end_type = start_type + sizeof_process_field[process_type]; for (unsigned int i = start_at_process; i < end_at_process && i < num_process; ++i) { memset(process_print_buffer, 0, sizeof(process_print_buffer)); size_t size = snprintf(pid_str, sizeof_process_field[process_pid] + 1, "%" PRIdMAX, proc[i].pid); if (size == sizeof_process_field[process_pid] + 1) pid_str[sizeof_process_field[process_pid]] = '\0'; size = snprintf(guid_str, sizeof_process_field[process_gpu_id] + 1, "%u", proc[i].gpu_id); if (size == sizeof_process_field[process_gpu_id] + 1) pid_str[sizeof_process_field[process_gpu_id]] = '\0'; printed = snprintf(process_print_buffer, process_buffer_line_size, "%*s %*s %*s", sizeof_process_field[process_pid], pid_str, sizeof_process_field[process_user], proc[i].user_name, sizeof_process_field[process_gpu_id], guid_str); if (proc[i].is_graphical) { printed += snprintf(&process_print_buffer[printed], process_buffer_line_size - printed, " %*s ", sizeof_process_field[process_type], "Graphic"); } else { printed += snprintf(&process_print_buffer[printed], process_buffer_line_size - printed, " %*s ", sizeof_process_field[process_type], "Compute"); } snprintf(memory, 9, "%6lluMB", proc[i].used_memory / 1048576); snprintf(memory + 8, sizeof_process_field[process_memory] - 7, " %3.0f%%", proc[i].mem_percentage); printed += snprintf(&process_print_buffer[printed], process_buffer_line_size - printed, "%*s ", sizeof_process_field[process_memory], memory); snprintf(cpu_percent, sizeof_process_field[process_cpu_usage] + 1, "%.f%%", proc[i].cpu_percent); printed += snprintf(&process_print_buffer[printed], process_buffer_line_size - printed, "%*s ", sizeof_process_field[process_cpu_usage], cpu_percent); snprintf(cpu_mem, sizeof_process_field[process_cpu_mem_usage] + 1, "%zuMB", proc[i].cpu_memory / 1048576); printed += snprintf(&process_print_buffer[printed], process_buffer_line_size - printed, "%*s ", sizeof_process_field[process_cpu_mem_usage], cpu_mem); snprintf(&process_print_buffer[printed], process_buffer_line_size - printed, "%.*s", process_buffer_line_size - printed, proc[i].process_name); unsigned int write_at = i - start_at_process + 1; mvwprintw(win, write_at, 0, "%.*s", cols, &process_print_buffer[process->offset_column]); if (i == special_row) { mvwchgat(win, write_at, 0, -1, A_STANDOUT, cyan_color, NULL); } else { if (proc[i].is_graphical) { set_attribute_between( win, write_at, start_type - (int)process->offset_column, end_type - (int)process->offset_column, 0, yellow_color); } else { set_attribute_between( win, write_at, start_type - (int)process->offset_column, end_type - (int)process->offset_column, 0, magenta_color); } } } wnoutrefresh(win); } static void draw_processes(struct device_info *dev_info, struct nvtop_interface *interface) { if (interface->process.process_win == NULL) return; unsigned int num_devices = interface->num_devices; unsigned int total_processes = 0; if (interface->process.option_window.state == nvtop_option_state_hidden) { total_processes = copy_processes_for_processing(num_devices, dev_info, interface); interface->process.num_processes = total_processes; sort_process(interface->process.all_process, total_processes, interface->process.sort_criterion, interface->process.sort_asc); } else { total_processes = interface->process.num_processes; } sizeof_process_field[process_user] = interface->process.size_biggest_name; print_processes_on_screen(total_processes, &interface->process); } static const char *signalsName[] = { "Cancel", "SIGABRT", "SIGALRM", "SIGBUS", "SIGCHLD", "SIGCONT", "SIGFPE", "SIGHUP", "SIGILL", "SIGINT", "SIGKILL", "SIGPIPE", "SIGQUIT", "SIGSEGV", "SIGSTOP", "SIGTERM", "SIGTSTP", "SIGTTIN", "SIGTTOU", "SIGUSR1", "SIGUSR2", "SIGPOLL", "SIGPROF", "SIGSYS", "SIGTRAP", "SIGURG", "SIGVTALRM", "SIGXCPU", "SIGXFSZ", }; static const int signalsValues[] = { SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGKILL, SIGPIPE, SIGQUIT, SIGSEGV, SIGSTOP, SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ, }; static const size_t nvtop_num_signals = 28; static void draw_kill_option(struct nvtop_interface *interface) { WINDOW *win = interface->process.option_window.option_win; wattron(win, COLOR_PAIR(green_color) | A_REVERSE); mvwprintw(win, 0, 0, "Send signal:"); wattroff(win, COLOR_PAIR(green_color) | A_REVERSE); wprintw(win, " "); int rows, cols; getmaxyx(win, rows, cols); size_t start_at_option = interface->process.option_window.offset; size_t end_at_option = start_at_option + rows - 1; for (size_t i = start_at_option; i < end_at_option && i <= nvtop_num_signals; ++i) { if (i == interface->process.option_window.selected_row) { wattron(win, COLOR_PAIR(cyan_color) | A_STANDOUT); } wprintw(win, "%*d %s", 2, i, signalsName[i]); getyx(win, rows, cols); for (unsigned int j = cols; j < option_window_size; ++j) wprintw(win, " "); if (i == interface->process.option_window.selected_row) { wattroff(win, COLOR_PAIR(cyan_color) | A_STANDOUT); mvwprintw(win, rows, option_window_size - 1, " "); } } wnoutrefresh(win); } static void draw_sort_option(struct nvtop_interface *interface) { WINDOW *win = interface->process.option_window.option_win; wattron(win, COLOR_PAIR(green_color) | A_REVERSE); mvwprintw(win, 0, 0, "Sort by "); wattroff(win, COLOR_PAIR(green_color) | A_REVERSE); wprintw(win, " "); int rows, cols; if (interface->process.option_window.offset == 0) { if (interface->process.option_window.selected_row == 0) { wattron(win, COLOR_PAIR(cyan_color) | A_STANDOUT); } wprintw(win, "Cancel"); getyx(win, rows, cols); for (unsigned int j = cols; j < option_window_size; ++j) wprintw(win, " "); if (interface->process.option_window.selected_row == 0) { wattroff(win, COLOR_PAIR(cyan_color) | A_STANDOUT); mvwprintw(win, rows, option_window_size - 1, " "); } } getmaxyx(win, rows, cols); size_t start_at_option = interface->process.option_window.offset == 0 ? interface->process.option_window.offset : interface->process.option_window.offset - 1; size_t end_at_option = interface->process.option_window.offset == 0 ? start_at_option + rows - 2 : start_at_option + rows - 1; for (size_t i = start_at_option; i < end_at_option && i < process_end; ++i) { if (i + 1 == interface->process.option_window.selected_row) { wattron(win, COLOR_PAIR(cyan_color) | A_STANDOUT); } wprintw(win, "%s", columnName[i]); getyx(win, rows, cols); for (unsigned int j = cols; j < option_window_size; ++j) wprintw(win, " "); if (i + 1 == interface->process.option_window.selected_row) { wattroff(win, COLOR_PAIR(cyan_color) | A_STANDOUT); mvwprintw(win, rows, option_window_size - 1, " "); } } wnoutrefresh(win); } static void draw_options(struct nvtop_interface *interface) { unsigned int rows, cols; getmaxyx(interface->process.option_window.option_win, rows, cols); rows -= 1; (void)cols; unsigned int num_options = 0; switch (interface->process.option_window.state) { case nvtop_option_state_kill: num_options = nvtop_num_signals + 1; // Option + Cancel break; case nvtop_option_state_sort_by: num_options = process_end + 1; // Option + Cancel break; case nvtop_option_state_hidden: default: break; } update_selected_offset_with_window_size( &interface->process.option_window.selected_row, &interface->process.option_window.offset, rows, num_options); switch (interface->process.option_window.state) { case nvtop_option_state_kill: draw_kill_option(interface); break; case nvtop_option_state_sort_by: draw_sort_option(interface); break; case nvtop_option_state_hidden: default: break; } } static const char *option_selection_hidden[] = { "Kill", "Sort", "Quit", }; static const char *option_selection_sort[][2] = { {"Enter", "Sort"}, {"ESC", "Cancel"}, {"+", "Ascending"}, {"-", "Descending"}, }; static const char *option_selection_kill[][2] = { {"Enter", "Send"}, {"ESC", "Cancel"}, }; static const unsigned int option_selection_width = 8; static void draw_option_selection(struct nvtop_interface *interface) { WINDOW *win = interface->process.option_window.option_selection_window; wmove(win, 0, 0); switch (interface->process.option_window.state) { case nvtop_option_state_hidden: for (size_t i = 0; i < 3; ++i) { wprintw(win, "F%zu", i + 1); wattron(win, COLOR_PAIR(cyan_color) | A_STANDOUT); wprintw(win, "%s", option_selection_hidden[i]); for (size_t j = strlen(option_selection_hidden[i]); j < option_selection_width; ++j) wprintw(win, " "); wattroff(win, COLOR_PAIR(cyan_color) | A_STANDOUT); } break; case nvtop_option_state_kill: for (size_t i = 0; i < 2; ++i) { wprintw(win, "%s", option_selection_kill[i][0]); wattron(win, COLOR_PAIR(cyan_color) | A_STANDOUT); wprintw(win, "%s", option_selection_kill[i][1]); for (size_t j = strlen(option_selection_kill[i][1]); j < option_selection_width; ++j) wprintw(win, " "); wattroff(win, COLOR_PAIR(cyan_color) | A_STANDOUT); } break; case nvtop_option_state_sort_by: for (size_t i = 0; i < 4; ++i) { wprintw(win, "%s", option_selection_sort[i][0]); wattron(win, COLOR_PAIR(cyan_color) | A_STANDOUT); wprintw(win, "%s", option_selection_sort[i][1]); for (size_t j = strlen(option_selection_sort[i][1]); j < option_selection_width; ++j) wprintw(win, " "); wattroff(win, COLOR_PAIR(cyan_color) | A_STANDOUT); } break; default: break; } unsigned int cur_col, maxcols, tmp; getmaxyx(stdscr, tmp, maxcols); getyx(win, tmp, cur_col); (void)tmp; wattron(win, COLOR_PAIR(cyan_color) | A_STANDOUT); for (unsigned int j = cur_col; j < maxcols; ++j) wprintw(win, " "); wattroff(win, COLOR_PAIR(cyan_color) | A_STANDOUT); wnoutrefresh(win); } static void update_retained_data(struct device_info *dev_info, struct nvtop_interface *interface) { nvtop_time time_now; nvtop_get_current_time(&time_now); double time_diff = nvtop_difftime(interface->past_data.last_collect, time_now) * 1000; if (time_diff >= interface->past_data.collect_interval) { interface->past_data.last_collect = time_now; for (size_t i = 0; i < interface->num_devices; ++i) { ((unsigned(*)[interface->past_data.size_data_buffer])interface->past_data .gpu_util)[i][interface->past_data.num_collected_data % interface->past_data.size_data_buffer] = dev_info[i].gpu_util_rate; ((unsigned(*)[interface->past_data.size_data_buffer])interface->past_data .mem_util)[i][interface->past_data.num_collected_data % interface->past_data.size_data_buffer] = 100 * dev_info[i].used_memory / dev_info[i].total_memory; } interface->past_data.num_collected_data++; } } static void populate_plot_data_gpu_mem(struct nvtop_interface *interface, struct plot_window *plot) { memset(plot->data, 0, plot->num_data * sizeof(double)); unsigned num_cols = plot->type == plot_gpu_duo ? 4 : 2; unsigned upper_bound = plot->num_data / num_cols > interface->past_data.num_collected_data ? interface->past_data.num_collected_data : plot->num_data / num_cols; for (unsigned i = 0; i < upper_bound; ++i) { unsigned(*gpudata)[interface->past_data.size_data_buffer] = (unsigned(*)[interface->past_data.size_data_buffer]) interface->past_data.gpu_util; unsigned(*memdata)[interface->past_data.size_data_buffer] = (unsigned(*)[interface->past_data.size_data_buffer]) interface->past_data.mem_util; plot->data[i * num_cols] = gpudata[plot->gpu_ids[0]] [(interface->past_data.size_data_buffer + interface->past_data.num_collected_data - i - 1) % interface->past_data.size_data_buffer]; plot->data[i * num_cols + 1] = memdata[plot->gpu_ids[0]] [(interface->past_data.size_data_buffer + interface->past_data.num_collected_data - i - 1) % interface->past_data.size_data_buffer]; if (plot->type == plot_gpu_duo) { plot->data[i * num_cols + 2] = gpudata[plot->gpu_ids[1]] [(interface->past_data.size_data_buffer + interface->past_data.num_collected_data - i - 1) % interface->past_data.size_data_buffer]; plot->data[i * num_cols + 3] = memdata[plot->gpu_ids[1]] [(interface->past_data.size_data_buffer + interface->past_data.num_collected_data - i - 1) % interface->past_data.size_data_buffer]; } } } static void populate_plot_data_max_gpu_mem(struct nvtop_interface *interface, struct plot_window *plot) { // Populate data memset(plot->data, 0, plot->num_data * sizeof(double)); unsigned upper_bound = plot->num_data / 2 > interface->past_data.num_collected_data ? interface->past_data.num_collected_data : plot->num_data / 2; for (unsigned k = 0; k < interface->num_devices; ++k) { for (unsigned i = 0; i < upper_bound; ++i) { unsigned(*gpudata)[interface->past_data.size_data_buffer] = (unsigned(*)[interface->past_data.size_data_buffer]) interface->past_data.gpu_util; unsigned(*memdata)[interface->past_data.size_data_buffer] = (unsigned(*)[interface->past_data.size_data_buffer]) interface->past_data.mem_util; plot->data[i * 2] = max(plot->data[i * 2], gpudata[k][(interface->past_data.size_data_buffer + interface->past_data.num_collected_data - i - 1) % interface->past_data.size_data_buffer]); plot->data[i * 2 + 1] = max(plot->data[i * 2 + 1], memdata[k][(interface->past_data.size_data_buffer + interface->past_data.num_collected_data - i - 1) % interface->past_data.size_data_buffer]); } } } static void draw_plots(struct nvtop_interface *interface) { for (unsigned i = 0; i < interface->num_plots; ++i) { wnoutrefresh(interface->plots[i].win); werase(interface->plots[i].plot_window); switch (interface->plots[i].type) { case plot_gpu_max: populate_plot_data_max_gpu_mem(interface, &interface->plots[i]); nvtop_line_plot(interface->plots[i].plot_window, interface->plots[i].num_data, interface->plots[i].data, 0., 100., 2, (const char * [2]){"MAX GPU", "MAX MEM"}); break; case plot_gpu_solo: { populate_plot_data_gpu_mem(interface, &interface->plots[i]); char gpuNum[8]; snprintf(gpuNum, 8, "GPU %zu", interface->plots[i].gpu_ids[0]); nvtop_line_plot(interface->plots[i].plot_window, interface->plots[i].num_data, interface->plots[i].data, 0., 100., 2, (const char * [2]){gpuNum, "MEM"}); } break; case plot_gpu_duo: { populate_plot_data_gpu_mem(interface, &interface->plots[i]); char gpuNum[2][8]; char memNum[2][8]; snprintf(gpuNum[0], 8, "GPU %zu", interface->plots[i].gpu_ids[0]); snprintf(gpuNum[1], 8, "GPU %zu", interface->plots[i].gpu_ids[1]); snprintf(memNum[0], 8, "MEM %zu", interface->plots[i].gpu_ids[0]); snprintf(memNum[1], 8, "MEM %zu", interface->plots[i].gpu_ids[1]); nvtop_line_plot( interface->plots[i].plot_window, interface->plots[i].num_data, interface->plots[i].data, 0., 100., 4, (const char * [4]){gpuNum[0], memNum[0], gpuNum[1], memNum[1]}); } break; default: break; } wnoutrefresh(interface->plots[i].plot_window); } } void draw_gpu_info_ncurses(struct device_info *dev_info, struct nvtop_interface *interface) { update_retained_data(dev_info, interface); draw_devices(dev_info, interface); draw_processes(dev_info, interface); if (interface->process.option_window.state != nvtop_option_state_hidden) draw_options(interface); draw_option_selection(interface); draw_plots(interface); doupdate(); refresh(); } void update_window_size_to_terminal_size(struct nvtop_interface *inter) { endwin(); erase(); refresh(); refresh(); delete_all_windows(inter); struct option_window options = inter->process.option_window; initialize_all_windows(inter); inter->process.option_window.selected_row = options.selected_row; inter->process.option_window.state = options.state; } bool is_escape_for_quit(struct nvtop_interface *inter) { if (inter->process.option_window.state == nvtop_option_state_hidden) return true; else return false; } static void option_do_kill(struct nvtop_interface *inter) { if (inter->process.option_window.selected_row == 0) return; pid_t pid = inter->process.all_process[inter->process.selected_row].pid; int sig = signalsValues[inter->process.option_window.selected_row - 1]; kill(pid, sig); } static void option_change_sort(struct nvtop_interface *inter) { if (inter->process.option_window.selected_row == 0) return; inter->process.sort_criterion = process_pid + inter->process.option_window.selected_row - 1; } void interface_key(int keyId, struct nvtop_interface *inter) { switch (keyId) { case KEY_F(1): if (inter->process.option_window.state == nvtop_option_state_hidden) { inter->process.option_window.state = nvtop_option_state_kill; inter->process.option_window.selected_row = 0; } break; case KEY_F(2): if (inter->process.option_window.state == nvtop_option_state_hidden) { inter->process.option_window.state = nvtop_option_state_sort_by; inter->process.option_window.selected_row = 0; } break; case KEY_RIGHT: if (inter->process.option_window.state == nvtop_option_state_hidden) inter->process.offset_column += 4; break; case KEY_LEFT: if (inter->process.option_window.state == nvtop_option_state_hidden && inter->process.offset_column >= 4) inter->process.offset_column -= 4; break; case KEY_UP: switch (inter->process.option_window.state) { case nvtop_option_state_kill: case nvtop_option_state_sort_by: if (inter->process.option_window.selected_row != 0) inter->process.option_window.selected_row--; break; case nvtop_option_state_hidden: if (inter->process.selected_row != 0) inter->process.selected_row--; break; default: break; } break; case KEY_DOWN: switch (inter->process.option_window.state) { case nvtop_option_state_kill: case nvtop_option_state_sort_by: inter->process.option_window.selected_row++; break; case nvtop_option_state_hidden: inter->process.selected_row++; break; default: break; } break; case '+': inter->process.sort_asc = true; break; case '-': inter->process.sort_asc = false; break; case '\n': case KEY_ENTER: switch (inter->process.option_window.state) { case nvtop_option_state_kill: option_do_kill(inter); inter->process.option_window.state = nvtop_option_state_hidden; break; case nvtop_option_state_sort_by: option_change_sort(inter); inter->process.option_window.state = nvtop_option_state_hidden; break; case nvtop_option_state_hidden: default: break; } break; case 27: inter->process.option_window.state = nvtop_option_state_hidden; break; default: break; } } nvtop-1.0.0/src/interface_layout_selection.c000066400000000000000000000166371341567056100212400ustar00rootroot00000000000000#include "nvtop/interface.h" #include "nvtop/interface_layout_selection.h" #include #include #include #include #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) static void min_size_taken_by_process(unsigned rows, unsigned num_devices, unsigned *rows_needed) { *rows_needed = 1 + max(5, min(rows / 4, num_devices * 3)); } static const unsigned cols_needed_box_drawing = 5; static void min_size_taken_by_plot(unsigned num_data_info_to_plot, unsigned *rows_needed, unsigned *cols_needed) { *rows_needed = 7; *cols_needed = cols_needed_box_drawing + 10 * num_data_info_to_plot; } void compute_sizes_from_layout( bool show_graphs, bool show_header, bool show_process, size_t num_devices, unsigned num_info_per_device, unsigned device_header_rows, unsigned device_header_cols, unsigned rows, unsigned cols, struct window_position *device_positions, struct window_position *process_position, unsigned *num_plots, struct window_position **plot_positions, enum plot_type *plot_types) { unsigned min_rows_for_header = 0, header_stacks = 0, num_device_per_row = 0; if (show_header) { num_device_per_row = max(1, cols / device_header_cols); header_stacks = num_devices / num_device_per_row + ((num_devices % num_device_per_row) > 0); if (num_devices % header_stacks == 0) num_device_per_row = num_devices / header_stacks; min_rows_for_header = header_stacks * device_header_rows; } unsigned min_rows_for_process = 0; if (show_process) { min_size_taken_by_process(rows, num_devices, &min_rows_for_process); } // Not enough room for the header and process if (rows < min_rows_for_header + min_rows_for_process) { if (rows >= min_rows_for_header + 2) { // Shrink process min_rows_for_process = rows - min_rows_for_header; } else { // Only header if possible min_rows_for_header = rows; min_rows_for_process = 0; } } unsigned rows_for_header = min_rows_for_header; unsigned rows_for_process = min_rows_for_process; unsigned rows_left = rows - min_rows_for_header - min_rows_for_process; unsigned min_plot_rows, min_plot_cols_solo, min_plot_cols_duo; min_size_taken_by_plot(num_info_per_device, &min_plot_rows, &min_plot_cols_solo); min_size_taken_by_plot(num_info_per_device * 2, &min_plot_rows, &min_plot_cols_duo); enum plot_type preferred_plot_type = plot_gpu_duo; unsigned max_plot_per_row = cols / min_plot_cols_duo; if (max_plot_per_row == 0) { if (cols >= min_plot_cols_solo) { max_plot_per_row = 1; preferred_plot_type = plot_gpu_solo; } else { max_plot_per_row = 0; } } unsigned num_borrow_line = 0; unsigned num_plot_stacks = 0; if (max_plot_per_row > 0 && show_graphs) { if (preferred_plot_type == plot_gpu_duo) { num_plot_stacks = (num_devices + (num_devices % 2)) / 2 / max_plot_per_row; } else { num_plot_stacks = num_devices / max_plot_per_row; } num_plot_stacks = max(num_plot_stacks, 1); if (num_plot_stacks * min_plot_rows > rows_left) { if (rows_left >= min_plot_rows) { preferred_plot_type = plot_gpu_max; num_plot_stacks = 1; } else { num_plot_stacks = 0; } } if (num_plot_stacks > 0) { switch (preferred_plot_type) { case plot_gpu_duo: *num_plots = (num_devices + (num_devices % 2)) / 2; break; case plot_gpu_solo: *num_plots = num_devices; break; case plot_gpu_max: *num_plots = 1; break; } num_borrow_line = rows_left - num_plot_stacks * min_plot_rows; } else { goto no_plot; } } else { no_plot: num_borrow_line = rows_left; *num_plots = 0; } unsigned space_for_header = header_stacks == 0 ? 0 : header_stacks - 1; bool space_between_header_stack = false; if (num_borrow_line >= space_for_header && show_header) { rows_for_header += space_for_header; rows_left -= space_for_header; space_between_header_stack = true; } if (*num_plots == 0 && show_process && rows_left > 0) { rows_for_process += rows_left - 1; } if (num_plot_stacks > 0) { // Allocate new plot stack is enough vertical room while (num_plot_stacks < *num_plots && rows_left / (num_plot_stacks + 1) >= 11 && (num_plot_stacks + 1) * min_plot_rows <= rows_left) num_plot_stacks++; } // Now compute the interface window positions // Device Information Header unsigned cols_header_left = cols - num_device_per_row * device_header_cols; bool space_between_header_col = false; bool space_before_header = false; if (cols_header_left > num_device_per_row) { space_between_header_col = true; cols_header_left -= num_device_per_row - 1; } if (cols_header_left > 0) space_before_header = true; unsigned num_this_row = 0; unsigned headerPosX = space_before_header; unsigned headerPosY = 0; for (unsigned i = 0; i < num_devices; ++i) { device_positions[i].posX = headerPosX; device_positions[i].posY = headerPosY; device_positions[i].sizeX = device_header_cols; device_positions[i].sizeY = device_header_rows; num_this_row++; if (num_this_row == num_device_per_row) { headerPosX = space_before_header; headerPosY += device_header_rows + space_between_header_stack; num_this_row = 0; } else { headerPosX += device_header_cols + space_between_header_col; } } unsigned rows_left_for_process = 0; if (*num_plots == 0) { *plot_positions = NULL; } else { *plot_positions = malloc(*num_plots * sizeof(**plot_positions)); *plot_types = preferred_plot_type; unsigned rows_per_stack = rows_left / num_plot_stacks; if (rows_per_stack > 23) rows_per_stack = 23; unsigned plot_per_row = *num_plots / num_plot_stacks; unsigned num_plot_done = 0; unsigned currentPosX = 0, currentPosY = rows_for_header; for (unsigned i = 0; i < num_plot_stacks; ++i) { unsigned plot_in_this_row = min(*num_plots - num_plot_done, plot_per_row); unsigned cols_per_plot = cols / plot_in_this_row; if (*plot_types == plot_gpu_duo) cols_per_plot -= (cols_per_plot - cols_needed_box_drawing) % (2 * num_info_per_device); else cols_per_plot -= (cols_per_plot - cols_needed_box_drawing) % num_info_per_device; unsigned extra_cols = cols - cols_per_plot * plot_per_row; unsigned cols_between_plots = extra_cols / (plot_in_this_row <= 1 ? 1 : plot_in_this_row - 1); for (unsigned j = 0; j < plot_in_this_row; ++j) { (*plot_positions)[num_plot_done].posX = currentPosX; (*plot_positions)[num_plot_done].posY = currentPosY; (*plot_positions)[num_plot_done].sizeX = cols_per_plot; (*plot_positions)[num_plot_done].sizeY = rows_per_stack; currentPosX += cols_per_plot + cols_between_plots; num_plot_done++; } currentPosY += rows_per_stack; currentPosX = 0; } rows_left_for_process = rows_left - rows_per_stack * num_plot_stacks; } process_position->posX = 0; process_position->posY = rows - rows_for_process - rows_left_for_process; process_position->sizeY = rows_for_process + rows_left_for_process; process_position->sizeX = cols; } nvtop-1.0.0/src/nvtop.c000066400000000000000000000224311341567056100147710ustar00rootroot00000000000000/* * * Copyright (C) 2017 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #include #include #include #include #include #include #include #include #include "nvtop/interface.h" #include "nvtop/time.h" #include "nvtop/version.h" static volatile sig_atomic_t signal_exit = 0; static volatile sig_atomic_t signal_resize_win = 0; static void exit_handler(int signum) { (void)signum; signal_exit = 1; } static void resize_handler(int signum) { (void)signum; signal_resize_win = 1; } static const char helpstring[] = "Available options:\n" " -d --delay : Select the refresh rate (1 == 0.1s)\n" " -v --version : Print the version and exit\n" " -s --gpu-select : Column separated list of GPU IDs to monitor\n" " -i --gpu-ignore : Column separated list of GPU IDs to ignore\n" " -p --no-plot : Disable bar plot\n" " -C --no-color : No colors\n" " -N --no-cache : Always query the system for user names and command " "line information\n" " -f --freedom-unit : Use fahrenheit\n" " -E --encode-hide : Set encode/decode auto hide time in seconds " "(default 30s, negative = always on screen)\n" " -h --help : Print help and exit\n"; static const char versionString[] = "nvtop version " NVTOP_VERSION_STRING; static const struct option long_opts[] = { {.name = "delay", .has_arg = required_argument, .flag = NULL, .val = 'd'}, {.name = "version", .has_arg = no_argument, .flag = NULL, .val = 'v'}, {.name = "help", .has_arg = no_argument, .flag = NULL, .val = 'h'}, {.name = "no-color", .has_arg = no_argument, .flag = NULL, .val = 'C'}, {.name = "no-colour", .has_arg = no_argument, .flag = NULL, .val = 'C'}, {.name = "no-cache", .has_arg = no_argument, .flag = NULL, .val = 'N'}, {.name = "freedom-unit", .has_arg = no_argument, .flag = NULL, .val = 'f'}, {.name = "gpu-select", .has_arg = required_argument, .flag = NULL, .val = 's'}, {.name = "gpu-ignore", .has_arg = required_argument, .flag = NULL, .val = 'i'}, {.name = "encode-hide", .has_arg = required_argument, .flag = NULL, .val = 'E'}, {.name = "no-plot", .has_arg = no_argument, .flag = NULL, .val = 'p'}, {0, 0, 0, 0}, }; static const char opts[] = "hvd:s:i:CNfE:p"; static size_t update_mask_value(const char *str, size_t entry_mask, bool addTo) { char *saveptr; char *option_copy = malloc((strlen(str) + 1) * sizeof(*option_copy)); strcpy(option_copy, str); char *gpu_num = strtok_r(option_copy, ":", &saveptr); while (gpu_num != NULL) { char *endptr; unsigned num_used = strtoul(gpu_num, &endptr, 0); if (endptr == gpu_num) { fprintf(stderr, "Use GPU IDs (unsigned integer) to select GPU with " "option 's' or 'i'\n"); exit(EXIT_FAILURE); } if (num_used >= CHAR_BIT * sizeof(entry_mask)) { fprintf(stderr, "Select GPU X with option 's' or 'i' where 0 <= X < %zu\n", CHAR_BIT * sizeof(entry_mask)); exit(EXIT_FAILURE); } if (addTo) entry_mask |= 1 << num_used; else entry_mask &= ~(1 << num_used); gpu_num = strtok_r(NULL, ":", &saveptr); } free(option_copy); return entry_mask; } int main(int argc, char **argv) { (void)setlocale(LC_CTYPE, ""); opterr = 0; int refresh_interval = 1000; char *selectedGPU = NULL; char *ignoredGPU = NULL; bool use_color_if_available = true; bool cache_pid_infos = true; bool use_fahrenheit = false; bool show_plot = true; double encode_decode_hide_time = 30.; while (true) { int optchar = getopt_long(argc, argv, opts, long_opts, NULL); if (optchar == -1) break; switch (optchar) { case 'd': { char *endptr = NULL; long int delay_val = strtol(optarg, &endptr, 0); if (endptr == optarg) { fprintf(stderr, "Error: The delay must be a positive value " "representing tenths of seconds\n"); exit(EXIT_FAILURE); } if (delay_val < 0) { fprintf(stderr, "Error: A negative delay requires a time machine!\n"); exit(EXIT_FAILURE); } refresh_interval = (int)delay_val * 100u; } break; case 's': selectedGPU = optarg; break; case 'i': ignoredGPU = optarg; break; case 'v': printf("%s\n", versionString); exit(EXIT_SUCCESS); case 'h': printf("%s\n%s", versionString, helpstring); exit(EXIT_SUCCESS); case 'C': use_color_if_available = false; break; case 'N': cache_pid_infos = false; break; case 'f': use_fahrenheit = true; break; case 'E': { if (sscanf(optarg, "%lf", &encode_decode_hide_time) == EOF) { fprintf(stderr, "Invalid format for encode/decode hide time: %s\n", optarg); exit(EXIT_FAILURE); } } break; case 'p': show_plot = false; break; case ':': case '?': switch (optopt) { case 'd': fprintf(stderr, "Error: The delay option takes a positive value " "representing tenths of seconds\n"); break; default: fprintf(stderr, "Unhandled error in getopt missing argument\n"); exit(EXIT_FAILURE); break; } exit(EXIT_FAILURE); } } setenv("ESCDELAY", "10", 1); struct sigaction siga; siga.sa_flags = 0; sigemptyset(&siga.sa_mask); siga.sa_handler = exit_handler; if (sigaction(SIGINT, &siga, NULL) != 0) { perror("Impossible to set signal handler for SIGINT: "); exit(EXIT_FAILURE); } if (sigaction(SIGQUIT, &siga, NULL) != 0) { perror("Impossible to set signal handler for SIGQUIT: "); exit(EXIT_FAILURE); } siga.sa_handler = resize_handler; if (sigaction(SIGWINCH, &siga, NULL) != 0) { perror("Impossible to set signal handler for SIGWINCH: "); exit(EXIT_FAILURE); } size_t gpu_mask; if (selectedGPU != NULL) { gpu_mask = 0; gpu_mask = update_mask_value(selectedGPU, gpu_mask, true); } else { gpu_mask = UINT_MAX; } if (ignoredGPU != NULL) { gpu_mask = update_mask_value(ignoredGPU, gpu_mask, false); } if (!init_gpu_info_extraction()) return EXIT_FAILURE; size_t num_devices; struct device_info *dev_infos; num_devices = initialize_device_info(&dev_infos, gpu_mask); if (num_devices == 0) { fprintf(stdout, "No GPU left to monitor.\n"); free(dev_infos); return EXIT_SUCCESS; } size_t biggest_name = 0; for (size_t i = 0; i < num_devices; ++i) { size_t device_name_size = strlen(dev_infos->device_name); if (device_name_size > biggest_name) { biggest_name = device_name_size; } } struct nvtop_interface *interface = initialize_curses( num_devices, biggest_name, use_color_if_available, use_fahrenheit, show_plot, encode_decode_hide_time, refresh_interval); timeout(refresh_interval); double time_slept = refresh_interval; while (!signal_exit) { if (signal_resize_win) { update_window_size_to_terminal_size(interface); signal_resize_win = 0; } if (!cache_pid_infos) clean_pid_cache(); if (time_slept >= refresh_interval) { update_device_infos(num_devices, dev_infos); timeout(refresh_interval); time_slept = 0.; } else { int next_sleep = (int)((refresh_interval - time_slept)); timeout(next_sleep); } draw_gpu_info_ncurses(dev_infos, interface); nvtop_time time_before_sleep, time_after_sleep; nvtop_get_current_time(&time_before_sleep); int input_char = getch(); nvtop_get_current_time(&time_after_sleep); time_slept += nvtop_difftime(time_before_sleep, time_after_sleep) * 1000; switch (input_char) { case 27: // ESC { timeout(0); int in = getch(); if (in == ERR) { // ESC alone if (is_escape_for_quit(interface)) signal_exit = 1; else interface_key(27, interface); } // else ALT key } break; case KEY_F(3): if (is_escape_for_quit(interface)) signal_exit = 1; break; case 'q': signal_exit = 1; break; case KEY_F(1): case KEY_F(2): case '+': case '-': interface_key(input_char, interface); break; case KEY_LEFT: case KEY_RIGHT: case KEY_UP: case KEY_DOWN: case KEY_ENTER: case '\n': interface_key(input_char, interface); break; case ERR: default: break; } } clean_ncurses(interface); clean_device_info(num_devices, dev_infos); shutdown_gpu_info_extraction(); return EXIT_SUCCESS; } nvtop-1.0.0/src/plot.c000066400000000000000000000114261341567056100146030ustar00rootroot00000000000000#include #include #include "nvtop/plot.h" static inline int data_level(double rows, double data, double increment) { return (int)(rows - round(data / increment)); } void nvtop_line_plot(WINDOW *win, size_t num_data, const double *data, double min, double max, unsigned num_plots, const char *legend[]) { if (num_data == 0) return; int rows, cols; getmaxyx(win, rows, cols); rows -= 1; // Maximum drawable character double increment = (max - min) / (double)(rows); int low_data_level = data_level(0, min, increment); for (size_t k = 0; k < num_plots; ++k) { int level_previous = data_level(rows, data[k], increment) - low_data_level; int level_next, level_current; wattron(win, COLOR_PAIR(1 + k % 5)); for (size_t i = k; i < num_data || i < (size_t)cols; i += num_plots) { level_next = i + num_plots >= num_data ? level_next : data_level(rows, data[i + num_plots], increment) - low_data_level; level_current = data_level(rows, data[i], increment) - low_data_level; int top, bottom; if (level_current == level_previous) { mvwaddch(win, level_current, i, ACS_HLINE); top = bottom = level_current; } else { if (level_current < level_previous) { top = level_previous; bottom = level_current; } else { top = level_current; bottom = level_previous; } for (int j = bottom + 1; j < top; j++) { mvwaddch(win, j, i, ACS_VLINE); } if (level_current > level_previous) { mvwaddch(win, level_current, i, ACS_LLCORNER); mvwaddch(win, level_previous, i, ACS_URCORNER); } else { mvwaddch(win, level_current, i, ACS_ULCORNER); mvwaddch(win, level_previous, i, ACS_LRCORNER); } } for (unsigned j = 0; j < num_plots; ++j) { if (j == k) continue; int cross_level = -low_data_level; if (j < k || i + j < num_plots + k) cross_level += data_level(rows, data[i - k + j], increment); else cross_level += data_level(rows, data[i - k + j - num_plots], increment); if (cross_level == top && top == bottom) continue; if (cross_level > bottom && cross_level < top) { mvwaddch(win, cross_level, i, ACS_PLUS); } else { if (cross_level == top) { mvwaddch(win, cross_level, i, ACS_BTEE); } else { if (cross_level == bottom) { mvwaddch(win, cross_level, i, ACS_TTEE); } else { wattroff(win, COLOR_PAIR(1 + k % 5)); wattron(win, COLOR_PAIR(1 + j % 5)); mvwaddch(win, cross_level, i, ACS_HLINE); wattroff(win, COLOR_PAIR(1 + j % 5)); wattron(win, COLOR_PAIR(1 + k % 5)); } } } } level_previous = level_current; } wattroff(win, COLOR_PAIR(1 + k % 5)); } int plot_y_position = 0; for (unsigned i = 0; i < num_plots && plot_y_position < rows; ++i) { if (legend[i]) { size_t length = strlen(legend[i]); wattron(win, COLOR_PAIR(1 + i % 5)); if (length < (size_t)cols) { mvwprintw(win, plot_y_position, cols - length, "%s", legend[i]); } else { wmove(win, plot_y_position, 0); for (int j = 0; j < cols; ++j) { waddch(win, legend[i][j]); } } wattroff(win, COLOR_PAIR(1 + i % 5)); plot_y_position++; } } } void nvtop_bar_plot(WINDOW *win, size_t num_data, const double *data, double min, double max) { if (num_data == 0) return; int rows, cols; getmaxyx(win, rows, cols); rows -= 1; double increment = (max - min) / (double)(rows); int low_data_level = data_level(0, min, increment); for (size_t i = 0; i < num_data || i < (size_t)cols; ++i) { for (int j = data_level(rows, data[i], increment) - low_data_level; j <= rows; j++) { mvwaddch(win, j, i, ACS_CKBOARD); } } } void draw_rectangle(WINDOW *win, unsigned startX, unsigned startY, unsigned sizeX, unsigned sizeY) { for (unsigned i = 0; i < sizeX - 2; ++i) { mvwaddch(win, startY, startX + 1 + i, ACS_HLINE); mvwaddch(win, startY + sizeY - 1, startX + 1 + i, ACS_HLINE); } for (unsigned i = 0; i < sizeY - 2; ++i) { mvwaddch(win, startY + 1 + i, startX, ACS_VLINE); mvwaddch(win, startY + 1 + i, startX + sizeX - 1, ACS_VLINE); } mvwaddch(win, startY, startX, ACS_ULCORNER); mvwaddch(win, startY, startX + sizeX - 1, ACS_URCORNER); mvwaddch(win, startY + sizeY - 1, startX, ACS_LLCORNER); mvwaddch(win, startY + sizeY - 1, startX + sizeX - 1, ACS_LRCORNER); } nvtop-1.0.0/src/time.c000066400000000000000000000022441341567056100145610ustar00rootroot00000000000000/* * * Copyright (C) 2018 Maxime Schmitt * * This file is part of Nvtop. * * Nvtop is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Nvtop is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with nvtop. If not, see . * */ #include "nvtop/time.h" extern inline void nvtop_get_current_time(nvtop_time *time); extern inline double nvtop_difftime(nvtop_time t0, nvtop_time t1); extern inline nvtop_time nvtop_add_time(nvtop_time t0, nvtop_time t1); extern inline nvtop_time nvtop_substract_time(nvtop_time t0, nvtop_time t1); extern inline nvtop_time nvtop_hmns_to_time(unsigned hour, unsigned minutes, unsigned long nanosec);