Last active
October 6, 2022 17:16
-
-
Save Trass3r/8aefa4ae8526856fb7c65525b5e50b0c to your computer and use it in GitHub Desktop.
get statistics on preprocessed C++ code size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -eux | |
cd /build/ | |
ninja -k0 | |
export CCACHE_DISABLE=1 | |
# fix CMake deps: https://gitlab.kitware.com/cmake/cmake/-/issues/15555 | |
sed -ri 's/(build .+?\.cpp\.o: .+?) \|\| \S+depends\S+/\1/g' build.ninja | |
# produce preprocessed sources without #line markers | |
# -fdirectives-only only available in clang 15+ | |
sed -i 's/\$out -c \$in/$out.i -E -P $in/' CMakeFiles/rules.ninja | |
# ninja -t commands xxx.cpp.o | |
# ninja -v xxx.cpp.o | |
# build all object files | |
ninja $(ninja -t targets | cut -d: -f1 | grep -E '.cpp.o$' | tr '\n' ' ') | |
# count per-file lines | tokens | bytes | |
find -name '*.i' | xargs wc -mwl | |
# size of preprocessed code | |
find -name '*.i' -exec du -ch {} + | |
# count sum of lines | tokens | bytes | |
find -name '*.i' -exec cat {} + | wc -mwl | |
# non-empty lines | |
find -name '*.i' -exec cat {} + | grep -cv ^$ | |
find -name '*.i' -exec rm {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment