diff --git a/CMakeLists.txt b/CMakeLists.txt index 96ef8c6fe2e..a400fe5cc32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -491,5 +491,21 @@ add_definitions( -DNO_PAL_MINMAX -DPAL_STDCPP_COMPAT ) + +if (ENABLE_JS_LTTNG_SH) + unset(ENABLE_JS_LTTNG_SH CACHE) + include_directories ( + ${CMAKE_CURRENT_SOURCE_DIR}/out/lttng + ) + add_subdirectory ($ENV{TARGET_PATH}/lttng ${CMAKE_CURRENT_BINARY_DIR}/lttng) + + add_definitions( + -DENABLE_JS_ETW + -DENABLE_JS_LTTNG + ) + set(USE_LTTNG "1") +endif() + add_subdirectory (lib) + add_subdirectory (bin) diff --git a/bin/GCStress/StubExternalApi.cpp b/bin/GCStress/StubExternalApi.cpp index 78669cae0c1..cac9b97c7af 100644 --- a/bin/GCStress/StubExternalApi.cpp +++ b/bin/GCStress/StubExternalApi.cpp @@ -21,7 +21,7 @@ void ConfigParserAPI::DisplayInitialOutput(__in LPWSTR moduleName) Output::Print(_u("INIT: DLL Path : %s\n"), moduleName); } -#ifdef ENABLE_JS_ETW +#if defined(ENABLE_JS_ETW) && !defined(ENABLE_JS_LTTNG) void EtwCallbackApi::OnSessionChange(ULONG /* controlCode */, PVOID /* callbackContext */) { // Does nothing diff --git a/build.sh b/build.sh index 19c94832d34..1cd1ada807f 100755 --- a/build.sh +++ b/build.sh @@ -52,6 +52,7 @@ PRINT_USAGE() { echo " --libs-only Do not build CH and GCStress" echo " --lto Enables LLVM Full LTO" echo " --lto-thin Enables LLVM Thin LTO - xcode 8+ or clang 3.9+" + echo " --lttng Enables LTTng support for ETW events" echo " --static Build as static library. Default: shared library" echo " --sanitize=CHECKS Build with clang -fsanitize checks," echo " e.g. undefined,signed-integer-overflow." @@ -104,6 +105,7 @@ OS_LINUX=0 OS_APT_GET=0 OS_UNIX=0 LTO="" +LTTNG="" TARGET_OS="" ENABLE_CC_XPLAT_TRACE="" WB_CHECK= @@ -230,6 +232,11 @@ while [[ $# -gt 0 ]]; do HAS_LTO=1 ;; + --lttng) + LTTNG="-DENABLE_JS_LTTNG_SH=1" + HAS_LTTNG=1 + ;; + -n | --ninja) CMAKE_GEN="-G Ninja" MAKE=ninja @@ -516,6 +523,15 @@ else exit 1 fi fi +export TARGET_PATH + +if [[ $HAS_LTTNG == 1 ]]; then + CHAKRACORE_ROOT=`dirname $0` + python $CHAKRACORE_ROOT/tools/lttng.py --man $CHAKRACORE_ROOT/manifests/Microsoft-Scripting-Chakra-Instrumentation.man --intermediate $TARGET_PATH/intermediate + mkdir -p $TARGET_PATH/lttng + (diff -q $TARGET_PATH/intermediate/lttng/jscriptEtw.h $TARGET_PATH/lttng/jscriptEtw.h && echo "jscriptEtw.h up to date; skipping") || cp $TARGET_PATH/intermediate/lttng/* $TARGET_PATH/lttng/ +fi + BUILD_DIRECTORY="${TARGET_PATH}/${BUILD_TYPE:0}" echo "Build path: ${BUILD_DIRECTORY}" @@ -603,7 +619,7 @@ fi echo Generating $BUILD_TYPE makefiles echo $EXTRA_DEFINES -cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH $LTO $STATIC_LIBRARY $ARCH $TARGET_OS \ +cmake $CMAKE_GEN $CC_PREFIX $ICU_PATH $LTO $LTTNG $STATIC_LIBRARY $ARCH $TARGET_OS \ $ENABLE_CC_XPLAT_TRACE $EXTRA_DEFINES -DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $INTL_ICU \ $WITHOUT_FEATURES $WB_FLAG $WB_ARGS $CMAKE_EXPORT_COMPILE_COMMANDS $LIBS_ONLY_BUILD\ $VALGRIND $BUILD_RELATIVE_DIRECTORY diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 089f4aa5e1e..ec8a3805f9f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -14,6 +14,10 @@ if(CAN_BUILD_WABT) set(wabt_includes ${CHAKRACORE_SOURCE_DIR}/lib/wabt) endif() +if (USE_LTTNG) + set(lttng_objects $) +endif() + add_library (ChakraCoreStatic STATIC ChakraCoreStatic.cpp $ @@ -38,8 +42,16 @@ add_library (ChakraCoreStatic STATIC $ ${wasm_objects} ${wabt_objects} + ${lttng_objects} ) +if(USE_LTTNG) + target_link_libraries(ChakraCoreStatic + -llttng-ust + -ldl + ) +endif() + if(CC_TARGET_OS_OSX) target_link_libraries(ChakraCoreStatic "-framework CoreFoundation" diff --git a/lib/Common/Core/EtwTraceCore.cpp b/lib/Common/Core/EtwTraceCore.cpp index d0ebb6aa543..a2e5f849d6f 100644 --- a/lib/Common/Core/EtwTraceCore.cpp +++ b/lib/Common/Core/EtwTraceCore.cpp @@ -6,6 +6,7 @@ #include "Core/EtwTraceCore.h" #ifdef ENABLE_JS_ETW +#ifndef ENABLE_JS_LTTNG extern "C" { ETW_INLINE VOID EtwCallback( @@ -64,4 +65,5 @@ void EtwTraceCore::UnRegister() } } -#endif +#endif // !ENABLE_JS_LTTNG +#endif // ENABLE_JS_ETW diff --git a/lib/Common/Core/EtwTraceCore.h b/lib/Common/Core/EtwTraceCore.h index 9f44040c2f6..ad9bc0c58d5 100644 --- a/lib/Common/Core/EtwTraceCore.h +++ b/lib/Common/Core/EtwTraceCore.h @@ -47,6 +47,10 @@ #define JS_ETW(s) s #define IS_JS_ETW(s) s +#ifdef ENABLE_JS_LTTNG +#include "jscriptEtw.h" + +#else // C-style callback extern "C" { void EtwCallback( @@ -87,6 +91,7 @@ class EtwTraceCore static bool s_registered; }; +#endif // ENABLE_JS_LTTNG #else #define GCETW(e, ...) diff --git a/lib/Common/Memory/Recycler.cpp b/lib/Common/Memory/Recycler.cpp index d0ab2b36edb..c1e80830d9a 100644 --- a/lib/Common/Memory/Recycler.cpp +++ b/lib/Common/Memory/Recycler.cpp @@ -5968,7 +5968,8 @@ Recycler::ThreadProc() } #endif -#ifdef ENABLE_JS_ETW +#if defined(ENABLE_JS_ETW) && ! defined(ENABLE_JS_LTTNG) + // LTTng has no concept of EventActivityIdControl // Create an ETW ActivityId for this thread, to help tools correlate ETW events we generate GUID activityId = { 0 }; auto eventActivityIdControlResult = EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_SET_ID, &activityId); @@ -6536,7 +6537,8 @@ RecyclerParallelThread::StaticThreadProc(LPVOID lpParameter) dllHandle = NULL; } #endif -#ifdef ENABLE_JS_ETW +#if defined(ENABLE_JS_ETW) && ! defined(ENABLE_JS_LTTNG) + // LTTng has no concept of EventActivityIdControl // Create an ETW ActivityId for this thread, to help tools correlate ETW events we generate GUID activityId = { 0 }; auto eventActivityIdControlResult = EventActivityIdControl(EVENT_ACTIVITY_CTRL_CREATE_SET_ID, &activityId); @@ -8776,4 +8778,4 @@ template char* Recycler::AllocZeroWithAttributesInlined(size_t); template char* Recycler::AllocZeroWithAttributesInlined(size_t); template char* Recycler::AllocZeroWithAttributesInlined(size_t); -#endif \ No newline at end of file +#endif diff --git a/lib/Jsrt/JsrtHelper.cpp b/lib/Jsrt/JsrtHelper.cpp index 65203a66270..5f750d34046 100644 --- a/lib/Jsrt/JsrtHelper.cpp +++ b/lib/Jsrt/JsrtHelper.cpp @@ -143,7 +143,7 @@ void JsrtCallbackState::ObjectBeforeCallectCallbackWrapper(JsObjectBeforeCollect ConfigParser::ParseOnModuleLoad(parser, mod); } - #ifdef ENABLE_JS_ETW + #if defined(ENABLE_JS_ETW) && !defined(ENABLE_JS_LTTNG) EtwTrace::Register(); #endif #ifdef VTUNE_PROFILING diff --git a/lib/Jsrt/JsrtSourceHolder.cpp b/lib/Jsrt/JsrtSourceHolder.cpp index d60cac3df00..21aef9c7200 100644 --- a/lib/Jsrt/JsrtSourceHolder.cpp +++ b/lib/Jsrt/JsrtSourceHolder.cpp @@ -113,7 +113,7 @@ namespace Js #if ENABLE_DEBUG_CONFIG_OPTIONS AssertMsg(reasonString != nullptr, "Reason string for why we are mapping the source was not provided."); - JS_ETW(EventWriteJSCRIPT_SOURCEMAPPING((uint32)wcslen(reasonString), reasonString, (ushort)requestedFor)); + JS_ETW(EventWriteJSCRIPT_SOURCEMAPPING(reasonString, (ushort)requestedFor)); #endif } @@ -285,7 +285,7 @@ namespace Js #if ENABLE_DEBUG_CONFIG_OPTIONS AssertMsg(reasonString != nullptr, "Reason string for why we are mapping the source was not provided."); - JS_ETW(EventWriteJSCRIPT_SOURCEMAPPING((uint32)wcslen(reasonString), reasonString, (ushort)requestedFor)); + JS_ETW(EventWriteJSCRIPT_SOURCEMAPPING(reasonString, (ushort)requestedFor)); #endif } diff --git a/lib/Runtime/Base/EtwTrace.cpp b/lib/Runtime/Base/EtwTrace.cpp index fddc82e1993..ce4b50cccad 100644 --- a/lib/Runtime/Base/EtwTrace.cpp +++ b/lib/Runtime/Base/EtwTrace.cpp @@ -10,6 +10,7 @@ using namespace Js; +#ifndef ENABLE_JS_LTTNG // // This C style callback is invoked by ETW when a trace session is started/stopped // by an ETW controller for the Jscript and MSHTML providers. @@ -47,6 +48,7 @@ void EtwCallbackApi::OnSessionChange(ULONG controlCode, PVOID callbackContext) } } } +#endif // // Registers the ETW provider - this is usually done on Jscript DLL load @@ -54,7 +56,9 @@ void EtwCallbackApi::OnSessionChange(ULONG controlCode, PVOID callbackContext) // void EtwTrace::Register() { +#ifndef ENABLE_JS_LTTNG EtwTraceCore::Register(); +#endif #ifdef TEST_ETW_EVENTS TestEtwEventSink::Load(); @@ -66,8 +70,10 @@ void EtwTrace::Register() // void EtwTrace::UnRegister() { +#ifndef ENABLE_JS_LTTNG EtwTraceCore::UnRegister(); - +#endif + #ifdef TEST_ETW_EVENTS TestEtwEventSink::Unload(); #endif diff --git a/lib/Runtime/Base/ScriptContext.cpp b/lib/Runtime/Base/ScriptContext.cpp index 21a69d758a9..3dd5b1278cc 100644 --- a/lib/Runtime/Base/ScriptContext.cpp +++ b/lib/Runtime/Base/ScriptContext.cpp @@ -6159,11 +6159,11 @@ void ScriptContext::RegisterPrototypeChainEnsuredToHaveOnlyWritableDataPropertie if (emitV2AsyncStackEvent) { - JS_ETW(EventWriteJSCRIPT_ASYNCCAUSALITY_STACKTRACE_V2(operationID, frameCount, nameBufferLength, sizeof(StackFrameInfo), &stackFrames.Item(0), nameBufferString)); + JS_ETW(EventWriteJSCRIPT_ASYNCCAUSALITY_STACKTRACE_V2(operationID, frameCount, nameBufferLength, nameBufferString, sizeof(StackFrameInfo), &stackFrames.Item(0))); } else { - JS_ETW(EventWriteJSCRIPT_STACKTRACE(operationID, frameCount, nameBufferLength, sizeof(StackFrameInfo), &stackFrames.Item(0), nameBufferString)); + JS_ETW(EventWriteJSCRIPT_STACKTRACE(operationID, frameCount, nameBufferLength, nameBufferString, sizeof(StackFrameInfo), &stackFrames.Item(0))); } } } diff --git a/lib/Runtime/Library/GlobalObject.cpp b/lib/Runtime/Library/GlobalObject.cpp index c4c8f71eefc..5eca5eaa267 100644 --- a/lib/Runtime/Library/GlobalObject.cpp +++ b/lib/Runtime/Library/GlobalObject.cpp @@ -1621,8 +1621,7 @@ namespace Js return function->GetScriptContext()->GetLibrary()->GetUndefined(); } - Js::JavascriptString* jsString = Js::JavascriptConversion::ToString(args[1], function->GetScriptContext()); - PlatformAgnostic::EventTrace::FireGenericEventTrace(jsString->GetSz()); + JS_ETW(EventWriteJSCRIPT_INTERNAL_GENERIC_EVENT(Js::JavascriptConversion::ToString(args[1], function->GetScriptContext())->GetSz())); return function->GetScriptContext()->GetLibrary()->GetUndefined(); } #endif diff --git a/lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj b/lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj index ec78fb1ee68..ba1ef3d206b 100644 --- a/lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj +++ b/lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj @@ -55,7 +55,6 @@ - @@ -63,7 +62,6 @@ - diff --git a/lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj.filters b/lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj.filters index a29ec48615f..36761c623b7 100644 --- a/lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj.filters +++ b/lib/Runtime/PlatformAgnostic/Chakra.Runtime.PlatformAgnostic.vcxproj.filters @@ -1,12 +1,9 @@ - + Platform\Windows - - Platform\Windows - Platform\Windows @@ -51,9 +48,6 @@ - - Interfaces - Interfaces @@ -61,4 +55,4 @@ Interfaces - \ No newline at end of file + diff --git a/lib/Runtime/PlatformAgnostic/ChakraPlatform.h b/lib/Runtime/PlatformAgnostic/ChakraPlatform.h index 37c36ce3300..35c593f6974 100644 --- a/lib/Runtime/PlatformAgnostic/ChakraPlatform.h +++ b/lib/Runtime/PlatformAgnostic/ChakraPlatform.h @@ -5,7 +5,6 @@ #pragma once #include "UnicodeText.h" -#include "EventTrace.h" // Configure whether we configure a signal handler // to produce perf-.map files diff --git a/lib/Runtime/PlatformAgnostic/EventTrace.h b/lib/Runtime/PlatformAgnostic/EventTrace.h deleted file mode 100644 index 4543c1103cc..00000000000 --- a/lib/Runtime/PlatformAgnostic/EventTrace.h +++ /dev/null @@ -1,15 +0,0 @@ -//------------------------------------------------------------------------------------------------------- -// Copyright (C) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. -//------------------------------------------------------------------------------------------------------- -#pragma once - -#include "Core/CommonTypedefs.h" - -namespace PlatformAgnostic -{ - namespace EventTrace - { - void FireGenericEventTrace(const void* traceData); - } -} \ No newline at end of file diff --git a/lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt b/lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt index 0c3b5b0ab1d..c62bd85f1d3 100644 --- a/lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt +++ b/lib/Runtime/PlatformAgnostic/Platform/CMakeLists.txt @@ -4,7 +4,6 @@ set(PL_SOURCE_FILES Common/UnicodeText.Common.cpp Common/HiResTimer.cpp Common/DateTime.cpp - Linux/EventTrace.cpp Linux/UnicodeText.ICU.cpp Linux/NumbersUtility.cpp Linux/Thread.cpp diff --git a/lib/Runtime/PlatformAgnostic/Platform/Linux/EventTrace.cpp b/lib/Runtime/PlatformAgnostic/Platform/Linux/EventTrace.cpp deleted file mode 100644 index 01007a39c40..00000000000 --- a/lib/Runtime/PlatformAgnostic/Platform/Linux/EventTrace.cpp +++ /dev/null @@ -1,18 +0,0 @@ -//------------------------------------------------------------------------------------------------------- -// Copyright (C) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. -//------------------------------------------------------------------------------------------------------- - -#include "RuntimePlatformAgnosticPch.h" -#include "CommonPal.h" - -namespace PlatformAgnostic -{ - namespace EventTrace - { - void FireGenericEventTrace(const void* /*traceData*/) - { - // TODO: Implement this on Linux - } - } // namespace EventTrace -} // namespace PlatformAgnostic diff --git a/lib/Runtime/PlatformAgnostic/Platform/Windows/EventTrace.cpp b/lib/Runtime/PlatformAgnostic/Platform/Windows/EventTrace.cpp deleted file mode 100644 index aaf195c81b0..00000000000 --- a/lib/Runtime/PlatformAgnostic/Platform/Windows/EventTrace.cpp +++ /dev/null @@ -1,19 +0,0 @@ -//------------------------------------------------------------------------------------------------------- -// Copyright (C) Microsoft. All rights reserved. -// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. -//------------------------------------------------------------------------------------------------------- - -#include "RuntimePlatformAgnosticPch.h" -#include "Common.h" -#include "ChakraPlatform.h" - -namespace PlatformAgnostic -{ - namespace EventTrace - { - void FireGenericEventTrace(const void* traceData) - { - JS_ETW(EventWriteJSCRIPT_INTERNAL_GENERIC_EVENT(static_cast(traceData))); - } - } -} \ No newline at end of file diff --git a/manifests/Microsoft-Scripting-Chakra-Instrumentation.man b/manifests/Microsoft-Scripting-Chakra-Instrumentation.man index 1dede1bec40..1255d4ef791 100644 --- a/manifests/Microsoft-Scripting-Chakra-Instrumentation.man +++ b/manifests/Microsoft-Scripting-Chakra-Instrumentation.man @@ -1614,6 +1614,11 @@ inType="win:UInt16" name="NameBufferCount" /> + -