[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH] Add ETW support
Defines ETW schema with EtwEnter and EtwExit events, which can be used to track code-paths and produce flamegraphs of executions. Only uses EtwEnter and EtwExit in the driver.c file of XenVif, but more events will be added in subsequent patches. Signed-off-by: Owen Smith <owen.smith@xxxxxxxxx> --- src/xenvif/dbg_print.h | 60 +++++++++++++++++++++++++++++++++++ src/xenvif/driver.c | 10 ++++++ src/xenvif/xenvif_etw.xml | 61 ++++++++++++++++++++++++++++++++++++ vs2019/xenvif/xenvif.vcxproj | 13 +++++++- vs2022/xenvif/xenvif.vcxproj | 13 +++++++- 5 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 src/xenvif/xenvif_etw.xml diff --git a/src/xenvif/dbg_print.h b/src/xenvif/dbg_print.h index e39a50c..9cbd286 100644 --- a/src/xenvif/dbg_print.h +++ b/src/xenvif/dbg_print.h @@ -42,6 +42,66 @@ #pragma warning(disable:4127) // conditional expression is constant +#ifdef ETW_HEADER +#include ETW_HEADER + +static __inline VOID +__EtwEnter( + IN const CHAR *Module, + IN const CHAR *Function, + IN ULONG Line + ) +{ + CHAR _Module[16]; + CHAR _Function[32]; + + if (!EventEnabledEvtEnter()) + return; + + RtlZeroMemory(_Module, sizeof(_Module)); + RtlZeroMemory(_Function, sizeof(_Function)); + + strncpy(_Module, Module, ARRAYSIZE(_Module) -1); + strncpy(_Function, Function, ARRAYSIZE(_Function) - 1); + + EventWriteEvtEnter(NULL, _Module, _Function, Line); +} + +static __inline VOID +__EtwExit( + IN const CHAR *Module, + IN const CHAR *Function, + IN ULONG Line, + IN NTSTATUS Status + ) +{ + CHAR _Module[16]; + CHAR _Function[32]; + + if (!EventEnabledEvtExit()) + return; + + RtlZeroMemory(_Module, sizeof(_Module)); + RtlZeroMemory(_Function, sizeof(_Function)); + + strncpy(_Module, Module, sizeof(_Module)); + strncpy(_Function, Function, sizeof(_Function)); + + EventWriteEvtExit(NULL, _Module, _Function, Line, (ULONG)Status); +} + +#define EtwEnter() __EtwEnter(__MODULE__, __FUNCTION__, __LINE__) +#define EtwExit() __EtwExit(__MODULE__, __FUNCTION__, __LINE__, STATUS_SUCCESS) +#define EtwExit2(status) __EtwExit(__MODULE__, __FUNCTION__, __LINE__, status) + +#else + +#define EtwEnter() (VOID)0 +#define EtwExit() (VOID)0 +#define EtwExit2(status) (VOID)status + +#endif + static __inline VOID __Error( IN const CHAR *Prefix, diff --git a/src/xenvif/driver.c b/src/xenvif/driver.c index 3345607..fec047d 100644 --- a/src/xenvif/driver.c +++ b/src/xenvif/driver.c @@ -303,6 +303,8 @@ DriverUnload( __DriverSetDriverObject(NULL); + EventUnregisterXenVif_Driver(); + ASSERT(IsZeroMemory(&Driver, sizeof (XENVIF_DRIVER))); Trace("<====\n"); @@ -318,6 +320,7 @@ AddDevice( { NTSTATUS status; + EtwEnter(); ASSERT3P(DriverObject, ==, __DriverGetDriverObject()); status = FdoCreate(DeviceObject); @@ -328,11 +331,13 @@ AddDevice( ASSERT(!(DeviceObject->Flags & DO_DEVICE_INITIALIZING)); DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; + EtwExit(); return STATUS_SUCCESS; fail1: Error("fail1 (%08x)\n", status); + EtwExit2(status); return status; } @@ -347,6 +352,7 @@ Dispatch( PXENVIF_DX Dx; NTSTATUS status; + EtwEnter(); Dx = (PXENVIF_DX)DeviceObject->DeviceExtension; ASSERT3P(Dx->DeviceObject, ==, DeviceObject); @@ -390,6 +396,7 @@ Dispatch( } done: + EtwExit2(status); return status; } @@ -410,6 +417,7 @@ DriverEntry( ASSERT3P(__DriverGetDriverObject(), ==, NULL); + EventRegisterXenVif_Driver(); ExInitializeDriverRuntime(DrvRtPoolNxOptIn); WdmlibProcgrpInitialize(); @@ -506,6 +514,8 @@ fail1: __DriverSetDriverObject(NULL); + EventUnregisterXenVif_Driver(); + ASSERT(IsZeroMemory(&Driver, sizeof (XENVIF_DRIVER))); return status; diff --git a/src/xenvif/xenvif_etw.xml b/src/xenvif/xenvif_etw.xml new file mode 100644 index 0000000..06f088b --- /dev/null +++ b/src/xenvif/xenvif_etw.xml @@ -0,0 +1,61 @@ +<?xml version='1.0' encoding='utf-8' standalone='yes'?> +<instrumentationManifest + xmlns="http://schemas.microsoft.com/win/2004/08/events" + xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://schemas.microsoft.com/win/2004/08/events eventman.xsd" > + <instrumentation> + <events> + <provider + guid="{6c02b05a-c66d-49db-bd06-4fbe1adcbe13}" + messageFileName="%SystemDrive%\windows\system32\drivers\xenvif.sys" + name="XenVif_Driver" + resourceFileName="%SystemDrive%\windows\system32\drivers\xenvif.sys" + symbol="DriverControlGuid" > + <channels> + <channel chid="XENVIF" name="XenVif" type="Analytic" enabled="true" /> + </channels> + <templates> + <template tid="tid_enter"> + <data name="Module" inType="win:Int8" count="16" outType="xs:string" /> <!-- 16 chars --> + <data name="Function" inType="win:Int8" count="32" outType="xs:string" /> <!-- 32 chars --> + <data name="Line" inType="win:UInt32" outType="xs:unsignedInt" /> <!-- line number --> + </template> + <template tid="tid_exit"> + <data name="Module" inType="win:Int8" count="16" outType="xs:string" /> <!-- 16 chars --> + <data name="Function" inType="win:Int8" count="32" outType="xs:string" /> <!-- 32 chars --> + <data name="Line" inType="win:UInt32" outType="xs:unsignedInt" /> <!-- line number --> + <data name="Status" inType="win:UInt32" outType="xs:unsignedInt" /> <!-- NTSTATUS --> + </template> + </templates> + <events> + <event + channel="XENVIF" + level="win:Informational" + message="$(string.EventTraceInfo.Enter)" + opcode="win:Info" + symbol="EvtEnter" + template="tid_enter" + value="10" /> + <event + channel="XENVIF" + level="win:Informational" + message="$(string.EventTraceInfo.Exit)" + opcode="win:Info" + symbol="EvtExit" + template="tid_exit" + value="11" /> + </events> + </provider> + </events> + </instrumentation> + <localization xmlns="http://schemas.microsoft.com/win/2004/08/events"> + <resources culture="en-US"> + <stringTable> + <string id="EventTraceInfo.Enter" value="[Enter]" /> + <string id="EventTraceInfo.Exit" value="[Exit ]" /> + </stringTable> + </resources> + </localization> +</instrumentationManifest> diff --git a/vs2019/xenvif/xenvif.vcxproj b/vs2019/xenvif/xenvif.vcxproj index d070a03..7bb566b 100644 --- a/vs2019/xenvif/xenvif.vcxproj +++ b/vs2019/xenvif/xenvif.vcxproj @@ -21,7 +21,7 @@ <ClCompile> <AdditionalOptions>/ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions> <AdditionalIncludeDirectories>$(WindowsSdkDir)\include\km;..\..\include;..\..\include\xen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;ETW_HEADER="xenvif_etw.h";%(PreprocessorDefinitions)</PreprocessorDefinitions> <IntrinsicFunctions>true</IntrinsicFunctions> <WarningLevel>EnableAllWarnings</WarningLevel> <DisableSpecificWarnings>4061;4464;4711;4770;4548;4820;4668;4255;5045;6001;6054;26451;28196;30030;30029;%(DisableSpecificWarnings)</DisableSpecificWarnings> @@ -35,6 +35,13 @@ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration> <CETCompat>true</CETCompat> </Link> + <MessageCompile> + <HeaderFilePath>..\..\include</HeaderFilePath> + <GeneratedFilesBaseName>%(Filename)</GeneratedFilesBaseName> + <RCFilePath>..\..\src\xenvif</RCFilePath> + <GenerateKernelModeLoggingMacros>true</GenerateKernelModeLoggingMacros> + <UseBaseNameOfInput>true</UseBaseNameOfInput> + </MessageCompile> <DriverSign> <FileDigestAlgorithm>sha256</FileDigestAlgorithm> </DriverSign> @@ -65,6 +72,7 @@ <ItemGroup> <FilesToPackage Include="$(TargetPath)" /> <FilesToPackage Include="$(OutDir)$(TargetName).pdb" /> + <FilesToPackage Include="..\..\src\xenvif\xenvif_etw.xml" /> </ItemGroup> <ItemGroup> <ClCompile Include="../../src/xenvif/bus.c" /> @@ -87,6 +95,9 @@ <ItemGroup> <ResourceCompile Include="..\..\src\xenvif\xenvif.rc" /> </ItemGroup> + <ItemGroup> + <MessageCompile Include="..\..\src\xenvif\xenvif_etw.xml" /> + </ItemGroup> <ItemGroup> <None Include="..\package\package.vcxproj" /> </ItemGroup> diff --git a/vs2022/xenvif/xenvif.vcxproj b/vs2022/xenvif/xenvif.vcxproj index 85c0a05..9f5aad2 100644 --- a/vs2022/xenvif/xenvif.vcxproj +++ b/vs2022/xenvif/xenvif.vcxproj @@ -21,7 +21,7 @@ <ClCompile> <AdditionalOptions>/ZH:SHA_256 %(AdditionalOptions)</AdditionalOptions> <AdditionalIncludeDirectories>$(WindowsSdkDir)\include\km;..\..\include;..\..\include\xen;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> - <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <PreprocessorDefinitions>PROJECT=$(ProjectName);POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;ETW_HEADER="xenvif_etw.h";%(PreprocessorDefinitions)</PreprocessorDefinitions> <IntrinsicFunctions>true</IntrinsicFunctions> <WarningLevel>EnableAllWarnings</WarningLevel> <DisableSpecificWarnings>4061;4464;4711;4770;4548;4820;4668;4255;5045;6001;6054;26451;28196;30030;30029;%(DisableSpecificWarnings)</DisableSpecificWarnings> @@ -35,6 +35,13 @@ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration> <CETCompat>true</CETCompat> </Link> + <MessageCompile> + <HeaderFilePath>..\..\include</HeaderFilePath> + <GeneratedFilesBaseName>%(Filename)</GeneratedFilesBaseName> + <RCFilePath>..\..\src\xenvif</RCFilePath> + <GenerateKernelModeLoggingMacros>true</GenerateKernelModeLoggingMacros> + <UseBaseNameOfInput>true</UseBaseNameOfInput> + </MessageCompile> <DriverSign> <FileDigestAlgorithm>sha256</FileDigestAlgorithm> </DriverSign> @@ -57,6 +64,7 @@ <ItemGroup> <FilesToPackage Include="$(TargetPath)" /> <FilesToPackage Include="$(OutDir)$(TargetName).pdb" /> + <FilesToPackage Include="..\..\src\xenvif\xenvif_etw.xml" /> </ItemGroup> <ItemGroup> <ClCompile Include="../../src/xenvif/bus.c" /> @@ -79,6 +87,9 @@ <ItemGroup> <ResourceCompile Include="..\..\src\xenvif\xenvif.rc" /> </ItemGroup> + <ItemGroup> + <MessageCompile Include="..\..\src\xenvif\xenvif_etw.xml" /> + </ItemGroup> <ItemGroup> <None Include="..\package\package.vcxproj" /> </ItemGroup> -- 2.41.0.windows.3
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |