source: git/m4/google-perftools.m4 @ 0c86ae

spielwiese
Last change on this file since 0c86ae was 0c86ae, checked in by Oleksandr Motsak <motsak@…>, 11 years ago
For profiling: use google proftools (optionally)
  • Property mode set to 100644
File size: 5.3 KB
Line 
1dnl
2dnl    Copyright 2005-2006 Intel Corporation
3dnl
4dnl    Licensed under the Apache License, Version 2.0 (the "License");
5dnl    you may not use this file except in compliance with the License.
6dnl    You may obtain a copy of the License at
7dnl
8dnl        http://www.apache.org/licenses/LICENSE-2.0
9dnl
10dnl    Unless required by applicable law or agreed to in writing, software
11dnl    distributed under the License is distributed on an "AS IS" BASIS,
12dnl    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13dnl    See the License for the specific language governing permissions and
14dnl    limitations under the License.
15dnl
16
17dnl
18dnl Autoconf support for linking with google's performace code
19dnl
20
21AC_DEFUN([AC_CONFIG_GOOGLE_PERFTOOLS], [
22
23    ac_google_perfdir='no'
24    AC_ARG_WITH(google-perftools,
25        AC_HELP_STRING([--with-google-perftools=DIR],
26            [location of a google perftools installation (default none)]),
27        ac_google_perfdir=$withval)
28
29    AC_ARG_ENABLE(google-profiling,
30                  AC_HELP_STRING([--enable-google-profiling],
31                  [compile with google profiling]),
32                  [google_profile=$enableval],
33                  [google_profile=no])
34   
35    AC_MSG_CHECKING([whether to compile with google profiling])
36    AC_MSG_RESULT($google_profile)
37
38    GOOGLE_PROFILE_ENABLED=0
39    if test $google_profile = yes ; then
40        if test $ac_google_perfdir = no ; then
41           AC_MSG_ERROR([must specify --with-google-perftools to use google profiling])
42        fi
43        GOOGLE_PROFILE_ENABLED=1
44    fi
45   
46    AC_DEFINE_UNQUOTED(GOOGLE_PROFILE_ENABLED, $GOOGLE_PROFILE_ENABLED,
47         [whether google profiling support is enabled])
48
49    dnl
50    dnl First make sure we even want it
51    dnl
52    if test "$ac_google_perfdir" = no; then
53    GOOGLE_PERFTOOLS_ENABLED=0
54    else
55
56    GOOGLE_PERFTOOLS_ENABLED=1
57    AC_DEFINE_UNQUOTED(GOOGLE_PERFTOOLS_ENABLED, 1,
58         [whether google perftools support is enabled])
59
60    dnl
61    dnl Now check if we have a cached value, unless the user specified
62    dnl something explicit with the --with-google-perf= argument, in
63    dnl which case we force it to redo the checks (i.e. ignore the
64    dnl cached values)
65    dnl
66    if test "$ac_google_perfdir" = yes -a \
67            ! "$oasys_cv_path_google_perf_h" = "" ; then
68        echo "checking for google_perf installation... (cached)"
69    else
70        AC_OASYS_FIND_GOOGLE_PERFTOOLS
71    fi
72
73    if test ! $oasys_cv_path_google_perf_h = /usr/include ; then
74        GOOGLE_PERFTOOLS_CFLAGS="-I$oasys_cv_path_google_perf_h"
75    fi
76
77    if test ! $oasys_cv_path_google_perf_lib = /usr/lib ; then
78        GOOGLE_PERFTOOLS_LDFLAGS="-L$oasys_cv_path_google_perf_lib"
79    fi
80   
81    GOOGLE_PERFTOOL_LDFLAGS="$GOOGLE_PERFTOOLS_LDFLAGS -Wl,-Bstatic -lprofiler -Wl,-Bdynamic"
82   
83    fi # GOOGLE_PERF_ENABLED
84])
85
86AC_DEFUN([AC_OASYS_FIND_GOOGLE_PERFTOOLS], [
87    oasys_cv_path_google_perf_h=
88    oasys_cv_path_google_perf_lib=
89
90    ac_save_CPPFLAGS="$CPPFLAGS"
91    ac_save_LDFLAGS="$LDFLAGS"
92    ac_save_LIBS="$LIBS"
93
94    AC_LANG_PUSH(C++)
95
96    if test "$ac_google_perfdir" = system -o \
97            "$ac_google_perfdir" = yes -o \
98            "$ac_google_perfdir" = "" ;
99    then
100        ac_google_perfincdirs="/usr/local/include \
101                               /usr/local/google-perftools/include"
102        ac_google_perflibdirs="/usr/local/lib \
103                               /usr/local/google-perftools/lib"
104    else
105        ac_google_perfincdirs="$ac_google_perfdir/include"
106        ac_google_perflibdirs="$ac_google_perfdir/lib"
107    fi
108
109    for ac_google_perfincdir in $ac_google_perfincdirs; do
110
111        CPPFLAGS="$ac_save_CPPFLAGS -I$ac_google_perfincdir"
112        LDFLAGS="$ac_save_LDFLAGS"
113        LIBS="$ac_save_LIBS"
114
115        dnl
116        dnl First check the version in the header file. If there's a match,
117        dnl fall through to the other check to make sure it links.
118        dnl If not, then we can break out of the two inner loops.
119        dnl
120        AC_MSG_CHECKING([for google perftools header profiler.h in $ac_google_perfincdir])
121        AC_LINK_IFELSE(
122          [AC_LANG_PROGRAM(
123            [
124                #include <google/profiler.h>
125            ],
126           
127            [
128            ])],
129          [
130              AC_MSG_RESULT([yes])
131              oasys_cv_path_google_perf_h=$ac_google_perfincdir
132              break
133          ],
134          [
135              AC_MSG_RESULT([no])
136              continue
137          ])
138    done
139
140    AC_LANG_POP(C++)
141
142    if test x$oasys_cv_path_google_perf_h = x ; then
143        AC_MSG_ERROR([can't find usable google perftools installation])
144    fi
145
146    AC_LANG_PUSH(C++)
147
148    for ac_google_perflibdir in $ac_google_perflibdirs; do
149
150        LDFLAGS="$ac_save_LDFLAGS -L$ac_google_perflibdir"
151        LIBS="$ac_save_LIBS -lprofiler"
152
153        AC_MSG_CHECKING([for google perftolos library libprofiler in $ac_google_perflibdir])
154        AC_LINK_IFELSE(
155          [AC_LANG_PROGRAM(
156            [
157                #include <google/profiler.h>
158            ],
159           
160            [
161                ProfilerStart("test");
162            ])],
163
164          [
165              AC_MSG_RESULT([yes])
166              oasys_cv_path_google_perf_lib=$ac_google_perflibdir
167              break
168          ],
169          [
170              AC_MSG_RESULT([no])
171          ])
172    done
173
174    CPPFLAGS="$ac_save_CPPFLAGS"
175    LDFLAGS="$ac_save_LDFLAGS"
176    LIBS="$ac_save_LIBS"
177
178    AC_LANG_POP(C++)
179
180    if test x$oasys_cv_path_google_perf_lib = x ; then
181        AC_MSG_ERROR([can't find usable google perftools library])
182    fi
183])
Note: See TracBrowser for help on using the repository browser.