From 58ba255e29bad8a3d7e660620d9b0201c42a3fdc Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 22 Mar 2016 15:59:15 +0000 Subject: Add Google Perf Tools build. "make build=gperf" will now build and link the google perf tools library into mutool. When mutool is then run, a mutool.prof file is dropped into the current directory that can be analysed. --- Makerules | 3 +++ source/tools/mutool.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Makerules b/Makerules index f9f2b06f..c73d8242 100644 --- a/Makerules +++ b/Makerules @@ -32,6 +32,9 @@ ifeq "$(HAVE_LIBDL)" "yes" CFLAGS += -DHAVE_LIBDL LIBS += -ldl endif +else ifeq "$(build)" "gperf" +CFLAGS += -pipe -O2 -DNDEBUG -fomit-frame-pointer -DGPERF +LIBS += -lprofiler else $(error unknown build setting: '$(build)') endif diff --git a/source/tools/mutool.c b/source/tools/mutool.c index 6d2cfa40..1f163b21 100644 --- a/source/tools/mutool.c +++ b/source/tools/mutool.c @@ -41,12 +41,30 @@ namematch(const char *end, const char *start, const char *match) return ((end-len >= start) && (strncmp(end-len, match, len) == 0)); } +#ifdef GPERF +#include "gperftools/profiler.h" + +static int profiled_main(int argc, char **argv); + +int main(int argc, char **argv) +{ + int ret; + ProfilerStart("mutool.prof"); + ret = profiled_main(argc, argv); + ProfilerStop(); + return ret; +} + +static int profiled_main(int argc, char **argv) +#else int main(int argc, char **argv) +#endif { char *start, *end; char buf[32]; int i; + if (argc == 0) { fprintf(stderr, "No command name found!\n"); -- cgit v1.2.3