From 910dafbb85952815e4b8f36f86ecae0050f36b9f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 24 Nov 2020 11:04:19 -0800 Subject: [PATCH] configure: Improve profile build related. --- configure.ac | 39 ++++++++++++++++++++++++++++++++------- construct/Makefile.am | 6 ++++++ ircd/Makefile.am | 27 +++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 84923902a..c93ae7a75 100644 --- a/configure.ac +++ b/configure.ac @@ -381,30 +381,54 @@ dnl dnl Profiling mode dnl -AC_MSG_CHECKING(whether to do a profile build) -AC_ARG_ENABLE(profile, RB_HELP_STRING([--enable-profile], [Enable profiling]), +AC_MSG_CHECKING(whether to instrument build for runtime profile generation) +AC_ARG_ENABLE(profile, RB_HELP_STRING([--enable-profile], [Generate profile at runtime]), [ profiling="yes" + AC_DEFINE(CHARYBDIS_PROFILE, 1, [Define this if you are profiling.]) + AM_COND_IF(GCC, [ AC_MSG_RESULT([yes, adding -pg]) RB_VAR_PREPEND([CXXFLAGS], ["-pg"]) - AC_DEFINE(CHARYBDIS_PROFILE, 1, [Define this if you are profiling.]) ]) AM_COND_IF(CLANG, [ AC_MSG_RESULT([yes, adding profiling flags]) - RB_VAR_PREPEND([CXXFLAGS], ["-fprofile-instr-generate"]) - RB_VAR_PREPEND([CXXFLAGS], ["-fcoverage-mapping"]) - RB_VAR_PREPEND([LDFLAGS], ["-fprofile-instr-generate"]) - AC_DEFINE(CHARYBDIS_PROFILE, 1, [Define this if you are profiling.]) + + #RB_VAR_PREPEND([CXXFLAGS], ["-fprofile-generate"]) + #RB_VAR_PREPEND([LDFLAGS], ["-Wl,-fprofile-generate"]) + + dnl TODO: $enableval=instr? + dnl RB_VAR_PREPEND([CXXFLAGS], ["-fprofile-instr-generate"]) + dnl RB_VAR_PREPEND([CXXFLAGS], ["-fcoverage-mapping"]) + dnl RB_VAR_PREPEND([LDFLAGS], ["-Wl,-fprofile-instr-generate"]) ]) + ], [ AC_MSG_RESULT([no]) profiling="no" ]) +AC_MSG_CHECKING(whether to use a specific runtime profile) +AC_ARG_WITH(profile, RB_HELP_STRING([--with-profile[[[=$PWD]]]], [Path to profdata]), +[ + profiling_use=$withval + AC_MSG_RESULT([yes, "$profiling_use"]) + AC_SUBST(PROFILE_USE, $profiling_use) + +dnl AM_COND_IF(CLANG, +dnl [ +dnl RB_VAR_PREPEND([CXXFLAGS], [-fprofile-use="$profiling_use"]) +dnl ]) + +], [ + AC_MSG_RESULT([no]) +]) + +AM_CONDITIONAL([PROFILE], [[[[ "$profiling" = "yes" ]]]]) + dnl dnl Precompiled headers dnl @@ -2593,6 +2617,7 @@ echo "Developer profiling ............... $profiling" echo "Precompiled headers ............... $build_pch" echo "Optimized compile ................. $optimize" echo "Optimized linking ................. $lto" +echo "Optimized runtime ................. $profiling_used" echo "Optimization level ................ $optimize_level" echo "Machine tuned ..................... $machine_tuning" echo diff --git a/construct/Makefile.am b/construct/Makefile.am index 2db4f8da0..e94fec890 100644 --- a/construct/Makefile.am +++ b/construct/Makefile.am @@ -36,6 +36,12 @@ AM_LDFLAGS = \ $(EXTRA_LDFLAGS) \ ### +if PROFILE +if CLANG +AM_CXXFLAGS += -fprofile-generate +endif +endif + bin_PROGRAMS = construct construct_LDFLAGS = \ diff --git a/ircd/Makefile.am b/ircd/Makefile.am index 38cbcdcf7..232a15ec2 100644 --- a/ircd/Makefile.am +++ b/ircd/Makefile.am @@ -61,6 +61,18 @@ AM_LDFLAGS += -Wl,--enable-runtime-pseudo-reloc AM_LDFLAGS += -export-symbols-regex '*' endif +if PROFILE +if CLANG +AM_CXXFLAGS += -fprofile-generate +AM_LDFLAGS += -Wl,-fprofile-generate +#TODO: XXX +#AM_CXXFLAGS += -fprofile-instr-generate +#AM_CXXFLAGS += -fcoverage-mapping +#AM_LDFLAGS += -Wl,-fprofile-instr-generate +#AM_LDFLAGS += -Wl,-fcoverage-mapping +endif +endif + # # libircd # @@ -108,6 +120,13 @@ libircd_la_LIBADD = \ $(EXTRA_LIBS) \ ### +if PROFILE +if CLANG11 +#TODO: XXX +libircd_la_LIBADD += /usr/lib/llvm-11/lib/clang/11.0.0/lib/linux/libclang_rt.profile-x86_64.a +endif +endif + # # Unit list # @@ -221,6 +240,14 @@ libircd_la_SOURCES += ircd.cc # Specific unit configurations # +if CLANG +if !PROFILE +if !DEBUG +SPIRIT_UNIT_CXXFLAGS += -fprofile-use +endif +endif +endif + client.lo: AM_CPPFLAGS := ${ASIO_UNIT_CPPFLAGS} ${AM_CPPFLAGS} ctx_x86_64.lo: AM_CPPFLAGS := -I$(top_srcdir)/include ctx.lo: AM_CPPFLAGS := ${ASIO_UNIT_CPPFLAGS} ${AM_CPPFLAGS}