Skip to content

Commit 3011754

Browse files
greenc-FNALgithub-actions[bot]Copilot
authored
Enable compile/link time profiling (#410)
* Enable compile/link time profiling --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b2205f1 commit 3011754

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,26 @@ option(ENABLE_TSAN "Enable Thread Sanitizer" OFF)
9696
option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
9797
option(PHLEX_USE_FORM "Enable experimental integration with FORM" OFF)
9898
option(ENABLE_COVERAGE "Enable code coverage instrumentation" OFF)
99+
option(ENABLE_BUILD_PROFILING "Enable monitoring of compile and link operations" OFF)
100+
101+
# ##############################################################################
102+
# Enable collection of compile/link statistics.
103+
#
104+
# If lld is available but not default for the current toolset, then use
105+
# `-DCMAKE_LINKER_TYPE=LLD`
106+
if(ENABLE_BUILD_PROFILING)
107+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
108+
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CMAKE_COMMAND} -E time")
109+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
110+
add_compile_options("-ftime-trace")
111+
endif()
112+
if(CMAKE_CXX_COMPILER_LINKER_ID STREQUAL "LLD")
113+
message(STATUS "LLD detected (Phlex build) - Enabling tracing")
114+
add_link_options("-Wl,--time-trace")
115+
add_link_options("-Wl,--print-archive-stats=-")
116+
endif()
117+
endif()
118+
# ##############################################################################
99119

100120
add_compile_options(
101121
-Wall

0 commit comments

Comments
 (0)