PresentMon Capture Application
repository·main·Indexed 25 days ago
https://github.com/gametechdev/presentmonA tool for trace capture and real-time performance overlaying for games and graphics-intensive applications. It leverages the PresentMon Service for data collection, provides detailed performance metrics via CSV output, and includes an Intel-PresentMon ETW provider for direct communication between applications, libraries, and drivers.
What's inside PresentMon
- The PresentMon Console Application is a standalone tool that utilizes the PresentMon SDK to capture and analyze performance data from graphics applications. It provides real-time data output to the console and can also export captured data to CSV file(s) for further analysis.
Use the PresentMon Console Application
mainThe PresentMon console application is a standalone tool that uses the PresentMon SDK to capture and analyze graphics application performance. It outputs data to the console and/or CSV files. You can download pre-built binaries from the project releases (e.g.,PresentMon-2.3.1-x64.exe).What is the PresentMon Service?
mainThe PresentMon Service is a backend component that aggregates ETW (Event Tracing for Windows) frame data from the PresentMon Analysis library with hardware telemetry (such as GPU temperature and power). It acts as a central provider that exposes this aggregated data to client applications through the PresentMon API.How Z-bands and uiAccess ensure overlay visibility
mainTo ensure the performance monitoring overlay appears above target applications (including those in fullscreen exclusive mode), PresentMon utilizes Windows Z-bands and the
uiAccessmanifest option.Z-bands
Windows uses Z-bands to create hierarchical layers of Z-order. Windows in a higher Z-band always appear above windows in lower Z-bands. While most applications reside in
ZBID_DESKTOP, PresentMon uses the undocumented WinAPI functionCreateWindowInBandto place the overlay in a higher band.uiAccess
To gain the privileges required to use
CreateWindowInBand, the application manifest must setuiAccess=true. This allows the application to bypass certain UI restrictions, similar to accessibility tools.Requirements for
uiAccessapplications:- The executable must be cryptographically signed.
- The executable must be run from a trusted location (e.g.,
C:\Program Files).
Capabilities enabled by
uiAccess:- Setting the foreground window.
- Driving application windows via
SendInput. - Using low-level hooks, raw input,
GetKeyState,GetAsyncKeyState, andGetKeyboardInputto read input across all integrity levels. - Setting journal hooks.
- Using
AttachThreadInputto attach to a higher integrity input queue.
Understanding the CEF implementation in PresentMon
mainThe PresentMon Capture Application uses the Chromium Embedded Framework (CEF) to implement its control UI. CEF is a C++ framework that integrates Chromium components (rendering, inputs, sockets, etc.) into the application.
Key Implementation Details:
- Customization: Behavior is customized by inheriting from base class interfaces and injecting them into the framework to hook callback functions.
- JS/C++ Interop: Custom C++ objects can be injected into the global (window) namespace in V8, allowing JavaScript code to interact with C++ logic.
- Multi-process Architecture: Developers must account for Chromium's multi-process nature. Code execution depends on the specific process and thread. Operations must be coordinated using thread task queues and IPC message queues to ensure they execute on the correct thread/process. V8 contexts must be explicitly captured and managed during interaction.
Understand CSV file output and naming conventions
mainThe PresentMon capture application generates two CSV files for every capture session. By default, these are stored in the user's appdata local directory under
Intel\PresentMon\Capture.Raw Frame Data File: Records the raw frame data.
- Pattern:
pmcap-[executablename]-YYMMDD-HHMMSS.csv
- Pattern:
Stats Summary File: Includes capture duration, total frames captured, and FPS percentiles (average, minimum, maximum, 99th, 95th, and 90th).
- Pattern:
pmcap-[executablename]-YYMMDD-HHMMSS-stats.csv
- Pattern:
Understand the CSV data format and structure
mainThe CSV output from PresentMon provides frame-level granularity for application performance analysis.
- Row Definition: Each row in the CSV represents a single frame that an application rendered and presented to the system.
- Column Definition: Each column contains a specific metric value associated with that frame.
- Time Units: All time-based values in the columns are expressed in milliseconds (ms).
Upgrade the locked CEF runtime
mainTo intentionally upgrade the CEF version, use the
upgrade-cef.ps1script. This script downloads the provided archive, stages the new payload, updatesIntelPresentMon\AppCef\cef-lock.json, and regenerates the installer CEF WiX fragments. You should review all generated changes after the upgrade.> IntelPresentMon\AppCef\Batch\upgrade-cef.ps1 https://example.com/path/to/cef_archive.tar.bz2Integrate with the PresentMon Service using the SDK
mainTo communicate with the PresentMon Service, client applications should use the PresentMon SDK.
Starting from version 2.3.1, the service installs
PresentMonAPI2.dllalongside the service itself. You have two primary integration paths:1. Manual Dynamic Loading
Include the C header
PresentMonAPI.hin your project and dynamically loadPresentMonAPI2.dllat runtime.Warning: If your application ships its own copy of
PresentMonAPI2.dllinstead of using the one provided by the service installation, binary compatibility with the service is not guaranteed.2. Using the Loader Library (Recommended)
To simplify the process of manually loading the DLL and resolving endpoints, use the provided loader library.
- Build time: Link against the
PresentMonAPI2Loader.libimport library. - Runtime: Deploy
PresentMonAPI2Loader.dllalongside your application.
SDK Location
If installed with the service, the SDK files (
PresentMonAPI.h,PresentMonAPI2Loader.lib, andPresentMonAPI2Loader.dll) are located by default in:Program Files\Intel\PresentMon\SDK- Build time: Link against the
Install build tool dependencies for PresentMon
mainTo build the full PresentMon application, you must install the following build tools:
- Visual Studio 2022
- vcpkg
- CMake
- Node.js / NPM
- WiX toolset v3 (including the VS extension)
Note: If you only need to build the
PresentDatalibrary or thePresentMon Consoleapplication, you only require Visual Studio. In this case, you can ignore the other dependencies and buildPresentData\PresentData.vcxprojorPresentMon\ConsoleApplication.slndirectly.Bootstrap auxiliary test data
mainTo set up the required auxiliary test data for the project, run the bootstrap script from the repository root. This script automates cloning the
IPMAuxTestDatarepository, checking out the specific commit pinned inTests\aux-data.lock.json, downloading ETL release assets, and verifying their hashes..\bootstrap.ps1Run the PresentMon Capture Application
mainTo start the application, executePresentMon.exe. The application provides both trace capture capabilities and a real-time performance overlay for games and graphics-intensive applications. It relies on the PresentMon Service for data collection, uses a custom Direct3D 11 renderer for the overlay, and a CEF-based UI for configuration.PresentMon.exe