ruby-prof 0.11.2 → 0.13.0

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.
Files changed (150) hide show
  1. data/CHANGES +31 -0
  2. data/README.rdoc +17 -17
  3. data/Rakefile +28 -5
  4. data/bin/ruby-prof +274 -265
  5. data/doc/LICENSE.html +155 -0
  6. data/doc/README_rdoc.html +640 -0
  7. data/doc/Rack/RubyProf.html +319 -0
  8. data/doc/Rack.html +167 -0
  9. data/doc/RubyProf/AbstractPrinter.html +580 -0
  10. data/doc/RubyProf/AggregateCallInfo.html +570 -0
  11. data/doc/RubyProf/CallInfo.html +512 -0
  12. data/doc/RubyProf/CallInfoPrinter.html +190 -0
  13. data/doc/RubyProf/CallInfoVisitor.html +332 -0
  14. data/doc/RubyProf/CallStackPrinter.html +1600 -0
  15. data/doc/RubyProf/CallTreePrinter.html +413 -0
  16. data/doc/RubyProf/Cmd.html +669 -0
  17. data/doc/RubyProf/DotPrinter.html +312 -0
  18. data/doc/RubyProf/FlatPrinter.html +229 -0
  19. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +267 -0
  20. data/doc/RubyProf/GraphHtmlPrinter.html +631 -0
  21. data/doc/RubyProf/GraphPrinter.html +209 -0
  22. data/doc/RubyProf/MethodInfo.html +713 -0
  23. data/doc/RubyProf/MultiPrinter.html +407 -0
  24. data/doc/RubyProf/Profile.html +821 -0
  25. data/doc/RubyProf/ProfileTask.html +532 -0
  26. data/doc/RubyProf/Test.html +578 -0
  27. data/doc/RubyProf/Thread.html +262 -0
  28. data/doc/RubyProf.html +999 -0
  29. data/doc/created.rid +32 -0
  30. data/doc/examples/flat_txt.html +191 -0
  31. data/doc/examples/graph_txt.html +305 -0
  32. data/doc/images/add.png +0 -0
  33. data/doc/images/brick.png +0 -0
  34. data/doc/images/brick_link.png +0 -0
  35. data/doc/images/bug.png +0 -0
  36. data/doc/images/bullet_black.png +0 -0
  37. data/doc/images/bullet_toggle_minus.png +0 -0
  38. data/doc/images/bullet_toggle_plus.png +0 -0
  39. data/doc/images/date.png +0 -0
  40. data/doc/images/delete.png +0 -0
  41. data/doc/images/find.png +0 -0
  42. data/doc/images/loadingAnimation.gif +0 -0
  43. data/doc/images/macFFBgHack.png +0 -0
  44. data/doc/images/package.png +0 -0
  45. data/doc/images/page_green.png +0 -0
  46. data/doc/images/page_white_text.png +0 -0
  47. data/doc/images/page_white_width.png +0 -0
  48. data/doc/images/plugin.png +0 -0
  49. data/doc/images/ruby.png +0 -0
  50. data/doc/images/tag_blue.png +0 -0
  51. data/doc/images/tag_green.png +0 -0
  52. data/doc/images/transparent.png +0 -0
  53. data/doc/images/wrench.png +0 -0
  54. data/doc/images/wrench_orange.png +0 -0
  55. data/doc/images/zoom.png +0 -0
  56. data/doc/index.html +639 -0
  57. data/doc/js/darkfish.js +155 -0
  58. data/doc/js/jquery.js +18 -0
  59. data/doc/js/navigation.js +142 -0
  60. data/doc/js/search.js +94 -0
  61. data/doc/js/search_index.js +1 -0
  62. data/doc/js/searcher.js +228 -0
  63. data/doc/rdoc.css +543 -0
  64. data/doc/table_of_contents.html +462 -0
  65. data/examples/empty.png +0 -0
  66. data/examples/minus.png +0 -0
  67. data/examples/plus.png +0 -0
  68. data/ext/ruby_prof/extconf.rb +7 -1
  69. data/ext/ruby_prof/rp_call_info.c +33 -24
  70. data/ext/ruby_prof/rp_call_info.h +2 -1
  71. data/ext/ruby_prof/rp_measure.c +1 -1
  72. data/ext/ruby_prof/rp_measure.h +1 -1
  73. data/ext/ruby_prof/rp_measure_allocations.c +1 -1
  74. data/ext/ruby_prof/rp_measure_cpu_time.c +1 -1
  75. data/ext/ruby_prof/rp_measure_gc_runs.c +1 -1
  76. data/ext/ruby_prof/rp_measure_gc_time.c +7 -11
  77. data/ext/ruby_prof/rp_measure_memory.c +1 -2
  78. data/ext/ruby_prof/rp_measure_process_time.c +2 -2
  79. data/ext/ruby_prof/rp_measure_wall_time.c +2 -2
  80. data/ext/ruby_prof/rp_method.c +11 -24
  81. data/ext/ruby_prof/rp_method.h +2 -3
  82. data/ext/ruby_prof/rp_stack.c +50 -14
  83. data/ext/ruby_prof/rp_stack.h +10 -10
  84. data/ext/ruby_prof/rp_thread.c +54 -29
  85. data/ext/ruby_prof/rp_thread.h +8 -7
  86. data/ext/ruby_prof/ruby_prof.c +35 -98
  87. data/ext/ruby_prof/ruby_prof.h +1 -1
  88. data/ext/ruby_prof/vc/ruby_prof.sln +12 -6
  89. data/ext/ruby_prof/vc/{ruby_prof.vcxproj → ruby_prof_19.vcxproj} +1 -0
  90. data/ext/ruby_prof/vc/ruby_prof_20.vcxproj +110 -0
  91. data/ext/ruby_prof/version.h +4 -4
  92. data/lib/ruby-prof/call_info.rb +1 -1
  93. data/lib/ruby-prof/call_info_visitor.rb +4 -2
  94. data/lib/ruby-prof/compatibility.rb +21 -6
  95. data/lib/ruby-prof/images/empty.png +0 -0
  96. data/lib/ruby-prof/images/minus.png +0 -0
  97. data/lib/ruby-prof/images/plus.png +0 -0
  98. data/lib/ruby-prof/method_info.rb +1 -1
  99. data/lib/ruby-prof/printers/call_info_printer.rb +3 -2
  100. data/lib/ruby-prof/printers/call_stack_printer.rb +10 -7
  101. data/lib/ruby-prof/printers/dot_printer.rb +2 -2
  102. data/lib/ruby-prof/printers/flat_printer.rb +5 -4
  103. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +2 -2
  104. data/lib/ruby-prof/printers/graph_html_printer.rb +16 -8
  105. data/lib/ruby-prof/printers/graph_printer.rb +17 -16
  106. data/lib/ruby-prof/profile.rb +1 -1
  107. data/lib/ruby-prof/rack.rb +1 -6
  108. data/lib/ruby-prof/task.rb +0 -0
  109. data/lib/ruby-prof/thread.rb +22 -0
  110. data/lib/ruby-prof.rb +1 -0
  111. data/ruby-prof.gemspec +5 -3
  112. data/test/aggregate_test.rb +0 -0
  113. data/test/basic_test.rb +77 -45
  114. data/test/call_info_test.rb +78 -0
  115. data/test/call_info_visitor_test.rb +1 -1
  116. data/test/duplicate_names_test.rb +0 -0
  117. data/test/dynamic_method_test.rb +21 -8
  118. data/test/enumerable_test.rb +0 -0
  119. data/test/exceptions_test.rb +0 -0
  120. data/test/exclude_threads_test.rb +0 -0
  121. data/test/exec_test.rb +0 -0
  122. data/test/fiber_test.rb +65 -0
  123. data/test/line_number_test.rb +0 -0
  124. data/test/measure_cpu_time_test.rb +23 -12
  125. data/test/measure_gc_runs_test.rb +4 -1
  126. data/test/measure_gc_time_test.rb +10 -3
  127. data/test/measure_memory_test.rb +3 -8
  128. data/test/measure_process_time_test.rb +27 -170
  129. data/test/measure_wall_time_test.rb +59 -13
  130. data/test/method_elimination_test.rb +31 -21
  131. data/test/module_test.rb +0 -0
  132. data/test/multi_printer_test.rb +9 -8
  133. data/test/no_method_class_test.rb +0 -0
  134. data/test/pause_resume_test.rb +125 -20
  135. data/test/prime.rb +1 -2
  136. data/test/printers_test.rb +10 -17
  137. data/test/recursive_test.rb +6 -50
  138. data/test/singleton_test.rb +0 -0
  139. data/test/stack_printer_test.rb +9 -6
  140. data/test/stack_test.rb +0 -0
  141. data/test/start_stop_test.rb +0 -0
  142. data/test/test_helper.rb +45 -11
  143. data/test/test_suite.rb +1 -2
  144. data/test/thread_test.rb +0 -0
  145. data/test/unique_call_path_test.rb +0 -0
  146. metadata +107 -12
  147. data/test/bug_test.rb +0 -6
  148. data/test/gc_test.rb +0 -35
  149. data/test/pause_test.rb +0 -57
  150. data/test/prime_test.rb +0 -13
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  #include "ruby_prof.h"
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  /* :nodoc: */
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  /* :nodoc: */
@@ -17,16 +17,16 @@ measure_gc_time()
17
17
  {
18
18
  #if defined(HAVE_RB_GC_TIME)
19
19
  #define MEASURE_GC_TIME_ENABLED Qtrue
20
- const int conversion = 1000000;
20
+ const double conversion = 1000000.0;
21
21
  #if HAVE_LONG_LONG
22
- return NUM2LL(rb_gc_time() / conversion);
22
+ return NUM2LL(rb_gc_time()) / conversion;
23
23
  #else
24
- return NUM2LONG(rb_gc_time() / conversion));
24
+ return NUM2LONG(rb_gc_time()) / conversion;
25
25
  #endif
26
26
 
27
27
  #else
28
28
  #define MEASURE_GC_TIME_ENABLED Qfalse
29
- return 0;
29
+ return 0.0;
30
30
  #endif
31
31
  }
32
32
 
@@ -40,15 +40,11 @@ prof_measurer_t* prof_measurer_gc_time()
40
40
  /* call-seq:
41
41
  measure -> float
42
42
 
43
- Returns the number of GC runs.*/
43
+ Returns the time spent performing GC.*/
44
44
  static VALUE
45
45
  prof_measure_gc_time(VALUE self)
46
46
  {
47
- #if defined(HAVE_LONG_LONG)
48
- return ULL2NUM(measure_gc_time());
49
- #else
50
- return ULONG2NUM(measure_gc_time());
51
- #endif
47
+ return rb_float_new(measure_gc_time());
52
48
  }
53
49
 
54
50
  void rp_init_measure_gc_time()
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  /* :nodoc: */
@@ -25,7 +25,6 @@ static double
25
25
  measure_memory()
26
26
  {
27
27
  #if defined(HAVE_RB_GC_ALLOCATED_SIZE)
28
- #define TOGGLE_GC_STATS 1
29
28
  #define MEASURE_MEMORY_ENABLED Qtrue
30
29
  #if defined(HAVE_LONG_LONG)
31
30
  return NUM2LL(rb_gc_allocated_size()) / 1024.0;
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  #include "ruby_prof.h"
@@ -12,7 +12,7 @@ measure_process_time()
12
12
  #if defined(__linux__)
13
13
  struct timespec clock;
14
14
  clock_gettime(CLOCK_PROCESS_CPUTIME_ID , &clock);
15
- return (clock.tv_sec * 1000000000 + clock.tv_nsec) / 1000000000.0;
15
+ return clock.tv_sec + (clock.tv_nsec/1000000000.0);
16
16
  #elif defined(_win32)
17
17
  FILETIME createTime;
18
18
  FILETIME exitTime;
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  /* :nodoc: */
@@ -11,7 +11,7 @@ measure_wall_time()
11
11
  {
12
12
  struct timeval tv;
13
13
  gettimeofday(&tv, NULL);
14
- return (tv.tv_sec * 1000000 + tv.tv_usec) / 1000000.0;
14
+ return tv.tv_sec + (tv.tv_usec/1000000.0);
15
15
  }
16
16
 
17
17
  prof_measurer_t* prof_measurer_wall_time()
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  #include "ruby_prof.h"
@@ -98,10 +98,12 @@ method_name(ID mid)
98
98
  {
99
99
  VALUE result;
100
100
 
101
- if (mid == ID_ALLOCATOR)
102
- result = rb_str_new2("allocate");
103
- else if (mid == 0)
101
+ if (mid == 0)
104
102
  result = rb_str_new2("[No method]");
103
+ #ifdef ID_ALLOCATOR
104
+ else if (mid == ID_ALLOCATOR)
105
+ result = rb_str_new2("allocate");
106
+ #endif
105
107
  else
106
108
  result = rb_String(ID2SYM(mid));
107
109
 
@@ -139,7 +141,6 @@ prof_method_create(VALUE klass, ID mid, const char* source_file, int line)
139
141
  prof_method_t *result = ALLOC(prof_method_t);
140
142
  result->object = Qnil;
141
143
  result->call_infos = prof_call_infos_create();
142
- result->call_infos2 = Qnil;
143
144
 
144
145
  result->key = ALLOC(prof_method_key_t);
145
146
  method_key(result->key, klass, mid);
@@ -188,6 +189,7 @@ prof_method_free(prof_method_t* method)
188
189
  {
189
190
  prof_method_ruby_gc_free(method);
190
191
  prof_call_infos_free(method->call_infos);
192
+ xfree(method->call_infos);
191
193
 
192
194
  xfree(method->key);
193
195
  method->key = NULL;
@@ -195,28 +197,13 @@ prof_method_free(prof_method_t* method)
195
197
  xfree(method);
196
198
  }
197
199
 
198
- /*static int
199
- mark_call_infos(st_data_t key, st_data_t value, st_data_t result)
200
- {
201
- prof_call_info_t *call_info = (prof_call_info_t *) value;
202
- prof_call_info_mark(call_info);
203
- return ST_CONTINUE;
204
- }
205
- */
206
-
207
200
  void
208
201
  prof_method_mark(prof_method_t *method)
209
202
  {
210
203
  if (method->object)
211
204
  rb_gc_mark(method->object);
212
205
 
213
- if (method->call_infos2)
214
- rb_gc_mark(method->call_infos2);
215
-
216
- if (method->call_infos->object)
217
- rb_gc_mark(method->call_infos->object);
218
-
219
- //st_foreach(method->call_info_table, mark_call_infos, NULL);
206
+ prof_call_infos_mark(method->call_infos);
220
207
  }
221
208
 
222
209
  VALUE
@@ -409,11 +396,11 @@ static VALUE
409
396
  prof_method_call_infos(VALUE self)
410
397
  {
411
398
  prof_method_t *method = get_prof_method(self);
412
- if (method->call_infos2 == Qnil)
399
+ if (method->call_infos->object == Qnil)
413
400
  {
414
- method->call_infos2 = prof_call_infos_wrap(method->call_infos);
401
+ method->call_infos->object = prof_call_infos_wrap(method->call_infos);
415
402
  }
416
- return method->call_infos2;
403
+ return method->call_infos->object;
417
404
  }
418
405
 
419
406
  void rp_init_method_info()
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  #ifndef __RP_METHOD_INFO__
@@ -31,9 +31,8 @@ typedef struct
31
31
  prof_method_key_t *key; /* Method key */
32
32
  const char *source_file; /* The method's source file */
33
33
  int line; /* The method's line number. */
34
- struct prof_call_infos_t *call_infos; /* Call info objects for this method */
34
+ struct prof_call_infos_t *call_infos; /* Call info objects for this method */
35
35
  VALUE object; /* Cached ruby object */
36
- VALUE call_infos2; /* Cached array of RubyProf::CallInfo */
37
36
  } prof_method_t;
38
37
 
39
38
  void rp_init_method_info(void);
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  #include "rp_stack.h"
@@ -6,16 +6,16 @@
6
6
  #define INITIAL_STACK_SIZE 8
7
7
 
8
8
  void
9
- frame_pause(prof_frame_t *frame, double current_measurement)
9
+ prof_frame_pause(prof_frame_t *frame, double current_measurement)
10
10
  {
11
- if (frame && frame_is_unpaused(frame))
11
+ if (frame && prof_frame_is_unpaused(frame))
12
12
  frame->pause_time = current_measurement;
13
13
  }
14
14
 
15
15
  void
16
- frame_unpause(prof_frame_t *frame, double current_measurement)
16
+ prof_frame_unpause(prof_frame_t *frame, double current_measurement)
17
17
  {
18
- if (frame && frame_is_paused(frame)) {
18
+ if (frame && prof_frame_is_paused(frame)) {
19
19
  frame->dead_time += (current_measurement - frame->pause_time);
20
20
  frame->pause_time = -1;
21
21
  }
@@ -25,7 +25,7 @@ frame_unpause(prof_frame_t *frame, double current_measurement)
25
25
  /* Creates a stack of prof_frame_t to keep track
26
26
  of timings for active methods. */
27
27
  prof_stack_t *
28
- stack_create()
28
+ prof_stack_create()
29
29
  {
30
30
  prof_stack_t *stack = ALLOC(prof_stack_t);
31
31
  stack->start = ALLOC_N(prof_frame_t, INITIAL_STACK_SIZE);
@@ -36,14 +36,14 @@ stack_create()
36
36
  }
37
37
 
38
38
  void
39
- stack_free(prof_stack_t *stack)
39
+ prof_stack_free(prof_stack_t *stack)
40
40
  {
41
41
  xfree(stack->start);
42
42
  xfree(stack);
43
43
  }
44
44
 
45
45
  prof_frame_t *
46
- stack_push(prof_stack_t *stack)
46
+ prof_stack_push(prof_stack_t *stack, double measurement)
47
47
  {
48
48
  prof_frame_t* result = NULL;
49
49
 
@@ -64,7 +64,9 @@ stack_push(prof_stack_t *stack)
64
64
  result->child_time = 0;
65
65
  result->switch_time = 0;
66
66
  result->wait_time = 0;
67
+ result->dead_time = 0;
67
68
  result->depth = (int)(stack->ptr - stack->start); // shortening of 64 bit into 32
69
+ result->start_time = measurement;
68
70
 
69
71
  // Increment the stack ptr for next time
70
72
  stack->ptr++;
@@ -74,16 +76,50 @@ stack_push(prof_stack_t *stack)
74
76
  }
75
77
 
76
78
  prof_frame_t *
77
- stack_pop(prof_stack_t *stack)
79
+ prof_stack_pop(prof_stack_t *stack, double measurement)
78
80
  {
79
- if (stack->ptr == stack->start)
80
- return NULL;
81
- else
82
- return --stack->ptr;
81
+ prof_frame_t *frame = NULL;
82
+ prof_frame_t* parent_frame = NULL;
83
+ prof_call_info_t *call_info;
84
+
85
+ double total_time;
86
+ double self_time;
87
+
88
+ /* Frame can be null. This can happen if RubProf.start is called from
89
+ a method that exits. And it can happen if an exception is raised
90
+ in code that is being profiled and the stack unwinds (RubyProf is
91
+ not notified of that by the ruby runtime. */
92
+ if (stack->ptr == stack->start)
93
+ return NULL;
94
+
95
+ frame = --stack->ptr;
96
+
97
+ /* Calculate the total time this method took */
98
+ prof_frame_unpause(frame, measurement);
99
+ total_time = measurement - frame->start_time - frame->dead_time;
100
+ self_time = total_time - frame->child_time - frame->wait_time;
101
+
102
+ /* Update information about the current method */
103
+ call_info = frame->call_info;
104
+ call_info->called++;
105
+ call_info->total_time += total_time;
106
+ call_info->self_time += self_time;
107
+ call_info->wait_time += frame->wait_time;
108
+
109
+ parent_frame = prof_stack_peek(stack);
110
+ if (parent_frame)
111
+ {
112
+ parent_frame->child_time += total_time;
113
+ parent_frame->dead_time += frame->dead_time;
114
+
115
+ call_info->line = parent_frame->line;
116
+ }
117
+
118
+ return frame;
83
119
  }
84
120
 
85
121
  prof_frame_t *
86
- stack_peek(prof_stack_t *stack)
122
+ prof_stack_peek(prof_stack_t *stack)
87
123
  {
88
124
  if (stack->ptr == stack->start)
89
125
  return NULL;
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  #ifndef __RP_STACK__
@@ -28,10 +28,10 @@ typedef struct
28
28
  unsigned int line;
29
29
  } prof_frame_t;
30
30
 
31
- #define frame_is_paused(f) (f->pause_time >= 0)
32
- #define frame_is_unpaused(f) (f->pause_time < 0)
33
- void frame_pause(prof_frame_t*, double current_measurement);
34
- void frame_unpause(prof_frame_t*, double current_measurement);
31
+ #define prof_frame_is_paused(f) (f->pause_time >= 0)
32
+ #define prof_frame_is_unpaused(f) (f->pause_time < 0)
33
+ void prof_frame_pause(prof_frame_t*, double current_measurement);
34
+ void prof_frame_unpause(prof_frame_t*, double current_measurement);
35
35
 
36
36
 
37
37
  /* Current stack of active methods.*/
@@ -42,10 +42,10 @@ typedef struct
42
42
  prof_frame_t *ptr;
43
43
  } prof_stack_t;
44
44
 
45
- prof_stack_t * stack_create();
46
- void stack_free(prof_stack_t *stack);
47
- prof_frame_t * stack_push(prof_stack_t *stack);
48
- prof_frame_t * stack_pop(prof_stack_t *stack);
49
- prof_frame_t * stack_peek(prof_stack_t *stack);
45
+ prof_stack_t * prof_stack_create();
46
+ void prof_stack_free(prof_stack_t *stack);
47
+ prof_frame_t * prof_stack_push(prof_stack_t *stack, double measurement);
48
+ prof_frame_t * prof_stack_pop(prof_stack_t *stack, double measurement);
49
+ prof_frame_t * prof_stack_peek(prof_stack_t *stack);
50
50
 
51
51
  #endif //__RP_STACK__
@@ -1,4 +1,4 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  #include "ruby_prof.h"
@@ -10,9 +10,8 @@ thread_data_t*
10
10
  thread_data_create()
11
11
  {
12
12
  thread_data_t* result = ALLOC(thread_data_t);
13
- result->stack = stack_create();
13
+ result->stack = prof_stack_create();
14
14
  result->method_table = method_table_create();
15
- result->top = NULL;
16
15
  result->object = Qnil;
17
16
  result->methods = Qnil;
18
17
  return result;
@@ -42,9 +41,8 @@ static void
42
41
  thread_data_free(thread_data_t* thread_data)
43
42
  {
44
43
  thread_data_ruby_gc_free(thread_data);
45
- thread_data->top = NULL;
46
44
  method_table_free(thread_data->method_table);
47
- stack_free(thread_data->stack);
45
+ prof_stack_free(thread_data->stack);
48
46
 
49
47
  thread_data->thread_id = Qnil;
50
48
 
@@ -67,8 +65,13 @@ prof_thread_mark(thread_data_t *thread)
67
65
 
68
66
  if (thread->methods != Qnil)
69
67
  rb_gc_mark(thread->methods);
70
-
71
- prof_method_mark(thread->top);
68
+
69
+ if (thread->thread_id != Qnil)
70
+ rb_gc_mark(thread->thread_id);
71
+
72
+ if (thread->fiber_id != Qnil)
73
+ rb_gc_mark(thread->fiber_id);
74
+
72
75
  st_foreach(thread->method_table, mark_methods, 0);
73
76
  }
74
77
 
@@ -119,20 +122,20 @@ threads_table_free(st_table *table)
119
122
  }
120
123
 
121
124
  size_t
122
- threads_table_insert(prof_profile_t* profile, VALUE thread, thread_data_t *thread_data)
125
+ threads_table_insert(prof_profile_t* profile, VALUE fiber, thread_data_t *thread_data)
123
126
  {
124
127
  /* Its too slow to key on the real thread id so just typecast thread instead. */
125
- return st_insert(profile->threads_tbl, (st_data_t) thread, (st_data_t) thread_data);
128
+ return st_insert(profile->threads_tbl, (st_data_t) fiber, (st_data_t) thread_data);
126
129
  }
127
130
 
128
131
  thread_data_t *
129
- threads_table_lookup(prof_profile_t* profile, VALUE thread_id)
132
+ threads_table_lookup(prof_profile_t* profile, VALUE thread_id, VALUE fiber_id)
130
133
  {
131
134
  thread_data_t* result;
132
135
  st_data_t val;
133
136
 
134
137
  /* Its too slow to key on the real thread id so just typecast thread instead. */
135
- if (st_lookup(profile->threads_tbl, (st_data_t) thread_id, &val))
138
+ if (st_lookup(profile->threads_tbl, (st_data_t) fiber_id, &val))
136
139
  {
137
140
  result = (thread_data_t *) val;
138
141
  }
@@ -140,24 +143,25 @@ threads_table_lookup(prof_profile_t* profile, VALUE thread_id)
140
143
  {
141
144
  result = thread_data_create();
142
145
  result->thread_id = thread_id;
146
+ result->fiber_id = fiber_id;
143
147
 
144
148
  /* Insert the table */
145
- threads_table_insert(profile, thread_id, result);
149
+ threads_table_insert(profile, fiber_id, result);
146
150
  }
147
151
  return result;
148
152
  }
149
153
 
150
154
  thread_data_t *
151
- switch_thread(void* prof, VALUE thread_id)
155
+ switch_thread(void* prof, VALUE thread_id, VALUE fiber_id)
152
156
  {
153
157
  prof_profile_t* profile = (prof_profile_t*)prof;
154
158
  double measurement = profile->measurer->measure();
155
159
 
156
160
  /* Get new thread information. */
157
- thread_data_t *thread_data = threads_table_lookup(profile, thread_id);
161
+ thread_data_t *thread_data = threads_table_lookup(profile, thread_id, fiber_id);
158
162
 
159
163
  /* Get current frame for this thread */
160
- prof_frame_t *frame = stack_peek(thread_data->stack);
164
+ prof_frame_t *frame = prof_stack_peek(thread_data->stack);
161
165
 
162
166
  /* Update the time this thread waited for another thread */
163
167
  if (frame)
@@ -170,7 +174,7 @@ switch_thread(void* prof, VALUE thread_id)
170
174
  and reset this thread's last context switch to 0.*/
171
175
  if (profile->last_thread_data)
172
176
  {
173
- prof_frame_t *last_frame = stack_peek(profile->last_thread_data->stack);
177
+ prof_frame_t *last_frame = prof_stack_peek(profile->last_thread_data->stack);
174
178
  if (last_frame)
175
179
  last_frame->switch_time = measurement;
176
180
  }
@@ -179,6 +183,28 @@ switch_thread(void* prof, VALUE thread_id)
179
183
  return thread_data;
180
184
  }
181
185
 
186
+ int pause_thread(st_data_t key, st_data_t value, st_data_t data)
187
+ {
188
+ thread_data_t* thread_data = (thread_data_t *) value;
189
+ prof_profile_t* profile = (prof_profile_t*)data;
190
+
191
+ prof_frame_t* frame = prof_stack_peek(thread_data->stack);
192
+ prof_frame_pause(frame, profile->measurement_at_pause_resume);
193
+
194
+ return ST_CONTINUE;
195
+ }
196
+
197
+ int unpause_thread(st_data_t key, st_data_t value, st_data_t data)
198
+ {
199
+ thread_data_t* thread_data = (thread_data_t *) value;
200
+ prof_profile_t* profile = (prof_profile_t*)data;
201
+
202
+ prof_frame_t* frame = prof_stack_peek(thread_data->stack);
203
+ prof_frame_unpause(frame, profile->measurement_at_pause_resume);
204
+
205
+ return ST_CONTINUE;
206
+ }
207
+
182
208
  static int
183
209
  collect_methods(st_data_t key, st_data_t value, st_data_t result)
184
210
  {
@@ -203,6 +229,17 @@ prof_thread_id(VALUE self)
203
229
  return thread->thread_id;
204
230
  }
205
231
 
232
+ /* call-seq:
233
+ fiber_id -> number
234
+
235
+ Returns the fiber id of this thread. */
236
+ static VALUE
237
+ prof_fiber_id(VALUE self)
238
+ {
239
+ thread_data_t* thread = prof_get_thread(self);
240
+ return thread->fiber_id;
241
+ }
242
+
206
243
  /* call-seq:
207
244
  methods -> Array of MethodInfo
208
245
 
@@ -220,24 +257,12 @@ prof_thread_methods(VALUE self)
220
257
  return thread->methods;
221
258
  }
222
259
 
223
- /* call-seq:
224
- method -> MethodInfo
225
-
226
- Returns the top level method for this thread (ie, the starting
227
- method). */
228
- static VALUE
229
- prof_thread_top_method(VALUE self)
230
- {
231
- thread_data_t* thread = prof_get_thread(self);
232
- return prof_method_wrap(thread->top);
233
- }
234
-
235
260
  void rp_init_thread()
236
261
  {
237
262
  cRpThread = rb_define_class_under(mProf, "Thread", rb_cObject);
238
263
  rb_undef_method(CLASS_OF(cRpThread), "new");
239
264
 
240
265
  rb_define_method(cRpThread, "id", prof_thread_id, 0);
266
+ rb_define_method(cRpThread, "fiber_id", prof_fiber_id, 0);
241
267
  rb_define_method(cRpThread, "methods", prof_thread_methods, 0);
242
- rb_define_method(cRpThread, "top_method", prof_thread_top_method, 0);
243
268
  }
@@ -1,26 +1,27 @@
1
- /* Copyright (C) 2005-2011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
1
+ /* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  Please see the LICENSE file for copyright and distribution information */
3
3
 
4
4
  #ifndef __RP_THREAD__
5
5
  #define __RP_THREAD__
6
6
 
7
7
  /* Profiling information for a thread. */
8
- typedef struct
8
+ typedef struct
9
9
  {
10
- VALUE object; /* Cache to wrapped object */
11
- VALUE methods; /* Array of RubyProf::MethodInfo */
10
+ VALUE object; /* Cache to wrapped object */
11
+ VALUE methods; /* Array of RubyProf::MethodInfo */
12
12
  VALUE thread_id; /* Thread id */
13
+ VALUE fiber_id; /* Fiber id */
13
14
  st_table* method_table; /* Methods called in the thread */
14
15
  prof_stack_t* stack; /* Stack of frames */
15
- prof_method_t* top; /* The top method called in this thread */
16
16
  } thread_data_t;
17
17
 
18
18
  void rp_init_thread();
19
19
  st_table * threads_table_create();
20
- thread_data_t* switch_thread(void* prof, VALUE thread_id);
20
+ thread_data_t* switch_thread(void* prof, VALUE thread_id, VALUE fiber_id);
21
21
  void threads_table_free(st_table *table);
22
22
  VALUE prof_thread_wrap(thread_data_t *thread);
23
23
  void prof_thread_mark(thread_data_t *thread);
24
-
24
+ int pause_thread(st_data_t key, st_data_t value, st_data_t data);
25
+ int unpause_thread(st_data_t key, st_data_t value, st_data_t data);
25
26
 
26
27
  #endif //__RP_THREAD__