blob: c8813a22df20875069e0578e2813b92e7e932145 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
require 'rubinius/agent'
module ActiveSupport
module Testing
module Performance
if !ARGV.include?('--benchmark')
DEFAULTS.merge!(
{ :metrics => [:wall_time],
:formats => [:flat, :graph] })
end
protected
def run_gc
GC.run(true)
end
class Performer; end
class Profiler < Performer
def run
@profiler = Rubinius::Profiler::Instrumenter.new
@profiler.profile(false) do
profile_options[:runs].to_i.times { run_test(@metric, :profile) }
end
@total = @profiler.info[:runtime] / 1000 / 1000 / 1000.0 # seconds
end
def report
super
end
def record
if(profile_options[:formats].include?(:flat))
File.open(output_filename('FlatPrinter'), 'wb') do |file|
@profiler.show(file)
end
end
if(profile_options[:formats].include?(:graph))
@profiler.set_options({:graph => true})
File.open(output_filename('GraphPrinter'), 'wb') do |file|
@profiler.show(file)
end
end
end
protected
def output_filename(printer)
suffix =
case printer
when 'FlatPrinter'; 'flat.txt'
when 'GraphPrinter'; 'graph.txt'
else printer.sub(/Printer$/, '').underscore
end
"#{super()}_#{suffix}"
end
end
module Metrics
class Base
attr_reader :loopback
def profile
yield
end
protected
def with_gc_stats
@loopback = Rubinius::Agent.loopback
GC.run(true)
yield
end
end
class Time < Base; end
class ProcessTime < Time
# unsupported
def measure; 0; end
end
class WallTime < Time
def measure
super
end
end
class CpuTime < Time
# unsupported
def measure; 0; end
end
class Memory < Base
def measure
loopback.get("system.memory.counter.bytes").last
end
end
class Objects < Amount
def measure
loopback.get("system.memory.counter.objects").last
end
end
class GcRuns < Amount
def measure
loopback.get("system.gc.full.count").last + loopback.get("system.gc.young.count").last
end
end
class GcTime < Time
def measure
(loopback.get("system.gc.full.wallclock").last + loopback.get("system.gc.young.wallclock").last) / 1000.0
end
end
end
end
end
end
|