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

Remove some unnecessary indirection to DiagnosticServerAdapter/EventPipeAdapter in nativeaot #90132

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/coreclr/nativeaot/Runtime/CommonMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@

#ifndef __GCENV_BASE_INCLUDED__

#include <cstdint>

//
// This macro returns val rounded up as necessary to be a multiple of alignment; alignment must be a power of 2
//
Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/nativeaot/Runtime/DisabledEventPipeInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

void EventPipeAdapter_Initialize() {}
void EventPipe_Initialize() {}

bool DiagnosticServerAdapter_Initialize() { return false; }
void DiagnosticServerAdapter_PauseForDiagnosticsMonitor() {}
bool DiagnosticServer_Initialize() { return false; }
void DiagnosticServer_PauseForDiagnosticsMonitor() {}

void EventPipeAdapter_FinishInitialize() {}
void EventPipe_FinishInitialize() {}

void EventPipe_ThreadShutdown() { }

void EventPipeAdapter_Shutdown() {}
bool DiagnosticServerAdapter_Shutdown() { return false; }
void EventPipe_Shutdown() {}
bool DiagnosticServer_Shutdown() { return false; }
17 changes: 9 additions & 8 deletions src/coreclr/nativeaot/Runtime/EnabledEventPipeInterface.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#include "eventpipeadapter.h"
#include "diagnosticserveradapter.h"
#include <eventpipe/ep.h>
#include <eventpipe/ep-rt-aot.h>
#include <eventpipe/ds-server.h>

void EventPipeAdapter_Initialize() { EventPipeAdapter::Initialize(); }
void EventPipe_Initialize() { ep_init(); }

bool DiagnosticServerAdapter_Initialize() { return DiagnosticServerAdapter::Initialize(); }
void DiagnosticServerAdapter_PauseForDiagnosticsMonitor() { DiagnosticServerAdapter::PauseForDiagnosticsMonitor();}
bool DiagnosticServer_Initialize() { return ds_server_init(); }
void DiagnosticServer_PauseForDiagnosticsMonitor() { ds_server_pause_for_diagnostics_monitor(); }

void EventPipeAdapter_FinishInitialize() { EventPipeAdapter::FinishInitialize(); }
void EventPipe_FinishInitialize() { ep_finish_init(); }

void EventPipe_ThreadShutdown() { ep_rt_aot_thread_exited(); }

void EventPipeAdapter_Shutdown() { EventPipeAdapter::Shutdown(); }
bool DiagnosticServerAdapter_Shutdown() { return DiagnosticServerAdapter::Shutdown(); }
void EventPipe_Shutdown() { ep_shutdown(); }
bool DiagnosticServer_Shutdown() { return ds_server_shutdown(); }
13 changes: 6 additions & 7 deletions src/coreclr/nativeaot/Runtime/EventPipeInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
#define EVENTPIPE_INTERFACE_H

// Initialize EventPipe
void EventPipeAdapter_Initialize();
void EventPipe_Initialize();

// Initialize DS
bool DiagnosticServerAdapter_Initialize();
void DiagnosticServerAdapter_PauseForDiagnosticsMonitor();
bool DiagnosticServer_Initialize();
void DiagnosticServer_PauseForDiagnosticsMonitor();


void EventPipeAdapter_FinishInitialize();
void EventPipe_FinishInitialize();

void EventPipe_ThreadShutdown();

void EventPipeAdapter_Shutdown();
bool DiagnosticServerAdapter_Shutdown();
void EventPipe_Shutdown();
bool DiagnosticServer_Shutdown();

void EventTracing_Initialize();
#endif //EVENTPIPE_INTERFACE_H
4 changes: 4 additions & 0 deletions src/coreclr/nativeaot/Runtime/PalRedhawk.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

#include <sal.h>
#include <stdarg.h>
#ifdef TARGET_UNIX
#include <pthread.h>
#endif

#include "CommonTypes.h"
#include "CommonMacros.h"
#include "gcenv.structs.h" // CRITICAL_SECTION
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/nativeaot/Runtime/StackFrameIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
#ifndef __StackFrameIterator_h__
#define __StackFrameIterator_h__

#include "CommonMacros.h"
#include "ICodeManager.h"
#include "PalRedhawk.h" // NATIVE_CONTEXT
#include "regdisplay.h"

#include "forward_declarations.h"

struct ExInfo;
typedef DPTR(ExInfo) PTR_ExInfo;
Expand All @@ -22,6 +27,7 @@ struct EHEnum
EHEnumState m_state;
};

class StackFrameIterator;
EXTERN_C FC_BOOL_RET FASTCALL RhpSfiInit(StackFrameIterator* pThis, PAL_LIMITED_CONTEXT* pStackwalkCtx, CLR_BOOL instructionFault);
EXTERN_C FC_BOOL_RET FASTCALL RhpSfiNext(StackFrameIterator* pThis, uint32_t* puExCollideClauseIdx, CLR_BOOL* pfUnwoundReversePInvoke);

Expand Down
42 changes: 0 additions & 42 deletions src/coreclr/nativeaot/Runtime/diagnosticserveradapter.h

This file was deleted.

19 changes: 8 additions & 11 deletions src/coreclr/nativeaot/Runtime/disabledeventpipeinternal.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#include "common.h"
#include "eventpipeadapter.h"
#include "CommonTypes.h"
#include "CommonMacros.h"
#include "PalRedhawk.h"

#ifdef FEATURE_PERFTRACING
#include <eventpipe/ep.h>

#include "gcenv.h"
#include "regdisplay.h"
#include "StackFrameIterator.h"
#include "thread.h"
#include "SpinLock.h"
#ifdef FEATURE_PERFTRACING

struct EventPipeEventInstanceData;

struct EventPipeSessionInfo;

EXTERN_C NATIVEAOT_API uint64_t __cdecl RhEventPipeInternal_Enable(
LPCWSTR outputFile,
const WCHAR* outputFile,
EventPipeSerializationFormat format,
uint32_t circularBufferSizeInMB,
/* COR_PRF_EVENTPIPE_PROVIDER_CONFIG */ const void * pProviders,
Expand All @@ -31,7 +28,7 @@ EXTERN_C NATIVEAOT_API void __cdecl RhEventPipeInternal_Disable(uint64_t session
}

EXTERN_C NATIVEAOT_API intptr_t __cdecl RhEventPipeInternal_CreateProvider(
LPCWSTR providerName,
const WCHAR* providerName,
EventPipeCallback pCallbackFunc,
void* pCallbackContext)
{
Expand All @@ -50,7 +47,7 @@ EXTERN_C NATIVEAOT_API intptr_t __cdecl RhEventPipeInternal_DefineEvent(
return 0;
}

EXTERN_C NATIVEAOT_API intptr_t __cdecl RhEventPipeInternal_GetProvider(LPCWSTR providerName)
EXTERN_C NATIVEAOT_API intptr_t __cdecl RhEventPipeInternal_GetProvider(const WCHAR* providerName)
{
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#include "eventpipeadapter.h"
#include "CommonTypes.h"
#include "CommonMacros.h"
#include "PalRedhawk.h"

#ifdef FEATURE_PERFTRACING

Expand Down Expand Up @@ -78,7 +80,7 @@ EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogThreadPoolIOPack
{
}

EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogExceptionThrown(LPCWSTR exceptionTypeName, LPCWSTR exceptionMessage, void* faultingIP, HRESULT hresult)
EXTERN_C NATIVEAOT_API void __cdecl NativeRuntimeEventSource_LogExceptionThrown(const WCHAR* exceptionTypeName, const WCHAR* exceptionMessage, void* faultingIP, HRESULT hresult)
{
}

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/nativeaot/Runtime/eventpipe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ list(APPEND GEN_EVENTPIPE_SOURCES
list(APPEND AOT_EVENTPIPE_MANAGED_TO_NATIVE_SOURCES
${RUNTIME_DIR}/eventpipeinternal.cpp
${RUNTIME_DIR}/eventpipeadapter.h
${RUNTIME_DIR}/diagnosticserveradapter.h
${RUNTIME_DIR}/EnabledEventPipeInterface.cpp
${RUNTIME_DIR}/runtimeeventinternal.cpp
)
Expand Down
10 changes: 6 additions & 4 deletions src/coreclr/nativeaot/Runtime/eventpipe/dotnetruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
// @TODO: Audit native events in NativeAOT Runtime

#include <common.h>
#include "eventpipeadapter.h"
#include "eventtrace_context.h"
#include "gcheaputilities.h"
#include <gcenv.h>

#include <eventpipeadapter.h>
#include <eventtrace_context.h>
#include <gcheaputilities.h>

#ifndef ERROR_WRITE_FAULT
#define ERROR_WRITE_FAULT 29L
Expand Down Expand Up @@ -3010,7 +3012,7 @@ void InitDotNETRuntime(void)

bool DotNETRuntimeProvider_IsEnabled(unsigned char level, unsigned long long keyword)
{
if (!EventPipeAdapter::Enabled())
if (!ep_enabled())
return false;

EVENTPIPE_TRACE_CONTEXT& context = MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_DOTNET_Context.EventPipeProvider;
Expand Down
80 changes: 2 additions & 78 deletions src/coreclr/nativeaot/Runtime/eventpipeadapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,95 +17,19 @@
#include <eventpipe/ep-event-payload.h>
#include <eventpipe/ep-buffer-manager.h>

#include "gcenv.h"
#include "regdisplay.h"
#include "StackFrameIterator.h"
#include "thread.h"
#include "holder.h"
#include "SpinLock.h"
#include "CommonTypes.h"

class EventPipeAdapter final
{
public:
static inline void Initialize()
{
CONTRACTL
{
NOTHROW;
}
CONTRACTL_END;

ep_init();
}

static inline EventPipeProvider * CreateProvider(LPCWSTR providerName, EventPipeCallback callback, void* pCallbackContext = nullptr)
static inline EventPipeProvider * CreateProvider(const WCHAR* providerName, EventPipeCallback callback, void* pCallbackContext = nullptr)
{
ep_char8_t *providerNameUTF8 = ep_rt_utf16_to_utf8_string(reinterpret_cast<const ep_char16_t *>(providerName), -1);
EventPipeProvider * provider = ep_create_provider (providerNameUTF8, callback, pCallbackContext);
ep_rt_utf8_string_free (providerNameUTF8);
return provider;
}

static inline void DeleteProvider (EventPipeProvider * provider)
{
ep_delete_provider (provider);
}


static inline void FinishInitialize()
{
CONTRACTL
{
NOTHROW;
}
CONTRACTL_END;

ep_finish_init();
}

static inline void Shutdown()
{
ep_shutdown();
}

static inline bool Enabled()
{
STATIC_CONTRACT_NOTHROW;
return ep_enabled();
}

static inline void Disable(EventPipeSessionID id)
{
CONTRACTL
{
NOTHROW;
GC_TRIGGERS;
MODE_ANY;
}
CONTRACTL_END;

ep_disable(id);
}

static inline EventPipeProvider * GetProvider (LPCWSTR providerName)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
}
CONTRACTL_END;

if (!providerName)
return NULL;

ep_char8_t *providerNameUTF8 = ep_rt_utf16_to_utf8_string(reinterpret_cast<const ep_char16_t *>(providerName), -1);
EventPipeProvider * provider = ep_get_provider (providerNameUTF8);
ep_rt_utf8_string_free(providerNameUTF8);
return provider;
}

static inline EventPipeEvent * AddEvent(
EventPipeProvider *provider,
uint32_t eventID,
Expand Down
Loading