mirror of
https://github.com/Syllo/nvtop.git
synced 2024-03-13 10:04:14 +03:00
Initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
*.o
|
||||
*ctags
|
||||
build/*
|
||||
87
CMakeLists.txt
Normal file
87
CMakeLists.txt
Normal file
@@ -0,0 +1,87 @@
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
|
||||
#///////////////////////////////////////////////////////////////////#
|
||||
# PROJECT #
|
||||
#///////////////////////////////////////////////////////////////////#
|
||||
|
||||
set(NVTOP_VERSION_MAJOR 0)
|
||||
set(NVTOP_VERSION_MINOR 1)
|
||||
set(NVTOP_VERSION_PATCH 0)
|
||||
|
||||
project(nvtop
|
||||
LANGUAGES C)
|
||||
|
||||
# Default build type
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
message(STATUS "No building type advertised, default to Release")
|
||||
endif()
|
||||
|
||||
#///////////////////////////////////////////////////////////////////#
|
||||
# DEPENDENCIES #
|
||||
#///////////////////////////////////////////////////////////////////#
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
|
||||
|
||||
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)
|
||||
find_package(Curses REQUIRED)
|
||||
|
||||
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 #
|
||||
#///////////////////////////////////////////////////////////////////#
|
||||
|
||||
include(cmake/compiler-flags.cmake)
|
||||
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3 -mtune=generic")
|
||||
set(CMAKE_C_FLAGS_DEBUG
|
||||
"${COMPILER_AVALIABLE_WARNINGS} ${COMPILER_ADDRESS_SANITIZER_FLAG} ${COMPILER_UNDEFINED_SANITIZER_FLAG} -Og -g")
|
||||
set(CMAKE_C_FLAGS_OPTIMIZED
|
||||
"${COMPILER_LTO_FLAG} ${COMPILER_MARCH_NATIVE} -O3")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} -g")
|
||||
|
||||
# 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 #
|
||||
#///////////////////////////////////////////////////////////////////#
|
||||
|
||||
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include/"
|
||||
DESTINATION include FILES_MATCHING PATTERN "*.h")
|
||||
|
||||
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)
|
||||
674
COPYING
Normal file
674
COPYING
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
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.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
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
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
13
TODO
Normal file
13
TODO
Normal file
@@ -0,0 +1,13 @@
|
||||
What is in the pipeline:
|
||||
|
||||
- Add command line option to configure the behaviour like
|
||||
- Refresh interval
|
||||
- Version
|
||||
- Whatever
|
||||
|
||||
- Instead of returning the value 0 when the NVML library errors, set an error
|
||||
value instead and print it accordingly in the UI.
|
||||
|
||||
- Add mouse and some keyboard shortcut for ncurses.
|
||||
|
||||
- Do a manpage
|
||||
23
cmake/cmake_uninstall.cmake.in
Normal file
23
cmake/cmake_uninstall.cmake.in
Normal file
@@ -0,0 +1,23 @@
|
||||
if(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)
|
||||
90
cmake/compiler-flags.cmake
Normal file
90
cmake/compiler-flags.cmake
Normal file
@@ -0,0 +1,90 @@
|
||||
include (CheckCCompilerFlag)
|
||||
|
||||
set (ALL_WARNING_FLAGS
|
||||
"-Waggressive-loop-optimizations"
|
||||
"-Wall"
|
||||
"-Wbad-function-cast"
|
||||
"-Wcast-align"
|
||||
"-Wcast-qual"
|
||||
#"-Wconversion"
|
||||
"-Wdisabled-optimization"
|
||||
"-Wdouble-promotion"
|
||||
"-Wextra"
|
||||
"-Wfloat-conversion"
|
||||
"-Wfloat-equal"
|
||||
"-Whsa"
|
||||
"-Winit-self"
|
||||
"-Wlogical-op"
|
||||
"-Wmissing-declarations"
|
||||
"-Wmissing-parameter-type"
|
||||
"-Wmissing-prototypes"
|
||||
"-Wnested-externs"
|
||||
"-Wnormalized=nfc"
|
||||
"-Wnull-dereference"
|
||||
"-Wold-style-declaration"
|
||||
"-Wold-style-definition"
|
||||
#"-Wpadded"
|
||||
"-Wpedantic"
|
||||
"-Wpointer-sign"
|
||||
"-Wshadow"
|
||||
"-Wstrict-aliasing"
|
||||
"-Wstrict-prototypes"
|
||||
#"-Wsuggest-attribute=const"
|
||||
"-Wswitch-enum"
|
||||
"-Wtrampolines"
|
||||
"-Wuninitialized"
|
||||
"-Wunsafe-loop-optimizations"
|
||||
"-Wunused-result"
|
||||
)
|
||||
|
||||
function (check_all_warning_flags flag_list)
|
||||
|
||||
foreach (warning_flag ${flag_list})
|
||||
check_c_compiler_flag(${warning_flag} "Working${warning_flag}")
|
||||
if ("${Working${warning_flag}}")
|
||||
list(APPEND VALID_WARNINGS "${warning_flag}")
|
||||
endif ("${Working${warning_flag}}")
|
||||
endforeach (warning_flag)
|
||||
|
||||
string(REPLACE ";" " " COMPILER_AVALIABLE_WARNINGS "${VALID_WARNINGS}")
|
||||
set (COMPILER_AVALIABLE_WARNINGS ${COMPILER_AVALIABLE_WARNINGS} PARENT_SCOPE)
|
||||
|
||||
endfunction (check_all_warning_flags)
|
||||
|
||||
check_all_warning_flags("${ALL_WARNING_FLAGS}")
|
||||
|
||||
string(REPLACE ";" " "
|
||||
COMPILER_AVALIABLE_WARNINGS "${COMPILER_AVALIABLE_WARNINGS}")
|
||||
|
||||
set(CMAKE_REQUIRED_FLAGS "-fsanitize=address")
|
||||
check_c_compiler_flag("-fsanitize=address" compiler_has_address_sanitizer)
|
||||
unset(CMAKE_REQUIRED_FLAGS)
|
||||
if(compiler_has_address_sanitizer)
|
||||
set(COMPILER_ADDRESS_SANITIZER_FLAG "-fsanitize=address")
|
||||
# Nicer stack trace
|
||||
check_c_compiler_flag("-fno-omit-frame-pointer"
|
||||
compiler_has_no_omit_frame_pointer)
|
||||
if(compiler_has_no_omit_frame_pointer)
|
||||
set(COMPILER_ADDRESS_SANITIZER_FLAG
|
||||
"${COMPILER_ADDRESS_SANITIZER_FLAG} -fno-omit-frame-pointer")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_FLAGS "-fsanitize=undefined")
|
||||
check_c_compiler_flag("-fsanitize=undefined" compiler_has_undefined_sanitizer)
|
||||
unset(CMAKE_REQUIRED_FLAGS)
|
||||
if(compiler_has_undefined_sanitizer)
|
||||
set(COMPILER_UNDEFINED_SANITIZER_FLAG "-fsanitize=undefined")
|
||||
endif()
|
||||
|
||||
set(CMAKE_REQUIRED_FLAGS "-flto")
|
||||
check_c_compiler_flag("-flto" compiler_has_lto)
|
||||
unset(CMAKE_REQUIRED_FLAGS)
|
||||
if(compiler_has_lto)
|
||||
set(COMPILER_LTO_FLAG "-flto")
|
||||
endif()
|
||||
|
||||
check_c_compiler_flag("-march=native" compiler_has_march_native)
|
||||
if(compiler_has_march_native)
|
||||
set(COMPILER_MARCH_NATIVE "-march=native")
|
||||
endif()
|
||||
52
cmake/modules/FindNVML.cmake
Normal file
52
cmake/modules/FindNVML.cmake
Normal file
@@ -0,0 +1,52 @@
|
||||
# Version 1.1
|
||||
# Public Domain
|
||||
# Written by Maxime SCHMITT <maxime.schmitt@etu.unistra.fr>
|
||||
|
||||
#/////////////////////////////////////////////////////////////////////////////#
|
||||
# #
|
||||
# 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/local/cuda*/include /opt/cuda*/include)
|
||||
find_path(NVML_INCLUDE_DIRS NAMES nvml.h
|
||||
HINTS ${nvml_header_path_hint})
|
||||
|
||||
# library
|
||||
find_library(NVML_LIBRARIES NAMES nvml nvidia-ml)
|
||||
|
||||
# Version
|
||||
set(filename "${NVML_INCLUDE_DIRS}/nvml.h")
|
||||
if (NOT EXISTS ${filename} AND NOT quiet)
|
||||
message(AUTHOR_WARNING "Unable to find ${filename}")
|
||||
endif()
|
||||
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)
|
||||
message(AUTHOR_WARNING "Unable to find nvml api version")
|
||||
else()
|
||||
set(NVML_API_VERSION "${nvml_api_version}")
|
||||
endif()
|
||||
|
||||
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)
|
||||
83
include/extract_gpuinfo.h
Normal file
83
include/extract_gpuinfo.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2017 Maxime Schmitt <maxime.schmitt91@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __EXTRACT_GPUINFO_H_
|
||||
#define __EXTRACT_GPUINFO_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <nvml.h>
|
||||
|
||||
struct gpu_process {
|
||||
unsigned int pid; // Process ID
|
||||
char process_name[64]; // Process Name
|
||||
char user_name[64]; // Process User Name
|
||||
unsigned long long used_memory; // Memory used by process
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
bool init_gpu_info_extraction(void);
|
||||
|
||||
bool shutdown_gpu_info_extraction(void);
|
||||
|
||||
unsigned int initialize_device_info(struct device_info **dev_info);
|
||||
|
||||
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);
|
||||
|
||||
#endif // __EXTRACT_GPUINFO_H_
|
||||
29
include/get_process_info.h
Normal file
29
include/get_process_info.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2017 Maxime Schmitt <maxime.schmitt91@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __GET_PROCESS_INFO_H_
|
||||
#define __GET_PROCESS_INFO_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
void get_username_from_pid(pid_t pid, size_t size_buffer, char *buffer);
|
||||
|
||||
#endif // __GET_PROCESS_INFO_H_
|
||||
53
include/interface.h
Normal file
53
include/interface.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2017 Maxime Schmitt <maxime.schmitt91@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __INTERFACE_H_
|
||||
#define __INTERFACE_H_
|
||||
|
||||
#include "extract_gpuinfo.h"
|
||||
|
||||
enum sort_gpu_process_by {
|
||||
sort_pid,
|
||||
sort_username,
|
||||
sort_process_name,
|
||||
sort_mem_usage,
|
||||
sort_by_gpu,
|
||||
sort_none,
|
||||
};
|
||||
|
||||
struct nvtop_interface;
|
||||
|
||||
void show_gpu_infos_ascii(
|
||||
unsigned int num_devices,
|
||||
struct device_info *dev_info);
|
||||
|
||||
struct nvtop_interface* initialize_curses(void);
|
||||
|
||||
void clean_ncurses(struct nvtop_interface *interface);
|
||||
|
||||
void draw_gpu_info_ncurses(
|
||||
unsigned int num_devices,
|
||||
struct device_info *dev_info,
|
||||
struct nvtop_interface *interface);
|
||||
|
||||
void update_window_size_to_terminal_size(struct nvtop_interface *inter);
|
||||
|
||||
#endif // __INTERFACE_H_
|
||||
18
src/CMakeLists.txt
Normal file
18
src/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
add_executable (nvtop
|
||||
nvtop.c
|
||||
interface.c
|
||||
get_process_info_linux.c
|
||||
extract_gpuinfo.c)
|
||||
|
||||
target_include_directories(nvtop PRIVATE
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
|
||||
$<BUILD_INTERFACE:${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)
|
||||
411
src/extract_gpuinfo.c
Normal file
411
src/extract_gpuinfo.c
Normal file
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2017 Maxime Schmitt <maxime.schmitt91@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "extract_gpuinfo.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "get_process_info.h"
|
||||
|
||||
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);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
memcpy(dev_info->device_name, "UNKNOWN", strlen("UNKNOWN")+1);
|
||||
}
|
||||
|
||||
// PCIe LINK GEN MAX
|
||||
retval = nvmlDeviceGetMaxPcieLinkGeneration(
|
||||
dev_info->device_handle,
|
||||
&dev_info->max_pcie_link_gen
|
||||
);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info->max_pcie_link_gen = 0;
|
||||
}
|
||||
// PCIe LINK WIDTH MAX
|
||||
retval = nvmlDeviceGetMaxPcieLinkWidth(
|
||||
dev_info->device_handle,
|
||||
&dev_info->max_pcie_link_width
|
||||
);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info->max_pcie_link_width = 0;
|
||||
}
|
||||
|
||||
// GPU TEMP SHUTDOWN
|
||||
retval = nvmlDeviceGetTemperatureThreshold(
|
||||
dev_info->device_handle,
|
||||
NVML_TEMPERATURE_THRESHOLD_SHUTDOWN,
|
||||
&dev_info->gpu_temp_shutdown
|
||||
);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info->gpu_temp_shutdown = 0;
|
||||
}
|
||||
|
||||
// GPU TEMP SLOWDOWN
|
||||
retval = nvmlDeviceGetTemperatureThreshold(
|
||||
dev_info->device_handle,
|
||||
NVML_TEMPERATURE_THRESHOLD_SLOWDOWN,
|
||||
&dev_info->gpu_temp_slowdown
|
||||
);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info->gpu_temp_slowdown = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void update_gpu_process_from_process_info(
|
||||
unsigned int num_process,
|
||||
nvmlProcessInfo_t *p_info,
|
||||
struct gpu_process *gpu_proc_info) {
|
||||
|
||||
nvmlReturn_t retval;
|
||||
for (unsigned int i = 0; i < num_process; ++i) {
|
||||
gpu_proc_info[i].pid = p_info[i].pid;
|
||||
retval =
|
||||
nvmlSystemGetProcessName(p_info[i].pid, gpu_proc_info[i].process_name, 64);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
memcpy(gpu_proc_info[i].process_name, "N/A", 4);
|
||||
}
|
||||
gpu_proc_info[i].used_memory = p_info[i].usedGpuMemory;
|
||||
get_username_from_pid(gpu_proc_info[i].pid, 64, gpu_proc_info[i].user_name);
|
||||
if (gpu_proc_info[i].user_name[0] == '\0')
|
||||
memcpy(gpu_proc_info[i].user_name, "N/A", 4);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
// GPU CLK
|
||||
nvmlReturn_t retval = nvmlDeviceGetClockInfo(
|
||||
dev_info[i].device_handle,
|
||||
NVML_CLOCK_GRAPHICS,
|
||||
&dev_info[i].gpu_clock_speed);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].gpu_clock_speed = 0;
|
||||
}
|
||||
|
||||
// MEM CLK
|
||||
retval = nvmlDeviceGetClockInfo(
|
||||
dev_info[i].device_handle,
|
||||
NVML_CLOCK_MEM,
|
||||
&dev_info[i].mem_clock_speed);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].mem_clock_speed = 0;
|
||||
}
|
||||
|
||||
// GPU CLK MAX
|
||||
retval = nvmlDeviceGetMaxClockInfo(
|
||||
dev_info[i].device_handle,
|
||||
NVML_CLOCK_GRAPHICS,
|
||||
&dev_info[i].gpu_clock_speed_max);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].gpu_clock_speed_max = 0;
|
||||
}
|
||||
|
||||
// MEM CLK MAX
|
||||
retval = nvmlDeviceGetMaxClockInfo(
|
||||
dev_info[i].device_handle,
|
||||
NVML_CLOCK_MEM,
|
||||
&dev_info[i].mem_clock_speed_max);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].mem_clock_speed_max = 0;
|
||||
}
|
||||
|
||||
// GPU / MEM UTIL RATE
|
||||
nvmlUtilization_t util_rate;
|
||||
retval = nvmlDeviceGetUtilizationRates(
|
||||
dev_info[i].device_handle,
|
||||
&util_rate);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].gpu_util_rate = 0;
|
||||
dev_info[i].mem_util_rate = 0;
|
||||
} else {
|
||||
dev_info[i].gpu_util_rate = util_rate.gpu;
|
||||
dev_info[i].mem_util_rate = util_rate.memory;
|
||||
}
|
||||
|
||||
// FREE / TOTAL / USED MEMORY
|
||||
nvmlMemory_t meminfo;
|
||||
retval = nvmlDeviceGetMemoryInfo(
|
||||
dev_info[i].device_handle,
|
||||
&meminfo);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].free_memory = 0;
|
||||
dev_info[i].total_memory = 0;
|
||||
dev_info[i].used_memory = 0;
|
||||
} else {
|
||||
dev_info[i].free_memory = meminfo.free;
|
||||
dev_info[i].total_memory = meminfo.total;
|
||||
dev_info[i].used_memory = meminfo.used;
|
||||
}
|
||||
|
||||
// PCIe LINK GEN
|
||||
retval = nvmlDeviceGetCurrPcieLinkGeneration(
|
||||
dev_info[i].device_handle,
|
||||
&dev_info[i].cur_pcie_link_gen);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].cur_pcie_link_gen = 0;
|
||||
}
|
||||
|
||||
// PCIe LINK WIDTH
|
||||
retval = nvmlDeviceGetCurrPcieLinkWidth(
|
||||
dev_info[i].device_handle,
|
||||
&dev_info[i].cur_pcie_link_width);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].cur_pcie_link_width = 0;
|
||||
}
|
||||
|
||||
// PCIe TX THROUGHPUT
|
||||
retval = nvmlDeviceGetPcieThroughput(
|
||||
dev_info[i].device_handle,
|
||||
NVML_PCIE_UTIL_TX_BYTES,
|
||||
&dev_info[i].pcie_tx);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].pcie_tx = 0;
|
||||
}
|
||||
|
||||
// PCIe RX THROUGHPUT
|
||||
retval = nvmlDeviceGetPcieThroughput(
|
||||
dev_info[i].device_handle,
|
||||
NVML_PCIE_UTIL_RX_BYTES,
|
||||
&dev_info[i].pcie_rx);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].pcie_rx = 0;
|
||||
}
|
||||
|
||||
// FAN SPEED
|
||||
retval = nvmlDeviceGetFanSpeed(
|
||||
dev_info[i].device_handle,
|
||||
&dev_info[i].fan_speed);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].fan_speed = 0;
|
||||
}
|
||||
|
||||
// GPU TEMP
|
||||
retval = nvmlDeviceGetTemperature(
|
||||
dev_info[i].device_handle,
|
||||
NVML_TEMPERATURE_GPU,
|
||||
&dev_info[i].gpu_temp);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].gpu_temp = 0;
|
||||
}
|
||||
|
||||
// POWER DRAW
|
||||
retval = nvmlDeviceGetPowerUsage(
|
||||
dev_info[i].device_handle,
|
||||
&dev_info[i].power_draw);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].power_draw = 0;
|
||||
}
|
||||
|
||||
// POWER MAX
|
||||
retval = nvmlDeviceGetEnforcedPowerLimit(
|
||||
dev_info[i].device_handle,
|
||||
&dev_info[i].power_draw_max);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].power_draw_max = 0;
|
||||
}
|
||||
|
||||
// Encoder infos
|
||||
retval = nvmlDeviceGetEncoderUtilization(
|
||||
dev_info[i].device_handle,
|
||||
&dev_info[i].encoder_rate,
|
||||
&dev_info[i].encoder_sampling);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].encoder_rate = 0;
|
||||
dev_info[i].encoder_sampling = 0;
|
||||
}
|
||||
|
||||
// Decoder infos
|
||||
retval = nvmlDeviceGetDecoderUtilization(
|
||||
dev_info[i].device_handle,
|
||||
&dev_info[i].decoder_rate,
|
||||
&dev_info[i].decoder_sampling);
|
||||
if (retval != NVML_SUCCESS) {
|
||||
dev_info[i].decoder_rate = 0;
|
||||
dev_info[i].decoder_sampling = 0;
|
||||
}
|
||||
|
||||
// Process informations
|
||||
update_graphical_process(&dev_info[i]);
|
||||
update_compute_process(&dev_info[i]);
|
||||
|
||||
} // Loop over devices
|
||||
}
|
||||
|
||||
unsigned int initialize_device_info(struct device_info **dev_info) {
|
||||
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 (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_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);
|
||||
}
|
||||
52
src/get_process_info_linux.c
Normal file
52
src/get_process_info_linux.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2017 Maxime Schmitt <maxime.schmitt91@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "get_process_info.h"
|
||||
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static char pid_path[64];
|
||||
|
||||
void get_username_from_pid(pid_t pid, size_t size_buffer, char *buffer) {
|
||||
size_t written = snprintf(pid_path, 64, "/proc/%d", pid);
|
||||
if (written == 64) {
|
||||
buffer[0] = '\0';
|
||||
return;
|
||||
}
|
||||
struct stat folder_stat;
|
||||
int starval = stat(pid_path, &folder_stat);
|
||||
if (starval == -1) {
|
||||
buffer[0] = '\0';
|
||||
return;
|
||||
}
|
||||
uid_t user_id = folder_stat.st_uid;
|
||||
struct passwd *user_info = getpwuid(user_id);
|
||||
if (user_info == NULL) {
|
||||
buffer[0] = '\0';
|
||||
return;
|
||||
}
|
||||
strncpy(buffer, user_info->pw_name, size_buffer);
|
||||
}
|
||||
752
src/interface.c
Normal file
752
src/interface.c
Normal file
@@ -0,0 +1,752 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2017 Maxime Schmitt <maxime.schmitt91@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#define DEVICE_ID_SIZE 16
|
||||
|
||||
enum interface_color {
|
||||
cyan_color = 1,
|
||||
red_color,
|
||||
green_color,
|
||||
yellow_color,
|
||||
blue_color,
|
||||
magenta_color,
|
||||
};
|
||||
|
||||
struct device_window {
|
||||
char *device_name;
|
||||
WINDOW *name_win; // Name of the GPU
|
||||
WINDOW* gpu_util;
|
||||
WINDOW* mem_util;
|
||||
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;
|
||||
};
|
||||
|
||||
struct all_gpu_processes {
|
||||
unsigned int pid;
|
||||
char process_name[64];
|
||||
char user_name[64];
|
||||
unsigned long long used_memory;
|
||||
double mem_percentage;
|
||||
unsigned int gpu_id;
|
||||
bool is_graphical;
|
||||
};
|
||||
|
||||
struct process_window {
|
||||
unsigned int size_biggest_name;
|
||||
unsigned int size_processes_buffer;
|
||||
unsigned int offset;
|
||||
struct all_gpu_processes *all_process;
|
||||
WINDOW *process_win;
|
||||
};
|
||||
|
||||
struct nvtop_interface {
|
||||
size_t num_devices;
|
||||
struct device_window *devices_win;
|
||||
struct process_window process;
|
||||
};
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
enum process_field {
|
||||
process_pid = 0,
|
||||
process_user,
|
||||
process_memory,
|
||||
process_gpu_id,
|
||||
process_type,
|
||||
};
|
||||
|
||||
static unsigned int sizeof_process_field[] = {
|
||||
[process_pid] = 5,
|
||||
[process_user] = 4,
|
||||
[process_memory] = 6,
|
||||
[process_gpu_id] = 3,
|
||||
[process_type] = 7,
|
||||
};
|
||||
|
||||
static void alloc_device_window_data(
|
||||
unsigned int biggest_device_name_size,
|
||||
unsigned int row,
|
||||
unsigned int totalcol,
|
||||
struct device_window *dwin) {
|
||||
|
||||
unsigned int size_name_win = 11 // strlen(" Device []")
|
||||
+ biggest_device_name_size;
|
||||
sizeof_device_field[device_name] = size_name_win;
|
||||
|
||||
const unsigned int spacer = 1;
|
||||
|
||||
// Assume at least 80 columns
|
||||
|
||||
// Line 1 = Name | PCIe info
|
||||
|
||||
dwin->name_win = newwin(1, sizeof_device_field[device_name],
|
||||
row,
|
||||
spacer);
|
||||
dwin->pcie_info = newwin(1, sizeof_device_field[device_pcie],
|
||||
row,
|
||||
spacer*2 + sizeof_device_field[device_name]);
|
||||
|
||||
// Line 2 = GPU clk | MEM clk | Temp | Fan | Power
|
||||
dwin->gpu_clock_info = newwin(1, sizeof_device_field[device_clock],
|
||||
row+1,
|
||||
spacer);
|
||||
dwin->mem_clock_info = newwin(1, sizeof_device_field[device_clock],
|
||||
row+1,
|
||||
spacer * 2 + sizeof_device_field[device_clock]);
|
||||
dwin->temperature = newwin(1, sizeof_device_field[device_temperature],
|
||||
row+1,
|
||||
spacer * 3 + sizeof_device_field[device_clock] * 2);
|
||||
dwin->fan_speed = newwin(1, sizeof_device_field[device_fan_speed],
|
||||
row+1,
|
||||
spacer * 4 +
|
||||
sizeof_device_field[device_clock] * 2 +
|
||||
sizeof_device_field[device_temperature]);
|
||||
dwin->power_info = newwin(1, sizeof_device_field[device_power],
|
||||
row+1,
|
||||
spacer * 5 +
|
||||
sizeof_device_field[device_clock] * 2 +
|
||||
sizeof_device_field[device_temperature] +
|
||||
sizeof_device_field[device_fan_speed]);
|
||||
|
||||
// Line 3 = GPU used | MEM used | Encoder | Decoder
|
||||
|
||||
int remaining_cols = totalcol - 5 * 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 = newwin(1, size_gpu, row+2, spacer);
|
||||
dwin->mem_util = newwin(1, size_mem,
|
||||
row+2,
|
||||
spacer * 2 + size_gpu);
|
||||
dwin->encode_util = newwin(1, size_encode,
|
||||
row+2,
|
||||
spacer * 3 + size_gpu + size_mem);
|
||||
dwin->decode_util = newwin(1, size_decode,
|
||||
row+2,
|
||||
spacer * 4 + size_gpu + size_mem + size_encode);
|
||||
}
|
||||
|
||||
static void free_device_window_data(struct device_window *dwin) {
|
||||
delwin(dwin->name_win);
|
||||
delwin(dwin->gpu_util);
|
||||
delwin(dwin->mem_util);
|
||||
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);
|
||||
free(dwin->device_name);
|
||||
}
|
||||
|
||||
|
||||
static void initialize_interface(
|
||||
struct nvtop_interface *dwin,
|
||||
unsigned int num_devices,
|
||||
unsigned int biggest_device_name_size) {
|
||||
|
||||
int rows, cols;
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
|
||||
dwin->devices_win = malloc(num_devices * sizeof(*dwin->devices_win));
|
||||
memset(dwin->devices_win, 0, num_devices * sizeof(*dwin->devices_win));
|
||||
dwin->num_devices = num_devices;
|
||||
for (unsigned int i = 0; i < num_devices; ++i) {
|
||||
alloc_device_window_data(biggest_device_name_size, i*4, cols, &dwin->devices_win[i]);
|
||||
}
|
||||
|
||||
int remaining_rows = rows - num_devices * 4 - 1;
|
||||
if (remaining_rows > 0) {
|
||||
dwin->process.size_processes_buffer =
|
||||
remaining_rows > 50 ? remaining_rows : 50;
|
||||
dwin->process.process_win = newwin(remaining_rows, cols-2, num_devices*4, 1);
|
||||
dwin->process.all_process = malloc(dwin->process.size_processes_buffer *
|
||||
sizeof(*dwin->process.all_process));
|
||||
} else {
|
||||
memset(&dwin->process, 0, sizeof(dwin->process));
|
||||
}
|
||||
dwin->process.offset = 0;
|
||||
}
|
||||
|
||||
static void clear_interface(
|
||||
struct nvtop_interface *dwin) {
|
||||
for (unsigned int i = 0; i < dwin->num_devices; ++i) {
|
||||
free_device_window_data(&dwin->devices_win[i]);
|
||||
}
|
||||
free(dwin->devices_win);
|
||||
free(dwin->process.all_process);
|
||||
delwin(dwin->process.process_win);
|
||||
memset(dwin, 0, sizeof(*dwin));
|
||||
}
|
||||
|
||||
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();
|
||||
init_pair(cyan_color, COLOR_CYAN, COLOR_BLACK);
|
||||
init_pair(red_color, COLOR_RED, COLOR_BLACK);
|
||||
init_pair(green_color, COLOR_GREEN, COLOR_BLACK);
|
||||
init_pair(yellow_color, COLOR_YELLOW, COLOR_BLACK);
|
||||
init_pair(blue_color, COLOR_BLUE, COLOR_BLACK);
|
||||
init_pair(magenta_color, COLOR_MAGENTA, COLOR_BLACK);
|
||||
}
|
||||
|
||||
struct nvtop_interface* initialize_curses(void) {
|
||||
struct nvtop_interface *interface = malloc(sizeof(*interface));
|
||||
memset(interface, 0, sizeof(*interface));
|
||||
initscr();
|
||||
if (has_colors() == TRUE) {
|
||||
initialize_colors();
|
||||
}
|
||||
cbreak();
|
||||
noecho();
|
||||
keypad(stdscr, TRUE);
|
||||
curs_set(0);
|
||||
refresh();
|
||||
return interface;
|
||||
}
|
||||
|
||||
void clean_ncurses(struct nvtop_interface *interface) {
|
||||
endwin();
|
||||
clear_interface(interface);
|
||||
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;
|
||||
double 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) {
|
||||
mvwprintw(win, 0, 0, "TEMP %3u°C", temp);
|
||||
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 void draw_devices(
|
||||
unsigned int num_devices,
|
||||
struct device_info *dev_info,
|
||||
struct nvtop_interface *interface) {
|
||||
|
||||
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];
|
||||
snprintf(buff, 1024, "%u%%", dinfo->gpu_util_rate);
|
||||
draw_bare_percentage(dev->gpu_util, "GPU-Util", dinfo->gpu_util_rate, buff);
|
||||
|
||||
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(dev->mem_util, "MEM-Util",
|
||||
(unsigned int)(100. * dinfo->used_memory / (double)dinfo->total_memory),
|
||||
buff);
|
||||
snprintf(buff, 1024, "%u%%", dinfo->encoder_rate);
|
||||
draw_bare_percentage(dev->encode_util, "Encoder",
|
||||
dinfo->encoder_rate,
|
||||
buff);
|
||||
snprintf(buff, 1024, "%u%%", dinfo->decoder_rate);
|
||||
draw_bare_percentage(dev->decode_util, "Decoder",
|
||||
dinfo->decoder_rate,
|
||||
buff);
|
||||
draw_temp_color(dev->temperature,
|
||||
dinfo->gpu_temp,
|
||||
dinfo->gpu_temp_slowdown);
|
||||
|
||||
// FAN
|
||||
mvwprintw(dev->fan_speed, 0, 0, "FAN %3u%%", dinfo->fan_speed);
|
||||
mvwchgat(dev->fan_speed, 0, 0, 3, 0, cyan_color, NULL);
|
||||
wnoutrefresh(dev->fan_speed);
|
||||
|
||||
// GPU CLOCK
|
||||
werase(dev->gpu_clock_info);
|
||||
mvwprintw(dev->gpu_clock_info, 0, 0,
|
||||
"GPU %uMHz",
|
||||
dinfo->gpu_clock_speed);
|
||||
mvwchgat(dev->gpu_clock_info, 0, 0, 3, 0, cyan_color, NULL);
|
||||
wnoutrefresh(dev->gpu_clock_info);
|
||||
|
||||
// MEM CLOCK
|
||||
werase(dev->mem_clock_info);
|
||||
mvwprintw(dev->mem_clock_info, 0, 0,
|
||||
"MEM %uMHz",
|
||||
dinfo->mem_clock_speed);
|
||||
mvwchgat(dev->mem_clock_info, 0, 0, 3, 0, cyan_color, NULL);
|
||||
wnoutrefresh(dev->mem_clock_info);
|
||||
|
||||
// POWER
|
||||
werase(dev->power_info);
|
||||
mvwprintw(dev->power_info, 0, 0,
|
||||
"POW %3u / %3u W",
|
||||
dinfo->power_draw / 1000, dinfo->power_draw_max / 1000);
|
||||
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));
|
||||
wprintw(dev->pcie_info, "%u@%2ux", dinfo->cur_pcie_link_gen,
|
||||
dinfo->cur_pcie_link_width);
|
||||
wattron(dev->pcie_info, COLOR_PAIR(magenta_color));
|
||||
wprintw(dev->pcie_info, " RX: ");
|
||||
wattroff(dev->pcie_info, COLOR_PAIR(magenta_color));
|
||||
print_pcie_at_scale(dev->pcie_info, dinfo->pcie_rx);
|
||||
wattron(dev->pcie_info, COLOR_PAIR(magenta_color));
|
||||
wprintw(dev->pcie_info, " TX: ");
|
||||
wattroff(dev->pcie_info, COLOR_PAIR(magenta_color));
|
||||
print_pcie_at_scale(dev->pcie_info, dinfo->pcie_tx);
|
||||
|
||||
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;
|
||||
memcpy(interface->process.all_process[offset+j].process_name,
|
||||
dev_info[i].compute_procs[j].process_name,
|
||||
sizeof(interface->process.all_process[offset+j].process_name));
|
||||
memcpy(interface->process.all_process[offset+j].user_name,
|
||||
dev_info[i].compute_procs[j].user_name,
|
||||
sizeof(interface->process.all_process[offset+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;
|
||||
}
|
||||
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;
|
||||
memcpy(interface->process.all_process[offset+j].process_name,
|
||||
dev_info[i].graphic_procs[j].process_name,
|
||||
sizeof(interface->process.all_process[offset+j].process_name));
|
||||
memcpy(interface->process.all_process[offset+j].user_name,
|
||||
dev_info[i].graphic_procs[j].user_name,
|
||||
sizeof(interface->process.all_process[offset+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;
|
||||
}
|
||||
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(
|
||||
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_username(
|
||||
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->user_name, p2->user_name, sizeof(p1->user_name));
|
||||
}
|
||||
|
||||
static int compare_process_name(
|
||||
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_mem_usage(
|
||||
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_gpu(
|
||||
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 void sort_process(
|
||||
struct all_gpu_processes *proc,
|
||||
unsigned int total_process,
|
||||
enum sort_gpu_process_by criterion) {
|
||||
int (*sort_fun)(const void*, const void*) = compare_mem_usage;
|
||||
switch (criterion) {
|
||||
case sort_pid:
|
||||
sort_fun = compare_pid;
|
||||
break;
|
||||
case sort_username:
|
||||
sort_fun = compare_username;
|
||||
break;
|
||||
case sort_process_name:
|
||||
sort_fun = compare_process_name;
|
||||
break;
|
||||
case sort_mem_usage:
|
||||
sort_fun = compare_mem_usage;
|
||||
break;
|
||||
case sort_by_gpu:
|
||||
sort_fun = compare_gpu;
|
||||
break;
|
||||
case sort_none:
|
||||
return;
|
||||
}
|
||||
qsort(proc, total_process, sizeof(*proc), sort_fun);
|
||||
}
|
||||
|
||||
static void print_process_preamble(WINDOW *win) {
|
||||
// PID | Username | GPU id | GPU_TYPE | Mem usage | Process name
|
||||
wattron(win, COLOR_PAIR(green_color) | A_REVERSE);
|
||||
mvwprintw(win, 0, 0, "%*s %*s %*s %*s %*s %s",
|
||||
sizeof_process_field[process_pid],
|
||||
"PID",
|
||||
sizeof_process_field[process_user],
|
||||
"USER",
|
||||
sizeof_process_field[process_gpu_id],
|
||||
"GPU",
|
||||
sizeof_process_field[process_type],
|
||||
"TYPE",
|
||||
sizeof_process_field[process_memory],
|
||||
"MEM",
|
||||
"Command");
|
||||
wchgat(win, -1, A_REVERSE, green_color, NULL);
|
||||
wattroff(win, COLOR_PAIR(green_color) | A_REVERSE);
|
||||
wnoutrefresh(win);
|
||||
}
|
||||
|
||||
static void print_processes_on_screen(
|
||||
unsigned int num_process,
|
||||
struct all_gpu_processes *proc,
|
||||
WINDOW *win,
|
||||
unsigned int offset) {
|
||||
werase(win);
|
||||
print_process_preamble(win);
|
||||
|
||||
unsigned int rows, cols;
|
||||
getmaxyx(win, rows, cols);
|
||||
(void) cols;
|
||||
|
||||
|
||||
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];
|
||||
for (unsigned int i = 0; i < rows-1 && i < num_process; ++i) {
|
||||
unsigned int write_at = i+1;
|
||||
size_t size = snprintf(pid_str, sizeof_process_field[process_pid]+1,
|
||||
"%u", proc[i+offset].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+offset].gpu_id);
|
||||
if (size == sizeof_process_field[process_gpu_id]+1)
|
||||
pid_str[sizeof_process_field[process_gpu_id]] = '\0';
|
||||
size = snprintf(memory, sizeof_process_field[process_memory]+1,
|
||||
"%.1f%%", proc[i+offset].mem_percentage);
|
||||
mvwprintw(win, write_at, 0, "%*s %*s %*s",
|
||||
sizeof_process_field[process_pid],
|
||||
pid_str,
|
||||
sizeof_process_field[process_user],
|
||||
proc[i+offset].user_name,
|
||||
sizeof_process_field[process_gpu_id],
|
||||
guid_str);
|
||||
if (proc[i+offset].is_graphical) {
|
||||
wattron(win, COLOR_PAIR(yellow_color));
|
||||
wprintw(win, " %*s ", sizeof_process_field[process_type], "Graphic");
|
||||
wattroff(win, COLOR_PAIR(yellow_color));
|
||||
} else {
|
||||
wattron(win, COLOR_PAIR(magenta_color));
|
||||
wprintw(win, " %*s ", sizeof_process_field[process_type], "Compute");
|
||||
wattroff(win, COLOR_PAIR(magenta_color));
|
||||
}
|
||||
wprintw(win, "%*s %s",
|
||||
sizeof_process_field[process_memory],
|
||||
memory,
|
||||
proc[i+offset].process_name);
|
||||
}
|
||||
wnoutrefresh(win);
|
||||
}
|
||||
|
||||
static void draw_processes(
|
||||
unsigned int num_devices,
|
||||
struct device_info *dev_info,
|
||||
struct nvtop_interface *interface,
|
||||
enum sort_gpu_process_by sort_criterion) {
|
||||
|
||||
if (interface->process.process_win == NULL)
|
||||
return;
|
||||
|
||||
unsigned int total_processes = copy_processes_for_processing(num_devices,
|
||||
dev_info, interface);
|
||||
sort_process(interface->process.all_process, total_processes, sort_criterion);
|
||||
|
||||
// Offset
|
||||
unsigned int offset = interface->process.offset;
|
||||
unsigned int rows, cols;
|
||||
getmaxyx(interface->process.process_win, rows, cols);
|
||||
(void) cols;
|
||||
rows -= 1;
|
||||
unsigned int borne_max = rows + offset;
|
||||
if (borne_max > total_processes) {
|
||||
if (total_processes > rows)
|
||||
offset = total_processes - rows;
|
||||
else
|
||||
offset = 0;
|
||||
}
|
||||
interface->process.offset = offset;
|
||||
sizeof_process_field[process_user] = interface->process.size_biggest_name;
|
||||
|
||||
print_processes_on_screen(total_processes, interface->process.all_process,
|
||||
interface->process.process_win, interface->process.offset);
|
||||
|
||||
}
|
||||
|
||||
void draw_gpu_info_ncurses(
|
||||
unsigned int num_devices,
|
||||
struct device_info *dev_info,
|
||||
struct nvtop_interface *interface) {
|
||||
|
||||
if (interface->devices_win == NULL) {
|
||||
size_t biggest_name = 0;
|
||||
for (size_t i = 0; i < num_devices; ++i) {
|
||||
size_t device_name_size = strlen(dev_info->device_name);
|
||||
if (device_name_size > biggest_name) {
|
||||
biggest_name = device_name_size;
|
||||
}
|
||||
}
|
||||
initialize_interface(interface, num_devices, biggest_name);
|
||||
}
|
||||
|
||||
draw_devices(num_devices, dev_info, interface);
|
||||
draw_processes(num_devices, dev_info, interface, sort_mem_usage);
|
||||
doupdate();
|
||||
refresh();
|
||||
|
||||
}
|
||||
|
||||
void update_window_size_to_terminal_size(struct nvtop_interface *inter) {
|
||||
clear_interface(inter);
|
||||
endwin();
|
||||
erase();
|
||||
refresh();
|
||||
refresh();
|
||||
}
|
||||
116
src/nvtop.c
Normal file
116
src/nvtop.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2017 Maxime Schmitt <maxime.schmitt91@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
#define STOP_SIGNAL 0x1
|
||||
#define RESIZE_SIGNAL 0x2
|
||||
|
||||
static volatile unsigned char signal_bits = 0;
|
||||
|
||||
static void exit_handler(int signum) {
|
||||
(void) signum;
|
||||
signal_bits |= STOP_SIGNAL;
|
||||
}
|
||||
|
||||
static void resize_handler(int signum) {
|
||||
(void) signum;
|
||||
signal_bits |= RESIZE_SIGNAL;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv) {
|
||||
(void) argc; (void) argv;
|
||||
(void) setlocale(LC_CTYPE, "");
|
||||
|
||||
int refresh_interval = 1000;
|
||||
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 SIGQUIT: ");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
init_gpu_info_extraction();
|
||||
size_t num_devices;
|
||||
struct device_info *dev_infos;
|
||||
num_devices = initialize_device_info(&dev_infos);
|
||||
struct nvtop_interface *interface = initialize_curses();
|
||||
timeout(refresh_interval);
|
||||
|
||||
while (!(signal_bits & STOP_SIGNAL)) {
|
||||
update_device_infos(num_devices, dev_infos);
|
||||
if (signal_bits & RESIZE_SIGNAL) {
|
||||
update_window_size_to_terminal_size(interface);
|
||||
signal_bits &= ~RESIZE_SIGNAL;
|
||||
}
|
||||
draw_gpu_info_ncurses(num_devices, dev_infos, interface);
|
||||
|
||||
int input_char = getch();
|
||||
switch (input_char) {
|
||||
case 27:
|
||||
{
|
||||
timeout(0);
|
||||
int in = getch();
|
||||
timeout(refresh_interval);
|
||||
if (in == ERR) {
|
||||
signal_bits |= STOP_SIGNAL;
|
||||
} else { // ALT key
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'q':
|
||||
signal_bits |= STOP_SIGNAL;
|
||||
break;
|
||||
case ERR:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
clean_ncurses(interface);
|
||||
clean_device_info(num_devices, dev_infos);
|
||||
shutdown_gpu_info_extraction();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user