Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Mengambil statistik eksekusi untuk konteks saat ini.
Sintaks
virtual HRESULT GetCurrentExecutionStats(
DWORD* pdwNotification,
DWORD* pdwNotificationStartTickCount = NULL,
PCWSTR* ppszModule = NULL,
DWORD* pdwModuleStartTickCount = NULL,
DWORD* pdwAsyncNotification = NULL,
DWORD* pdwAsyncNotificationStartTickCount = NULL
) const = 0;
Parameter
pdwNotification
Penunjuk ke yang DWORD berisi pemberitahuan saat ini.
pdwNotificationStartTickCount
Penunjuk ke yang DWORD berisi jumlah centang untuk awal pemberitahuan saat ini.
ppszModule
Penunjuk ke string yang berisi nama modul saat ini.
pdwModuleStartTickCount
Pointer ke yang DWORD berisi jumlah centang untuk awal modul saat ini.
pdwAsyncNotification
Penunjuk ke yang DWORD berisi pemberitahuan asinkron saat ini.
pdwAsyncNotificationStartTickCount
Penunjuk ke yang DWORD berisi jumlah centang untuk awal pemberitahuan asinkron.
Tampilkan Nilai
Sebuah HRESULT. Nilai yang mungkin termasuk, tetapi tidak terbatas pada, yang ada dalam tabel berikut.
| Nilai | Deskripsi |
|---|---|
| NO_ERROR | Menunjukkan bahwa operasi berhasil. |
| E_INVALIDARG | Menunjukkan bahwa parameter yang ditentukan tidak valid. |
Keterangan
Pengembang dapat menggunakan metode untuk GetCurrentExecutionStats mengambil informasi eksekusi tertentu untuk konteks saat ini. Misalnya, pdwNotification parameter dan pdwAsyncNotification berisi nilai untuk pemberitahuan sinkron atau asinkron saat ini, dan ppszModule parameter berisi nama modul untuk konteks saat ini.
Tiga parameter pengembalian, pdwModuleStartTickCount, , pdwNotificationStartTickCountdan pdwAsyncNotificationStartTickCount, masing-masing, berisi jumlah centang untuk awal modul dan awal pemberitahuan sinkron dan asinkron saat ini.
Catatan
Jumlah centang adalah jumlah milidetik yang telah berlalu sejak sistem dimulai. Untuk informasi selengkapnya tentang mengambil jumlah centang, lihat metode GetTickCount .
Contoh
Contoh kode berikut menunjukkan cara membuat modul HTTP yang melakukan tugas berikut:
Modul ini mendaftar untuk pemberitahuan RQ_BEGIN_REQUEST, RQ_MAP_REQUEST_HANDLER, dan RQ_SEND_RESPONSE .
Modul membuat kelas CHttpModule yang berisi metode OnBeginRequest, OnMapRequestHandler, dan OnSendResponse .
Saat klien Web meminta URL, IIS memanggil metode , ,
OnMapRequestHandlerdanOnSendResponsemodulOnBeginRequest. Masing-masing metode ini memanggil metode privat bernamaRetrieveExecutionStatsyang melakukan tugas berikut:Mengambil statistik eksekusi dengan menggunakan
GetCurrentExecutionStatsmetode dan pengujian untuk kesalahan.Membuat string yang berisi jumlah centang untuk awal pemberitahuan saat ini.
Jeda selama satu detik.
Membuat string yang berisi jumlah centang yang berlalu dari awal pemberitahuan saat ini.
Menulis statistik eksekusi sebagai peristiwa ke log aplikasi Penampil Peristiwa.
Modul menghapus
CHttpModulekelas dari memori lalu keluar.
#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
);
}
Modul Anda harus mengekspor fungsi RegisterModule . Anda dapat mengekspor fungsi ini dengan membuat file definisi modul (.def) untuk proyek Anda, atau Anda dapat mengkompilasi modul dengan menggunakan sakelar /EXPORT:RegisterModule . Untuk informasi selengkapnya, lihat Panduan: Membuat Modul HTTP Request-Level Dengan Menggunakan Kode Asli.
Anda dapat secara opsional mengkompilasi kode dengan menggunakan __stdcall (/Gz) konvensi panggilan alih-alih secara eksplisit mendeklarasikan konvensi panggilan untuk setiap fungsi.
Persyaratan
| Jenis | Deskripsi |
|---|---|
| Klien | - IIS 7.0 di Windows Vista - IIS 7.5 di Windows 7 - IIS 8.0 di Windows 8 - IIS 10.0 pada Windows 10 |
| Server | - IIS 7.0 di Windows Server 2008 - IIS 7.5 di Windows Server 2008 R2 - IIS 8.0 di Windows Server 2012 - IIS 8.5 di Windows Server 2012 R2 - IIS 10.0 di Windows Server 2016 |
| Produk | - 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 |
| Header | Httpserv.h |