Skip to content
This repository was archived by the owner on Apr 30, 2020. It is now read-only.

Commit d1626d9

Browse files
committed
Fix for CODEXL-2999, CODEXL-2977, CodeXL fails to detect the exit of game.
1 parent 05a8813 commit d1626d9

7 files changed

Lines changed: 117 additions & 13 deletions

File tree

CodeXL/Components/Graphics/Server/Common/HTTPRequest.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ bool HTTPRequestHeader::CheckProcessStillRunning()
549549
{
550550
char* ptr = this->GetUrl();
551551
char* sCmd = &ptr[1];
552-
bool isAlive = false;
552+
bool isAlive = true;
553553

554554
gtASCIIString str(sCmd);
555555

@@ -561,9 +561,14 @@ bool HTTPRequestHeader::CheckProcessStillRunning()
561561
str.truncate(0, end - 1);
562562
processID = atoi(str.asCharArray());
563563

564+
Log(logMESSAGE, "HTTPRequestHeader::CheckProcessStillRunning: processID = %d\n", processID);
565+
566+
if (processID > 0)
567+
{
564568
// check to see if process is still running
565569
osIsProcessAlive((DWORD)processID, isAlive);
566570
}
571+
}
567572

568573
return isAlive;
569574
}

CodeXL/Components/Graphics/Server/WebServer/PluginResponseThread.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ void PluginResponseThread::WaitForPluginResponses(void* pData)
7272
NetSocket* client_socket = ProcessTracker::Instance()->GetSocketFromHandle(requestID);
7373
ProcessTracker::Instance()->RemoveSocketFromMap(requestID);
7474

75+
#ifdef CODEXL_GRAPHICS
76+
#ifdef USE_GRAPHICS_SERVER_STATUS_RETURN_CODES
7577
// We can remove this message from the DB as we no longer need to monitor it anymore
76-
//RequestsInFlightDatabase::Instance()->Remove(client_socket);
77-
78+
RequestsInFlightDatabase::Instance()->Remove(client_socket);
79+
#endif
80+
#endif
7881
// now try to get the mime type
7982
if (smGet("PLUGINS_TO_GPS", &pcMimeType, PS_MAX_PATH) > 0)
8083
{

CodeXL/Components/Graphics/Server/WebServer/ProcessTracker.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ gtASCIIString ProcessTracker::GetProcessesXML()
176176
/// \param pRequestHeader The request header.
177177
/// \param client_socket The socket used for the request
178178
//////////////////////////////////////////////////////////////////////////////////////////////////////////
179-
static void HandleServerStatusResponse(GRAPHICS_SERVER_STATE serverState, HTTPRequestHeader* pRequestHeader, NetSocket* client_socket)
179+
void ProcessTracker::HandleServerStatusResponse(GRAPHICS_SERVER_STATE serverState, HTTPRequestHeader* pRequestHeader, NetSocket* client_socket)
180180
{
181181
char* strResquest = pRequestHeader->GetUrl();
182182

@@ -1045,12 +1045,16 @@ bool ProcessTracker::PassRequestToPlugin(const char* strDestination,
10451045
pRequestHeader->SetPostDataSize(0);
10461046
}
10471047

1048+
#ifdef CODEXL_GRAPHICS
1049+
#ifdef USE_GRAPHICS_SERVER_STATUS_RETURN_CODES
10481050
// Create a new record of this request
10491051
// We will check to see when it comes back from the server.
1050-
//RequestInFlight* pNewRequest = new RequestInFlight(pRequestHeader, pClientSocket);
1052+
RequestInFlight* pNewRequest = new RequestInFlight(pRequestHeader, pClientSocket, pid);
10511053

10521054
// Add the new record to the DB.
1053-
//RequestsInFlightDatabase::Instance()->Add(pClientSocket, pNewRequest);
1055+
RequestsInFlightDatabase::Instance()->Add(pClientSocket, pNewRequest);
1056+
#endif
1057+
#endif
10541058

10551059
bResult = smPut(strDestination, pRequestHeader->GetHeaderData(), sizeof(HTTPHeaderData));
10561060

CodeXL/Components/Graphics/Server/WebServer/ProcessTracker.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ class ProcessTracker : public TSingleton< ProcessTracker >
144144
/// \return socket corresponding to the handle
145145
NetSocket* GetSocketFromHandle(CommunicationID handle);
146146

147+
/// Used to send a server status message back to the requesting command.
148+
/// \param serverState The server state type to return
149+
/// \param pRequestHeader The requesting HTTP command
150+
/// \param client_socket The socket to communicate over
151+
void HandleServerStatusResponse(GRAPHICS_SERVER_STATE serverState, HTTPRequestHeader* pRequestHeader, NetSocket* client_socket);
152+
147153
protected:
148154

149155
/// Prevents default instances of the ProcessTracker class.

CodeXL/Components/Graphics/Server/WebServer/RenderStallThread.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "RenderStallThread.h"
1010
#include "../Common/GraphicsServerState.h"
1111
#include "../Common/SharedGlobal.h"
12+
#include "RequestsInFlightDatabase.h"
1213

1314
/////////////////////////////////////////////////////////////////////////////////////////////////////////
1415
/// Checks to see if the app has stopped rendering (or ever rendered at all).
@@ -17,12 +18,11 @@
1718
void RenderStallThread::CheckForRenderStall()
1819
{
1920
static double lastPresentTime = 0.0f;
21+
int delay = 0;
22+
int outerDelay = 0;
2023

2124
for (;;) // loop forever
2225
{
23-
//int stallCount = 0;
24-
int delay = 0;
25-
2626
if (GetServerShutdownState() == true)
2727
{
2828
return;
@@ -59,14 +59,34 @@ void RenderStallThread::CheckForRenderStall()
5959
if (delay > GRAPHICS_SERVER_STATUS_STALL_THRESHOLD_TIME)
6060
{
6161
SetServerStalledState(true);
62+
63+
#ifdef CODEXL_GRAPHICS
64+
#ifdef USE_GRAPHICS_SERVER_STATUS_RETURN_CODES
65+
int inFlight = RequestsInFlightDatabase::Instance()->InFlightCount();
66+
67+
Log(logMESSAGE, "RenderStallThread::CheckForRenderStall(): App has not rendered for %ld (ms), inFlightCount = %d\n", outerDelay, inFlight);
68+
69+
if (inFlight > 0)
70+
{
71+
// Send process not running status back to the messages in flight
72+
Log(logMESSAGE, "RenderStallThread::CheckForRenderStall(): Check messages in flight to see if process is still running\n");
73+
RequestsInFlightDatabase::Instance()->CheckProcessesAreRunning();
74+
}
75+
#endif
76+
#endif
77+
78+
delay = 0;
6279
}
6380

6481
delay += GRAPHICS_SERVER_STATUS_STALL_LOOP_SLEEP_TIME;
82+
83+
outerDelay += GRAPHICS_SERVER_STATUS_STALL_LOOP_SLEEP_TIME;
6584
}
6685
else
6786
{
6887
SetServerStalledState(false);
6988
delay = 0;
89+
outerDelay = 0;
7090
}
7191
}
7292

CodeXL/Components/Graphics/Server/WebServer/RequestInFlight.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ class RequestInFlight
1919
/// Constructor
2020
/// \param pRequestHeader Input request
2121
/// \param pClientSocket Client socket
22-
RequestInFlight(HTTPRequestHeader* pRequestHeader, NetSocket* pClientSocket)
22+
/// \param processID The process ID
23+
RequestInFlight(HTTPRequestHeader* pRequestHeader, NetSocket* pClientSocket, unsigned long processID)
2324
{
2425
m_pRequestHeader = pRequestHeader;
2526
m_pClientSocket = pClientSocket;
27+
m_processID = processID;
2628
}
2729

28-
private:
2930

30-
HTTPRequestHeader* m_pRequestHeader; ///< Stores the request in flight
31+
HTTPRequestHeader* m_pRequestHeader; ///< Stores the request header
3132

32-
NetSocket* m_pClientSocket; ///< STores teh client socket
33+
NetSocket* m_pClientSocket; ///< Stores the client socket
34+
35+
unsigned long m_processID; ///< Record the process ID
3336

3437
};
3538

CodeXL/Components/Graphics/Server/WebServer/RequestsInFlightDatabase.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
#include "RequestInFlight.h"
1010
#include "../Common/NetSocket.h"
11+
#include "ProcessTracker.h"
1112

1213
#ifndef REQUESTS_IN_FLIGHT_DATABASE_H_
1314
#define REQUESTS_IN_FLIGHT_DATABASE_H_
1415

1516
/// Record the requests that are sent to the server
1617
typedef std::map<NetSocket*, RequestInFlight*> RequestsInFlightDB;
18+
typedef std::map<NetSocket*, RequestInFlight*>::iterator RequestsInFlightDBIter;
1719

1820
/// Responsible for tracking commands that are currently in the shared memory
1921
/// being processed by the graphics server
@@ -44,6 +46,9 @@ class RequestsInFlightDatabase : public TSingleton< RequestsInFlightDatabase >
4446
{
4547
ScopeLock sc(m_mutex);
4648
m_RequestsInFlight[pSocket] = pRequest;
49+
50+
// Used for debugging
51+
Log(logMESSAGE, "Adding request socket 0x%p\n", pSocket);
4752
}
4853

4954
/// Remove a tracked request from this DB
@@ -52,6 +57,64 @@ class RequestsInFlightDatabase : public TSingleton< RequestsInFlightDatabase >
5257
{
5358
ScopeLock sc(m_mutex);
5459
m_RequestsInFlight.erase(pSocket);
60+
61+
// Used for debugging
62+
Log(logMESSAGE, "Removing request socket 0x%p\n", pSocket);
63+
}
64+
65+
/// Get a count of the number of requests in flight
66+
/// \return Number of requests in flight
67+
int InFlightCount()
68+
{
69+
return (int)m_RequestsInFlight.size();
70+
}
71+
72+
/// Sends the stalled state to all commands in flight
73+
void SendServerStalledStateToAll()
74+
{
75+
ScopeLock sc(m_mutex);
76+
RequestsInFlightDBIter iter = m_RequestsInFlight.begin();
77+
while (iter != m_RequestsInFlight.end())
78+
{
79+
RequestInFlight* pRequest = iter->second;
80+
81+
ProcessTracker::Instance()->HandleServerStatusResponse(GRAPHICS_SERVER_STATE_PROCESS_NOT_RUNNING, pRequest->m_pRequestHeader, pRequest->m_pClientSocket);
82+
83+
++iter;
84+
}
85+
}
86+
87+
/// Checks to see if the process that a request was sent to is still running.
88+
void CheckProcessesAreRunning()
89+
{
90+
ScopeLock sc(m_mutex);
91+
RequestsInFlightDBIter iter = m_RequestsInFlight.begin();
92+
while (iter != m_RequestsInFlight.end())
93+
{
94+
NetSocket* pSock = iter->first;
95+
RequestInFlight* pRequest = iter->second;
96+
97+
unsigned long pid = pRequest->m_processID;
98+
bool isAlive = true;
99+
osIsProcessAlive((DWORD)pid, isAlive);
100+
101+
Log(logMESSAGE, "CheckProcessesAreRunning:: Checking for process %ld\n", pid);
102+
103+
if (isAlive == false)
104+
{
105+
Log(logMESSAGE, "CheckProcessesAreRunning::Process %ld is not running: URL = %s\n", pid, pRequest->m_pRequestHeader->GetUrl());
106+
// Need to return the correct error data for process not running
107+
ProcessTracker::Instance()->HandleServerStatusResponse(GRAPHICS_SERVER_STATE_PROCESS_NOT_RUNNING, pRequest->m_pRequestHeader, pRequest->m_pClientSocket);
108+
// Clear the request
109+
m_RequestsInFlight.erase(pSock);
110+
}
111+
else
112+
{
113+
Log(logMESSAGE, "CheckProcessesAreRunning:: Process %ld is running\n", pid);
114+
}
115+
116+
++iter;
117+
}
55118
}
56119

57120
private:

0 commit comments

Comments
 (0)