ruby-prof 0.16.2 → 1.1.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.
- checksums.yaml +5 -5
- data/CHANGES +532 -467
- data/LICENSE +24 -24
- data/README.rdoc +5 -454
- data/Rakefile +110 -113
- data/bin/ruby-prof +380 -340
- data/bin/ruby-prof-check-trace +45 -45
- data/ext/ruby_prof/extconf.rb +36 -64
- data/ext/ruby_prof/rp_allocation.c +279 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_info.c +271 -407
- data/ext/ruby_prof/rp_call_info.h +35 -48
- data/ext/ruby_prof/rp_measure_allocations.c +52 -76
- data/ext/ruby_prof/rp_measure_memory.c +42 -77
- data/ext/ruby_prof/rp_measure_process_time.c +67 -71
- data/ext/ruby_prof/rp_measure_wall_time.c +62 -45
- data/ext/ruby_prof/rp_measurement.c +230 -0
- data/ext/ruby_prof/rp_measurement.h +50 -0
- data/ext/ruby_prof/rp_method.c +630 -411
- data/ext/ruby_prof/rp_method.h +70 -52
- data/ext/ruby_prof/rp_profile.c +895 -0
- data/ext/ruby_prof/rp_profile.h +37 -0
- data/ext/ruby_prof/rp_stack.c +196 -128
- data/ext/ruby_prof/rp_stack.h +56 -51
- data/ext/ruby_prof/rp_thread.c +337 -273
- data/ext/ruby_prof/rp_thread.h +36 -27
- data/ext/ruby_prof/ruby_prof.c +48 -671
- data/ext/ruby_prof/ruby_prof.h +17 -56
- data/ext/ruby_prof/vc/ruby_prof.sln +20 -21
- data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +38 -5
- data/lib/ruby-prof.rb +52 -58
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +713 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
- data/lib/ruby-prof/call_info.rb +57 -126
- data/lib/ruby-prof/call_info_visitor.rb +38 -40
- data/lib/ruby-prof/compatibility.rb +109 -178
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +14 -0
- data/lib/ruby-prof/method_info.rb +90 -129
- data/lib/ruby-prof/printers/abstract_printer.rb +127 -85
- data/lib/ruby-prof/printers/call_info_printer.rb +51 -41
- data/lib/ruby-prof/printers/call_stack_printer.rb +182 -260
- data/lib/ruby-prof/printers/call_tree_printer.rb +151 -130
- data/lib/ruby-prof/printers/dot_printer.rb +132 -132
- data/lib/ruby-prof/printers/flat_printer.rb +52 -70
- data/lib/ruby-prof/printers/graph_html_printer.rb +63 -244
- data/lib/ruby-prof/printers/graph_printer.rb +114 -116
- data/lib/ruby-prof/printers/multi_printer.rb +127 -58
- data/lib/ruby-prof/profile.rb +33 -55
- data/lib/ruby-prof/rack.rb +171 -95
- data/lib/ruby-prof/task.rb +147 -147
- data/lib/ruby-prof/thread.rb +35 -41
- data/lib/ruby-prof/version.rb +3 -3
- data/lib/unprof.rb +10 -10
- data/ruby-prof.gemspec +58 -57
- data/test/abstract_printer_test.rb +26 -0
- data/test/alias_test.rb +129 -0
- data/test/basic_test.rb +129 -128
- data/test/call_info_visitor_test.rb +31 -31
- data/test/duplicate_names_test.rb +32 -32
- data/test/dynamic_method_test.rb +53 -55
- data/test/enumerable_test.rb +21 -21
- data/test/exceptions_test.rb +24 -16
- data/test/exclude_methods_test.rb +146 -0
- data/test/exclude_threads_test.rb +53 -53
- data/test/fiber_test.rb +73 -79
- data/test/gc_test.rb +96 -0
- data/test/line_number_test.rb +161 -71
- data/test/marshal_test.rb +119 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +385 -26
- data/test/measure_allocations_trace_test.rb +385 -0
- data/test/measure_memory_trace_test.rb +756 -0
- data/test/measure_process_time_test.rb +849 -63
- data/test/measure_times.rb +54 -0
- data/test/measure_wall_time_test.rb +459 -255
- data/test/multi_printer_test.rb +71 -83
- data/test/no_method_class_test.rb +15 -15
- data/test/parser_timings.rb +24 -0
- data/test/pause_resume_test.rb +166 -166
- data/test/prime.rb +56 -54
- data/test/printer_call_stack_test.rb +28 -0
- data/test/printer_call_tree_test.rb +31 -0
- data/test/printer_flat_test.rb +68 -0
- data/test/printer_graph_html_test.rb +60 -0
- data/test/printer_graph_test.rb +41 -0
- data/test/printers_test.rb +141 -255
- data/test/printing_recursive_graph_test.rb +81 -127
- data/test/rack_test.rb +157 -93
- data/test/recursive_test.rb +210 -215
- data/test/singleton_test.rb +38 -38
- data/test/stack_printer_test.rb +64 -78
- data/test/start_stop_test.rb +109 -112
- data/test/test_helper.rb +24 -264
- data/test/thread_test.rb +144 -187
- data/test/unique_call_path_test.rb +190 -202
- data/test/yarv_test.rb +56 -55
- metadata +34 -114
- data/doc/LICENSE.html +0 -114
- data/doc/README_rdoc.html +0 -603
- data/doc/Rack.html +0 -95
- data/doc/Rack/RubyProf.html +0 -226
- data/doc/RubyProf.html +0 -962
- data/doc/RubyProf/AbstractPrinter.html +0 -546
- data/doc/RubyProf/AggregateCallInfo.html +0 -551
- data/doc/RubyProf/CallInfo.html +0 -639
- data/doc/RubyProf/CallInfoPrinter.html +0 -120
- data/doc/RubyProf/CallInfoVisitor.html +0 -198
- data/doc/RubyProf/CallStackPrinter.html +0 -1121
- data/doc/RubyProf/CallTreePrinter.html +0 -641
- data/doc/RubyProf/Cmd.html +0 -631
- data/doc/RubyProf/DotPrinter.html +0 -257
- data/doc/RubyProf/FlatPrinter.html +0 -163
- data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -208
- data/doc/RubyProf/GraphHtmlPrinter.html +0 -552
- data/doc/RubyProf/GraphPrinter.html +0 -139
- data/doc/RubyProf/MethodInfo.html +0 -745
- data/doc/RubyProf/MultiPrinter.html +0 -360
- data/doc/RubyProf/Profile.html +0 -763
- data/doc/RubyProf/ProfileTask.html +0 -490
- data/doc/RubyProf/Thread.html +0 -310
- data/doc/created.rid +0 -31
- data/doc/css/fonts.css +0 -167
- data/doc/css/rdoc.css +0 -590
- data/doc/examples/flat_txt.html +0 -138
- data/doc/examples/graph_html.html +0 -909
- data/doc/examples/graph_txt.html +0 -247
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -626
- data/doc/js/darkfish.js +0 -161
- data/doc/js/jquery.js +0 -4
- data/doc/js/navigation.js +0 -142
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search.js +0 -109
- data/doc/js/search_index.js +0 -1
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js +0 -228
- data/doc/js/searcher.js.gz +0 -0
- data/doc/table_of_contents.html +0 -942
- data/examples/cachegrind.out.1 +0 -114
- data/examples/cachegrind.out.1.32313213 +0 -114
- data/examples/flat.txt +0 -50
- data/examples/graph.dot +0 -84
- data/examples/graph.html +0 -823
- data/examples/graph.txt +0 -139
- data/examples/multi.flat.txt +0 -23
- data/examples/multi.graph.html +0 -760
- data/examples/multi.grind.dat +0 -114
- data/examples/multi.stack.html +0 -547
- data/examples/stack.html +0 -547
- data/ext/ruby_prof/rp_measure.c +0 -40
- data/ext/ruby_prof/rp_measure.h +0 -45
- data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
- data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
- data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
- data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
- data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
- data/lib/ruby-prof/aggregate_call_info.rb +0 -76
- data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
- data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -64
- data/test/aggregate_test.rb +0 -136
- data/test/block_test.rb +0 -74
- data/test/call_info_test.rb +0 -78
- data/test/issue137_test.rb +0 -63
- data/test/measure_cpu_time_test.rb +0 -213
- data/test/measure_gc_runs_test.rb +0 -32
- data/test/measure_gc_time_test.rb +0 -36
- data/test/measure_memory_test.rb +0 -33
- data/test/method_elimination_test.rb +0 -84
- data/test/module_test.rb +0 -45
- data/test/stack_test.rb +0 -138
data/bin/ruby-prof-check-trace
CHANGED
@@ -1,45 +1,45 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
stacks = Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] = []}}
|
4
|
-
i = 0
|
5
|
-
File.open(ARGV[0]).each_line do |l|
|
6
|
-
i += 1
|
7
|
-
unless l =~ /^(\d+):(\d+): *\d+ms *([^ ]+) *(.*): *(\d+) *(.+)$/
|
8
|
-
next if l =~/^ *$/
|
9
|
-
puts "line doesn't match: #{l}"
|
10
|
-
next
|
11
|
-
end
|
12
|
-
details = $1.to_i, $2.to_i, $3, $4, $5.to_i, $6
|
13
|
-
thread, fiber, event, file, line, method = *details
|
14
|
-
# puts method
|
15
|
-
stack = stacks[thread][fiber]
|
16
|
-
case event
|
17
|
-
when 'call', 'c-call'
|
18
|
-
stack << method
|
19
|
-
when 'return', 'c-return'
|
20
|
-
last_method = stack.pop
|
21
|
-
if last_method != method
|
22
|
-
puts "LINE #{i}: return event without call: #{method}"
|
23
|
-
puts "STACK: #{stack.inspect}"
|
24
|
-
if stack.find(method)
|
25
|
-
puts "fixing stack"
|
26
|
-
while (popped = stack.pop) && (popped != method)
|
27
|
-
puts "popped #{popped}"
|
28
|
-
end
|
29
|
-
else
|
30
|
-
raise "stack unfixable"
|
31
|
-
end
|
32
|
-
# stack << last_method
|
33
|
-
end
|
34
|
-
when 'line'
|
35
|
-
last_method = stack[-1]
|
36
|
-
if last_method != method
|
37
|
-
unless stack.find(method)
|
38
|
-
raise "LINE #{i}: line event without call: #{method}"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
else
|
42
|
-
puts "unkown event"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
puts stacks.inspect
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
stacks = Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] = []}}
|
4
|
+
i = 0
|
5
|
+
File.open(ARGV[0]).each_line do |l|
|
6
|
+
i += 1
|
7
|
+
unless l =~ /^(\d+):(\d+): *\d+ms *([^ ]+) *(.*): *(\d+) *(.+)$/
|
8
|
+
next if l =~/^ *$/
|
9
|
+
puts "line doesn't match: #{l}"
|
10
|
+
next
|
11
|
+
end
|
12
|
+
details = $1.to_i, $2.to_i, $3, $4, $5.to_i, $6
|
13
|
+
thread, fiber, event, file, line, method = *details
|
14
|
+
# puts method
|
15
|
+
stack = stacks[thread][fiber]
|
16
|
+
case event
|
17
|
+
when 'call', 'c-call'
|
18
|
+
stack << method
|
19
|
+
when 'return', 'c-return'
|
20
|
+
last_method = stack.pop
|
21
|
+
if last_method != method
|
22
|
+
puts "LINE #{i}: return event without call: #{method}"
|
23
|
+
puts "STACK: #{stack.inspect}"
|
24
|
+
if stack.find(method)
|
25
|
+
puts "fixing stack"
|
26
|
+
while (popped = stack.pop) && (popped != method)
|
27
|
+
puts "popped #{popped}"
|
28
|
+
end
|
29
|
+
else
|
30
|
+
raise "stack unfixable"
|
31
|
+
end
|
32
|
+
# stack << last_method
|
33
|
+
end
|
34
|
+
when 'line'
|
35
|
+
last_method = stack[-1]
|
36
|
+
if last_method != method
|
37
|
+
unless stack.find(method)
|
38
|
+
raise "LINE #{i}: line event without call: #{method}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
else
|
42
|
+
puts "unkown event"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
puts stacks.inspect
|
data/ext/ruby_prof/extconf.rb
CHANGED
@@ -1,64 +1,36 @@
|
|
1
|
-
require "mkmf"
|
2
|
-
|
3
|
-
if RUBY_ENGINE != "ruby"
|
4
|
-
STDERR.puts("\n\n***** This gem is MRI-specific. It does not support #{RUBY_ENGINE}. *****\n\n")
|
5
|
-
exit(1)
|
6
|
-
end
|
7
|
-
|
8
|
-
if RUBY_VERSION <
|
9
|
-
STDERR.puts("\n\n***** Ruby version #{RUBY_VERSION} is no longer supported. Please upgrade to
|
10
|
-
exit(1)
|
11
|
-
end
|
12
|
-
|
13
|
-
#
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
$defs.push("-D#{name}")
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def windows?
|
42
|
-
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
43
|
-
end
|
44
|
-
|
45
|
-
if !windows? && RUBY_PLATFORM !~ /(darwin|openbsd)/
|
46
|
-
$LDFLAGS += " -lrt" # for clock_gettime
|
47
|
-
end
|
48
|
-
add_define("RUBY_PROF_RUBY_VERSION", RUBY_VERSION.split('.')[0..2].inject(0){|v,d| v*100+d.to_i})
|
49
|
-
|
50
|
-
# for ruby 1.9, determine whether threads inherit trace flags (latest 1.9.2 and later should work correctly)
|
51
|
-
if RUBY_VERSION > "1.9"
|
52
|
-
require 'set'
|
53
|
-
threads = Set.new
|
54
|
-
set_trace_func lambda { |*args| threads << Thread.current.object_id }
|
55
|
-
Thread.new{1}.join
|
56
|
-
set_trace_func nil
|
57
|
-
if threads.size < 2
|
58
|
-
# if we end up here, ruby does not automatically activate tracing in spawned threads
|
59
|
-
STDERR.puts("Ruby #{RUBY_VERSION} does not activate tracing in spawned threads. Consider upgrading.")
|
60
|
-
exit(1)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
create_makefile("ruby_prof")
|
1
|
+
require "mkmf"
|
2
|
+
|
3
|
+
if RUBY_ENGINE != "ruby"
|
4
|
+
STDERR.puts("\n\n***** This gem is MRI-specific. It does not support #{RUBY_ENGINE}. *****\n\n")
|
5
|
+
exit(1)
|
6
|
+
end
|
7
|
+
|
8
|
+
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.4.0')
|
9
|
+
STDERR.puts("\n\n***** Ruby version #{RUBY_VERSION} is no longer supported. Please upgrade to 2.3 or higher. *****\n\n")
|
10
|
+
exit(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
# For the love of bitfields...
|
14
|
+
$CFLAGS += ' -std=c99'
|
15
|
+
|
16
|
+
# And since we are using C99
|
17
|
+
CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
|
18
|
+
|
19
|
+
def add_define(name, value = nil)
|
20
|
+
if value
|
21
|
+
$defs.push("-D#{name}=#{value}")
|
22
|
+
else
|
23
|
+
$defs.push("-D#{name}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def windows?
|
28
|
+
RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
29
|
+
end
|
30
|
+
|
31
|
+
add_define("RUBY_PROF_RUBY_VERSION", RUBY_VERSION.split('.')[0..2].inject(0){|v,d| v*100+d.to_i})
|
32
|
+
|
33
|
+
# This function was added in Ruby 2.5, so once Ruby 2.4 is no longer supported this can be removed
|
34
|
+
have_func('rb_tracearg_callee_id', ["ruby.h"])
|
35
|
+
|
36
|
+
create_makefile("ruby_prof")
|
@@ -0,0 +1,279 @@
|
|
1
|
+
/* Copyright (C) 2005-2013 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
|
2
|
+
Please see the LICENSE file for copyright and distribution information */
|
3
|
+
|
4
|
+
#include "rp_allocation.h"
|
5
|
+
|
6
|
+
VALUE cRpAllocation;
|
7
|
+
|
8
|
+
prof_allocation_t*
|
9
|
+
allocations_table_lookup(st_table *table, st_data_t key)
|
10
|
+
{
|
11
|
+
prof_allocation_t* result = NULL;
|
12
|
+
st_data_t value;
|
13
|
+
if (st_lookup(table, key, &value))
|
14
|
+
{
|
15
|
+
result = (prof_allocation_t*)value;
|
16
|
+
}
|
17
|
+
|
18
|
+
return result;
|
19
|
+
}
|
20
|
+
|
21
|
+
void
|
22
|
+
allocations_table_insert(st_table *table, st_data_t key, prof_allocation_t * allocation)
|
23
|
+
{
|
24
|
+
st_insert(table, (st_data_t)key, (st_data_t)allocation);
|
25
|
+
}
|
26
|
+
|
27
|
+
st_data_t
|
28
|
+
allocations_key(VALUE klass, int source_line)
|
29
|
+
{
|
30
|
+
return (klass << 4) + source_line;
|
31
|
+
}
|
32
|
+
|
33
|
+
/* ====== prof_allocation_t ====== */
|
34
|
+
prof_allocation_t*
|
35
|
+
prof_allocation_create(void)
|
36
|
+
{
|
37
|
+
prof_allocation_t *result = ALLOC(prof_allocation_t);
|
38
|
+
result->count = 0;
|
39
|
+
result->klass = Qnil;
|
40
|
+
result->klass_name = Qnil;
|
41
|
+
result->object = Qnil;
|
42
|
+
result->memory = 0;
|
43
|
+
result->source_line = 0;
|
44
|
+
result->source_file = Qnil;
|
45
|
+
result->key = 0;
|
46
|
+
|
47
|
+
return result;
|
48
|
+
}
|
49
|
+
|
50
|
+
prof_allocation_t*
|
51
|
+
prof_allocate_increment(prof_method_t* method, rb_trace_arg_t* trace_arg)
|
52
|
+
{
|
53
|
+
VALUE object = rb_tracearg_object(trace_arg);
|
54
|
+
if (BUILTIN_TYPE(object) == T_IMEMO)
|
55
|
+
return NULL;
|
56
|
+
|
57
|
+
VALUE klass = rb_obj_class(object);
|
58
|
+
|
59
|
+
int source_line = FIX2INT(rb_tracearg_lineno(trace_arg));
|
60
|
+
st_data_t key = allocations_key(klass, source_line);
|
61
|
+
|
62
|
+
prof_allocation_t* allocation = allocations_table_lookup(method->allocations_table, key);
|
63
|
+
if (!allocation)
|
64
|
+
{
|
65
|
+
allocation = prof_allocation_create();
|
66
|
+
allocation->source_line = source_line;
|
67
|
+
allocation->source_file = rb_tracearg_path(trace_arg);
|
68
|
+
allocation->klass_flags = 0;
|
69
|
+
allocation->klass = resolve_klass(klass, &allocation->klass_flags);
|
70
|
+
|
71
|
+
allocation->key = key;
|
72
|
+
allocations_table_insert(method->allocations_table, key, allocation);
|
73
|
+
}
|
74
|
+
|
75
|
+
allocation->count++;
|
76
|
+
allocation->memory += rb_obj_memsize_of(object);
|
77
|
+
|
78
|
+
return allocation;
|
79
|
+
}
|
80
|
+
|
81
|
+
static void
|
82
|
+
prof_allocation_ruby_gc_free(void *data)
|
83
|
+
{
|
84
|
+
prof_allocation_t* allocation = (prof_allocation_t*)data;
|
85
|
+
|
86
|
+
/* Has this allocation object been accessed by Ruby? If
|
87
|
+
yes clean it up so to avoid a segmentation fault. */
|
88
|
+
if (allocation->object != Qnil)
|
89
|
+
{
|
90
|
+
RDATA(allocation->object)->dmark = NULL;
|
91
|
+
RDATA(allocation->object)->dfree = NULL;
|
92
|
+
RDATA(allocation->object)->data = NULL;
|
93
|
+
allocation->object = Qnil;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
void
|
98
|
+
prof_allocation_free(prof_allocation_t* allocation)
|
99
|
+
{
|
100
|
+
prof_allocation_ruby_gc_free(allocation);
|
101
|
+
xfree(allocation);
|
102
|
+
}
|
103
|
+
|
104
|
+
size_t
|
105
|
+
prof_allocation_size(const void* data)
|
106
|
+
{
|
107
|
+
return sizeof(prof_allocation_t);
|
108
|
+
}
|
109
|
+
|
110
|
+
void
|
111
|
+
prof_allocation_mark(void *data)
|
112
|
+
{
|
113
|
+
prof_allocation_t* allocation = (prof_allocation_t*)data;
|
114
|
+
if (allocation->klass != Qnil)
|
115
|
+
rb_gc_mark(allocation->klass);
|
116
|
+
|
117
|
+
if (allocation->klass_name != Qnil)
|
118
|
+
rb_gc_mark(allocation->klass_name);
|
119
|
+
|
120
|
+
if (allocation->object != Qnil)
|
121
|
+
rb_gc_mark(allocation->object);
|
122
|
+
|
123
|
+
if (allocation->source_file != Qnil)
|
124
|
+
rb_gc_mark(allocation->source_file);
|
125
|
+
}
|
126
|
+
|
127
|
+
VALUE
|
128
|
+
prof_allocation_wrap(prof_allocation_t *allocation)
|
129
|
+
{
|
130
|
+
if (allocation->object == Qnil)
|
131
|
+
{
|
132
|
+
allocation->object = Data_Wrap_Struct(cRpAllocation, prof_allocation_mark , prof_allocation_ruby_gc_free, allocation);
|
133
|
+
}
|
134
|
+
return allocation->object;
|
135
|
+
}
|
136
|
+
|
137
|
+
static VALUE
|
138
|
+
prof_allocation_allocate(VALUE klass)
|
139
|
+
{
|
140
|
+
prof_allocation_t* allocation = prof_allocation_create();
|
141
|
+
allocation->object = prof_allocation_wrap(allocation);
|
142
|
+
return allocation->object;
|
143
|
+
}
|
144
|
+
|
145
|
+
prof_allocation_t*
|
146
|
+
prof_allocation_get(VALUE self)
|
147
|
+
{
|
148
|
+
/* Can't use Data_Get_Struct because that triggers the event hook
|
149
|
+
ending up in endless recursion. */
|
150
|
+
prof_allocation_t* result = DATA_PTR(self);
|
151
|
+
if (!result)
|
152
|
+
rb_raise(rb_eRuntimeError, "This RubyProf::Allocation instance has already been freed, likely because its profile has been freed.");
|
153
|
+
|
154
|
+
return result;
|
155
|
+
}
|
156
|
+
|
157
|
+
/* call-seq:
|
158
|
+
klass -> Class
|
159
|
+
|
160
|
+
Returns the type of Class being allocated. */
|
161
|
+
static VALUE
|
162
|
+
prof_allocation_klass_name(VALUE self)
|
163
|
+
{
|
164
|
+
prof_allocation_t* allocation = prof_allocation_get(self);
|
165
|
+
|
166
|
+
if (allocation->klass_name == Qnil)
|
167
|
+
allocation->klass_name = resolve_klass_name(allocation->klass, &allocation->klass_flags);
|
168
|
+
|
169
|
+
return allocation->klass_name;
|
170
|
+
}
|
171
|
+
|
172
|
+
/* call-seq:
|
173
|
+
klass_flags -> integer
|
174
|
+
|
175
|
+
Returns the klass flags */
|
176
|
+
|
177
|
+
static VALUE
|
178
|
+
prof_allocation_klass_flags(VALUE self)
|
179
|
+
{
|
180
|
+
prof_allocation_t* allocation = prof_allocation_get(self);
|
181
|
+
return INT2FIX(allocation->klass_flags);
|
182
|
+
}
|
183
|
+
|
184
|
+
/* call-seq:
|
185
|
+
source_file -> string
|
186
|
+
|
187
|
+
Returns the the line number where objects were allocated. */
|
188
|
+
static VALUE
|
189
|
+
prof_allocation_source_file(VALUE self)
|
190
|
+
{
|
191
|
+
prof_allocation_t* allocation = prof_allocation_get(self);
|
192
|
+
return allocation->source_file;
|
193
|
+
}
|
194
|
+
|
195
|
+
/* call-seq:
|
196
|
+
line -> number
|
197
|
+
|
198
|
+
Returns the the line number where objects were allocated. */
|
199
|
+
static VALUE
|
200
|
+
prof_allocation_source_line(VALUE self)
|
201
|
+
{
|
202
|
+
prof_allocation_t* allocation = prof_allocation_get(self);
|
203
|
+
return INT2FIX(allocation->source_line);
|
204
|
+
}
|
205
|
+
|
206
|
+
/* call-seq:
|
207
|
+
count -> number
|
208
|
+
|
209
|
+
Returns the number of times this class has been allocated. */
|
210
|
+
static VALUE
|
211
|
+
prof_allocation_count(VALUE self)
|
212
|
+
{
|
213
|
+
prof_allocation_t* allocation = prof_allocation_get(self);
|
214
|
+
return INT2FIX(allocation->count);
|
215
|
+
}
|
216
|
+
|
217
|
+
/* call-seq:
|
218
|
+
memory -> number
|
219
|
+
|
220
|
+
Returns the amount of memory allocated. */
|
221
|
+
static VALUE
|
222
|
+
prof_allocation_memory(VALUE self)
|
223
|
+
{
|
224
|
+
prof_allocation_t* allocation = prof_allocation_get(self);
|
225
|
+
return ULL2NUM(allocation->memory);
|
226
|
+
}
|
227
|
+
|
228
|
+
/* :nodoc: */
|
229
|
+
static VALUE
|
230
|
+
prof_allocation_dump(VALUE self)
|
231
|
+
{
|
232
|
+
prof_allocation_t* allocation = DATA_PTR(self);
|
233
|
+
|
234
|
+
VALUE result = rb_hash_new();
|
235
|
+
|
236
|
+
rb_hash_aset(result, ID2SYM(rb_intern("key")), INT2FIX(allocation->key));
|
237
|
+
rb_hash_aset(result, ID2SYM(rb_intern("klass_name")), prof_allocation_klass_name(self));
|
238
|
+
rb_hash_aset(result, ID2SYM(rb_intern("klass_flags")), INT2FIX(allocation->klass_flags));
|
239
|
+
rb_hash_aset(result, ID2SYM(rb_intern("source_file")), allocation->source_file);
|
240
|
+
rb_hash_aset(result, ID2SYM(rb_intern("source_line")), INT2FIX(allocation->source_line));
|
241
|
+
rb_hash_aset(result, ID2SYM(rb_intern("count")), INT2FIX(allocation->count));
|
242
|
+
rb_hash_aset(result, ID2SYM(rb_intern("memory")), LONG2FIX(allocation->memory));
|
243
|
+
|
244
|
+
return result;
|
245
|
+
}
|
246
|
+
|
247
|
+
/* :nodoc: */
|
248
|
+
static VALUE
|
249
|
+
prof_allocation_load(VALUE self, VALUE data)
|
250
|
+
{
|
251
|
+
prof_allocation_t* allocation = DATA_PTR(self);
|
252
|
+
allocation->object = self;
|
253
|
+
|
254
|
+
allocation->key = FIX2LONG(rb_hash_aref(data, ID2SYM(rb_intern("key"))));
|
255
|
+
allocation->klass_name = rb_hash_aref(data, ID2SYM(rb_intern("klass_name")));
|
256
|
+
allocation->klass_flags = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("klass_flags"))));
|
257
|
+
allocation->source_file = rb_hash_aref(data, ID2SYM(rb_intern("source_file")));
|
258
|
+
allocation->source_line = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("source_line"))));
|
259
|
+
allocation->count = FIX2INT(rb_hash_aref(data, ID2SYM(rb_intern("count"))));
|
260
|
+
allocation->memory = FIX2LONG(rb_hash_aref(data, ID2SYM(rb_intern("memory"))));
|
261
|
+
|
262
|
+
return data;
|
263
|
+
}
|
264
|
+
|
265
|
+
void rp_init_allocation(void)
|
266
|
+
{
|
267
|
+
cRpAllocation = rb_define_class_under(mProf, "Allocation", rb_cData);
|
268
|
+
rb_undef_method(CLASS_OF(cRpAllocation), "new");
|
269
|
+
rb_define_alloc_func(cRpAllocation, prof_allocation_allocate);
|
270
|
+
|
271
|
+
rb_define_method(cRpAllocation, "klass_name", prof_allocation_klass_name, 0);
|
272
|
+
rb_define_method(cRpAllocation, "klass_flags", prof_allocation_klass_flags, 0);
|
273
|
+
rb_define_method(cRpAllocation, "source_file", prof_allocation_source_file, 0);
|
274
|
+
rb_define_method(cRpAllocation, "line", prof_allocation_source_line, 0);
|
275
|
+
rb_define_method(cRpAllocation, "count", prof_allocation_count, 0);
|
276
|
+
rb_define_method(cRpAllocation, "memory", prof_allocation_memory, 0);
|
277
|
+
rb_define_method(cRpAllocation, "_dump_data", prof_allocation_dump, 0);
|
278
|
+
rb_define_method(cRpAllocation, "_load_data", prof_allocation_load, 1);
|
279
|
+
}
|