perftools.rb 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,17 +13,21 @@ require 'fileutils'
13
13
 
14
14
  if RUBY_VERSION >= "1.9"
15
15
  begin
16
- require "ruby_core_source"
16
+ require "debugger/ruby_core_source"
17
17
  rescue LoadError
18
18
  require 'rubygems/user_interaction' # for 1.9.1
19
19
  require 'rubygems/dependency_installer'
20
20
  installer = Gem::DependencyInstaller.new
21
- installer.install 'ruby_core_source'
21
+ installer.install 'debugger-ruby_core_source'
22
22
 
23
23
  Gem.refresh
24
- Gem.activate('ruby_core_source') # for 1.9.1
24
+ if Gem.method_defined? :activate
25
+ Gem.activate('debugger-ruby_core_source') # for 1.9.1
26
+ else
27
+ Gem::Specification.find_by_name('debugger-ruby_core_source').activate
28
+ end
25
29
 
26
- require "ruby_core_source"
30
+ require "debugger/ruby_core_source"
27
31
  end
28
32
  end
29
33
 
@@ -52,7 +56,8 @@ Dir.chdir('src') do
52
56
  ['perftools-debug', true],
53
57
  ['perftools-objects', true],
54
58
  ['perftools-frames', true],
55
- ['perftools-realtime', true]
59
+ ['perftools-realtime', true],
60
+ ['perftools-pause', true]
56
61
  ].each do |patch, apply|
57
62
  if apply
58
63
  sys("patch -p1 < ../../../patches/#{patch}.patch")
@@ -101,10 +106,10 @@ if RUBY_VERSION >= "1.9"
101
106
  have_header("insns_info.inc")
102
107
  }
103
108
 
104
- unless Ruby_core_source::create_makefile_with_core(hdrs, "perftools")
109
+ unless Debugger::RubyCoreSource::create_makefile_with_core(hdrs, "perftools")
105
110
  STDERR.puts "\n\n"
106
111
  STDERR.puts "***************************************************************************************"
107
- STDERR.puts "********************** Ruby_core_source::create_makefile FAILED ***********************"
112
+ STDERR.puts "****************** Debugger::RubyCoreSource::create_makefile FAILED *******************"
108
113
  STDERR.puts "***************************************************************************************"
109
114
  exit(1)
110
115
  end
@@ -14,6 +14,8 @@ void ProfilerGcMark(void (*cb)(VALUE));
14
14
  int ProfilerStart(const char*);
15
15
  void ProfilerStop();
16
16
  void ProfilerFlush();
17
+ void ProfilerPause();
18
+ void ProfilerResume();
17
19
  void ProfilerRecord(int, void*, void*);
18
20
  int ProfilingIsEnabledForAllThreads();
19
21
 
@@ -21,6 +23,10 @@ static VALUE Iallocate;
21
23
  static VALUE I__send__;
22
24
  static VALUE Isend;
23
25
 
26
+ #ifndef ID_ALLOCATOR
27
+ #define ID_ALLOCATOR Iallocate
28
+ #endif
29
+
24
30
  #define SAVE_FRAME() \
25
31
  if (method && method != I__send__ && method != Isend) { \
26
32
  if (self && FL_TEST(klass, FL_SINGLETON) && (BUILTIN_TYPE(self) == T_CLASS || BUILTIN_TYPE(self) == T_MODULE)) \
@@ -123,15 +129,25 @@ static VALUE Isend;
123
129
  #include <vm_core.h>
124
130
  #include <iseq.h>
125
131
 
126
- // Fix compile error in ruby 1.9.3
132
+ // Fix compile error in ruby 1.9.3 and 2.0.0
127
133
  #ifdef RTYPEDDATA_DATA
128
- #define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current()))
134
+ #if GET_THREAD
135
+ #define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current()))
136
+ #define GET_THREAD2 GET_THREAD
137
+ #else
138
+ rb_thread_t *ruby_current_thread;
139
+ rb_thread_t *GET_THREAD2(void)
140
+ {
141
+ ruby_current_thread = ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current()));
142
+ return GET_THREAD();
143
+ }
144
+ #endif
129
145
  #endif
130
146
 
131
147
  int
132
148
  rb_stack_trace(void** result, int max_depth)
133
149
  {
134
- rb_thread_t *th = GET_THREAD();
150
+ rb_thread_t *th = GET_THREAD2();
135
151
  rb_control_frame_t *cfp = th->cfp;
136
152
  rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th);
137
153
 
@@ -188,7 +204,7 @@ static VALUE Isend;
188
204
  void
189
205
  rb_dump_stack()
190
206
  {
191
- rb_thread_t *th = GET_THREAD();
207
+ rb_thread_t *th = GET_THREAD2();
192
208
  rb_control_frame_t *cfp = th->cfp;
193
209
  rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th);
194
210
  ID func;
@@ -228,8 +244,15 @@ static VALUE cPerfTools;
228
244
  static VALUE cCpuProfiler;
229
245
  static VALUE eError;
230
246
  static VALUE bProfilerRunning;
247
+ static VALUE bProfilerPaused;
231
248
  static VALUE gc_hook;
232
249
 
250
+ static VALUE
251
+ cpuprofiler_paused_p(VALUE self)
252
+ {
253
+ return bProfilerPaused;
254
+ }
255
+
233
256
  static VALUE
234
257
  cpuprofiler_running_p(VALUE self)
235
258
  {
@@ -237,14 +260,60 @@ cpuprofiler_running_p(VALUE self)
237
260
  }
238
261
 
239
262
  static VALUE
240
- cpuprofiler_stop(VALUE self)
263
+ cpuprofiler_pause(VALUE self)
264
+ {
265
+ if (!bProfilerRunning)
266
+ return Qfalse;
267
+ if (bProfilerPaused)
268
+ return Qfalse;
269
+
270
+ bProfilerPaused = Qtrue;
271
+ ProfilerPause();
272
+
273
+ return Qtrue;
274
+ }
275
+
276
+ static VALUE
277
+ cpuprofiler_resume(VALUE self)
241
278
  {
242
279
  if (!bProfilerRunning)
243
280
  return Qfalse;
281
+ if (!bProfilerPaused)
282
+ return Qfalse;
283
+
284
+ bProfilerPaused = Qfalse;
285
+ ProfilerResume();
244
286
 
287
+ return Qtrue;
288
+ }
289
+
290
+ static VALUE
291
+ cpuprofiler_flush(VALUE self)
292
+ {
293
+ if (!bProfilerRunning)
294
+ return Qfalse;
295
+ if (bProfilerPaused)
296
+ ProfilerResume();
297
+ ProfilerFlush();
298
+ if (bProfilerPaused)
299
+ ProfilerPause();
300
+ return Qtrue;
301
+ }
302
+
303
+ static VALUE
304
+ cpuprofiler_stop(VALUE self)
305
+ {
306
+ if (!bProfilerRunning)
307
+ return Qfalse;
245
308
  bProfilerRunning = Qfalse;
309
+
246
310
  objprofiler_teardown();
247
311
  methprofiler_teardown();
312
+
313
+ if (bProfilerPaused)
314
+ ProfilerResume();
315
+ bProfilerPaused = Qfalse;
316
+
248
317
  ProfilerStop();
249
318
  ProfilerFlush();
250
319
 
@@ -476,10 +545,15 @@ Init_perftools()
476
545
  Isend = rb_intern("send");
477
546
 
478
547
  bMethProfilerRunning = bObjProfilerRunning = bProfilerRunning = Qfalse;
548
+ bProfilerPaused = Qfalse;
479
549
 
480
550
  rb_define_singleton_method(cCpuProfiler, "running?", cpuprofiler_running_p, 0);
481
551
  rb_define_singleton_method(cCpuProfiler, "start", cpuprofiler_start, 1);
482
552
  rb_define_singleton_method(cCpuProfiler, "stop", cpuprofiler_stop, 0);
553
+ rb_define_singleton_method(cCpuProfiler, "paused?", cpuprofiler_paused_p, 0);
554
+ rb_define_singleton_method(cCpuProfiler, "pause", cpuprofiler_pause, 0);
555
+ rb_define_singleton_method(cCpuProfiler, "resume", cpuprofiler_resume, 0);
556
+ rb_define_singleton_method(cCpuProfiler, "flush", cpuprofiler_flush, 0);
483
557
 
484
558
  gc_hook = Data_Wrap_Struct(cCpuProfiler, cpuprofiler_gc_mark, NULL, NULL);
485
559
  rb_global_variable(&gc_hook);
@@ -0,0 +1,58 @@
1
+ diff --git a/src/gperftools/profiler.h b/src/gperftools/profiler.h
2
+ index 7971e04..5093604 100644
3
+ --- a/src/gperftools/profiler.h
4
+ +++ b/src/gperftools/profiler.h
5
+ @@ -138,6 +138,8 @@ PERFTOOLS_DLL_DECL void ProfilerStop();
6
+ */
7
+ PERFTOOLS_DLL_DECL void ProfilerFlush();
8
+
9
+ +PERFTOOLS_DLL_DECL void ProfilerPause();
10
+ +PERFTOOLS_DLL_DECL void ProfilerResume();
11
+
12
+ /* DEPRECATED: these functions were used to enable/disable profiling
13
+ * in the current thread, but no longer do anything.
14
+ diff --git a/src/profiler.cc b/src/profiler.cc
15
+ index 2f1af06..7c404c3 100644
16
+ --- a/src/profiler.cc
17
+ +++ b/src/profiler.cc
18
+ @@ -129,6 +129,7 @@ class CpuProfiler {
19
+ // ProfileHandlerUnregisterCallback.
20
+ ProfileHandlerToken* prof_handler_token_;
21
+
22
+ + public:
23
+ // Sets up a callback to receive SIGPROF interrupt.
24
+ void EnableHandler();
25
+
26
+ @@ -346,6 +347,16 @@ extern "C" PERFTOOLS_DLL_DECL void ProfilerStop() {
27
+ CpuProfiler::instance_.Stop();
28
+ }
29
+
30
+ +#ifdef BUILD_FOR_RUBY
31
+ +extern "C" PERFTOOLS_DLL_DECL void ProfilerPause() {
32
+ + CpuProfiler::instance_.DisableHandler();
33
+ +}
34
+ +
35
+ +extern "C" PERFTOOLS_DLL_DECL void ProfilerResume() {
36
+ + CpuProfiler::instance_.EnableHandler();
37
+ +}
38
+ +#endif
39
+ +
40
+ extern "C" PERFTOOLS_DLL_DECL void ProfilerGetCurrentState(
41
+ ProfilerState* state) {
42
+ CpuProfiler::instance_.GetCurrentState(state);
43
+ diff --git a/src/profiler.cc b/src/profiler.cc
44
+ index 7c404c3..735a885 100644
45
+ --- a/src/profiler.cc
46
+ +++ b/src/profiler.cc
47
+ @@ -268,8 +268,9 @@ void CpuProfiler::EnableHandler() {
48
+ }
49
+
50
+ void CpuProfiler::DisableHandler() {
51
+ - RAW_CHECK(prof_handler_token_ != NULL, "SIGPROF handler is not registered");
52
+ - ProfileHandlerUnregisterCallback(prof_handler_token_);
53
+ + //RAW_CHECK(prof_handler_token_ != NULL, "SIGPROF handler is not registered");
54
+ + if (prof_handler_token_ != NULL)
55
+ + ProfileHandlerUnregisterCallback(prof_handler_token_);
56
+ prof_handler_token_ = NULL;
57
+ }
58
+
@@ -1,9 +1,9 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'perftools.rb'
3
- s.version = '2.0.0'
3
+ s.version = '2.0.1'
4
4
  s.rubyforge_project = 'perftools-rb'
5
- s.summary = 'google-perftools for ruby code'
6
- s.description = 'A sampling profiler for ruby code based on patches to google-perftools'
5
+ s.summary = 'gperftools for ruby code'
6
+ s.description = 'A sampling profiler for ruby code based on patches to gperftools'
7
7
 
8
8
  s.homepage = "http://github.com/tmm1/perftools.rb"
9
9
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perftools.rb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 0
10
- version: 2.0.0
9
+ - 1
10
+ version: 2.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Aman Gupta
@@ -15,11 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-17 00:00:00 -07:00
19
- default_executable:
18
+ date: 2013-05-23 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
- description: A sampling profiler for ruby code based on patches to google-perftools
21
+ description: A sampling profiler for ruby code based on patches to gperftools
23
22
  email: perftools@tmm1.net
24
23
  executables:
25
24
  - pprof.rb
@@ -39,11 +38,11 @@ files:
39
38
  - patches/perftools-notests.patch
40
39
  - patches/perftools-objects.patch
41
40
  - patches/perftools-osx.patch
41
+ - patches/perftools-pause.patch
42
42
  - patches/perftools-pprof.patch
43
43
  - patches/perftools-realtime.patch
44
44
  - patches/perftools.patch
45
45
  - perftools.rb.gemspec
46
- has_rdoc: false
47
46
  homepage: http://github.com/tmm1/perftools.rb
48
47
  licenses: []
49
48
 
@@ -73,9 +72,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
72
  requirements: []
74
73
 
75
74
  rubyforge_project: perftools-rb
76
- rubygems_version: 1.6.2
75
+ rubygems_version: 1.8.24
77
76
  signing_key:
78
77
  specification_version: 3
79
- summary: google-perftools for ruby code
78
+ summary: gperftools for ruby code
80
79
  test_files: []
81
80
 
81
+ has_rdoc: false