Skip to content
Draft
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
3 changes: 2 additions & 1 deletion eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'browser' and '$(RuntimeFlavor)' == 'CoreCLR'"
Include="
$(CoreCLRSharedFrameworkDir)libcoreclr_static.a;
$(CoreCLRSharedFrameworkDir)libeventpipe-disabled.a;
$(CoreCLRSharedFrameworkDir)libeventpipe-enabled.a;
$(CoreCLRSharedFrameworkDir)libcoreclrminipal.a;
$(CoreCLRSharedFrameworkDir)libcoreclrpal.a;
$(CoreCLRSharedFrameworkDir)libgcinfo_unix_wasm.a;
Expand Down Expand Up @@ -306,7 +308,6 @@
$(LibrariesSharedFrameworkDir)dotnet.native.js.symbols;
$(LibrariesSharedFrameworkDir)dotnet.native.wasm;"
IsNative="true" />

<!-- Headers included by the CoreCLR native relink generated sources (see BrowserWasmApp.CoreCLR.targets).
The browserhost CMakeLists installs them into the host sharedFramework; mirrors the Mono include\wasm handling. -->
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'browser' and '$(RuntimeFlavor)' == 'CoreCLR' and '$(IsTestsCommonProject)' != 'true'"
Expand Down
1 change: 1 addition & 0 deletions eng/testing/tests.browser.targets
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<_BundleAOTTestWasmAppForHelixDependsOn>$(_BundleAOTTestWasmAppForHelixDependsOn);PrepareForWasmBuildApp;_PrepareForAOTOnHelix</_BundleAOTTestWasmAppForHelixDependsOn>
<UseSystemResourceKeys Condition="'$(UseSystemResourceKeys)' == ''">false</UseSystemResourceKeys>
<EventSourceSupport Condition="'$(EventSourceSupport)' == ''">true</EventSourceSupport>
<EnableDiagnostics Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(EnableDiagnostics)' == ''">$(EventSourceSupport)</EnableDiagnostics>
<NullabilityInfoContextSupport Condition="'$(NullabilityInfoContextSupport)' == ''">true</NullabilityInfoContextSupport>

<!-- Library tests run directly from bin/ without the static web assets middleware,
Expand Down
45 changes: 37 additions & 8 deletions src/coreclr/scripts/genEventPipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def generateMethodSignatureWrite(eventName, template, extern, runtimeFlavor):
return ''.join(sig_pieces)

def generateClrEventPipeWriteEventsImpl(
providerName, eventNodes, allTemplates, extern, target_cpp, runtimeFlavor, inclusionList, exclusionList):
providerName, eventNodes, allTemplates, extern, target_cpp, runtimeFlavor, inclusionList, exclusionList, stub):
providerPrettyName = providerName.replace("Windows-", '')
providerPrettyName = providerPrettyName.replace("Microsoft-", '')
providerPrettyName = providerPrettyName.replace('-', '_')
Expand All @@ -106,6 +106,24 @@ def generateClrEventPipeWriteEventsImpl(
if not includeEvent(inclusionList, providerName, eventName):
continue

if stub:
WriteEventImpl.append(
generateMethodSignatureEnabled(eventName, runtimeFlavor) + """
{
return false;
}

""")
template = allTemplates[templateName] if templateName else None
WriteEventImpl.append(generateMethodSignatureWrite(eventName, template, extern, runtimeFlavor))
WriteEventImpl.append("""
{
return ERROR_SUCCESS;
}

""")
continue

eventIsEnabledFunc = ""
if runtimeFlavor.coreclr:
eventIsEnabledFunc = "EventPipeAdapter::EventIsEnabled"
Expand Down Expand Up @@ -181,6 +199,10 @@ def generateClrEventPipeWriteEventsImpl(
"void Init" +
providerPrettyName +
"(void)\n{\n")
if stub:
WriteEventImpl.append("}\n")
return ''.join(WriteEventImpl)

if runtimeFlavor.coreclr:
callbackExpr = ("\n#ifdef FEATURE_EVENT_TRACE\n" +
" " + eventPipeCallbackCastExpr + "(" + callbackName + ")\n" +
Expand Down Expand Up @@ -829,14 +851,16 @@ def getAotEventPipeHelperFileImplSuffix():
return ""


def generateEventPipeHelperFile(etwmanifest, eventpipe_directory, target_cpp, runtimeFlavor, extern, dryRun):
def generateEventPipeHelperFile(etwmanifest, eventpipe_directory, target_cpp, runtimeFlavor, extern, stub, dryRun):
eventpipehelpersPath = os.path.join(eventpipe_directory, "eventpipehelpers" + (".cpp" if target_cpp else ".c"))
if dryRun:
print(eventpipehelpersPath)
else:
with open_for_update(eventpipehelpersPath) as helper:
helper.write(stdprolog_cpp)
if runtimeFlavor.coreclr:
if runtimeFlavor.coreclr and stub:
helper.write("#include <common.h>\n\n")
elif runtimeFlavor.coreclr:
helper.write(getCoreCLREventPipeHelperFileImplPrefix())
elif runtimeFlavor.mono:
helper.write(getMonoEventPipeHelperFileImplPrefix())
Expand Down Expand Up @@ -1215,7 +1239,7 @@ def getAotEventPipeImplFileSuffix():
"""

def generateEventPipeImplFiles(
etwmanifest, eventpipe_directory, extern, target_cpp, runtimeFlavor, inclusionList, exclusionList, dryRun):
etwmanifest, eventpipe_directory, extern, target_cpp, runtimeFlavor, inclusionList, exclusionList, stub, dryRun):
tree = DOM.parse(etwmanifest)

for providerNode in tree.getElementsByTagName('provider'):
Expand Down Expand Up @@ -1276,7 +1300,8 @@ def generateEventPipeImplFiles(
target_cpp,
runtimeFlavor,
inclusionList,
exclusionList) + "\n")
exclusionList,
stub) + "\n")

if runtimeFlavor.coreclr:
eventpipeImpl.write(getCoreCLREventPipeImplFileSuffix())
Expand All @@ -1286,15 +1311,15 @@ def generateEventPipeImplFiles(
eventpipeImpl.write(getAotEventPipeImplFileSuffix())

def generateEventPipeFiles(
etwmanifest, intermediate, extern, target_cpp, runtimeFlavor, inclusionList, exclusionList, dryRun):
etwmanifest, intermediate, extern, target_cpp, runtimeFlavor, inclusionList, exclusionList, stub, dryRun):
eventpipe_directory = os.path.join(intermediate, eventpipe_dirname)
tree = DOM.parse(etwmanifest)

if not os.path.exists(eventpipe_directory):
os.makedirs(eventpipe_directory)

# generate helper file
generateEventPipeHelperFile(etwmanifest, eventpipe_directory, target_cpp, runtimeFlavor, extern, dryRun)
generateEventPipeHelperFile(etwmanifest, eventpipe_directory, target_cpp, runtimeFlavor, extern, stub, dryRun)

# generate all keywords
for keywordNode in tree.getElementsByTagName('keyword'):
Expand All @@ -1311,6 +1336,7 @@ def generateEventPipeFiles(
runtimeFlavor,
inclusionList,
exclusionList,
stub,
dryRun
)

Expand Down Expand Up @@ -1338,6 +1364,8 @@ def main(argv):
help='if specified, will generate files to be compiled into the CLR rather than extern' )
required.add_argument('--dry-run', action='store_true',
help='if specified, will output the names of the generated files instead of generating the files' )
required.add_argument('--stub', action='store_true',
help='if specified, will generate no-op provider and event implementations' )
args, unknown = parser.parse_known_args(argv)
if unknown:
print('Unknown argument(s): ', ', '.join(unknown))
Expand All @@ -1350,6 +1378,7 @@ def main(argv):
runtimeFlavor = RuntimeFlavor(args.runtimeflavor)
extern = not args.nonextern
dryRun = args.dry_run
stub = args.stub

target_cpp = True
if runtimeFlavor.mono:
Expand All @@ -1359,7 +1388,7 @@ def main(argv):
inclusion_list = parseInclusionList(inclusion_filename)
exclusion_list = parseExclusionList(exclusion_filename)

generateEventPipeFiles(sClrEtwAllMan, intermediate, extern, target_cpp, runtimeFlavor, inclusion_list, exclusion_list, dryRun)
generateEventPipeFiles(sClrEtwAllMan, intermediate, extern, target_cpp, runtimeFlavor, inclusion_list, exclusion_list, stub, dryRun)

if __name__ == '__main__':
return_code = main(sys.argv[1:])
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ set(VM_SOURCES_WKS
${VM_SOURCES_GDBJIT}
)

if (CLR_CMAKE_TARGET_BROWSER)
list(REMOVE_ITEM VM_SOURCES_WKS eventpipeinternal.cpp)
endif()

if (FEATURE_MULTICOREJIT)
list(APPEND VM_SOURCES_WKS
multicorejit.cpp
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/vm/diagnosticserveradapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@

#include <eventpipe/ds-server.h>

#if defined(TARGET_BROWSER)

class DiagnosticServerAdapter final
{
public:
static bool Initialize();
static bool Shutdown();
static void PauseForDiagnosticsMonitor();
static void ResumeRuntimeStartup();
static bool IsPausedInRuntimeStartup();
};

#else // TARGET_BROWSER

class DiagnosticServerAdapter final
{
public:
Expand Down Expand Up @@ -37,6 +51,8 @@ class DiagnosticServerAdapter final
}
};

#endif // TARGET_BROWSER

#endif // FEATURE_PERFTRACING

#endif // __DIAGNOSTIC_SERVER_ADAPTER_H__
83 changes: 82 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(GENERATE_SCRIPT ${CLR_DIR}/scripts/genEventPipe.py)
set(GENERATE_COMMAND ${Python_EXECUTABLE} ${GENERATE_SCRIPT} --man ${EVENT_MANIFEST} --exc ${EVENT_EXCLUSIONS} --intermediate ${CMAKE_CURRENT_BINARY_DIR} ${NONEXTERN_ARG})
set(GENERATE_STUB_COMMAND ${Python_EXECUTABLE} ${GENERATE_SCRIPT} --man ${EVENT_MANIFEST} --exc ${EVENT_EXCLUSIONS} --intermediate ${CMAKE_CURRENT_BINARY_DIR}/stub ${NONEXTERN_ARG} --stub)

execute_process(
COMMAND ${GENERATE_COMMAND} --dry-run
Expand All @@ -24,10 +25,44 @@ foreach(GEN_EVENTPIPE_SOURCE_PATH ${GEN_EVENTPIPE_SOURCE_PATHS})
list(APPEND GEN_EVENTPIPE_SOURCES ${GEN_EVENTPIPE_SOURCE})
endforeach()

if (CLR_CMAKE_TARGET_BROWSER)
execute_process(
COMMAND ${GENERATE_STUB_COMMAND} --dry-run
RESULT_VARIABLE GEN_EVENTPIPE_STUB_RESULT
OUTPUT_VARIABLE GEN_EVENTPIPE_STUB_SOURCE_PATHS
ERROR_VARIABLE GEN_EVENTPIPE_STUB_ERRORS
)

if (NOT GEN_EVENTPIPE_STUB_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to generate EventPipe stubs: ${GEN_EVENTPIPE_STUB_ERRORS}")
endif()

string(REPLACE "\n" ";" GEN_EVENTPIPE_STUB_SOURCE_PATHS ${GEN_EVENTPIPE_STUB_SOURCE_PATHS})

set(GEN_EVENTPIPE_STUB_SOURCES "")
foreach(GEN_EVENTPIPE_STUB_SOURCE_PATH ${GEN_EVENTPIPE_STUB_SOURCE_PATHS})
file(TO_CMAKE_PATH ${GEN_EVENTPIPE_STUB_SOURCE_PATH} GEN_EVENTPIPE_STUB_SOURCE)
list(APPEND GEN_EVENTPIPE_STUB_SOURCES ${GEN_EVENTPIPE_STUB_SOURCE})
endforeach()
endif()

add_custom_command(OUTPUT ${GEN_EVENTPIPE_SOURCES}
COMMAND ${GENERATE_COMMAND}
DEPENDS ${GENERATE_SCRIPT} ${EVENT_MANIFEST} ${EVENT_EXCLUSIONS})

if (CLR_CMAKE_TARGET_BROWSER)
add_custom_command(OUTPUT ${GEN_EVENTPIPE_STUB_SOURCES}
COMMAND ${GENERATE_STUB_COMMAND}
DEPENDS ${GENERATE_SCRIPT} ${EVENT_MANIFEST} ${EVENT_EXCLUSIONS})
endif()

if (CLR_CMAKE_TARGET_BROWSER)
list(APPEND CORECLR_EVENTPIPE_SHIM_SOURCES
diagnosticserveradapter.cpp
eventpipeadapter.cpp
)
endif()

list(APPEND CORECLR_EVENTPIPE_SHIM_SOURCES
ep-rt-coreclr.cpp
ep-rt-coreclr-wasm-sampling.cpp
Expand All @@ -47,6 +82,14 @@ set_target_properties(eventpipe_gen_objs PROPERTIES LINKER_LANGUAGE CXX)
add_dependencies(eventpipe_gen_objs eventing_headers)
target_compile_definitions(eventpipe_gen_objs PRIVATE FEATURE_PERFTRACING)

if (CLR_CMAKE_TARGET_BROWSER)
add_library_clr(eventpipe_stub_gen_objs OBJECT ${GEN_EVENTPIPE_STUB_SOURCES})
target_precompile_headers(eventpipe_stub_gen_objs PRIVATE [["common.h"]])
set_target_properties(eventpipe_stub_gen_objs PROPERTIES LINKER_LANGUAGE CXX)
add_dependencies(eventpipe_stub_gen_objs eventing_headers)
target_compile_definitions(eventpipe_stub_gen_objs PRIVATE FEATURE_PERFTRACING)
endif()

add_library_clr(eventpipe_objs OBJECT ${CORECLR_EVENTPIPE_SHIM_SOURCES} ${CORECLR_EVENTPIPE_SHIM_HEADERS})
set_target_properties(eventpipe_objs PROPERTIES
LINKER_LANGUAGE CXX
Expand All @@ -70,4 +113,42 @@ set_source_files_properties(${diagnosticserver_sources} ${eventpipe_sources} PRO
set (SHARED_EVENTPIPE_SOURCE_PATH "${CLR_SRC_NATIVE_DIR}/eventpipe")

add_library(eventpipe INTERFACE)
target_sources(eventpipe INTERFACE $<TARGET_OBJECTS:eventpipe_gen_objs> $<TARGET_OBJECTS:eventpipe_objs> $<TARGET_OBJECTS:dn-containers>)
if (CLR_CMAKE_TARGET_BROWSER)
add_library_clr(coreclr-eventpipe-enabled STATIC
${VM_DIR}/eventpipeinternal.cpp
$<TARGET_OBJECTS:eventpipe_gen_objs>
$<TARGET_OBJECTS:eventpipe_objs>
$<TARGET_OBJECTS:dn-containers>
)
set_target_properties(coreclr-eventpipe-enabled PROPERTIES OUTPUT_NAME eventpipe-enabled)
target_precompile_headers(coreclr-eventpipe-enabled PRIVATE [["common.h"]])
add_dependencies(coreclr-eventpipe-enabled eventing_headers)

add_library_clr(coreclr-eventpipe-disabled STATIC
diagnosticserveradapter-stub.cpp
ep-rt-coreclr-wasm-sampling-stub.cpp
eventpipeadapter-stub.cpp
eventpipeinternal-stub.cpp
$<TARGET_OBJECTS:eventpipe_stub_gen_objs>
)
set_target_properties(coreclr-eventpipe-disabled PROPERTIES OUTPUT_NAME eventpipe-disabled)
target_precompile_headers(coreclr-eventpipe-disabled PRIVATE [["common.h"]])
add_dependencies(coreclr-eventpipe-disabled eventing_headers)

if (FEATURE_PERFTRACING_DISABLE_THREADS)
target_compile_definitions(coreclr-eventpipe-enabled PRIVATE PERFTRACING_DISABLE_THREADS)
target_compile_definitions(coreclr-eventpipe-disabled PRIVATE PERFTRACING_DISABLE_THREADS)
endif()

target_link_libraries(eventpipe INTERFACE coreclr-eventpipe-enabled)

install_clr(
TARGETS coreclr-eventpipe-enabled coreclr-eventpipe-disabled
DESTINATIONS . sharedFramework
COMPONENT runtime)
else()
target_sources(eventpipe INTERFACE
$<TARGET_OBJECTS:eventpipe_gen_objs>
$<TARGET_OBJECTS:eventpipe_objs>
$<TARGET_OBJECTS:dn-containers>)
endif()
28 changes: 28 additions & 0 deletions src/coreclr/vm/eventing/eventpipe/diagnosticserveradapter-stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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 "diagnosticserveradapter.h"

bool DiagnosticServerAdapter::Initialize()
{
return false;
}

bool DiagnosticServerAdapter::Shutdown()
{
return false;
}

void DiagnosticServerAdapter::PauseForDiagnosticsMonitor()
{
}

void DiagnosticServerAdapter::ResumeRuntimeStartup()
{
}

bool DiagnosticServerAdapter::IsPausedInRuntimeStartup()
{
return false;
}
30 changes: 30 additions & 0 deletions src/coreclr/vm/eventing/eventpipe/diagnosticserveradapter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 "diagnosticserveradapter.h"

bool DiagnosticServerAdapter::Initialize()
{
return ds_server_init();
}

bool DiagnosticServerAdapter::Shutdown()
{
return ds_server_shutdown();
}

void DiagnosticServerAdapter::PauseForDiagnosticsMonitor()
{
ds_server_pause_for_diagnostics_monitor();
}

void DiagnosticServerAdapter::ResumeRuntimeStartup()
{
ds_server_resume_runtime_startup();
}

bool DiagnosticServerAdapter::IsPausedInRuntimeStartup()
{
return ds_server_is_paused_in_startup();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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"

#ifdef PERFTRACING_DISABLE_THREADS

extern "C" bool SamplingProfiler_ShouldSample()
{
LIMITED_METHOD_CONTRACT;
return false;
}

extern "C" void SamplingProfiler_CollectSample()
{
LIMITED_METHOD_CONTRACT;
}

extern "C" void SamplingProfiler_OnSamplepoint()
{
LIMITED_METHOD_CONTRACT;
}

#endif // PERFTRACING_DISABLE_THREADS
Loading
Loading