Skip to content

Commit

Permalink
Merge pull request grpc#70 from ctiller/benchmark
Browse files Browse the repository at this point in the history
Opportunistically use perftools if installed.
  • Loading branch information
vjpai committed Jan 17, 2015
2 parents 55c3b27 + 7132d51 commit a537ae4
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
13 changes: 10 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions templates/Makefile.template
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions test/build/perftools.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <gperftools/profiler.h>

int main() {
ProfilerStart("/dev/null");
ProfilerStop();
return 0;
}
18 changes: 17 additions & 1 deletion test/core/util/grpc_profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a537ae4

Please sign in to comment.