Skip to content
Browse files

adding support for etw tracing

  • Loading branch information...
1 parent 4a86f39 commit a95960b2dee96ed5fe53f55a212cfe3682dc5aaa @tjanczuk committed Sep 28, 2011
View
23 src/iisnode/cnodeapplicationmanager.cpp
@@ -2,7 +2,7 @@
CNodeApplicationManager::CNodeApplicationManager(IHttpServer* server, HTTP_MODULE_ID moduleId)
: server(server), moduleId(moduleId), applications(NULL), asyncManager(NULL), jobObject(NULL),
- breakAwayFromJobObject(FALSE), fileWatcher(NULL), initialized(FALSE)
+ breakAwayFromJobObject(FALSE), fileWatcher(NULL), initialized(FALSE), eventProvider(NULL)
{
InitializeCriticalSection(&this->syncRoot);
}
@@ -18,6 +18,8 @@ HRESULT CNodeApplicationManager::Initialize(IHttpContext* context)
return S_OK;
}
+ ErrorIf(NULL == (this->eventProvider = new CNodeEventProvider()), ERROR_NOT_ENOUGH_MEMORY);
+ CheckError(this->eventProvider->Initialize());
ErrorIf(NULL != this->asyncManager, ERROR_INVALID_OPERATION);
ErrorIf(NULL == (this->asyncManager = new CAsyncManager()), ERROR_NOT_ENOUGH_MEMORY);
CheckError(this->asyncManager->Initialize(context));
@@ -68,6 +70,8 @@ HRESULT CNodeApplicationManager::Initialize(IHttpContext* context)
this->initialized = TRUE;
+ this->GetEventProvider()->Log(L"iisnode has initialized the application manager", WINEVENT_LEVEL_INFO);
+
return S_OK;
Error:
@@ -89,6 +93,12 @@ HRESULT CNodeApplicationManager::Initialize(IHttpContext* context)
this->fileWatcher = NULL;
}
+ if (NULL != this->eventProvider)
+ {
+ delete this->eventProvider;
+ this->eventProvider = NULL;
+ }
+
return hr;
}
@@ -120,6 +130,12 @@ CNodeApplicationManager::~CNodeApplicationManager()
this->fileWatcher = NULL;
}
+ if (NULL != this->eventProvider)
+ {
+ delete this->eventProvider;
+ this->eventProvider = NULL;
+ }
+
DeleteCriticalSection(&this->syncRoot);
}
@@ -238,3 +254,8 @@ BOOL CNodeApplicationManager::GetBreakAwayFromJobObject()
{
return this->breakAwayFromJobObject;
}
+
+CNodeEventProvider* CNodeApplicationManager::GetEventProvider()
+{
+ return this->eventProvider;
+}
View
3 src/iisnode/cnodeapplicationmanager.h
@@ -4,6 +4,7 @@
class CNodeApplication;
class CAsyncManager;
class CFileWatcher;
+class CNodeEventProvider;
class CNodeApplicationManager
{
@@ -22,6 +23,7 @@ class CNodeApplicationManager
HANDLE jobObject;
BOOL breakAwayFromJobObject;
CFileWatcher* fileWatcher;
+ CNodeEventProvider* eventProvider;
BOOL initialized;
HRESULT GetOrCreateNodeApplication(IHttpContext* context, CNodeApplication** application);
@@ -36,6 +38,7 @@ class CNodeApplicationManager
IHttpServer* GetHttpServer();
HTTP_MODULE_ID GetModuleId();
CAsyncManager* GetAsyncManager();
+ CNodeEventProvider* GetEventProvider();
HANDLE GetJobObject();
BOOL GetBreakAwayFromJobObject();
View
68 src/iisnode/cnodeeventprovider.cpp
@@ -0,0 +1,68 @@
+#include "precomp.h"
+
+// {1040DFC4-61DB-484A-9530-584B2735F7F7}
+const GUID CNodeEventProvider::providerId = { 0x1040dfc4, 0x61db, 0x484a, { 0x95, 0x30, 0x58, 0x4b, 0x27, 0x35, 0xf7, 0xf7 } };
+
+CNodeEventProvider::CNodeEventProvider()
+ : handle(NULL), advapi(NULL), eventRegister(NULL), eventUnregister(NULL), eventWriteString(NULL), eventProviderEnabled(NULL)
+{
+}
+
+CNodeEventProvider::~CNodeEventProvider()
+{
+ if (this->advapi && this->eventUnregister)
+ {
+ this->eventUnregister(this->handle);
+ this->handle = NULL;
+ }
+
+ if (this->advapi)
+ {
+ FreeLibrary(this->advapi);
+ this->advapi = NULL;
+ }
+}
+
+HRESULT CNodeEventProvider::Initialize()
+{
+ HRESULT hr;
+
+ this->advapi = LoadLibrary("advapi32.dll");
+ this->eventRegister = (EventRegisterFunc)GetProcAddress(this->advapi, "EventRegister");
+ this->eventUnregister = (EventUnregisterFunc)GetProcAddress(this->advapi, "EventUnregister");
+ this->eventWriteString = (EventWriteStringFunc)GetProcAddress(this->advapi, "EventWriteString");
+ this->eventProviderEnabled = (EventProviderEnabledFunc)GetProcAddress(this->advapi, "EventProviderEnabled");
+
+ if (this->eventRegister)
+ {
+ CheckError(this->eventRegister(&providerId, NULL, NULL, &this->handle));
+ }
+
+ return S_OK;
+Error:
+
+ if (this->advapi)
+ {
+ FreeLibrary(this->advapi);
+ this->advapi = NULL;
+ }
+
+ return hr;
+}
+
+bool CNodeEventProvider::IsEnabled(UCHAR level)
+{
+ bool result = this->eventProviderEnabled ? this->eventProviderEnabled(this->handle, level, 0) : false;
+ return result;
+}
+
+HRESULT CNodeEventProvider::Log(PCWSTR message, UCHAR level)
+{
+ HRESULT hr;
+
+ CheckError(this->eventWriteString(this->handle, level, 0, message));
+
+ return S_OK;
+Error:
+ return hr;
+}
View
53 src/iisnode/cnodeeventprovider.h
@@ -0,0 +1,53 @@
+#ifndef __CNODEEVENTPROVIDER_H__
+#define __CNODEEVENTPROVIDER_H__
+
+typedef ULONG (*EventRegisterFunc)(
+ _In_ LPCGUID ProviderId,
+ _In_opt_ PENABLECALLBACK EnableCallback,
+ _In_opt_ PVOID CallbackContext,
+ _Out_ PREGHANDLE RegHandle
+);
+
+typedef ULONG (*EventUnregisterFunc)(
+ _In_ REGHANDLE RegHandle
+);
+
+typedef bool (*EventProviderEnabledFunc)(
+ __in REGHANDLE RegHandle,
+ __in UCHAR Level,
+ __in ULONGLONG Keyword
+);
+
+typedef ULONG (*EventWriteStringFunc)(
+ __in REGHANDLE RegHandle,
+ __in UCHAR Level,
+ __in ULONGLONG Keyword,
+ __in PCWSTR String
+);
+
+class CNodeEventProvider
+{
+private:
+ // {1040DFC4-61DB-484A-9530-584B2735F7F7}
+ static const GUID providerId;
+
+ REGHANDLE handle;
+ HMODULE advapi;
+ EventRegisterFunc eventRegister;
+ EventUnregisterFunc eventUnregister;
+ EventProviderEnabledFunc eventProviderEnabled;
+ EventWriteStringFunc eventWriteString;
+
+
+public:
+
+ CNodeEventProvider();
+ ~CNodeEventProvider();
+
+ HRESULT Initialize();
+ bool IsEnabled(UCHAR level);
+ HRESULT Log(PCWSTR message, UCHAR level);
+
+};
+
+#endif
View
12 src/iisnode/iisnode.sln
@@ -9,31 +9,43 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "iisnode-express-msi", "..\s
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
+ Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {D1F7201F-064B-48AB-868C-FED22464841C}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
+ {D1F7201F-064B-48AB-868C-FED22464841C}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{D1F7201F-064B-48AB-868C-FED22464841C}.Debug|Win32.ActiveCfg = Debug|Win32
{D1F7201F-064B-48AB-868C-FED22464841C}.Debug|Win32.Build.0 = Debug|Win32
{D1F7201F-064B-48AB-868C-FED22464841C}.Debug|x64.ActiveCfg = Debug|x64
{D1F7201F-064B-48AB-868C-FED22464841C}.Debug|x64.Build.0 = Debug|x64
+ {D1F7201F-064B-48AB-868C-FED22464841C}.Release|Mixed Platforms.ActiveCfg = Release|x64
+ {D1F7201F-064B-48AB-868C-FED22464841C}.Release|Mixed Platforms.Build.0 = Release|x64
{D1F7201F-064B-48AB-868C-FED22464841C}.Release|Win32.ActiveCfg = Release|Win32
{D1F7201F-064B-48AB-868C-FED22464841C}.Release|Win32.Build.0 = Release|Win32
{D1F7201F-064B-48AB-868C-FED22464841C}.Release|x64.ActiveCfg = Release|x64
{D1F7201F-064B-48AB-868C-FED22464841C}.Release|x64.Build.0 = Release|x64
+ {E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Debug|Mixed Platforms.ActiveCfg = Debug|x64
{E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Debug|Win32.ActiveCfg = Debug|x86
{E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Debug|Win32.Build.0 = Debug|x86
{E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Debug|x64.ActiveCfg = Debug|x64
{E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Debug|x64.Build.0 = Debug|x64
+ {E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Release|Mixed Platforms.ActiveCfg = Release|x64
{E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Release|Win32.ActiveCfg = Release|x86
{E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Release|Win32.Build.0 = Release|x86
{E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Release|x64.ActiveCfg = Release|x64
{E2C84D6A-20EA-48A8-858E-BDD64D98A94B}.Release|x64.Build.0 = Release|x64
+ {36D6E303-E057-4963-A093-C7AAE0FD92B3}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
+ {36D6E303-E057-4963-A093-C7AAE0FD92B3}.Debug|Mixed Platforms.Build.0 = Debug|x86
{36D6E303-E057-4963-A093-C7AAE0FD92B3}.Debug|Win32.ActiveCfg = Debug|x86
{36D6E303-E057-4963-A093-C7AAE0FD92B3}.Debug|Win32.Build.0 = Debug|x86
{36D6E303-E057-4963-A093-C7AAE0FD92B3}.Debug|x64.ActiveCfg = Debug|x86
+ {36D6E303-E057-4963-A093-C7AAE0FD92B3}.Release|Mixed Platforms.ActiveCfg = Release|x86
+ {36D6E303-E057-4963-A093-C7AAE0FD92B3}.Release|Mixed Platforms.Build.0 = Release|x86
{36D6E303-E057-4963-A093-C7AAE0FD92B3}.Release|Win32.ActiveCfg = Release|x86
{36D6E303-E057-4963-A093-C7AAE0FD92B3}.Release|Win32.Build.0 = Release|x86
{36D6E303-E057-4963-A093-C7AAE0FD92B3}.Release|x64.ActiveCfg = Release|x86
View
6 src/iisnode/iisnode.vcxproj
@@ -205,6 +205,7 @@ copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$
<ClCompile Include="cmoduleconfiguration.cpp" />
<ClCompile Include="cnodeapplication.cpp" />
<ClCompile Include="cnodeapplicationmanager.cpp" />
+ <ClCompile Include="cnodeeventprovider.cpp" />
<ClCompile Include="cnodehttpmodulefactory.cpp" />
<ClCompile Include="cnodehttpstoredcontext.cpp" />
<ClCompile Include="cnodeprocess.cpp" />
@@ -230,6 +231,7 @@ copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$
<None Include="..\..\test\functional\tests\105_logging.js" />
<None Include="..\..\test\functional\tests\106_autoupdate.bat" />
<None Include="..\..\test\functional\tests\107_filesystem.js" />
+ <None Include="..\..\test\functional\tests\108_appsettings.js" />
<None Include="..\..\test\functional\tests\200_samples.bat" />
<None Include="..\..\test\functional\tests\node_modules\iisnodeassert.js" />
<None Include="..\..\test\functional\tests\parts\106_autoupdate_first.js" />
@@ -253,6 +255,8 @@ copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$
<None Include="..\..\test\functional\www\107_filesystem\file.txt" />
<None Include="..\..\test\functional\www\107_filesystem\hello.js" />
<None Include="..\..\test\functional\www\107_filesystem\web.config" />
+ <None Include="..\..\test\functional\www\108_appsettings\hello.js" />
+ <None Include="..\..\test\functional\www\108_appsettings\web.config" />
<None Include="..\config\iisnode_schema.xml" />
<None Include="..\config\iisnode_schema_x64.xml" />
<None Include="..\samples\configuration\hello.js" />
@@ -288,6 +292,7 @@ copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$
<DeploymentContent>true</DeploymentContent>
</None>
<None Include="..\samples\urlrewrite\web.config" />
+ <None Include="..\scripts\etw.bat" />
<None Include="..\scripts\setupsamples.bat" />
<None Include="iisnode.def" />
</ItemGroup>
@@ -304,6 +309,7 @@ copy /y $(SolutionDir)\..\config\* $(SolutionDir)\..\..\build\$(Configuration)\$
<ClInclude Include="cnodehttpstoredcontext.h" />
<ClInclude Include="cnodeprocess.h" />
<ClInclude Include="cnodeprocessmanager.h" />
+ <ClInclude Include="cnodeeventprovider.h" />
<ClInclude Include="cpendingrequestqueue.h" />
<ClInclude Include="cprotocolbridge.h" />
<ClInclude Include="precomp.h" />
View
21 src/iisnode/iisnode.vcxproj.filters
@@ -85,6 +85,9 @@
<Filter Include="Tests\functional\www\107_filesystem">
<UniqueIdentifier>{cc6d4108-5cc9-4576-adf4-6ddc7d186998}</UniqueIdentifier>
</Filter>
+ <Filter Include="Tests\functional\www\108_appsettings">
+ <UniqueIdentifier>{f56c1f46-66cb-4585-adde-0ae7b04c5ee4}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
@@ -135,6 +138,9 @@
<ClCompile Include="cfilewatcher.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="cnodeeventprovider.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="precomp.h">
@@ -188,6 +194,9 @@
<ClInclude Include="version_autogenerated.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="cnodeeventprovider.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="iisnode.def">
@@ -361,5 +370,17 @@
<None Include="..\..\test\functional\www\107_filesystem\web.config">
<Filter>Tests\functional\www\107_filesystem</Filter>
</None>
+ <None Include="..\..\test\functional\www\108_appsettings\hello.js">
+ <Filter>Tests\functional\www\108_appsettings</Filter>
+ </None>
+ <None Include="..\..\test\functional\www\108_appsettings\web.config">
+ <Filter>Tests\functional\www\108_appsettings</Filter>
+ </None>
+ <None Include="..\..\test\functional\tests\108_appsettings.js">
+ <Filter>Tests\functional\tests</Filter>
+ </None>
+ <None Include="..\scripts\etw.bat">
+ <Filter>Scripts</Filter>
+ </None>
</ItemGroup>
</Project>
View
3 src/iisnode/precomp.h
@@ -11,6 +11,8 @@
#include <Rpc.h>
#include <queue>
#include <list>
+#include <Winmeta.h>
+#include <evntprov.h>
#include "version_autogenerated.h" // this is generated in the pre-build step
@@ -19,6 +21,7 @@
// Project header files
#include "utils.h"
+#include "cnodeeventprovider.h"
#include "casyncmanager.h"
#include "cmoduleconfiguration.h"
#include "cnodehttpmodule.h"
View
20 src/scripts/etw.bat
@@ -0,0 +1,20 @@
+@echo off
+setlocal
+echo ETW listener for iisnode.
+set ETL=%TEMP%\iisnode.etl
+logman stop iisnode -ets 2>&1 > nul
+logman start iisnode -ow -p {1040DFC4-61DB-484A-9530-584B2735F7F7} -o %ETL% -ets 2>&1 > nul
+if "%ERRORLEVEL%" neq "0" echo Error starting ETW listener for iisnode. & exit /b -1
+echo Started ETW listener for iisnode. Execute your test scenario, then press a key to stop the listener and see the traces.
+pause
+logman stop iisnode -ets 2>&1 > nul
+if "%ERRORLEVEL%" neq "0" echo Error stopping ETW listener for iisnode. & exit /b -1
+del /q %ETL%.xml 2>&1 > nul
+tracerpt %ETL% -o %ETL%.xml 2>&1 > nul
+if "%ERRORLEVEL%" neq "0" echo Error generating trace report from %ETL% & exit /b -1
+echo Traces are at %ETL%
+echo The report is at %ETL%.xml
+echo Press a key to see the report in your default *.xml viewer, or Ctrl-C to exit.
+pause
+start %ETL%.xml
+endlocal

0 comments on commit a95960b

Please sign in to comment.
Something went wrong with that request. Please try again.