This repository has been archived by the owner on Aug 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nvidia-query-resource-opengl: initial public release
Import nvidia-query-resource-opengl source from NVIDIA Perforce repository at changelist #19925091 for public release.
- Loading branch information
0 parents
commit c73f84f
Showing
13 changed files
with
1,781 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CMakeCache.txt | ||
CMakeFiles | ||
Makefile | ||
cmake_install.cmake | ||
*.o | ||
*.a | ||
*.so | ||
*.lib | ||
*.exe | ||
nvidia-query-resource-opengl | ||
*.sw[op] | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a | ||
# copy of this software and associated documentation files (the "Software"), | ||
# to deal in the Software without restriction, including without limitation | ||
# the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
# and/or sell copies of the Software, and to permit persons to whom the | ||
# Software is furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
# DEALINGS IN THE SOFTWARE. | ||
|
||
cmake_minimum_required (VERSION 2.6) | ||
|
||
project (nvidia-query-resource-opengl) | ||
|
||
include_directories(include) | ||
|
||
# The query tool executable | ||
|
||
add_executable (nvqrgl-bin | ||
tool/main.c | ||
) | ||
set_target_properties (nvqrgl-bin PROPERTIES | ||
OUTPUT_NAME nvidia-query-resource-opengl | ||
) | ||
|
||
# Static library for custom clients | ||
|
||
add_library (nvqrgl-lib STATIC | ||
common/nvidia-query-resource-opengl-ipc-util.c | ||
tool/nvidia-query-resource-opengl.c | ||
tool/nvidia-query-resource-opengl-data.c | ||
) | ||
set_target_properties (nvqrgl-lib PROPERTIES | ||
OUTPUT_NAME nvidia-query-resource-opengl | ||
) | ||
|
||
# Socket functionality is in a separate libsocket library on Solaris | ||
|
||
include (CheckLibraryExists) | ||
|
||
CHECK_LIBRARY_EXISTS (socket bind "" SOCKET_LIBRARY) | ||
if (SOCKET_LIBRARY) | ||
set(LINK_SOCKET socket) | ||
endif () | ||
|
||
target_link_libraries (nvqrgl-bin nvqrgl-lib ${LINK_SOCKET}) | ||
|
||
# Build the preload library on Unix | ||
|
||
if (NOT WIN32) | ||
add_library (nvidia-query-resource-opengl-preload SHARED | ||
common/nvidia-query-resource-opengl-ipc-util.c | ||
preload/nvidia-query-resource-opengl-preload.c | ||
) | ||
|
||
# Find GL and X11 include / link paths | ||
|
||
# XXX find_path() doesn't seem to work on Solaris, but it's okay, | ||
# since the GL and X11 headers tend to be in /usr/include there. | ||
if (NOT "${CMAKE_SYSTEM_NAME}" MATCHES "SunOS") | ||
find_path (GL_INCLUDE_DIR GL/gl.h) | ||
find_path (X11_INCLUDE_DIR X11/Xlib.h) | ||
|
||
include_directories("${GL_INCLUDE_DIR}" "${X11_INCLUDE_DIR}") | ||
endif () | ||
|
||
find_library (LIBGL_PATH GL) | ||
find_library (LIBX11_PATH X11) | ||
|
||
target_link_libraries (nvidia-query-resource-opengl-preload | ||
${LIBGL_PATH} ${LIBX11_PATH} pthread ${LINK_SOCKET} | ||
) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
nvidia-query-resource-opengl | ||
============================ | ||
|
||
About | ||
----- | ||
|
||
nvidia-query-resource-opengl queries the NVIDIA OpenGL driver to determine the | ||
OpenGL resource usage of an application. OpenGL applications may query their | ||
own resource usage using the GL\_NVX\_query\_resource extension, but the | ||
nvidia-query-resource-opengl tool allows users to perform resource queries | ||
externally, against unmodified OpenGL applications. | ||
|
||
Requirements | ||
------------ | ||
|
||
* A Windows, Linux, Solaris, or FreeBSD system with an NVIDIA GPU, running a | ||
version of the NVIDIA OpenGL driver supporting the GL\_NVX\_query\_resource | ||
extension. Support for this extension was introduced with the 355.xx driver | ||
release. **Note that this extension is still under development and subject to | ||
change, so applications developed against it, including this query resource | ||
tool, may need to be updated for compatibility with future driver versions.** | ||
* CMake 2.6 or later, and a suitable build system (e.g. Windows SDK and/or | ||
Microsoft Visual Studio on Windows; make and cc/gcc on Unix-like systems) | ||
that is supported by the CMake generators on the target platform. (Not needed | ||
when using precompiled executables on Windows.) | ||
|
||
Building | ||
-------- | ||
|
||
nvidia-query-resource-opengl uses [CMake](http://www.cmake.org) to support | ||
building on multiple platforms. In order to build nvidia-query-resource-opengl, | ||
you will need to first use the CMake graphical or command line interface to | ||
generate a build system that will work on your platform, then use the generated | ||
build system to build the project. For example, on a typical Unix-like system, | ||
the following commands run from within the top level directory of this source | ||
code repository will create a "build" directory and build within it: | ||
|
||
mkdir build | ||
cd build | ||
cmake .. | ||
make | ||
|
||
On Windows, run `nmake` instead of `make` from the Visual Studio command line | ||
when using the nmake build system generator with the Windows SDK, or choose a | ||
Visual Studio solution generator to create a solution that can be built within | ||
Microsoft Visual Studio. Windows users may also download precompiled executable | ||
files for convenience. | ||
|
||
A successful build will produce the following items: | ||
|
||
* The resource query tool, 'nvidia-query-resource-opengl' (on Windows, the .exe | ||
file extension is appended to the executable name.) | ||
* A static library, 'libnvidia-query-resource-opengl.a' on Unix-like systems, | ||
or 'nvidia-query-resource-opengl.lib' on Windows. This can be used together | ||
with the API defined in include/nvidia-query-resource-opengl.h to add OpenGL | ||
resource query functionality to your own monitoring tools. | ||
* On Unix-like systems only, the 'libnvidia-query-resource-preload.so' DSO, | ||
which must be preloaded into any OpenGL applications that will be the target | ||
of resource queries. (See "Usage" section below for more details.) | ||
|
||
Usage | ||
----- | ||
|
||
You can query an application's OpenGL resource usage by executing the command: | ||
|
||
nvidia-query-resource-opengl -p <pid> [-qt <query_type>] | ||
|
||
* pid: the process ID of the target OpenGL application of the query | ||
* query\_type: this may be 'summary' or 'detailed'. The default is 'summary'. | ||
+ summary: reports a summary, per device, of allocated video and system | ||
memory, the total amount of memory in use by the the driver, and the | ||
total amount of allocated but unused memory. | ||
+ detailed: includes the summary information, and additionally reports | ||
separate allocation amounts for various object types. The current set | ||
of reported object types includes: | ||
- SYSTEM RESERVED - driver allocated memory | ||
- TEXTURE - memory in use by 1D/2D/3D textures | ||
- RENDERBUFFER - render buffer memory | ||
- BUFFEROBJ_ARRAY - buffer object memory | ||
|
||
Resource queries are handled asynchronously to the OpenGL applications being | ||
queried. Due to this, and other factors, including object migration between | ||
video and system memory, it is possible for subsequent queries to yield | ||
different results. | ||
|
||
On Windows, nvidia-query-resource-opengl will communicate directly with any | ||
OpenGL application to perform resource queries; however, on Unix-like systems, | ||
the libnvidia-query-resource-preload.so DSO must be preloaded into the target | ||
application before a resource query can be performed. This is achieved by | ||
setting a relative or absolute path to the preload DSO in the LD\_PRELOAD | ||
variable of the target application's environment, e.g.: | ||
|
||
$ LD_PRELOAD=path/to/libnvidia-query-resource-opengl-preload.so app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "nvidia-query-resource-opengl-ipc-util.h" | ||
|
||
#if defined (_WIN32) | ||
static char *construct_name(const char *basename, DWORD pid) | ||
{ | ||
static const char basedir[] = "\\\\.\\pipe\\"; | ||
size_t len = strlen(basedir) + strlen(basename) + | ||
NVQR_IPC_MAX_DIGIT_LENGTH; | ||
char *buf = calloc(len + 1, 1); | ||
|
||
if (!buf) { | ||
fprintf(stderr, "Failed to allocate memory for connection name!"); | ||
exit(1); | ||
} | ||
|
||
_snprintf_s(buf, len + 1, len, "%s%s%d", basedir, basename, pid); | ||
return buf; | ||
} | ||
|
||
char *nvqr_ipc_client_pipe_name(DWORD pid) | ||
{ | ||
return construct_name("clientpipe", pid); | ||
} | ||
|
||
char *nvqr_ipc_server_pipe_name(DWORD pid) | ||
{ | ||
return construct_name("serverpipe", pid); | ||
} | ||
|
||
#else | ||
|
||
int nvqr_ipc_get_socket_name(char *dest, size_t len, pid_t pid) | ||
{ | ||
int total_len; | ||
static const char *basename = "nvidia-query-resource-opengl-socket."; | ||
|
||
#if __linux | ||
// Socket names in the abstract namespace are not strings; rather, the | ||
// entire contents of the sun_path field are considered. Zero out the | ||
// whole buffer to avoid surprises. | ||
memset(dest, 0, len); | ||
|
||
total_len = snprintf(dest, len, "0%s%d", basename, pid); | ||
dest[0] = '\0'; | ||
#else | ||
const char *basedir = "/tmp"; | ||
|
||
// Uncomment the below code if you want socket files to be created under | ||
// XDG_RUNTIME_DIR on FreeBSD and Solaris, when that variable is set. The | ||
// hardcoded default to "/tmp" is intentional, to facilitate use cases where | ||
// the user performing the query may not be the same as the user running the | ||
// queried process. | ||
|
||
/* | ||
basedir = getenv("XDG_RUNTIME_DIR"); | ||
if (!basedir) { | ||
basedir = "/tmp"; | ||
} | ||
*/ | ||
|
||
total_len = snprintf(dest, len, "%s/%s%ld", basedir, basename, (long) pid); | ||
#endif // __linux | ||
|
||
// Terminate the string properly if truncation occurred. | ||
if (total_len >= len) { | ||
dest[len - 1] = '\0'; | ||
} | ||
|
||
return total_len; | ||
} | ||
#endif // _WIN32 |
Oops, something went wrong.