diff --git a/cmake/mode.common.cmake b/cmake/mode.common.cmake index d36c20cc94..b8d3426d6d 100644 --- a/cmake/mode.common.cmake +++ b/cmake/mode.common.cmake @@ -137,6 +137,24 @@ endfunction() option(Scylla_WITH_DEBUG_INFO "Enable debug info" OFF) +# Time trace profiling: adds -ftime-trace to all C++ compilations (Clang only). +# Each .o produces a companion .json file in the build directory that can be +# analyzed with ClangBuildAnalyzer or loaded in chrome://tracing. +# +# Usage: +# cmake -DScylla_TIME_TRACE=ON ... +# ninja +# # Analyze results (requires ClangBuildAnalyzer): +# ClangBuildAnalyzer --all capture.bin +# ClangBuildAnalyzer --analyze capture.bin +option(Scylla_TIME_TRACE "Enable Clang -ftime-trace for build profiling" OFF) +if(Scylla_TIME_TRACE) + if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + message(FATAL_ERROR "Scylla_TIME_TRACE requires Clang (found ${CMAKE_CXX_COMPILER_ID})") + endif() + add_compile_options(-ftime-trace) +endif() + macro(update_build_flags config) cmake_parse_arguments ( parsed_args diff --git a/configure.py b/configure.py index 95d6f60c0b..8ee3364fd0 100755 --- a/configure.py +++ b/configure.py @@ -858,6 +858,10 @@ arg_parser.add_argument('--coverage', action = 'store_true', help = 'Compile scy arg_parser.add_argument('--build-dir', action='store', default='build', help='Build directory path') arg_parser.add_argument('--disable-precompiled-header', action='store_true', default=False, help='Disable precompiled header for scylla binary') +arg_parser.add_argument('--time-trace', action='store_true', default=False, + help='Enable Clang -ftime-trace for build profiling. ' + 'Each .o produces a .json file analyzable with ' + 'ClangBuildAnalyzer or chrome://tracing') arg_parser.add_argument('-h', '--help', action='store_true', help='show this help message and exit') args = arg_parser.parse_args() if args.help: @@ -1971,6 +1975,9 @@ user_cflags += ' -fextend-variable-liveness=none' if args.target != '': user_cflags += ' -march=' + args.target +if args.time_trace: + user_cflags += ' -ftime-trace' + for mode in modes: # Those flags are passed not only to Scylla objects, but also to libraries # that we compile ourselves.