Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add pause/resume

  • Loading branch information...
commit 6f9dc2efc18df228f4ac8f57d1abcf51c675b1e8 1 parent a6d5bde
@tmm1 authored
View
3  ext/extconf.rb
@@ -52,7 +52,8 @@ def sys(cmd)
['perftools-debug', true],
['perftools-objects', true],
['perftools-frames', true],
- ['perftools-realtime', true]
+ ['perftools-realtime', true],
+ ['perftools-pause', true]
].each do |patch, apply|
if apply
sys("patch -p1 < ../../../patches/#{patch}.patch")
View
41 ext/perftools.c
@@ -14,6 +14,8 @@ void ProfilerGcMark(void (*cb)(VALUE));
int ProfilerStart(const char*);
void ProfilerStop();
void ProfilerFlush();
+void ProfilerPause();
+void ProfilerResume();
void ProfilerRecord(int, void*, void*);
int ProfilingIsEnabledForAllThreads();
@@ -228,15 +230,50 @@ static VALUE cPerfTools;
static VALUE cCpuProfiler;
static VALUE eError;
static VALUE bProfilerRunning;
+static VALUE bProfilerPaused;
static VALUE gc_hook;
static VALUE
+cpuprofiler_paused_p(VALUE self)
+{
+ return bProfilerPaused;
+}
+
+static VALUE
cpuprofiler_running_p(VALUE self)
{
return bProfilerRunning;
}
static VALUE
+cpuprofiler_pause(VALUE self)
+{
+ if (!bProfilerRunning)
+ return Qfalse;
+ if (bProfilerPaused)
+ return Qfalse;
+
+ bProfilerPaused = Qtrue;
+ ProfilerPause();
+
+ return Qtrue;
+}
+
+static VALUE
+cpuprofiler_resume(VALUE self)
+{
+ if (!bProfilerRunning)
+ return Qfalse;
+ if (!bProfilerPaused)
+ return Qfalse;
+
+ bProfilerPaused = Qfalse;
+ ProfilerResume();
+
+ return Qtrue;
+}
+
+static VALUE
cpuprofiler_stop(VALUE self)
{
if (!bProfilerRunning)
@@ -476,10 +513,14 @@ Init_perftools()
Isend = rb_intern("send");
bMethProfilerRunning = bObjProfilerRunning = bProfilerRunning = Qfalse;
+ bProfilerPaused = Qfalse;
rb_define_singleton_method(cCpuProfiler, "running?", cpuprofiler_running_p, 0);
rb_define_singleton_method(cCpuProfiler, "start", cpuprofiler_start, 1);
rb_define_singleton_method(cCpuProfiler, "stop", cpuprofiler_stop, 0);
+ rb_define_singleton_method(cCpuProfiler, "paused?", cpuprofiler_paused_p, 0);
+ rb_define_singleton_method(cCpuProfiler, "pause", cpuprofiler_pause, 0);
+ rb_define_singleton_method(cCpuProfiler, "resume", cpuprofiler_resume, 0);
gc_hook = Data_Wrap_Struct(cCpuProfiler, cpuprofiler_gc_mark, NULL, NULL);
rb_global_variable(&gc_hook);
View
42 patches/perftools-pause.patch
@@ -0,0 +1,42 @@
+diff --git a/src/gperftools/profiler.h b/src/gperftools/profiler.h
+index 7971e04..5093604 100644
+--- a/src/gperftools/profiler.h
++++ b/src/gperftools/profiler.h
+@@ -138,6 +138,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 2f1af06..7c404c3 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();
+
+@@ -346,6 +347,16 @@ extern "C" PERFTOOLS_DLL_DECL void ProfilerStop() {
+ CpuProfiler::instance_.Stop();
+ }
+
++#ifdef BUILD_FOR_RUBY
++extern "C" PERFTOOLS_DLL_DECL void ProfilerPause() {
++ CpuProfiler::instance_.DisableHandler();
++}
++
++extern "C" PERFTOOLS_DLL_DECL void ProfilerResume() {
++ CpuProfiler::instance_.EnableHandler();
++}
++#endif
++
+ extern "C" PERFTOOLS_DLL_DECL void ProfilerGetCurrentState(
+ ProfilerState* state) {
+ CpuProfiler::instance_.GetCurrentState(state);
Please sign in to comment.
Something went wrong with that request. Please try again.