From b8a150e22c484d5b79e882c7da4df88f091babc8 Mon Sep 17 00:00:00 2001 From: Yaniv Michael Kaul Date: Mon, 13 Apr 2026 18:12:45 +0300 Subject: [PATCH] build: add -ftime-trace support for compilation profiling Add a --time-trace flag to configure.py and a Scylla_TIME_TRACE CMake option that enable Clang's -ftime-trace on all C++ compilations. When enabled, each .o file produces a companion .json trace that can be analyzed with ClangBuildAnalyzer or loaded in chrome://tracing to identify slow headers and costly template instantiations. This is the first step toward data-driven build speed improvements. Refs #1 Usage: configure.py: ./configure.py --time-trace --mode dev CMake: cmake -DScylla_TIME_TRACE=ON -DCMAKE_BUILD_TYPE=Dev .. Closes scylladb/scylladb#29462 --- cmake/mode.common.cmake | 18 ++++++++++++++++++ configure.py | 7 +++++++ 2 files changed, 25 insertions(+) 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.