Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to etw python script #92508

Merged
merged 12 commits into from
Sep 27, 2023
5 changes: 4 additions & 1 deletion src/coreclr/gc/env/gcenv.base.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@
typedef int BOOL;
typedef uint32_t DWORD;
typedef uint64_t DWORD64;
#ifdef _MSC_VER
typedef unsigned long ULONG;
#else
typedef uint32_t ULONG;

#endif
// -----------------------------------------------------------------------------------------------------------
// HRESULT subset.

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Bootstrap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ extern "C" bool RhRegisterOSModule(void * pModule,
extern "C" void* PalGetModuleHandleFromPointer(void* pointer);

extern "C" void GetRuntimeException();
extern "C" void FailFast();
extern "C" void RuntimeFailFast();
extern "C" void AppendExceptionStackFrame();
extern "C" void GetSystemArrayEEType();
extern "C" void OnFirstChanceException();
Expand All @@ -122,7 +122,7 @@ typedef void(*pfn)();

static const pfn c_classlibFunctions[] = {
&GetRuntimeException,
&FailFast,
&RuntimeFailFast,
nullptr, // &UnhandledExceptionHandler,
&AppendExceptionStackFrame,
nullptr, // &CheckStaticClassConstruction,
Expand Down
890 changes: 0 additions & 890 deletions src/coreclr/nativeaot/Runtime/EtwEvents.h

This file was deleted.

47 changes: 0 additions & 47 deletions src/coreclr/nativeaot/Runtime/PalRedhawk.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,46 +536,6 @@ typedef enum _EXCEPTION_DISPOSITION {
#endif // !_INC_WINDOWS
#endif // !DACCESS_COMPILE

typedef uint64_t REGHANDLE;
typedef uint64_t TRACEHANDLE;

#ifndef _EVNTPROV_H_
struct EVENT_DATA_DESCRIPTOR
{
uint64_t Ptr;
uint32_t Size;
uint32_t Reserved;
};

struct EVENT_DESCRIPTOR
{
uint16_t Id;
uint8_t Version;
uint8_t Channel;
uint8_t Level;
uint8_t Opcode;
uint16_t Task;
uint64_t Keyword;

};

struct EVENT_FILTER_DESCRIPTOR
{
uint64_t Ptr;
uint32_t Size;
uint32_t Type;
};

__forceinline
void
EventDataDescCreate(_Out_ EVENT_DATA_DESCRIPTOR * EventDataDescriptor, _In_opt_ const void * DataPtr, uint32_t DataSize)
{
EventDataDescriptor->Ptr = (uint64_t)DataPtr;
EventDataDescriptor->Size = DataSize;
EventDataDescriptor->Reserved = 0;
}
#endif // _EVNTPROV_H_

extern uint32_t g_RhNumberOfProcessors;

#ifdef TARGET_UNIX
Expand Down Expand Up @@ -726,13 +686,6 @@ typedef void (*PalHijackCallback)(_In_ NATIVE_CONTEXT* pThreadContext, _In_opt_
REDHAWK_PALIMPORT void REDHAWK_PALAPI PalHijack(HANDLE hThread, _In_opt_ void* pThreadToHijack);
REDHAWK_PALIMPORT UInt32_BOOL REDHAWK_PALAPI PalRegisterHijackCallback(_In_ PalHijackCallback callback);

#ifdef FEATURE_ETW
REDHAWK_PALIMPORT bool REDHAWK_PALAPI PalEventEnabled(REGHANDLE regHandle, _In_ const EVENT_DESCRIPTOR* eventDescriptor);
REDHAWK_PALIMPORT uint32_t REDHAWK_PALAPI PalEventRegister(const GUID * arg1, void * arg2, void * arg3, REGHANDLE * arg4);
REDHAWK_PALIMPORT uint32_t REDHAWK_PALAPI PalEventUnregister(REGHANDLE arg1);
REDHAWK_PALIMPORT uint32_t REDHAWK_PALAPI PalEventWrite(REGHANDLE arg1, const EVENT_DESCRIPTOR * arg2, uint32_t arg3, EVENT_DATA_DESCRIPTOR * arg4);
#endif

REDHAWK_PALIMPORT UInt32_BOOL REDHAWK_PALAPI PalAllocateThunksFromTemplate(_In_ HANDLE hTemplateModule, uint32_t templateRva, size_t templateSize, _Outptr_result_bytebuffer_(templateSize) void** newThunksOut);
REDHAWK_PALIMPORT UInt32_BOOL REDHAWK_PALAPI PalFreeThunksFromTemplate(_In_ void *pBaseAddress);

Expand Down
47 changes: 45 additions & 2 deletions src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,32 @@ set_source_files_properties(${EventingHeaders} PROPERTIES GENERATED TRUE)

add_custom_target(aot_eventing_headers DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/aot_eventing_headers.timestamp)

if(CLR_CMAKE_TARGET_WIN32)

set(ETW_PROVIDER_SCRIPT ${CLR_DIR}/scripts/genEtwProvider.py)

set (ETW_PROVIDER_OUTPUTS
${GENERATED_INCLUDE_DIR}/etw/ClrEtwAll.h
${GENERATED_INCLUDE_DIR}/etw/ClrEtwAll.rc
${GENERATED_INCLUDE_DIR}/etw/etwmacros.h
${GENERATED_INCLUDE_DIR}/etw/ClrEtwAll_MSG00001.bin
${GENERATED_INCLUDE_DIR}/etw/ClrEtwAllTEMP.bin
${GENERATED_INCLUDE_DIR}/clrxplatevents.h
)

set_source_files_properties(${ETW_PROVIDER_OUTPUTS} PROPERTIES GENERATED TRUE)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/eventprovider.timestamp
COMMAND ${Python_EXECUTABLE} ${ETW_PROVIDER_SCRIPT} --man ${EVENT_MANIFEST} --exc ${EVENT_EXCLUSIONS} --intermediate ${GENERATED_INCLUDE_DIR}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/eventprovider.timestamp
DEPENDS ${EVENT_MANIFEST} ${EVENT_EXCLUSIONS} ${ETW_PROVIDER_SCRIPT}
)

add_custom_target(aot_etw_headers DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/eventprovider.timestamp)

endif()

# EventPipe provider source, currently dotnetruntime provider and helper file
set(GENERATE_EVENTPIPE_SCRIPT ${CLR_DIR}/scripts/genEventPipe.py)
set(GENERATE_COMMAND ${Python_EXECUTABLE} ${GENERATE_EVENTPIPE_SCRIPT} --man ${EVENT_MANIFEST} --exc ${EVENT_EXCLUSIONS} --inc ${EVENT_INCLUSION_FILE} --intermediate ${CMAKE_CURRENT_BINARY_DIR} --runtimeflavor nativeaot ${NONEXTERN_ARG})
Expand Down Expand Up @@ -73,6 +99,11 @@ set(EP_GENERATED_HEADER_PATH "${GENERATED_INCLUDE_DIR}")
include (${CLR_SRC_NATIVE_DIR}/eventpipe/configure.cmake)
include_directories(${EP_GENERATED_HEADER_PATH})

if (CLR_CMAKE_TARGET_WIN32)
set(EP_ETW_GENERATED_HEADER_PATH "${GENERATED_INCLUDE_DIR}/etw")
include_directories(${EP_ETW_GENERATED_HEADER_PATH})
endif()

set(AOT_EVENTPIPE_SHIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}")

set (CONTAINER_SOURCES "")
Expand Down Expand Up @@ -151,7 +182,7 @@ if(CLR_CMAKE_HOST_UNIX)
set_source_files_properties(${EVENTPIPE_SOURCES} PROPERTIES COMPILE_OPTIONS -xc++)
endif(CLR_CMAKE_HOST_UNIX)

if (WIN32)
if (CLR_CMAKE_TARGET_WIN32)
set_source_files_properties(${EVENTPIPE_SOURCES} PROPERTIES COMPILE_FLAGS "/FI\"${RUNTIME_DIR}/eventpipe/NativeaotEventPipeSupport.h\"")
endif()

Expand Down Expand Up @@ -190,8 +221,16 @@ if (FEATURE_EVENT_TRACE)
${RUNTIME_DIR}/eventtrace_gcheap.cpp
)
endif()

if(CLR_CMAKE_TARGET_WIN32)
set_source_files_properties(${GEN_EVENTPIPE_PROVIDER_SOURCES} PROPERTIES COMPILE_FLAGS "/FI\"${RUNTIME_DIR}/eventpipe/NativeaotEventPipeSupport.h\"")
set_source_files_properties(${GEN_EVENTPIPE_PLAT_AGNOSTIC_SOURCES} PROPERTIES COMPILE_FLAGS "/FI\"${RUNTIME_DIR}/eventpipe/NativeaotEventPipeSupport.h\"")
set_source_files_properties(${AOT_EVENTTRACE_SOURCES} PROPERTIES COMPILE_FLAGS "/FI\"${RUNTIME_DIR}/eventpipe/NativeaotEventPipeSupport.h\"")
endif()
endif()


LakshanF marked this conversation as resolved.
Show resolved Hide resolved

list(APPEND EVENTPIPE_SOURCES
${AOT_EVENTPIPE_SHIM_SOURCES}
${AOT_EVENTPIPE_SHIM_HEADERS}
Expand All @@ -215,13 +254,17 @@ list(APPEND AOT_EVENTPIPE_DISABLED_SOURCES

add_library(eventpipe-enabled STATIC ${EVENTPIPE_SOURCES})
add_dependencies(eventpipe-enabled aot_eventing_headers)
if(CLR_CMAKE_TARGET_WIN32)
add_dependencies(eventpipe-enabled aot_etw_headers)
endif()

add_library(eventpipe-disabled STATIC ${AOT_EVENTPIPE_DISABLED_SOURCES})
add_dependencies(eventpipe-disabled aot_eventing_headers)

if (CLR_CMAKE_TARGET_WIN32)
add_library(eventpipe-enabled.GuardCF STATIC ${EVENTPIPE_SOURCES})
add_dependencies(eventpipe-enabled.GuardCF aot_eventing_headers)
add_dependencies(eventpipe-enabled.GuardCF aot_etw_headers)
add_library(eventpipe-disabled.GuardCF STATIC ${AOT_EVENTPIPE_DISABLED_SOURCES})
add_dependencies(eventpipe-disabled.GuardCF aot_eventing_headers)
set_target_properties(eventpipe-enabled.GuardCF PROPERTIES CLR_CONTROL_FLOW_GUARD ON)
Expand All @@ -233,4 +276,4 @@ install_static_library(eventpipe-disabled aotsdk nativeaot)
if (CLR_CMAKE_TARGET_WIN32)
install_static_library(eventpipe-enabled.GuardCF aotsdk nativeaot)
install_static_library(eventpipe-disabled.GuardCF aotsdk nativeaot)
endif (CLR_CMAKE_TARGET_WIN32)
endif (CLR_CMAKE_TARGET_WIN32)
10 changes: 3 additions & 7 deletions src/coreclr/nativeaot/Runtime/eventtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void EventTracing_Initialize()
MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_Context.IsEnabled = FALSE;

// Register the ETW providers with the system.
RH_ETW_REGISTER_Microsoft_Windows_DotNETRuntimePrivate();
RH_ETW_REGISTER_Microsoft_Windows_DotNETRuntime();
EventRegisterMicrosoft_Windows_DotNETRuntimePrivate();
EventRegisterMicrosoft_Windows_DotNETRuntime();

MICROSOFT_WINDOWS_DOTNETRUNTIME_PRIVATE_PROVIDER_Context.RegistrationHandle = Microsoft_Windows_DotNETRuntimePrivateHandle;
MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_Context.RegistrationHandle = Microsoft_Windows_DotNETRuntimeHandle;
Expand All @@ -94,10 +94,6 @@ enum CallbackProviderIndex
DotNETRuntimePrivate = 3
};

// @TODO
int const EVENT_CONTROL_CODE_ENABLE_PROVIDER=1;
int const EVENT_CONTROL_CODE_DISABLE_PROVIDER=0;

void EtwCallbackCommon(
CallbackProviderIndex ProviderIndex,
ULONG ControlCode,
Expand Down Expand Up @@ -180,7 +176,7 @@ void EtwCallbackCommon(
#ifdef FEATURE_ETW

void EtwCallback(
GUID * /*SourceId*/,
const GUID * /*SourceId*/,
uint32_t IsEnabled,
uint8_t Level,
uint64_t MatchAnyKeyword,
Expand Down
4 changes: 1 addition & 3 deletions src/coreclr/nativeaot/Runtime/eventtrace_bulktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

#if defined(FEATURE_EVENT_TRACE)

#define Win32EventWrite PalEventWrite

//---------------------------------------------------------------------------------------
// BulkTypeValue / BulkTypeEventLogger: These take care of batching up types so they can
// be logged via ETW in bulk
Expand Down Expand Up @@ -128,7 +126,7 @@ void BulkTypeEventLogger::FireBulkTypeEvent()
}
}

Win32EventWrite(Microsoft_Windows_DotNETRuntimeHandle, &BulkType, iDesc, EventData);
EventWrite(Microsoft_Windows_DotNETRuntimeHandle, &BulkType, iDesc, EventData);

// Reset state
m_nBulkTypeValueCount = 0;
Expand Down
20 changes: 19 additions & 1 deletion src/coreclr/nativeaot/Runtime/eventtrace_etw.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@

#ifdef FEATURE_ETW

#include "EtwEvents.h"
#include <evntprov.h>
extern "C" {
VOID EtwCallback(
_In_ const GUID * SourceId,
_In_ uint32_t ControlCode,
_In_ uint8_t Level,
_In_ uint64_t MatchAnyKeyword,
_In_ uint64_t MatchAllKeyword,
_In_opt_ EVENT_FILTER_DESCRIPTOR * FilterData,
_Inout_opt_ void * CallbackContext);
}

//
// Python script generated code will call this function when MCGEN_PRIVATE_ENABLE_CALLBACK_V2 is defined
// to enable runtime events
#define MCGEN_PRIVATE_ENABLE_CALLBACK_V2(SourceId, ControlCode, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext) \
EtwCallback(SourceId, ControlCode, Level, MatchAnyKeyword, MatchAllKeyword, FilterData, CallbackContext)

#include "ClrEtwAll.h"

#undef ETW_TRACING_INITIALIZED
#define ETW_TRACING_INITIALIZED(RegHandle) (RegHandle != NULL)
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/nativeaot/Runtime/inc/CommonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ typedef void* LPVOID;
typedef uint32_t UINT;
typedef void* PVOID;
typedef uint64_t ULONGLONG;
#ifdef _MSC_VER
typedef unsigned long ULONG;
#else
typedef uint32_t ULONG;
#endif
typedef int64_t LONGLONG;
typedef uint8_t BYTE;
typedef uint16_t UINT16;
Expand Down
21 changes: 0 additions & 21 deletions src/coreclr/nativeaot/Runtime/windows/PalRedhawkMinWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <windows.h>
#include <stdio.h>
#include <errno.h>
#include <evntprov.h>

#include "holder.h"

Expand Down Expand Up @@ -625,26 +624,6 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartEventPipeHelperThread(_In_ Backgro
return PalStartBackgroundWork(callback, pCallbackContext, FALSE);
}

REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalEventEnabled(REGHANDLE regHandle, _In_ const EVENT_DESCRIPTOR* eventDescriptor)
LakshanF marked this conversation as resolved.
Show resolved Hide resolved
{
return !!EventEnabled(regHandle, eventDescriptor);
}

REDHAWK_PALEXPORT uint32_t REDHAWK_PALAPI PalEventRegister(const GUID * arg1, void * arg2, void * arg3, REGHANDLE * arg4)
{
return EventRegister(arg1, reinterpret_cast<PENABLECALLBACK>(arg2), arg3, arg4);
}

REDHAWK_PALEXPORT uint32_t REDHAWK_PALAPI PalEventUnregister(REGHANDLE arg1)
{
return EventUnregister(arg1);
}

REDHAWK_PALEXPORT uint32_t REDHAWK_PALAPI PalEventWrite(REGHANDLE arg1, const EVENT_DESCRIPTOR * arg2, uint32_t arg3, EVENT_DATA_DESCRIPTOR * arg4)
{
return EventWrite(arg1, arg2, arg3, arg4);
}

REDHAWK_PALEXPORT void REDHAWK_PALAPI PalTerminateCurrentProcess(uint32_t arg2)
{
TerminateProcess(GetCurrentProcess(), arg2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static void ReportUnhandledException(Exception exception)
// This is the classlib-provided fail-fast function that will be invoked whenever the runtime
// needs to cause the process to exit. It is the classlib's opportunity to customize the
// termination behavior in whatever way necessary.
[RuntimeExport("FailFast")]
[RuntimeExport("RuntimeFailFast")]
internal static void RuntimeFailFast(RhFailFastReason reason, Exception? exception, IntPtr pExAddress, IntPtr pExContext)
{
if (!SafeToPerformRichExceptionSupport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static Exception GetRuntimeException(ExceptionIDs id)
// This is the classlib-provided fail-fast function that will be invoked whenever the runtime
// needs to cause the process to exit. It is the classlib's opportunity to customize the
// termination behavior in whatever way necessary.
[RuntimeExport("FailFast")]
[RuntimeExport("RuntimeFailFast")]
internal static void RuntimeFailFast(RhFailFastReason reason, Exception exception, IntPtr pExAddress, IntPtr pExContext)
{
RuntimeImports.RhpFallbackFailFast();
Expand Down
20 changes: 13 additions & 7 deletions src/coreclr/scripts/genEventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,13 +437,16 @@ def generateClrallEvents(eventNodes, allTemplates, target_cpp, runtimeFlavor, wr
clrallEvents.append(" {return ")
clrallEvents.append("EventPipeEventEnabled" + eventName + "()")

# @TODO Need to add this to nativeaot after switching to using genEtwProvider.py where this fn will be implemented
if runtimeFlavor.coreclr or write_xplatheader:
if runtimeFlavor.coreclr or write_xplatheader or runtimeFlavor.nativeaot:
if os.name == 'posix':
clrallEvents.append(" || (XplatEventLogger" +
("::" if target_cpp else "_") +
"IsEventLoggingEnabled() && EventXplatEnabled" +
eventName + "());}\n\n")
# native AOT does not support non-windows eventing other than via event pipe
if not runtimeFlavor.nativeaot:
clrallEvents.append(" || (XplatEventLogger" +
("::" if target_cpp else "_") +
"IsEventLoggingEnabled() && EventXplatEnabled" +
eventName + "());}\n\n")
else:
clrallEvents.append(";}\n\n")
else:
clrallEvents.append(" || EventXplatEnabled" + eventName + "();}\n\n")
else:
Expand Down Expand Up @@ -782,7 +785,10 @@ def updateclreventsfile(write_xplatheader, target_cpp, runtimeFlavor, eventpipe_
Clrallevents.write('#include <PalRedhawk.h>\n')
Clrallevents.write('#include "clretwallmain.h"\n')
Clrallevents.write('#include "clreventpipewriteevents.h"\n')
Clrallevents.write('#include "EtwEvents.h"\n\n')
Clrallevents.write('#ifdef FEATURE_ETW\n')
Clrallevents.write('#include "ClrEtwAll.h"\n')
LakshanF marked this conversation as resolved.
Show resolved Hide resolved
Clrallevents.write('#endif\n')
Clrallevents.write('\n')
elif generatedFileType == "source-impl-noop":
Clrallevents.write('#include <CommonTypes.h>\n')
Clrallevents.write('#include <CommonMacros.h>\n\n')
Expand Down