Index: configure
===================================================================
--- configure	(revision 8f194eeed15a35479c863bbeb0bdd3e9154c5a35)
+++ configure	(revision 114936a6f7965d93d3969bca38c3a9dbbc748d3e)
@@ -637,4 +637,8 @@
 LIBOBJS
 CFA_BACKEND_CC
+WITH_LIBTCMALLOC_FALSE
+WITH_LIBTCMALLOC_TRUE
+WITH_LIBPROFILER_FALSE
+WITH_LIBPROFILER_TRUE
 WITH_LIBFIBRE_FALSE
 WITH_LIBFIBRE_TRUE
@@ -16657,4 +16661,106 @@
 
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ProfilingIsEnabledForAllThreads in -lprofiler" >&5
+$as_echo_n "checking for ProfilingIsEnabledForAllThreads in -lprofiler... " >&6; }
+if ${ac_cv_lib_profiler_ProfilingIsEnabledForAllThreads+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lprofiler  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ProfilingIsEnabledForAllThreads ();
+int
+main ()
+{
+return ProfilingIsEnabledForAllThreads ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_profiler_ProfilingIsEnabledForAllThreads=yes
+else
+  ac_cv_lib_profiler_ProfilingIsEnabledForAllThreads=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_profiler_ProfilingIsEnabledForAllThreads" >&5
+$as_echo "$ac_cv_lib_profiler_ProfilingIsEnabledForAllThreads" >&6; }
+if test "x$ac_cv_lib_profiler_ProfilingIsEnabledForAllThreads" = xyes; then :
+  HAVE_LIBPROFILER=1
+else
+  HAVE_LIBPROFILER=0
+fi
+
+ if test "$HAVE_LIBPROFILER" -eq 1; then
+  WITH_LIBPROFILER_TRUE=
+  WITH_LIBPROFILER_FALSE='#'
+else
+  WITH_LIBPROFILER_TRUE='#'
+  WITH_LIBPROFILER_FALSE=
+fi
+
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for malloc in -ltcmalloc" >&5
+$as_echo_n "checking for malloc in -ltcmalloc... " >&6; }
+if ${ac_cv_lib_tcmalloc_malloc+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-ltcmalloc  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char malloc ();
+int
+main ()
+{
+return malloc ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_tcmalloc_malloc=yes
+else
+  ac_cv_lib_tcmalloc_malloc=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_tcmalloc_malloc" >&5
+$as_echo "$ac_cv_lib_tcmalloc_malloc" >&6; }
+if test "x$ac_cv_lib_tcmalloc_malloc" = xyes; then :
+  HAVE_LIBTCMALLOC=1
+else
+  HAVE_LIBTCMALLOC=0
+fi
+
+ if test "$HAVE_LIBTCMALLOC" -eq 1; then
+  WITH_LIBTCMALLOC_TRUE=
+  WITH_LIBTCMALLOC_FALSE='#'
+else
+  WITH_LIBTCMALLOC_TRUE='#'
+  WITH_LIBTCMALLOC_FALSE=
+fi
+
+
 # Checks for header files.
 for ac_header in libintl.h malloc.h unistd.h
@@ -16889,4 +16995,12 @@
 if test -z "${WITH_LIBFIBRE_TRUE}" && test -z "${WITH_LIBFIBRE_FALSE}"; then
   as_fn_error $? "conditional \"WITH_LIBFIBRE\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${WITH_LIBPROFILER_TRUE}" && test -z "${WITH_LIBPROFILER_FALSE}"; then
+  as_fn_error $? "conditional \"WITH_LIBPROFILER\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${WITH_LIBTCMALLOC_TRUE}" && test -z "${WITH_LIBTCMALLOC_FALSE}"; then
+  as_fn_error $? "conditional \"WITH_LIBTCMALLOC\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
Index: configure.ac
===================================================================
--- configure.ac	(revision 8f194eeed15a35479c863bbeb0bdd3e9154c5a35)
+++ configure.ac	(revision 114936a6f7965d93d3969bca38c3a9dbbc748d3e)
@@ -190,4 +190,10 @@
 AM_CONDITIONAL([WITH_LIBFIBRE], [test "$HAVE_LIBFIBRE" -eq 1])
 
+AC_CHECK_LIB([profiler], [ProfilingIsEnabledForAllThreads], [HAVE_LIBPROFILER=1], [HAVE_LIBPROFILER=0])
+AM_CONDITIONAL([WITH_LIBPROFILER], [test "$HAVE_LIBPROFILER" -eq 1])
+
+AC_CHECK_LIB([tcmalloc], [malloc], [HAVE_LIBTCMALLOC=1], [HAVE_LIBTCMALLOC=0])
+AM_CONDITIONAL([WITH_LIBTCMALLOC], [test "$HAVE_LIBTCMALLOC" -eq 1])
+
 # Checks for header files.
 AC_CHECK_HEADERS([libintl.h malloc.h unistd.h], [], [echo "Error: Missing required header"; exit 1])
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(revision 8f194eeed15a35479c863bbeb0bdd3e9154c5a35)
+++ src/Makefile.am	(revision 114936a6f7965d93d3969bca38c3a9dbbc748d3e)
@@ -56,4 +56,12 @@
 ___driver_cfa_cpp_LDADD = -ldl			# yywrap
 
+if WITH_LIBPROFILER
+	___driver_cfa_cpp_LDADD += -lprofiler
+endif
+
+if WITH_LIBTCMALLOC
+	___driver_cfa_cpp_LDADD += -ltcmalloc
+endif
+
 AM_CXXFLAGS = @HOST_FLAGS@ -Wno-deprecated -Wall -Wextra -DDEBUG_ALL -I./Parser -I$(srcdir)/Parser -I$(srcdir)/include -DYY_NO_INPUT -O2 -g -std=c++14
 AM_LDFLAGS  = @HOST_FLAGS@ -Xlinker -export-dynamic
Index: src/Makefile.in
===================================================================
--- src/Makefile.in	(revision 8f194eeed15a35479c863bbeb0bdd3e9154c5a35)
+++ src/Makefile.in	(revision 114936a6f7965d93d3969bca38c3a9dbbc748d3e)
@@ -1526,4 +1526,8 @@
 	@rm BasicTypes-gen
 
+@WITH_LIBPROFILER_TRUE@	___driver_cfa_cpp_LDADD += -lprofiler
+
+@WITH_LIBTCMALLOC_TRUE@	___driver_cfa_cpp_LDADD += -ltcmalloc
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
