diff --git a/.gitignore b/.gitignore index 954b3cfcc179e3ad8f9a5655e487949a114c75ef..3efc25aafb112ede07b130e699e8fcde7fed58fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,17 @@ +# C/C++ build outputs bins -coverage -deps -*.gcno gens libs objs + +# gcov coverage data +coverage +*.gcno + +# profiler output +*.prof + +# python compiled objects *.pyc # cache for run_tests.py diff --git a/Makefile b/Makefile index 4335a528a2792b79e93c69a0bb9bc1ca6a8cd23d..5af4f354279ce18637df3ea13abb3138d404e1f4 100644 --- a/Makefile +++ b/Makefile @@ -179,6 +179,13 @@ endif OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS) ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/zlib.c -lz $(LDFLAGS) +PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/perftools.c -lprofiler $(LDFLAGS) + +HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false) +ifeq ($(HAS_SYSTEM_PERFTOOLS),true) +DEFINES += GRPC_HAVE_PERFTOOLS +LIBS += profiler +endif ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false) diff --git a/templates/Makefile.template b/templates/Makefile.template index 0b94aa1073a6c6736a21b5f225eb9e92e5915bf3..b359d866acf3c6d33f0043284b3b9461bb140beb 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -196,6 +196,13 @@ endif OPENSSL_ALPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/openssl-alpn.c -lssl -lcrypto -ldl $(LDFLAGS) ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/zlib.c -lz $(LDFLAGS) +PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o /dev/null test/build/perftools.c -lprofiler $(LDFLAGS) + +HAS_SYSTEM_PERFTOOLS = $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false) +ifeq ($(HAS_SYSTEM_PERFTOOLS),true) +DEFINES += GRPC_HAVE_PERFTOOLS +LIBS += profiler +endif ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) HAS_SYSTEM_OPENSSL_ALPN = $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false) diff --git a/test/build/perftools.c b/test/build/perftools.c new file mode 100644 index 0000000000000000000000000000000000000000..03548b4c7ef198cc5a5b1eaa597360805c33a501 --- /dev/null +++ b/test/build/perftools.c @@ -0,0 +1,7 @@ +#include <gperftools/profiler.h> + +int main() { + ProfilerStart("/dev/null"); + ProfilerStop(); + return 0; +} diff --git a/test/core/util/grpc_profiler.c b/test/core/util/grpc_profiler.c index 340b2d53b96477bdfeac3207fd72985558866a92..46bfc1f533c8959edc7c6e6d231b40d528f17d40 100644 --- a/test/core/util/grpc_profiler.c +++ b/test/core/util/grpc_profiler.c @@ -33,6 +33,22 @@ #include "test/core/util/grpc_profiler.h" -void grpc_profiler_start(const char *filename) {} +#if GRPC_HAVE_PERFTOOLS +#include <gperftools/profiler.h> + +void grpc_profiler_start(const char *filename) { ProfilerStart(filename); } + +void grpc_profiler_stop() { ProfilerStop(); } +#else +#include <grpc/support/log.h> + +void grpc_profiler_start(const char *filename) { + gpr_log(GPR_DEBUG, + "You do not have google-perftools installed, profiling is disabled"); + gpr_log(GPR_DEBUG, + "To install on ubuntu: sudo apt-get install google-perftools " + "libgoogle-perftools-dev"); +} void grpc_profiler_stop(void) {} +#endif