ruby-prof 0.8.1-x86-mingw32 → 0.11.0.rc1-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +89 -13
- data/LICENSE +4 -3
- data/{README → README.rdoc} +155 -162
- data/Rakefile +50 -123
- data/bin/ruby-prof +86 -47
- data/examples/empty.png +0 -0
- data/examples/graph.dot +106 -0
- data/examples/graph.png +0 -0
- data/examples/minus.png +0 -0
- data/examples/multi.flat.txt +23 -0
- data/examples/multi.graph.html +906 -0
- data/examples/multi.grind.dat +194 -0
- data/examples/multi.stack.html +573 -0
- data/examples/plus.png +0 -0
- data/examples/stack.html +573 -0
- data/ext/ruby_prof/extconf.rb +53 -0
- data/ext/ruby_prof/rp_call_info.c +369 -0
- data/ext/ruby_prof/rp_call_info.h +46 -0
- data/ext/ruby_prof/rp_measure.c +48 -0
- data/ext/ruby_prof/rp_measure.h +45 -0
- data/ext/ruby_prof/rp_measure_allocations.c +86 -0
- data/ext/ruby_prof/rp_measure_cpu_time.c +112 -0
- data/ext/ruby_prof/rp_measure_gc_runs.c +87 -0
- data/ext/ruby_prof/rp_measure_gc_time.c +73 -0
- data/ext/ruby_prof/rp_measure_memory.c +81 -0
- data/ext/ruby_prof/rp_measure_process_time.c +71 -0
- data/ext/ruby_prof/rp_measure_wall_time.c +42 -0
- data/ext/ruby_prof/rp_method.c +363 -0
- data/ext/ruby_prof/rp_method.h +55 -0
- data/ext/ruby_prof/rp_stack.c +61 -0
- data/ext/ruby_prof/rp_stack.h +40 -0
- data/ext/ruby_prof/rp_thread.c +113 -0
- data/ext/ruby_prof/rp_thread.h +20 -0
- data/ext/ruby_prof/ruby_prof.c +332 -1377
- data/ext/ruby_prof/ruby_prof.h +54 -188
- data/ext/ruby_prof/version.h +6 -3
- data/lib/1.8/ruby_prof.so +0 -0
- data/lib/1.9/ruby_prof.exp +0 -0
- data/lib/1.9/ruby_prof.ilk +0 -0
- data/lib/1.9/ruby_prof.lib +0 -0
- data/lib/1.9/ruby_prof.pdb +0 -0
- data/lib/1.9/ruby_prof.so +0 -0
- data/lib/ruby-prof.rb +32 -18
- data/lib/ruby-prof/abstract_printer.rb +15 -5
- data/lib/ruby-prof/aggregate_call_info.rb +11 -3
- data/lib/ruby-prof/call_info.rb +68 -1
- data/lib/ruby-prof/call_stack_printer.rb +775 -0
- data/lib/ruby-prof/call_tree_printer.rb +17 -9
- data/lib/ruby-prof/compatibility.rb +134 -0
- data/lib/ruby-prof/dot_printer.rb +152 -0
- data/lib/ruby-prof/empty.png +0 -0
- data/lib/ruby-prof/flat_printer.rb +23 -24
- data/lib/ruby-prof/flat_printer_with_line_numbers.rb +17 -21
- data/lib/ruby-prof/graph_html_printer.rb +69 -39
- data/lib/ruby-prof/graph_printer.rb +35 -35
- data/lib/ruby-prof/method_info.rb +26 -4
- data/lib/ruby-prof/minus.png +0 -0
- data/lib/ruby-prof/multi_printer.rb +56 -0
- data/lib/ruby-prof/plus.png +0 -0
- data/lib/ruby-prof/profile.rb +72 -0
- data/lib/ruby-prof/rack.rb +31 -0
- data/lib/ruby-prof/symbol_to_proc.rb +3 -1
- data/lib/ruby-prof/task.rb +20 -19
- data/lib/ruby-prof/test.rb +5 -3
- data/lib/ruby_prof.exp +0 -0
- data/lib/ruby_prof.ilk +0 -0
- data/lib/ruby_prof.lib +0 -0
- data/lib/ruby_prof.pdb +0 -0
- data/lib/ruby_prof.so +0 -0
- data/lib/unprof.rb +2 -0
- data/test/aggregate_test.rb +29 -14
- data/test/basic_test.rb +3 -251
- data/test/bug_test.rb +6 -0
- data/test/duplicate_names_test.rb +4 -4
- data/test/dynamic_method_test.rb +61 -0
- data/test/enumerable_test.rb +4 -4
- data/test/exceptions_test.rb +6 -5
- data/test/exclude_threads_test.rb +47 -47
- data/test/exec_test.rb +5 -5
- data/test/line_number_test.rb +16 -16
- data/test/measure_allocations_test.rb +25 -0
- data/test/measure_cpu_time_test.rb +212 -0
- data/test/measure_gc_runs_test.rb +29 -0
- data/test/measure_gc_time_test.rb +29 -0
- data/test/measure_memory_test.rb +36 -0
- data/test/measure_process_time_test.rb +205 -0
- data/test/measure_wall_time_test.rb +209 -0
- data/test/method_elimination_test.rb +74 -0
- data/test/module_test.rb +12 -21
- data/test/multi_printer_test.rb +81 -0
- data/test/no_method_class_test.rb +5 -3
- data/test/prime.rb +7 -10
- data/test/prime_test.rb +3 -3
- data/test/printers_test.rb +180 -54
- data/test/recursive_test.rb +34 -72
- data/test/singleton_test.rb +5 -4
- data/test/stack_printer_test.rb +73 -0
- data/test/stack_test.rb +7 -7
- data/test/start_stop_test.rb +23 -6
- data/test/test_helper.rb +81 -0
- data/test/test_suite.rb +35 -21
- data/test/thread_test.rb +40 -39
- data/test/unique_call_path_test.rb +6 -6
- metadata +106 -51
- data/ext/ruby_prof/measure_allocations.h +0 -58
- data/ext/ruby_prof/measure_cpu_time.h +0 -152
- data/ext/ruby_prof/measure_gc_runs.h +0 -76
- data/ext/ruby_prof/measure_gc_time.h +0 -57
- data/ext/ruby_prof/measure_memory.h +0 -101
- data/ext/ruby_prof/measure_process_time.h +0 -52
- data/ext/ruby_prof/measure_wall_time.h +0 -53
- data/ext/ruby_prof/mingw/Rakefile +0 -23
- data/ext/ruby_prof/mingw/build.rake +0 -38
- data/rails/environment/profile.rb +0 -24
- data/rails/example/example_test.rb +0 -9
- data/rails/profile_test_helper.rb +0 -21
- data/test/current_failures_windows +0 -8
- data/test/measurement_test.rb +0 -121
- data/test/ruby-prof-bin +0 -20
@@ -1,14 +1,26 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module RubyProf
|
4
4
|
# Generate profiling information in calltree format
|
5
5
|
# for use by kcachegrind and similar tools.
|
6
6
|
|
7
7
|
class CallTreePrinter < AbstractPrinter
|
8
|
+
# Specify print options.
|
9
|
+
#
|
10
|
+
# options - Hash table
|
11
|
+
# :min_percent - Number 0 to 100 that specifes the minimum
|
12
|
+
# %self (the methods self time divided by the
|
13
|
+
# overall total time) that a method must take
|
14
|
+
# for it to be printed out in the report.
|
15
|
+
# Default value is 0.
|
16
|
+
#
|
17
|
+
# :print_file - True or false. Specifies if a method's source
|
18
|
+
# file should be printed. Default value if false.
|
19
|
+
#
|
8
20
|
def print(output = STDOUT, options = {})
|
9
21
|
@output = output
|
10
22
|
setup_options(options)
|
11
|
-
|
23
|
+
|
12
24
|
# add a header - this information is somewhat arbitrary
|
13
25
|
@output << "events: "
|
14
26
|
case RubyProf.measure_mode
|
@@ -55,15 +67,11 @@ module RubyProf
|
|
55
67
|
File.expand_path(method.source_file)
|
56
68
|
end
|
57
69
|
|
58
|
-
def name(method)
|
59
|
-
"#{method.klass_name}::#{method.method_name}"
|
60
|
-
end
|
61
|
-
|
62
70
|
def print_methods(thread_id, methods)
|
63
|
-
methods.reverse_each do |method|
|
71
|
+
methods.reverse_each do |method|
|
64
72
|
# Print out the file and method name
|
65
73
|
@output << "fl=#{file(method)}\n"
|
66
|
-
@output << "fn=#{
|
74
|
+
@output << "fn=#{method_name(method)}\n"
|
67
75
|
|
68
76
|
# Now print out the function line number and its self time
|
69
77
|
@output << "#{method.line} #{convert(method.self_time)}\n"
|
@@ -71,7 +79,7 @@ module RubyProf
|
|
71
79
|
# Now print out all the children methods
|
72
80
|
method.children.each do |callee|
|
73
81
|
@output << "cfl=#{file(callee.target)}\n"
|
74
|
-
@output << "cfn=#{
|
82
|
+
@output << "cfn=#{method_name(callee.target)}\n"
|
75
83
|
@output << "calls=#{callee.called} #{callee.line}\n"
|
76
84
|
|
77
85
|
# Print out total times here!
|
@@ -0,0 +1,134 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# These methods are here for backwards compatability with previous RubyProf releases
|
4
|
+
module RubyProf
|
5
|
+
# Measurements
|
6
|
+
def self.cpu_frequency
|
7
|
+
Measure::CpuTime.frequency
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.cpu_frequency=(value)
|
11
|
+
Measure::CpuTime.frequency = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.measure_allocations
|
15
|
+
Measure::Allocations.measure
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.measure_cpu_time
|
19
|
+
Measure::CpuTime.measure
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.measure_gc_runs
|
23
|
+
Measure::GcRuns.measure
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.measure_gc_time
|
27
|
+
Measure::GcTime.measure
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.measure_memory
|
31
|
+
Measure::Memory.measure
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.measure_process_time
|
35
|
+
Measure::ProcessTime.measure
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.measure_wall_time
|
39
|
+
Measure::WallTime.measure
|
40
|
+
end
|
41
|
+
|
42
|
+
# call-seq:
|
43
|
+
# measure_mode -> measure_mode
|
44
|
+
#
|
45
|
+
# Returns what ruby-prof is measuring. Valid values include:
|
46
|
+
#
|
47
|
+
# *RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock functions in the C Runtime library.
|
48
|
+
# *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
|
49
|
+
# *RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms.
|
50
|
+
# *RubyProf::ALLOCATIONS - Measure object allocations. This requires a patched Ruby interpreter.
|
51
|
+
# *RubyProf::MEMORY - Measure memory size. This requires a patched Ruby interpreter.
|
52
|
+
# *RubyProf::GC_RUNS - Measure number of garbage collections. This requires a patched Ruby interpreter.
|
53
|
+
# *RubyProf::GC_TIME - Measure time spent doing garbage collection. This requires a patched Ruby interpreter.*/
|
54
|
+
|
55
|
+
def self.measure_mode
|
56
|
+
@measure_mode ||= RubyProf::WALL_TIME
|
57
|
+
end
|
58
|
+
|
59
|
+
# call-seq:
|
60
|
+
# measure_mode=value -> void
|
61
|
+
#
|
62
|
+
# Specifies what ruby-prof should measure. Valid values include:
|
63
|
+
#
|
64
|
+
# *RubyProf::PROCESS_TIME - Measure process time. This is default. It is implemented using the clock functions in the C Runtime library.
|
65
|
+
# *RubyProf::WALL_TIME - Measure wall time using gettimeofday on Linx and GetLocalTime on Windows
|
66
|
+
# *RubyProf::CPU_TIME - Measure time using the CPU clock counter. This mode is only supported on Pentium or PowerPC platforms.
|
67
|
+
# *RubyProf::ALLOCATIONS - Measure object allocations. This requires a patched Ruby interpreter.
|
68
|
+
# *RubyProf::MEMORY - Measure memory size. This requires a patched Ruby interpreter.
|
69
|
+
# *RubyProf::GC_RUNS - Measure number of garbage collections. This requires a patched Ruby interpreter.
|
70
|
+
# *RubyProf::GC_TIME - Measure time spent doing garbage collection. This requires a patched Ruby interpreter.*/
|
71
|
+
def self.measure_mode=(value)
|
72
|
+
@measure_mode = value
|
73
|
+
end
|
74
|
+
|
75
|
+
# call-seq:
|
76
|
+
# exclude_threads= -> void
|
77
|
+
#
|
78
|
+
# Specifies what threads ruby-prof should exclude from profiling
|
79
|
+
|
80
|
+
def self.exclude_threads
|
81
|
+
@exclude_threads ||= Array.new
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.exclude_threads=(value)
|
85
|
+
@exclude_threads = value
|
86
|
+
end
|
87
|
+
|
88
|
+
# Profiling
|
89
|
+
def self.start
|
90
|
+
if running?
|
91
|
+
raise(RuntimeError, "RubyProf is already running");
|
92
|
+
end
|
93
|
+
@profile = Profile.new(self.measure_mode, self.exclude_threads)
|
94
|
+
@profile.start
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.pause
|
98
|
+
unless running?
|
99
|
+
raise(RuntimeError, "RubyProf.start was not yet called");
|
100
|
+
end
|
101
|
+
@profile.pause
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.running?
|
105
|
+
if defined?(@profile) and @profile
|
106
|
+
@profile.running?
|
107
|
+
else
|
108
|
+
false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.resume
|
113
|
+
unless running?
|
114
|
+
raise(RuntimeError, "RubyProf.start was not yet called");
|
115
|
+
end
|
116
|
+
@profile.resume
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.stop
|
120
|
+
unless running?
|
121
|
+
raise(RuntimeError, "RubyProf.start was not yet called");
|
122
|
+
end
|
123
|
+
result = @profile.stop
|
124
|
+
@profile = nil
|
125
|
+
result
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.profile(&block)
|
129
|
+
if running?
|
130
|
+
raise(RuntimeError, "RubyProf is already running");
|
131
|
+
end
|
132
|
+
Profile.profile(self.measure_mode, self.exclude_threads, &block)
|
133
|
+
end
|
134
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
module RubyProf
|
6
|
+
# Generates a graphviz graph in dot format.
|
7
|
+
# To use the dot printer:
|
8
|
+
#
|
9
|
+
# result = RubyProf.profile do
|
10
|
+
# [code to profile]
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# printer = RubyProf::DotPrinter.new(result)
|
14
|
+
# printer.print(STDOUT)
|
15
|
+
#
|
16
|
+
# You can use either dot viewer such as GraphViz, or the dot command line tool
|
17
|
+
# to reformat the output into a wide variety of outputs:
|
18
|
+
#
|
19
|
+
# dot -Tpng graph.dot > graph.png
|
20
|
+
#
|
21
|
+
class DotPrinter < RubyProf::AbstractPrinter
|
22
|
+
CLASS_COLOR = '"#666666"'
|
23
|
+
EDGE_COLOR = '"#666666"'
|
24
|
+
|
25
|
+
# Creates the DotPrinter using a RubyProf::Result.
|
26
|
+
def initialize(result)
|
27
|
+
super(result)
|
28
|
+
@seen_methods = Set.new
|
29
|
+
end
|
30
|
+
|
31
|
+
# Print a graph report to the provided output.
|
32
|
+
#
|
33
|
+
# output - Any IO object, including STDOUT or a file. The default value is
|
34
|
+
# STDOUT.
|
35
|
+
#
|
36
|
+
# options - Hash of print options. See #setup_options
|
37
|
+
# for more information.
|
38
|
+
#
|
39
|
+
# When profiling results that cover a large number of method calls it
|
40
|
+
# helps to use the :min_percent option, for example:
|
41
|
+
#
|
42
|
+
# DotPrinter.new(result).print(STDOUT, :min_percent=>5)
|
43
|
+
#
|
44
|
+
def print(output = STDOUT, options = {})
|
45
|
+
@output = output
|
46
|
+
setup_options(options)
|
47
|
+
|
48
|
+
total_time = thread_times.values.inject{|a,b| a+b}
|
49
|
+
|
50
|
+
puts 'digraph "Profile" {'
|
51
|
+
puts "label=\"#{mode_name} >=#{min_percent}%\\nTotal: #{total_time}\";"
|
52
|
+
puts "labelloc=t;"
|
53
|
+
puts "labeljust=l;"
|
54
|
+
print_threads
|
55
|
+
puts '}'
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# Something of a hack, figure out which constant went with the
|
61
|
+
# RubyProf.measure_mode so that we can display it. Otherwise it's easy to
|
62
|
+
# forget what measurement was made.
|
63
|
+
def mode_name
|
64
|
+
RubyProf.constants.find{|c| RubyProf.const_get(c) == RubyProf.measure_mode}
|
65
|
+
end
|
66
|
+
|
67
|
+
# Computes the total time per thread:
|
68
|
+
def thread_times
|
69
|
+
@thread_times ||= begin
|
70
|
+
times = {}
|
71
|
+
@result.threads.each do |thread_id, methods|
|
72
|
+
toplevel = methods.sort.last
|
73
|
+
|
74
|
+
total_time = toplevel.total_time
|
75
|
+
# This looks like a hack for very small times... from GraphPrinter
|
76
|
+
total_time = 0.01 if total_time == 0
|
77
|
+
times[thread_id] = total_time
|
78
|
+
end
|
79
|
+
|
80
|
+
times
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def print_threads
|
85
|
+
# sort assumes that spawned threads have higher object_ids
|
86
|
+
@result.threads.sort.each do |thread_id, methods|
|
87
|
+
puts "subgraph \"Thread #{thread_id}\" {"
|
88
|
+
|
89
|
+
print_methods(thread_id, methods)
|
90
|
+
puts "}"
|
91
|
+
|
92
|
+
print_classes(thread_id, methods)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Determines an ID to use to represent the subject in the Dot file.
|
97
|
+
def dot_id(subject)
|
98
|
+
subject.object_id
|
99
|
+
end
|
100
|
+
|
101
|
+
def print_methods(thread_id, methods)
|
102
|
+
total_time = thread_times[thread_id]
|
103
|
+
methods.sort_by(&sort_method).reverse_each do |method|
|
104
|
+
total_percentage = (method.total_time/total_time) * 100
|
105
|
+
|
106
|
+
next if total_percentage < min_percent
|
107
|
+
name = method_name(method).split("#").last
|
108
|
+
puts "#{dot_id(method)} [label=\"#{name}\\n(#{total_percentage.round}%)\"];"
|
109
|
+
@seen_methods << method
|
110
|
+
print_edges(total_time, method)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def print_classes(thread_id, methods)
|
115
|
+
grouped = {}
|
116
|
+
methods.each{|m| grouped[m.klass_name] ||= []; grouped[m.klass_name] << m}
|
117
|
+
grouped.each do |cls, methods2|
|
118
|
+
# Filter down to just seen methods
|
119
|
+
big_methods, small_methods = methods2.partition{|m| @seen_methods.include? m}
|
120
|
+
|
121
|
+
if !big_methods.empty?
|
122
|
+
puts "subgraph cluster_#{cls.object_id} {"
|
123
|
+
puts "label = \"#{cls}\";"
|
124
|
+
puts "fontcolor = #{CLASS_COLOR};"
|
125
|
+
puts "fontsize = 16;"
|
126
|
+
puts "color = #{CLASS_COLOR};"
|
127
|
+
big_methods.each do |m|
|
128
|
+
puts "#{m.object_id};"
|
129
|
+
end
|
130
|
+
puts "}"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def print_edges(total_time, method)
|
136
|
+
method.aggregate_children.sort_by(&:total_time).reverse.each do |child|
|
137
|
+
|
138
|
+
target_percentage = (child.target.total_time / total_time) * 100.0
|
139
|
+
next if target_percentage < min_percent
|
140
|
+
|
141
|
+
# Get children method
|
142
|
+
puts "#{dot_id(method)} -> #{dot_id(child.target)} [label=\"#{child.called}/#{child.target.called}\" fontsize=10 fontcolor=#{EDGE_COLOR}];"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Silly little helper for printing to the @output
|
147
|
+
def puts(str)
|
148
|
+
@output.puts(str)
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
Binary file
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
module RubyProf
|
4
|
-
# Generates flat[link:files/examples/flat_txt.html] profile reports as text.
|
4
|
+
# Generates flat[link:files/examples/flat_txt.html] profile reports as text.
|
5
5
|
# To use the flat printer:
|
6
6
|
#
|
7
7
|
# result = RubyProf.profile do
|
@@ -9,32 +9,35 @@ module RubyProf
|
|
9
9
|
# end
|
10
10
|
#
|
11
11
|
# printer = RubyProf::FlatPrinter.new(result)
|
12
|
-
# printer.print(STDOUT,
|
12
|
+
# printer.print(STDOUT, {})
|
13
13
|
#
|
14
14
|
class FlatPrinter < AbstractPrinter
|
15
15
|
# Print a flat profile report to the provided output.
|
16
|
-
#
|
17
|
-
# output - Any IO
|
16
|
+
#
|
17
|
+
# output - Any IO object, including STDOUT or a file.
|
18
18
|
# The default value is STDOUT.
|
19
|
-
#
|
20
|
-
# options - Hash of print options. See #setup_options
|
21
|
-
#
|
19
|
+
#
|
20
|
+
# options - Hash of print options. See #setup_options
|
21
|
+
# for more information.
|
22
22
|
#
|
23
23
|
def print(output = STDOUT, options = {})
|
24
24
|
@output = output
|
25
|
+
# Now sort methods by largest self time by default,
|
26
|
+
# not total time like in other printouts
|
27
|
+
options[:sort_method] ||= :self_time
|
25
28
|
setup_options(options)
|
26
29
|
print_threads
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
31
34
|
def print_threads
|
32
35
|
@result.threads.each do |thread_id, methods|
|
33
36
|
print_methods(thread_id, methods)
|
34
37
|
@output << "\n" * 2
|
35
38
|
end
|
36
39
|
end
|
37
|
-
|
40
|
+
|
38
41
|
def print_methods(thread_id, methods)
|
39
42
|
# Get total time
|
40
43
|
toplevel = methods.max
|
@@ -42,27 +45,23 @@ module RubyProf
|
|
42
45
|
if total_time == 0
|
43
46
|
total_time = 0.01
|
44
47
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
methods = methods.sort do |m1, m2|
|
49
|
-
m1.self_time <=> m2.self_time
|
50
|
-
end.reverse
|
51
|
-
|
48
|
+
|
49
|
+
methods = methods.sort_by(&sort_method).reverse
|
50
|
+
|
52
51
|
@output << "Thread ID: %d\n" % thread_id
|
53
52
|
@output << "Total: %0.6f\n" % total_time
|
54
53
|
@output << "\n"
|
55
54
|
@output << " %self total self wait child calls name\n"
|
56
55
|
|
57
|
-
sum = 0
|
56
|
+
sum = 0
|
58
57
|
methods.each do |method|
|
59
58
|
self_percent = (method.self_time / total_time) * 100
|
60
59
|
next if self_percent < min_percent
|
61
|
-
|
60
|
+
|
62
61
|
sum += method.self_time
|
63
62
|
#self_time_called = method.called > 0 ? method.self_time/method.called : 0
|
64
63
|
#total_time_called = method.called > 0? method.total_time/method.called : 0
|
65
|
-
|
64
|
+
|
66
65
|
@output << "%6.2f %8.2f %8.2f %8.2f %8.2f %8d %s\n" % [
|
67
66
|
method.self_time / total_time * 100, # %self
|
68
67
|
method.total_time, # total
|
@@ -75,4 +74,4 @@ module RubyProf
|
|
75
74
|
end
|
76
75
|
end
|
77
76
|
end
|
78
|
-
end
|
77
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
3
|
module RubyProf
|
4
|
-
# Generates flat[link:files/examples/flat_txt.html] profile reports as text.
|
4
|
+
# Generates flat[link:files/examples/flat_txt.html] profile reports as text.
|
5
5
|
# To use the flat printer with line numbers:
|
6
6
|
#
|
7
7
|
# result = RubyProf.profile do
|
@@ -9,7 +9,7 @@ module RubyProf
|
|
9
9
|
# end
|
10
10
|
#
|
11
11
|
# printer = RubyProf::FlatPrinterWithLineNumbers.new(result)
|
12
|
-
# printer.print(STDOUT,
|
12
|
+
# printer.print(STDOUT, {})
|
13
13
|
#
|
14
14
|
class FlatPrinterWithLineNumbers < FlatPrinter
|
15
15
|
|
@@ -20,26 +20,22 @@ module RubyProf
|
|
20
20
|
if total_time == 0
|
21
21
|
total_time = 0.01
|
22
22
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
methods = methods.sort do |m1, m2|
|
27
|
-
m1.self_time <=> m2.self_time
|
28
|
-
end.reverse
|
29
|
-
|
23
|
+
|
24
|
+
methods = methods.sort_by(&sort_method).reverse
|
25
|
+
|
30
26
|
@output << "Thread ID: %d\n" % thread_id
|
31
27
|
@output << "Total: %0.6f\n" % total_time
|
32
28
|
@output << "\n"
|
33
29
|
@output << " %self total self wait child calls name\n"
|
34
|
-
sum = 0
|
30
|
+
sum = 0
|
35
31
|
methods.each do |method|
|
36
32
|
self_percent = (method.self_time / total_time) * 100
|
37
33
|
next if self_percent < min_percent
|
38
|
-
|
34
|
+
|
39
35
|
sum += method.self_time
|
40
36
|
#self_time_called = method.called > 0 ? method.self_time/method.called : 0
|
41
37
|
#total_time_called = method.called > 0? method.total_time/method.called : 0
|
42
|
-
|
38
|
+
|
43
39
|
@output << "%6.2f %8.2f %8.2f %8.2f %8.2f %8d %s " % [
|
44
40
|
method.self_time / total_time * 100, # %self
|
45
41
|
method.total_time, # total
|
@@ -47,26 +43,26 @@ module RubyProf
|
|
47
43
|
method.wait_time, # wait
|
48
44
|
method.children_time, # children
|
49
45
|
method.called, # calls
|
50
|
-
method_name(method), # name
|
46
|
+
method_name(method), # name
|
51
47
|
]
|
52
48
|
if method.source_file != 'ruby_runtime'
|
53
49
|
@output << " %s:%s" % [File.expand_path(method.source_file), method.line]
|
54
50
|
end
|
55
51
|
@output << "\n\tcalled from: "
|
56
|
-
|
52
|
+
|
57
53
|
# make sure they're unique
|
58
|
-
method.call_infos.map{|ci|
|
54
|
+
method.call_infos.map{|ci|
|
59
55
|
if ci.parent && ci.parent.target.source_file != 'ruby_runtime'
|
60
56
|
[method_name(ci.parent.target), File.expand_path(ci.parent.target.source_file), ci.parent.target.line]
|
61
57
|
else
|
62
58
|
nil
|
63
|
-
end
|
59
|
+
end
|
64
60
|
}.compact.uniq.each{|args|
|
65
|
-
@output << " %s (%s:%s) " % args
|
61
|
+
@output << " %s (%s:%s) " % args
|
66
62
|
}
|
67
|
-
@output << "\n\n"
|
63
|
+
@output << "\n\n"
|
68
64
|
end
|
69
65
|
end
|
70
66
|
end
|
71
|
-
end
|
67
|
+
end
|
72
68
|
|