Skip to content
Open
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ option(USE_ASAN "Compile with address sanitizer" OFF)
option(USE_TSAN "Compile with thread sanitizer" OFF)
option(USE_CUDA "Compile CUDA-involved examples (Needed for examples/SubeventCUDAExample)." OFF)
option(USE_PODIO "Compile with PODIO support" OFF)
option(USE_PERFETTO "Include Perfetto tracing SDK for performance profiling." OFF)
option(BUILD_SHARED_LIBS "Build into both shared and static libs." ON)
option(BUILD_EXAMPLES "Build and install examples" ON)
option(BUILD_TESTS "Build and install tests" ON)
Expand Down Expand Up @@ -134,6 +135,44 @@ if (${USE_CUDA})
find_package(CUDA REQUIRED)
endif()

if (USE_PERFETTO)
set(PERFETTO_VERSION "55.3" CACHE STRING "Perfetto SDK version to download")
set(PERFETTO_HASH "443b148764c4259c9bf3e724bb508b66f3ff77d30e2ccfafbc0f1791cc08141c" CACHE STRING "Perfetto zip sha256 hash")
set(PERFETTO_SDK_URL "https://github.com/google/perfetto/releases/download/v${PERFETTO_VERSION}/perfetto-cpp-sdk-src.zip")
set(PERFETTO_SDK_ZIP "${CMAKE_BINARY_DIR}/perfetto-cpp-sdk-src-${PERFETTO_VERSION}.zip")
set(PERFETTO_SDK_DIR "${CMAKE_BINARY_DIR}/perfetto_sdk_${PERFETTO_VERSION}")

if(NOT EXISTS "${PERFETTO_SDK_DIR}/perfetto.cc")
message(STATUS "Downloading Perfetto SDK v${PERFETTO_VERSION}...")
file(DOWNLOAD "${PERFETTO_SDK_URL}" "${PERFETTO_SDK_ZIP}"
STATUS DOWNLOAD_STATUS
TLS_VERIFY ON
EXPECTED_HASH SHA256=${PERFETTO_HASH}
)
list(GET DOWNLOAD_STATUS 0 DOWNLOAD_ERROR_CODE)
if(DOWNLOAD_ERROR_CODE)
list(GET DOWNLOAD_STATUS 1 DOWNLOAD_ERROR_MSG)
message(FATAL_ERROR "Failed to download Perfetto SDK from ${PERFETTO_SDK_URL}: ${DOWNLOAD_ERROR_MSG}")
endif()
file(ARCHIVE_EXTRACT INPUT "${PERFETTO_SDK_ZIP}" DESTINATION "${PERFETTO_SDK_DIR}")
endif()
Comment thread
wdconinc marked this conversation as resolved.

add_library(perfetto_sdk STATIC ${PERFETTO_SDK_DIR}/perfetto.cc)
target_include_directories(perfetto_sdk PUBLIC
$<BUILD_INTERFACE:${PERFETTO_SDK_DIR}>
$<INSTALL_INTERFACE:include/perfetto>
)
target_compile_options(perfetto_sdk PRIVATE
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
-Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers>
)
install(TARGETS perfetto_sdk EXPORT jana2_targets DESTINATION lib)
install(FILES ${PERFETTO_SDK_DIR}/perfetto.h DESTINATION include/perfetto)
set(JANA2_HAVE_PERFETTO 1)
else()
set(JANA2_HAVE_PERFETTO 0)
endif()


#---------
# Report back to the user what we've discovered
Expand Down Expand Up @@ -178,6 +217,11 @@ if (${USE_CUDA})
else()
message(STATUS "USE_CUDA Off")
endif()
if (USE_PERFETTO)
message(STATUS "USE_PERFETTO On")
else()
message(STATUS "USE_PERFETTO Off")
endif()
if (${USE_PODIO})
message(STATUS "USE_PODIO On --> " ${podio_DIR})
else()
Expand Down
16 changes: 16 additions & 0 deletions src/libraries/JANA/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ if (NOT ${USE_XERCES})
message(STATUS "Skipping support for libJANA's JGeometryXML because USE_XERCES=Off")
endif()

# Always compiled — JPerfettoService.cc contains a JANA2_HAVE_PERFETTO==0 stub
# so it links correctly even when Perfetto support is not built in.
list(APPEND JANA2_SOURCES Services/JPerfettoService.cc)

add_library(jana2 OBJECT ${JANA2_SOURCES})

find_package(Threads REQUIRED)
Expand All @@ -74,6 +78,10 @@ target_link_libraries(jana2 PUBLIC ${CMAKE_DL_LIBS} Threads::Threads)
target_link_libraries(jana2 PRIVATE VendoredTomlPlusPlus)
target_link_libraries(jana2 PRIVATE VendoredMD5) # To pull in the header file

if (USE_PERFETTO)
target_link_libraries(jana2 PUBLIC perfetto_sdk)
endif()

if (${USE_PODIO})
target_link_libraries(jana2 PUBLIC podio::podio podio::podioRootIO)
elseif (${USE_ROOT})
Expand All @@ -89,6 +97,10 @@ target_include_directories(jana2_static_lib PUBLIC $<INSTALL_INTERFACE:include>)
target_link_libraries(jana2_static_lib PUBLIC ${CMAKE_DL_LIBS} Threads::Threads)
target_link_libraries(jana2_static_lib PUBLIC VendoredTomlPlusPlus)

if (USE_PERFETTO)
target_link_libraries(jana2_static_lib PUBLIC perfetto_sdk)
endif()

if (${USE_PODIO})
target_link_libraries(jana2_static_lib PUBLIC podio::podio podio::podioRootIO)
elseif (${USE_ROOT})
Expand All @@ -105,6 +117,10 @@ target_include_directories(jana2_shared_lib PUBLIC $<INSTALL_INTERFACE:include>)
target_link_libraries(jana2_shared_lib PUBLIC ${CMAKE_DL_LIBS} Threads::Threads)
target_link_libraries(jana2_shared_lib PUBLIC VendoredTomlPlusPlus)

if (USE_PERFETTO)
target_link_libraries(jana2_shared_lib PUBLIC perfetto_sdk)
endif()

if (${USE_PODIO})
target_link_libraries(jana2_shared_lib PUBLIC podio::podio podio::podioRootIO)
elseif (${USE_ROOT})
Expand Down
16 changes: 15 additions & 1 deletion src/libraries/JANA/Engine/JExecutionEngine.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

#include "JExecutionEngine.h"
#include <JANA/Utils/JApplicationInspector.h>
#include <JANA/JVersion.h>

#if JANA2_HAVE_PERFETTO
#include <JANA/Services/JPerfettoService.h>
#endif

#include <chrono>
#include <cstddef>
Expand Down Expand Up @@ -416,12 +421,21 @@ void JExecutionEngine::RunWorker(Worker worker) {
LOG_DEBUG(GetLogger()) << "Launched worker thread " << worker.worker_id << LOG_END;
jana2_worker_id = worker.worker_id;
jana2_worker_backtrace = worker.backtrace;
#if JANA2_HAVE_PERFETTO
JPerfettoService::RegisterCurrentThread(worker.worker_id);
#endif
try {
Task task;
while (true) {
ExchangeTask(task, worker.worker_id);
if (task.arrow == nullptr) break; // Exit as soon as ExchangeTask() stops blocking
task.arrow->Fire(task.input_event, task.outputs, task.output_count, task.status);
{
#if JANA2_HAVE_PERFETTO
TRACE_EVENT("jana", perfetto::DynamicString{task.arrow->GetName()},
"worker_id", (uint64_t)worker.worker_id);
#endif
task.arrow->Fire(task.input_event, task.outputs, task.output_count, task.status);
}
}
LOG_DEBUG(GetLogger()) << "Stopped worker thread " << worker.worker_id << LOG_END;
}
Expand Down
Loading
Loading