Skip to content

Instantly share code, notes, and snippets.

@tmm1
Created December 18, 2013 23:19
Show Gist options
  • Save tmm1/8031600 to your computer and use it in GitHub Desktop.
Save tmm1/8031600 to your computer and use it in GitHub Desktop.
diff --git a/src/gperftools/profiler.h b/src/gperftools/profiler.h
index 95b107f..816468d 100644
--- a/src/gperftools/profiler.h
+++ b/src/gperftools/profiler.h
@@ -139,6 +139,8 @@ PERFTOOLS_DLL_DECL void ProfilerStop();
*/
PERFTOOLS_DLL_DECL void ProfilerFlush();
+PERFTOOLS_DLL_DECL void ProfilerPause();
+PERFTOOLS_DLL_DECL void ProfilerResume();
/* DEPRECATED: these functions were used to enable/disable profiling
* in the current thread, but no longer do anything.
diff --git a/src/profiler.cc b/src/profiler.cc
index a2a4faa..82cdf6d 100644
--- a/src/profiler.cc
+++ b/src/profiler.cc
@@ -129,6 +129,7 @@ class CpuProfiler {
// ProfileHandlerUnregisterCallback.
ProfileHandlerToken* prof_handler_token_;
+ public:
// Sets up a callback to receive SIGPROF interrupt.
void EnableHandler();
@@ -325,8 +326,9 @@ void CpuProfiler::EnableHandler() {
}
void CpuProfiler::DisableHandler() {
- RAW_CHECK(prof_handler_token_ != NULL, "SIGPROF handler is not registered");
- ProfileHandlerUnregisterCallback(prof_handler_token_);
+ //RAW_CHECK(prof_handler_token_ != NULL, "SIGPROF handler is not registered");
+ if (prof_handler_token_ != NULL)
+ ProfileHandlerUnregisterCallback(prof_handler_token_);
prof_handler_token_ = NULL;
}
@@ -389,6 +391,14 @@ extern "C" PERFTOOLS_DLL_DECL void ProfilerStop() {
CpuProfiler::instance_.Stop();
}
+extern "C" PERFTOOLS_DLL_DECL void ProfilerPause() {
+ CpuProfiler::instance_.DisableHandler();
+}
+
+extern "C" PERFTOOLS_DLL_DECL void ProfilerResume() {
+ CpuProfiler::instance_.EnableHandler();
+}
+
extern "C" PERFTOOLS_DLL_DECL void ProfilerGetCurrentState(
ProfilerState* state) {
CpuProfiler::instance_.GetCurrentState(state);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment