Skip to content

Commit

Permalink
gperftools profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
sflow committed May 31, 2023
1 parent 032af6a commit 65e5174
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/Linux/evbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ extern "C" {
#include "util.h"
#include "evbus.h"

#ifdef GPROF
#include "gperftools/profiler.h"
#endif

// only one running bus in each thread - keep track with thread-local var
// so we can always know what the current "home" bus is and detect
// inter-bus (inter-thread) messages automatically in EVEventTx
Expand Down Expand Up @@ -463,6 +467,10 @@ extern "C" {
}

static void *busRun(void *magic) {
#ifdef GPROF
myDebug(1, "GPROF ProfilerRegisterThread()");
ProfilerRegisterThread();
#endif
EVBus *bus = (EVBus *)magic;
EVMod *mod = bus->root->rootModule;
assert(bus->running == NO);
Expand Down
11 changes: 6 additions & 5 deletions src/Linux/hsflowd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1832,11 +1832,6 @@ extern "C" {
#ifdef UTHEAP
UTHeapInit();
#endif

#ifdef GPROF
myDebug(1, "GPROF ProfilerStart()");
ProfilerStart(NULL);
#endif

// open syslog
openlog(HSP_DAEMON_NAME, LOG_CONS, LOG_USER);
Expand Down Expand Up @@ -1882,6 +1877,11 @@ extern "C" {
exit(EXIT_FAILURE);
}

#ifdef GPROF
myDebug(1, "GPROF ProfilerStart()");
ProfilerStart(NULL);
#endif

if(getDaemon()) {
// fork to daemonize
pid_t pid = fork();
Expand Down Expand Up @@ -2288,6 +2288,7 @@ extern "C" {

#ifdef GPROF
myDebug(1, "GPROF ProfilerStop()");
ProfilerFlush();
ProfilerStop();
#endif

Expand Down

0 comments on commit 65e5174

Please sign in to comment.