diff --git a/CMakeLists.txt b/CMakeLists.txt index 650352690..f79f1e5b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,11 @@ option(NS3_MONOLIB ) option(NS3_MPI "Build with MPI support" OFF) option(NS3_NATIVE_OPTIMIZATIONS "Build with -march=native -mtune=native" OFF) +option( + NS3_NINJA_TRACING + "Use ninjatracing to convert Ninja's build log to the about://tracing format" + OFF +) set(NS3_OUTPUT_DIRECTORY "" CACHE STRING "Directory to store built artifacts") option(NS3_PRECOMPILE_HEADERS "Precompile module headers to speed up compilation" ON diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 54eded8a0..f62125ef0 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -876,6 +876,37 @@ macro(process_options) endif() endif() + if(${NS3_NINJA_TRACING}) + if(${CMAKE_GENERATOR} STREQUAL Ninja) + include(ExternalProject) + ExternalProject_Add( + NinjaTracing + GIT_REPOSITORY "https://github.com/nico/ninjatracing.git" + GIT_TAG "f9d21e973cfdeafa913b83a927fef56258f70b9a" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + ) + ExternalProject_Get_Property(NinjaTracing SOURCE_DIR) + set(embed_time_trace) + if(${NS3_CLANG_TIMETRACE} AND ${CLANG}) + set(embed_time_trace --embed-time-trace) + endif() + add_custom_target( + ninjaTrace + COMMAND + ${Python3_EXECUTABLE} ${SOURCE_DIR}/ninjatracing -a + ${embed_time_trace} ${PROJECT_BINARY_DIR}/.ninja_log > + ${PROJECT_SOURCE_DIR}/ninja_performance_trace.json + DEPENDS NinjaTracing + ) + unset(embed_time_trace) + unset(SOURCE_DIR) + else() + message(FATAL_ERROR "Ninjatracing requires the Ninja generator") + endif() + endif() + # Disable the below warning from bindings built in debug mode with clang++: # "expression with side effects will be evaluated despite being used as an # operand to 'typeid'" diff --git a/ns3 b/ns3 index 925f2e6c1..a11662a6d 100755 --- a/ns3 +++ b/ns3 @@ -142,6 +142,7 @@ def parse_args(argv): ("logs", "the logs regardless of the compile mode"), ("monolib", "a single shared library with all ns-3 modules"), ("mpi", "the MPI support for distributed simulation"), + ("ninja-tracing", "the conversion of the Ninja generator log file into about://tracing format"), ("precompiled-headers", "precompiled headers"), ("python-bindings", "python bindings"), ("tests", "the ns-3 tests"), @@ -583,6 +584,7 @@ def configure_cmake(cmake, args, current_cmake_cache_folder, current_cmake_gener ("LOG", "logs"), ("MONOLIB", "monolib"), ("MPI", "mpi"), + ("NINJA_TRACING", "ninja_tracing"), ("PRECOMPILE_HEADERS", "precompiled_headers"), ("PYTHON_BINDINGS", "python_bindings"), ("SANITIZE", "sanitizers"), @@ -979,6 +981,7 @@ def build_step(args, "sphinx", "manual", "models", + "ninjaTrace", "timeTraceReport", "tutorial", "contributing",