Skip to content

Commit 8e3cac5

Browse files
committed
[build] Support the CPU profiler in gperftools
Enabled by ./configure --enable-profile=gperftools See also https://gperftools.github.io/gperftools/cpuprofile.html
1 parent a2acd31 commit 8e3cac5

File tree

2 files changed

+68
-26
lines changed

2 files changed

+68
-26
lines changed

configure.ac

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ case $host_cpu in
174174
;;
175175
esac
176176

177-
# Check for C compiler vendor. we assume that all compilers (CC, CXX, MPICC and
178-
# MPICXX) have the same vender and the same version.
177+
# Check for C compiler vendor. We assume that all compilers (CC, CXX, MPICC and
178+
# MPICXX) have the same vender and the same version. Clang most likely works
179+
# as GCC.
179180
vendors="
180181
intel: __ICC,__ECC,__INTEL_COMPILER
181182
gnu: __GNUC__
@@ -679,17 +680,20 @@ AC_SUBST([MPI_STATIC_LDFLAGS])
679680
# Check for native/universal build
680681
AC_ARG_ENABLE([native],
681682
[AS_HELP_STRING([--enable-native],
682-
[tune for the compiling machine (release versions) @<:@default=check@:>@])],
683+
[tune for the compiling machine (release versions) @<:@default=yes@:>@])],
683684
[AS_IF([test "x$enableval" = xno || test "x$cross_compiling" = xyes],
684685
[enable_native=no], [enable_native=yes])],
685686
[enable_native=yes])
686687

687688
# Check for profiling option
688689
AC_ARG_ENABLE([profile],
689-
[AS_HELP_STRING([--enable-profile],
690-
[build with profiling (release versions) @<:@default=no@:>@])],
690+
[AS_HELP_STRING([--enable-profile@<:@=PROFILER@:>@],
691+
[build with profiling (release versions) @<:@default=no@:>@ PROFILER: gprof (default) or gperftools])],
691692
[AS_IF([test "x$enableval" = xyes],
692-
[enable_profile=yes], [enable_profile=no])],
693+
[enable_profile=gprof],
694+
[AS_IF([test "x$enableval" = xgprof || test "x$enableval" = xgperftools],
695+
[enable_profile=$enableval],
696+
[enable_profile=no])])],
693697
[enable_profile=no])
694698

695699
# Check for coverage option
@@ -703,7 +707,7 @@ AC_ARG_ENABLE([coverage],
703707
# Check for sanitizers
704708
AC_ARG_ENABLE([sanitize],
705709
[AS_HELP_STRING([--enable-sanitize@<:@=CHECKS@:>@],
706-
[enable sanitizers (debugging versions) @<:@default=no@:>@])],
710+
[enable sanitizers (debugging versions) @<:@default=no@:>@ Optionally CHECKS will be passed via the compiler sanitizer option])],
707711
[AS_IF([test "x$enable_debug" != xyes],
708712
[enable_sanitize=no])],
709713
[enable_sanitize=no])
@@ -713,13 +717,15 @@ AC_ARG_VAR([COMPILEFLAGS], [Compiler flags for release versions])
713717
AC_ARG_VAR([LINKFLAGS], [Linker flags for release versions])
714718
AC_ARG_VAR([DEBUGCOMPILEFLAGS], [Compiler flags for debugging versions])
715719
AC_ARG_VAR([DEBUGLINKFLAGS], [Linker flags for debugging versions])
720+
TOOL_LIBS=
721+
DEBUGTOOL_LIBS=
716722

717723
my_test_COMPILEFLAGS=${COMPILEFLAGS+set}
718724
if test "$my_test_COMPILEFLAGS" != set; then
719725
if test "x$vendor" = xgnu; then
720726
# We don't use -pedantic option because of horrible warnings.
721727
COMPILEFLAGS="-Wall -Wextra -Wpadded -O3"
722-
if test "x$enable_profile" != xyes; then
728+
if test "x$enable_profile" != xgprof; then
723729
# -pg conflicts with -fomit-frame-pointer.
724730
COMPILEFLAGS="$COMPILEFLAGS -fomit-frame-pointer"
725731
fi
@@ -746,19 +752,26 @@ if test "$my_test_COMPILEFLAGS" != set; then
746752
fi
747753
fi
748754
# Profiling option.
749-
if test "x$enable_profile" = xyes; then
755+
if test "x$enable_profile" = xgprof; then
750756
COMPILEFLAGS="$COMPILEFLAGS -g -pg"
757+
elif test "x$enable_profile" = xgperftools; then
758+
COMPILEFLAGS="$COMPILEFLAGS -g"
759+
TOOL_LIBS="$TOOL_LIBS -lprofiler"
751760
fi
752761
elif test "x$vendor" = xintel; then
753762
# NOTE: -fast option includes -static and may cause an error in linking.
754763
COMPILEFLAGS="-Wall -ipo -O3 -no-prec-div"
755764
if test "x$enable_native" = xyes; then
756765
COMPILEFLAGS="$COMPILEFLAGS -xHost"
757766
fi
758-
enable_profile=false
767+
if test "x$enable_profile" != xno; then
768+
enable_profile=unavailable
769+
fi
759770
else
760771
COMPILEFLAGS=-O2
761-
enable_profile=false
772+
if test "x$enable_profile" != xno; then
773+
enable_profile=unavailable
774+
fi
762775
fi
763776
fi
764777
my_test_LINKFLAGS=${LINKFLAGS+set}
@@ -768,8 +781,8 @@ if test "$my_test_LINKFLAGS" != set; then
768781
# warns the option is obsolete and being ignored, it causes an internal
769782
# error "atom not found in symbolIndex...".
770783
LINKFLAGS=
771-
elif test "x$vendor" = xgnu && test "x$enable_profile" = xyes; then
772-
# gprof doesn't work with -s.
784+
elif test "x$enable_profile" != xno && test "x$enable_profile" != xunavailable; then
785+
# Profilers needs symbol tables.
773786
LINKFLAGS=
774787
else
775788
LINKFLAGS=-s
@@ -843,12 +856,20 @@ if test "$my_test_DEBUGCOMPILEFLAGS" != set && test "x$enable_debug" = xyes; the
843856
fi
844857
elif test "x$vendor" = xintel; then
845858
DEBUGCOMPILEFLAGS='-g3 -Wall -O0'
846-
enable_coverage=no
847-
enable_sanitize=no
859+
if test "x$enable_coverage" != xno; then
860+
enable_coverage=unavailable
861+
fi
862+
if test "x$enable_sanitize" != xno; then
863+
enable_sanitize=unavailable
864+
fi
848865
else
849866
DEBUGCOMPILEFLAGS=-g
850-
enable_coverage=no
851-
enable_sanitize=no
867+
if test "x$enable_coverage" != xno; then
868+
enable_coverage=unavailable
869+
fi
870+
if test "x$enable_sanitize" != xno; then
871+
enable_sanitize=unavailable
872+
fi
852873
fi
853874
fi
854875
my_test_DEBUGLINKFLAGS=${DEBUGLINKFLAGS+set}
@@ -880,6 +901,9 @@ if test "$my_test_DEBUGLINKFLAGS" != set && test "x$enable_debug" = xyes; then
880901
fi
881902
fi
882903

904+
AC_SUBST([TOOL_LIBS])
905+
AC_SUBST([DEBUGTOOL_LIBS])
906+
883907
# Check for doxygen
884908
AC_PATH_PROG(DOXYGEN, doxygen, "")
885909
AM_CONDITIONAL(CONFIG_DOXYGEN, [test "x$DOXYGEN" != x])
@@ -977,12 +1001,18 @@ if test "x$build_form" = xyes; then
9771001
fi
9781002
opts="${opts}statically linked"
9791003
fi
980-
if test "x$enable_profile" = xyes; then
1004+
if test "x$enable_profile" = xgprof; then
9811005
if test "x$opts" != x; then
9821006
opts="${opts}, "
9831007
fi
9841008
opts="${opts}gprof"
9851009
fi
1010+
if test "x$enable_profile" = xgperftools; then
1011+
if test "x$opts" != x; then
1012+
opts="${opts}, "
1013+
fi
1014+
opts="${opts}gperftools"
1015+
fi
9861016
if test "x$opts" != x; then
9871017
opts=" (${opts})"
9881018
fi
@@ -1023,12 +1053,18 @@ if test "x$build_tform" = xyes; then
10231053
fi
10241054
opts="${opts}statically linked"
10251055
fi
1026-
if test "x$enable_profile" = xyes; then
1056+
if test "x$enable_profile" = xgprof; then
10271057
if test "x$opts" != x; then
10281058
opts="${opts}, "
10291059
fi
10301060
opts="${opts}gprof"
10311061
fi
1062+
if test "x$enable_profile" = xgperftools; then
1063+
if test "x$opts" != x; then
1064+
opts="${opts}, "
1065+
fi
1066+
opts="${opts}gperftools"
1067+
fi
10321068
if test "x$opts" != x; then
10331069
opts=" (${opts})"
10341070
fi
@@ -1069,12 +1105,18 @@ if test "x$build_parform" = xyes; then
10691105
fi
10701106
opts="${opts}statically linked"
10711107
fi
1072-
if test "x$enable_profile" = xyes; then
1108+
if test "x$enable_profile" = xgprof; then
10731109
if test "x$opts" != x; then
10741110
opts="${opts}, "
10751111
fi
10761112
opts="${opts}gprof"
10771113
fi
1114+
if test "x$enable_profile" = xgperftools; then
1115+
if test "x$opts" != x; then
1116+
opts="${opts}, "
1117+
fi
1118+
opts="${opts}gperftools"
1119+
fi
10781120
if test "x$opts" != x; then
10791121
opts=" (${opts})"
10801122
fi

sources/Makefile.am

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ form_CPPFLAGS =
135135
form_CFLAGS = $(COMPILEFLAGS)
136136
form_CXXFLAGS = $(COMPILEFLAGS)
137137
form_LDFLAGS = $(LINKFLAGS) $(STATIC_LDFLAGS)
138-
form_LDADD =
138+
form_LDADD = $(TOOL_LIBS)
139139
if AUTOMAKE_GE_110
140140
form_LINK = $(CXXLD) $(form_CXXFLAGS) $(CXXFLAGS) $(form_LDFLAGS) $(LDFLAGS) -o $@
141141
else
@@ -150,7 +150,7 @@ vorm_CPPFLAGS = -DDEBUGGING
150150
vorm_CFLAGS = $(DEBUGCOMPILEFLAGS)
151151
vorm_CXXFLAGS = $(DEBUGCOMPILEFLAGS)
152152
vorm_LDFLAGS = $(DEBUGLINKFLAGS)
153-
vorm_LDADD =
153+
vorm_LDADD = $(DEBUGTOOL_LIBS)
154154
if AUTOMAKE_GE_110
155155
vorm_LINK = $(CXXLD) $(vorm_CXXFLAGS) $(CXXFLAGS) $(vorm_LDFLAGS) $(LDFLAGS) -o $@
156156
else
@@ -165,7 +165,7 @@ tform_CPPFLAGS = -DWITHPTHREADS $(PTHREAD_CPPFLAGS)
165165
tform_CFLAGS = $(COMPILEFLAGS) $(PTHREAD_CFLAGS)
166166
tform_CXXFLAGS = $(COMPILEFLAGS) $(PTHREAD_CFLAGS)
167167
tform_LDFLAGS = $(LINKFLAGS) $(STATIC_LDFLAGS)
168-
tform_LDADD = $(PTHREAD_LIBS)
168+
tform_LDADD = $(PTHREAD_LIBS) $(TOOL_LIBS)
169169
if AUTOMAKE_GE_110
170170
tform_LINK = $(CXXLD) $(tform_CXXFLAGS) $(CXXFLAGS) $(tform_LDFLAGS) $(LDFLAGS) -o $@
171171
else
@@ -180,7 +180,7 @@ tvorm_CPPFLAGS = -DWITHPTHREADS -DDEBUGGING $(PTHREAD_CPPFLAGS)
180180
tvorm_CFLAGS = $(DEBUGCOMPILEFLAGS) $(PTHREAD_CFLAGS)
181181
tvorm_CXXFLAGS = $(DEBUGCOMPILEFLAGS) $(PTHREAD_CFLAGS)
182182
tvorm_LDFLAGS = $(DEBUGLINKFLAGS)
183-
tvorm_LDADD = $(PTHREAD_LIBS)
183+
tvorm_LDADD = $(PTHREAD_LIBS) $(DEBUGTOOL_LIBS)
184184
if AUTOMAKE_GE_110
185185
tvorm_LINK = $(CXXLD) $(tvorm_CXXFLAGS) $(CXXFLAGS) $(tvorm_LDFLAGS) $(LDFLAGS) -o $@
186186
else
@@ -195,7 +195,7 @@ parform_CPPFLAGS = -DWITHMPI -DPF_WITHGETENV -DPF_WITHLOG $(MPI_CPPFLAGS)
195195
parform_CFLAGS = $(COMPILEFLAGS) $(MPI_CFLAGS)
196196
parform_CXXFLAGS = $(COMPILEFLAGS) $(MPI_CXXFLAGS)
197197
parform_LDFLAGS = $(LINKFLAGS) $(MPI_STATIC_LDFLAGS)
198-
parform_LDADD =
198+
parform_LDADD = $(TOOL_LIBS)
199199
if AUTOMAKE_GE_110
200200
parform_LINK = $(MPICXX) $(parform_CXXFLAGS) $(CXXFLAGS) $(parform_LDFLAGS) $(LDFLAGS) -o $@
201201
else
@@ -210,7 +210,7 @@ parvorm_CPPFLAGS = -DWITHMPI -DPF_WITHGETENV -DPF_WITHLOG -DDEBUGGING $(MPI_CPPF
210210
parvorm_CFLAGS = $(DEBUGCOMPILEFLAGS) $(MPI_CFLAGS)
211211
parvorm_CXXFLAGS = $(DEBUGCOMPILEFLAGS) $(MPI_CXXFLAGS)
212212
parvorm_LDFLAGS = $(DEBUGLINKFLAGS)
213-
parvorm_LDADD =
213+
parvorm_LDADD = $(DEBUGTOOL_LIBS)
214214
if AUTOMAKE_GE_110
215215
parvorm_LINK = $(MPICXX) $(parvorm_CXXFLAGS) $(CXXFLAGS) $(parvorm_LDFLAGS) $(LDFLAGS) -o $@
216216
else

0 commit comments

Comments
 (0)