From 297fafa078a8a43a4ddb693129b8e25b9d0bf618 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 15 Jan 2015 15:46:39 -0800 Subject: [PATCH 1/2] Opportunistically use perftools if installed. Allows us to collect profiles of the open source build using gprof. --- .gitignore | 13 ++++++++++--- Makefile | 7 +++++++ templates/Makefile.template | 7 +++++++ test/build/perftools.c | 7 +++++++ test/core/util/grpc_profiler.c | 9 +++++++++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 test/build/perftools.c diff --git a/.gitignore b/.gitignore index 3cae07ed12f..0bde1467656 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,15 @@ +# C/C++ build outputs bins -coverage -deps -*.gcno gens libs objs + +# gcov coverage data +coverage +*.gcno + +# profiler output +*.prof + +# python compiled objects *.pyc diff --git a/Makefile b/Makefile index b43cb734ba5..ab1ba14bb34 100644 --- a/Makefile +++ b/Makefile @@ -172,6 +172,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 25bc4069a1b..5f20bd7f35d 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -189,6 +189,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 00000000000..03548b4c7ef --- /dev/null +++ b/test/build/perftools.c @@ -0,0 +1,7 @@ +#include + +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 340b2d53b96..489d34396a4 100644 --- a/test/core/util/grpc_profiler.c +++ b/test/core/util/grpc_profiler.c @@ -33,6 +33,15 @@ #include "test/core/util/grpc_profiler.h" +#if GRPC_HAVE_PERFTOOLS +#include + +void grpc_profiler_start(const char *filename) { ProfilerStart(filename); } + +void grpc_profiler_stop() { ProfilerStop(); } +#else + void grpc_profiler_start(const char *filename) {} void grpc_profiler_stop(void) {} +#endif From 7132d51b2e833964416e28659e1d77cbe606b668 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 16 Jan 2015 09:00:12 -0800 Subject: [PATCH 2/2] Include some useful help text --- test/core/util/grpc_profiler.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/core/util/grpc_profiler.c b/test/core/util/grpc_profiler.c index 489d34396a4..46bfc1f533c 100644 --- a/test/core/util/grpc_profiler.c +++ b/test/core/util/grpc_profiler.c @@ -40,8 +40,15 @@ void grpc_profiler_start(const char *filename) { ProfilerStart(filename); } void grpc_profiler_stop() { ProfilerStop(); } #else +#include -void grpc_profiler_start(const char *filename) {} +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