IHttpContext::GetCurrentExecutionStats 메서드
현재 컨텍스트에 대한 실행 통계를 검색합니다.
구문
virtual HRESULT GetCurrentExecutionStats(
DWORD* pdwNotification,
DWORD* pdwNotificationStartTickCount = NULL,
PCWSTR* ppszModule = NULL,
DWORD* pdwModuleStartTickCount = NULL,
DWORD* pdwAsyncNotification = NULL,
DWORD* pdwAsyncNotificationStartTickCount = NULL
) const = 0;
매개 변수
pdwNotification
현재 알림을 포함하는 에 DWORD
대한 포인터입니다.
pdwNotificationStartTickCount
현재 알림의 시작에 대한 틱 수를 포함하는 에 대한 포인터 DWORD
입니다.
ppszModule
현재 모듈의 이름을 포함하는 문자열에 대한 포인터입니다.
pdwModuleStartTickCount
현재 모듈의 시작 부분에 대한 틱 수를 포함하는 에 대한 포인터 DWORD
입니다.
pdwAsyncNotification
현재 비동기 알림을 포함하는 에 대한 포인터 DWORD
입니다.
pdwAsyncNotificationStartTickCount
비동기 알림의 시작에 대한 틱 수를 포함하는 에 대한 포인터 DWORD
입니다.
반환 값
HRESULT
입니다. 가능한 값에는 다음 표에 있는 값이 포함되지만, 이에 국한되는 것은 아닙니다.
값 | Description |
---|---|
NO_ERROR | 작업이 성공했음을 나타냅니다. |
E_INVALIDARG | 지정된 매개 변수가 유효하지 않음을 나타냅니다. |
설명
개발자는 메서드를 GetCurrentExecutionStats
사용하여 현재 컨텍스트에 대한 특정 실행 정보를 검색할 수 있습니다. 예를 들어 및 pdwAsyncNotification
매개 변수는 pdwNotification
현재 동기 또는 비동기 알림에 대한 값을 포함하며 ppszModule
매개 변수에는 현재 컨텍스트에 대한 모듈의 이름이 포함됩니다.
반환 매개 변수, pdwModuleStartTickCount
, pdwNotificationStartTickCount
및 pdwAsyncNotificationStartTickCount
의 세 가지는 각각 모듈 시작 및 현재 동기 및 비동기 알림의 시작에 대한 틱 수를 포함합니다.
참고
틱 수는 시스템이 시작된 후 경과된 시간(밀리초)입니다. 틱 수를 검색하는 방법에 대한 자세한 내용은 GetTickCount 메서드를 참조하세요.
예제
다음 코드 예제에서는 다음 작업을 수행하는 HTTP 모듈을 만드는 방법을 보여 줍니다.
모듈은 RQ_BEGIN_REQUEST, RQ_MAP_REQUEST_HANDLER 및 RQ_SEND_RESPONSE 알림을 등록합니다.
모듈은 OnBeginRequest, OnMapRequestHandler 및 OnSendResponse 메서드를 포함하는 CHttpModule 클래스를 만듭니다.
웹 클라이언트가 URL을 요청하면 IIS는 모듈의
OnBeginRequest
,OnMapRequestHandler
및OnSendResponse
메서드를 호출합니다. 이러한 각 메서드는 다음 작업을 수행하는 라는RetrieveExecutionStats
프라이빗 메서드를 호출합니다.메서드를 사용하여
GetCurrentExecutionStats
실행 통계를 검색하고 오류를 테스트합니다.현재 알림의 시작에 대한 틱 수를 포함하는 문자열을 만듭니다.
1초 동안 일시 중지합니다.
현재 알림 시작부터 경과된 틱 수를 포함하는 문자열을 만듭니다.
실행 통계를 이벤트로 이벤트 뷰어 애플리케이션 로그에 씁니다.
모듈은 메모리에서 클래스를
CHttpModule
제거한 다음 종료합니다.
#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
);
}
모듈은 RegisterModule 함수를 내보내야 합니다. 프로젝트에 대한 모듈 정의(.def) 파일을 만들어 이 함수를 내보내거나 스위치를 사용하여 /EXPORT:RegisterModule
모듈을 컴파일할 수 있습니다. 자세한 내용은 연습: 네이티브 코드를 사용하여 Request-Level HTTP 모듈 만들기를 참조하세요.
필요에 따라 각 함수에 대한 호출 규칙을 명시적으로 선언하는 대신 호출 규칙을 사용하여 __stdcall (/Gz)
코드를 컴파일할 수 있습니다.
요구 사항
형식 | Description |
---|---|
클라이언트 | - Windows Vista의 IIS 7.0 - Windows 7의 IIS 7.5 - Windows 8의 IIS 8.0 - WINDOWS 10 IIS 10.0 |
서버 | - Windows Server 2008의 IIS 7.0 - Windows Server 2008 R2의 IIS 7.5 - Windows Server 2012의 IIS 8.0 - Windows Server 2012 R2의 IIS 8.5 - WINDOWS SERVER 2016 IIS 10.0 |
제품 | - 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 |
헤더 | Httpserv.h |