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
|
# File 'lib/fluent/rubyprof.rb', line 18
def parse_options(argv = ARGV)
op = OptionParser.new
op.banner += ' <start/stop> [output_file]'
(class<<self;self;end).module_eval do
define_method(:usage) do |msg|
puts op.to_s
puts "error: #{msg}" if msg
exit 1
end
end
opts = {
host: '127.0.0.1',
port: 24230,
unix: nil,
command: nil,
output: '/tmp/fluent-rubyprof.txt',
measure_mode: 'PROCESS_TIME',
printer: 'flat',
}
op.on('-h', '--host HOST', "fluent host (default: #{opts[:host]})") {|v|
opts[:host] = v
}
op.on('-p', '--port PORT', "debug_agent tcp port (default: #{opts[:host]})", Integer) {|v|
opts[:port] = v
}
op.on('-u', '--unix PATH', "use unix socket instead of tcp") {|v|
opts[:unix] = v
}
op.on('-o', '--output PATH', "output path (default: #{opts[:output]})") {|v|
opts[:output] = v
}
op.on('-m', '--measure_mode MEASURE_MODE', "ruby-prof measure mode (default: #{opts[:measure_mode]})") {|v|
opts[:measure_mode] = v
}
op.on('-P', '--printer PRINTER', PRINTERS.keys,
"ruby-prof print format (default: #{opts[:printer]})",
"currently one of: #{PRINTERS.keys.join(', ')}") {|v|
opts[:printer] = v
}
op.parse!(argv)
opts[:command] = argv.shift
unless %w[start stop].include?(opts[:command])
raise OptionParser::InvalidOption.new("`start` or `stop` must be specified as the 1st argument")
end
measure_modes = %w[PROCESS_TIME WALL_TIME CPU_TIME ALLOCATIONS MEMORY GC_RUNS GC_TIME]
unless measure_modes.include?(opts[:measure_mode])
raise OptionParser::InvalidOption.new("-m allows one of #{measure_modes.join(', ')}")
end
opts
end
|