forked from lix-project/lix
Enable clang build timing analysis
I didn't enable this by default for clang due to making the build time
10% worse or so. Unfortunate, but tbh devs for whom 10% of build time is
not *that* bad should probably simply enable this.
Change-Id: I8d1e5b6f3f76c649a4e2f115f534f7f97cee46e6
This commit is contained in:
parent
e6d371a35d
commit
663d20e6d5
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -154,3 +154,6 @@ result-*
|
|||
|
||||
# Mac OS
|
||||
.DS_Store
|
||||
|
||||
# ClangBuildAnalyzer output, see maintainers/buildtime_report.sh
|
||||
buildtime.bin
|
||||
|
|
15
doc/manual/rl-next-dev/build-timing-analysis.md
Normal file
15
doc/manual/rl-next-dev/build-timing-analysis.md
Normal file
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
synopsis: Clang build timing analysis
|
||||
cls: 587
|
||||
---
|
||||
|
||||
We now have Clang build profiling available, which generates Chrome
|
||||
tracing files for each compilation unit. To enable it, run `meson configure
|
||||
build -Dprofile-build=enabled` then rerun the compilation.
|
||||
|
||||
If you want to make the build go faster, do a clang build with meson, then run
|
||||
`maintainers/buildtime_report.sh build`, then contemplate how to improve the
|
||||
build time.
|
||||
|
||||
You can also look at individual object files' traces in
|
||||
<https://ui.perfetto.dev>.
|
|
@ -152,6 +152,7 @@
|
|||
|
||||
build-release-notes =
|
||||
final.buildPackages.callPackage ./maintainers/build-release-notes.nix { };
|
||||
clangbuildanalyzer = final.buildPackages.callPackage ./misc/clangbuildanalyzer.nix { };
|
||||
boehmgc-nix = (final.boehmgc.override {
|
||||
enableLargeConfig = true;
|
||||
}).overrideAttrs (o: {
|
||||
|
@ -360,6 +361,8 @@
|
|||
# FIXME(Qyriad): remove once the migration to Meson is complete.
|
||||
pkgs.buildPackages.meson
|
||||
pkgs.buildPackages.ninja
|
||||
|
||||
pkgs.buildPackages.clangbuildanalyzer
|
||||
];
|
||||
|
||||
src = null;
|
||||
|
|
20
maintainers/buildtime_report.sh
Executable file
20
maintainers/buildtime_report.sh
Executable file
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Generates a report of build time based on a meson build using -ftime-trace in
|
||||
# Clang.
|
||||
if [ $# -lt 1 ]; then
|
||||
echo "usage: $0 BUILD-DIR [filename]" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
scriptdir=$(cd "$(dirname -- "$0")" || exit ; pwd -P)
|
||||
filename=${2:-$scriptdir/../buildtime.bin}
|
||||
|
||||
if [ "$(meson introspect "$1" --buildoptions | jq -r '.[] | select(.name == "profile-build") | .value')" != enabled ]; then
|
||||
echo 'This build was not done with profile-build enabled, so cannot generate a report' >&2
|
||||
# shellcheck disable=SC2016
|
||||
echo 'Run `meson configure build -Dprofile-build=enabled` then rebuild, first' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ClangBuildAnalyzer --all "$1" "$filename" && ClangBuildAnalyzer --analyze "$filename"
|
|
@ -307,6 +307,14 @@ if cxx.get_linker_id() in ['ld.bfd', 'ld.gold']
|
|||
add_project_link_arguments('-Wl,--no-copy-dt-needed-entries', language : 'cpp')
|
||||
endif
|
||||
|
||||
# Generate Chromium tracing files for each compiled file, which enables
|
||||
# maintainers/buildtime_report.sh BUILD-DIR to simply work in clang builds.
|
||||
#
|
||||
# They can also be manually viewed at https://ui.perfetto.dev
|
||||
if get_option('profile-build').require(meson.get_compiler('cpp').get_id() == 'clang').enabled()
|
||||
add_project_arguments('-ftime-trace', language: 'cpp')
|
||||
endif
|
||||
|
||||
subdir('src')
|
||||
if enable_tests
|
||||
subdir('tests/unit')
|
||||
|
|
|
@ -31,6 +31,10 @@ option('tests-brief', type : 'boolean', value : false,
|
|||
description : 'set to true for shorter tests output',
|
||||
)
|
||||
|
||||
option('profile-build', type : 'feature', value: 'disabled',
|
||||
description : 'whether to enable -ftime-trace in clang builds, allowing for speeding up the build.'
|
||||
)
|
||||
|
||||
option('store-dir', type : 'string', value : '/nix/store',
|
||||
description : 'path of the Nix store',
|
||||
)
|
||||
|
|
27
misc/clangbuildanalyzer.nix
Normal file
27
misc/clangbuildanalyzer.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
# Upstreaming here, can be deleted once it's upstreamed:
|
||||
# https://github.com/NixOS/nixpkgs/pull/297102
|
||||
{ stdenv, lib, cmake, fetchFromGitHub }:
|
||||
stdenv.mkDerivation (finalAttrs: {
|
||||
pname = "clangbuildanalyzer";
|
||||
version = "1.5.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "aras-p";
|
||||
repo = "ClangBuildAnalyzer";
|
||||
rev = "v${finalAttrs.version}";
|
||||
sha256 = "sha256-kmgdk634zM0W0OoRoP/RzepArSipa5bNqdVgdZO9gxo=";
|
||||
};
|
||||
|
||||
nativeBuildInputs = [
|
||||
cmake
|
||||
];
|
||||
|
||||
meta = {
|
||||
description = "Tool for analyzing Clang's -ftrace-time files";
|
||||
homepage = "https://github.com/aras-p/ClangBuildAnalyzer";
|
||||
maintainers = with lib.maintainers; [ lf- ];
|
||||
license = lib.licenses.unlicense;
|
||||
platforms = lib.platforms.unix;
|
||||
mainProgram = "ClangBuildAnalyzer";
|
||||
};
|
||||
})
|
Loading…
Reference in a new issue