Metodo IHttpContext::GetCurrentExecutionStats
Recupera le statistiche di esecuzione per il contesto corrente.
Sintassi
virtual HRESULT GetCurrentExecutionStats(
DWORD* pdwNotification,
DWORD* pdwNotificationStartTickCount = NULL,
PCWSTR* ppszModule = NULL,
DWORD* pdwModuleStartTickCount = NULL,
DWORD* pdwAsyncNotification = NULL,
DWORD* pdwAsyncNotificationStartTickCount = NULL
) const = 0;
Parametri
pdwNotification
Puntatore a un DWORD
oggetto contenente la notifica corrente.
pdwNotificationStartTickCount
Puntatore a un DWORD
oggetto contenente il conteggio dei segni di graduazione per l'inizio della notifica corrente.
ppszModule
Puntatore a una stringa contenente il nome del modulo corrente.
pdwModuleStartTickCount
Puntatore a un DWORD
oggetto contenente il conteggio dei segni di graduazione per l'inizio del modulo corrente.
pdwAsyncNotification
Puntatore a un DWORD
oggetto contenente la notifica asincrona corrente.
pdwAsyncNotificationStartTickCount
Puntatore a un DWORD
oggetto contenente il conteggio dei tick per l'inizio di una notifica asincrona.
Valore restituito
Oggetto HRESULT
. I valori possibili includono, ma non sono limitati a, quelli indicati nella tabella seguente.
Valore | Descrizione |
---|---|
NO_ERROR | Indica che l'operazione è riuscita. |
E_INVALIDARG | Indica che un parametro specificato non è valido. |
Commenti
Gli sviluppatori possono usare il GetCurrentExecutionStats
metodo per recuperare informazioni di esecuzione specifiche per il contesto corrente. Ad esempio, i pdwNotification
parametri e pdwAsyncNotification
contengono i valori per la notifica sincrona o asincrona corrente e il ppszModule
parametro contiene il nome del modulo per il contesto corrente.
Tre dei parametri restituiti, pdwModuleStartTickCount
, pdwNotificationStartTickCount
e pdwAsyncNotificationStartTickCount
, rispettivamente, contengono i conteggi dei segni di graduazione per l'inizio del modulo e l'inizio delle notifiche sincrone e asincrone correnti.
Nota
Il conteggio dei tick è il numero di millisecondi trascorsi dall'avvio del sistema. Per altre informazioni sul recupero dei conteggi dei tick, vedere il metodo GetTickCount .
Esempio
L'esempio di codice seguente illustra come creare un modulo HTTP che esegue le attività seguenti:
Il modulo esegue la registrazione per le notifiche di RQ_BEGIN_REQUEST, RQ_MAP_REQUEST_HANDLER e RQ_SEND_RESPONSE .
Il modulo crea una classe CHttpModule che contiene i metodi OnBeginRequest, OnMapRequestHandler e OnSendResponse .
Quando un client Web richiede un URL, IIS chiama i metodi ,
OnMapRequestHandler
eOnSendResponse
delOnBeginRequest
modulo. Ognuno di questi metodi chiama un metodo privato denominatoRetrieveExecutionStats
che esegue le attività seguenti:Recupera le statistiche di esecuzione usando il
GetCurrentExecutionStats
metodo e verifica la ricerca di un errore.Crea una stringa contenente il conteggio dei tick per l'inizio della notifica corrente.
Sospende per un secondo.
Crea una stringa contenente il conteggio dei tick trascorsi dall'inizio della notifica corrente.
Scrive le statistiche di esecuzione come evento nel registro applicazioni del Visualizzatore eventi.
Il modulo rimuove la
CHttpModule
classe dalla memoria e quindi viene chiusa.
#define _WINSOCKAPI_
#include <windows.h>
#include <sal.h>
#include <httpserv.h>
#include <wchar.h>
// Create the module class.
class MyHttpModule : public CHttpModule
{
private:
// Create a handle for the event viewer.
HANDLE m_hEventLog;
// Define a method the retrieves the current execution statistics.
void RetrieveExecutionStats(
IHttpContext * pHttpContext, LPCSTR szNotification )
{
HRESULT hr = S_OK;
DWORD dwNotification = 0;
DWORD dwNotificationStart = 0;
PCWSTR pszModule = NULL;
// Retrieve the current execution statistics.
hr = pHttpContext->GetCurrentExecutionStats(
&dwNotification,&dwNotificationStart,
&pszModule,NULL,NULL,NULL);
// Test for an error.
if (SUCCEEDED(hr))
{
// Create strings for the statistics.
char szNotificationStart[256];
char szTimeElapsed[256];
// Retrieve and format the statistics.
sprintf_s(szNotificationStart,255,
"Tick count at start of notification: %u",
dwNotificationStart);
// Pause for one second.
Sleep(1000);
// Retrieve and format the statistics.
sprintf_s(szTimeElapsed,255,
"Ticks elapsed since start of notification: %u",
GetTickCount() - dwNotificationStart);
// Allocate space for the module name.
char * pszBuffer = (char*) pHttpContext->AllocateRequestMemory(
(DWORD) wcslen(pszModule)+1 );
// Test for an error.
if (pszBuffer!=NULL)
{
// Return the module information to the web client.
wcstombs(pszBuffer,pszModule,wcslen(pszModule));
// Create an array of strings.
LPCSTR szBuffer[4] = {szNotification,pszBuffer,
szNotificationStart,szTimeElapsed};
// Write the strings to the Event Viewer.
WriteEventViewerLog(szBuffer,4);
}
}
}
public:
REQUEST_NOTIFICATION_STATUS
OnBeginRequest(
IN IHttpContext * pHttpContext,
IN IHttpEventProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Retrieve and return the execution statistics.
RetrieveExecutionStats(pHttpContext,"OnBeginRequest");
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
REQUEST_NOTIFICATION_STATUS
OnMapRequestHandler(
IN IHttpContext * pHttpContext,
IN IMapHandlerProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Retrieve and return the execution statistics.
RetrieveExecutionStats(pHttpContext,"OnMapRequestHandler");
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
REQUEST_NOTIFICATION_STATUS
OnSendResponse(
IN IHttpContext * pHttpContext,
IN ISendResponseProvider * pProvider
)
{
UNREFERENCED_PARAMETER( pProvider );
// Retrieve and return the execution statistics.
RetrieveExecutionStats(pHttpContext,"OnSendResponse");
// Return processing to the pipeline.
return RQ_NOTIFICATION_CONTINUE;
}
MyHttpModule()
{
// Open a handle to the Event Viewer.
m_hEventLog = RegisterEventSource( NULL,"IISADMIN" );
}
~MyHttpModule()
{
// Test whether the handle for the Event Viewer is open.
if (NULL != m_hEventLog)
{
// Close the handle to the Event Viewer.
DeregisterEventSource( m_hEventLog );
m_hEventLog = NULL;
}
}
private:
// Define a method that writes to the Event Viewer.
BOOL WriteEventViewerLog(LPCSTR * lpStrings, WORD wNumStrings)
{
// Test whether the handle for the Event Viewer is open.
if (NULL != m_hEventLog)
{
// Write any strings to the Event Viewer and return.
return ReportEvent(
m_hEventLog, EVENTLOG_INFORMATION_TYPE,
0, 0, NULL, wNumStrings, 0, lpStrings, NULL );
}
return FALSE;
}
};
// Create the module's class factory.
class MyHttpModuleFactory : public IHttpModuleFactory
{
public:
HRESULT
GetHttpModule(
OUT CHttpModule ** ppModule,
IN IModuleAllocator * pAllocator
)
{
UNREFERENCED_PARAMETER( pAllocator );
// Create a new instance.
MyHttpModule * pModule = new MyHttpModule;
// Test for an error.
if (!pModule)
{
// Return an error if we cannot create the instance.
return HRESULT_FROM_WIN32( ERROR_NOT_ENOUGH_MEMORY );
}
else
{
// Return a pointer to the module.
*ppModule = pModule;
pModule = NULL;
// Return a success status.
return S_OK;
}
}
void Terminate()
{
// Remove the class from memory.
delete this;
}
};
// Create the module's exported registration function.
HRESULT
__stdcall
RegisterModule(
DWORD dwServerVersion,
IHttpModuleRegistrationInfo * pModuleInfo,
IHttpServer * pGlobalInfo
)
{
UNREFERENCED_PARAMETER( dwServerVersion );
UNREFERENCED_PARAMETER( pGlobalInfo );
return pModuleInfo->SetRequestNotifications(
new MyHttpModuleFactory,
RQ_BEGIN_REQUEST | RQ_MAP_REQUEST_HANDLER | RQ_SEND_RESPONSE,
0
);
}
Il modulo deve esportare la funzione RegisterModule . È possibile esportare questa funzione creando un file di definizione del modulo (con estensione def) per il progetto oppure è possibile compilare il modulo usando l'opzione /EXPORT:RegisterModule
. Per altre informazioni, vedere Procedura dettagliata: Creazione di un modulo HTTP Request-Level tramite codice nativo.
Facoltativamente, è possibile compilare il codice usando la __stdcall (/Gz)
convenzione di chiamata anziché dichiarare in modo esplicito la convenzione di chiamata per ogni funzione.
Requisiti
Tipo | Descrizione |
---|---|
Client | - IIS 7.0 in Windows Vista - IIS 7.5 in Windows 7 - IIS 8.0 in Windows 8 - IIS 10.0 in Windows 10 |
Server | - IIS 7.0 in Windows Server 2008 - IIS 7.5 in Windows Server 2008 R2 - IIS 8.0 in Windows Server 2012 - IIS 8.5 in Windows Server 2012 R2 - IIS 10.0 in Windows Server 2016 |
Prodotto | - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0 - IIS Express 7.5, IIS Express 8.0, IIS Express 10.0 |
Intestazione | Httpserv.h |