Git Product home page Git Product logo

Comments (2)

AlexUnwinder avatar AlexUnwinder commented on June 2, 2024

I used the following console app to reproduce that:

// GPUWaitGlitch.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

#include "Windows.h"
#include "PresentMonAPI.h"

#define MAX_FRAMES	1024
#define MAX_STEPS	10000

int main()
{
	STARTUPINFO	si;
	ZeroMemory(&si, sizeof(STARTUPINFO));
	si.cb = sizeof(STARTUPINFO);

	PROCESS_INFORMATION pi;
	ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));

	char szCmdLine[] = "Text3D_D3D9.exe";

	if (CreateProcess(NULL, szCmdLine, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi))
	{
		CloseHandle(pi.hProcess);
		CloseHandle(pi.hThread);

		PM_SESSION_HANDLE session;

		if (pmOpenSession(&session) == PM_STATUS_SUCCESS)
		{
			if (pmStartTrackingProcess(session, pi.dwProcessId) == PM_STATUS_SUCCESS)
			{
				PM_QUERY_ELEMENT queryElements[]
				{
					{ PM_METRIC_CPU_BUSY				, PM_STAT_NONE, 0, 0 },
					{ PM_METRIC_CPU_WAIT				, PM_STAT_NONE, 0, 0 },
					{ PM_METRIC_GPU_LATENCY				, PM_STAT_NONE, 0, 0 },
					{ PM_METRIC_GPU_BUSY				, PM_STAT_NONE, 0, 0 },
					{ PM_METRIC_GPU_WAIT				, PM_STAT_NONE, 0, 0 },
				};

				PM_FRAME_QUERY_HANDLE frameQuery;

				uint32_t dwBlobSize = 0;

				if (pmRegisterFrameQuery(session, &frameQuery, queryElements, _countof(queryElements), &dwBlobSize) == PM_STATUS_SUCCESS)
				{
					LPBYTE lpBlob = new BYTE[dwBlobSize * MAX_FRAMES];

					for (DWORD dwStep=0; dwStep<MAX_STEPS; dwStep++)
					{
						uint32_t dwFrames = MAX_FRAMES;

						do
						{
							PM_STATUS err;

							err = pmConsumeFrames(frameQuery, pi.dwProcessId, lpBlob, &dwFrames);

							if ((err == PM_STATUS_SUCCESS) ||
								(err == PM_STATUS_NO_DATA))
							{
								if (dwFrames)
								{	
									for (DWORD dwFrame=0; dwFrame<dwFrames; dwFrame++)
									{
										LPBYTE lpFrame = lpBlob + dwFrame * dwBlobSize;

										double cpuBusy				= *(double*		)(lpFrame + queryElements[0].dataOffset);
										double cpuWait				= *(double*		)(lpFrame + queryElements[1].dataOffset);
										double gpuLatency			= *(double*		)(lpFrame + queryElements[2].dataOffset);
										double gpuBusy				= *(double*		)(lpFrame + queryElements[3].dataOffset);
										double gpuWait				= *(double*		)(lpFrame + queryElements[4].dataOffset);

										std::cout << "Frametime : " << cpuBusy + gpuBusy << " ms, GPU wait : " << gpuWait << " ms\n";
									}
								}
							}
							else
								std::cout << "Failed to consume frames!\n";
						}
						while (dwFrames == MAX_FRAMES);

						Sleep(100);
					}

					delete[] lpBlob;

					pmFreeFrameQuery(frameQuery);
				}
				else
					std::cout << "Failed to register frame query!\n";

				pmStopTrackingProcess(session, pi.dwProcessId);
			}
			else
				std::cout << "Failed to start process tracking!\n";

			pmCloseSession(session);
		}
		else
			std::cout << "Failed to open session!\n";
	}
	else
		std::cout << "Failed to spawn process!\n";
}

from presentmon.

markgalvan-intel avatar markgalvan-intel commented on June 2, 2024

Thanks for reporting the issue and the sample source. We'll take a look at it.

from presentmon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.