Class: Morpheus::Cli::BenchmarkCommand
- Inherits:
-
Object
- Object
- Morpheus::Cli::BenchmarkCommand
show all
- Includes:
- CliCommand
- Defined in:
- lib/morpheus/cli/commands/standard/benchmark_command.rb
Instance Attribute Summary
Attributes included from CliCommand
#no_prompt
Instance Method Summary
collapse
Methods included from CliCommand
#build_common_options, #build_option_type_options, #command_name, #default_subcommand, #establish_remote_appliance_connection, #full_command_usage, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_command_result, #parse_id_list, #parse_list_options, #parse_list_subtitles, #print, #print_error, #print_to_file, #puts, #puts_error, #raise_command_error, #render_with_format, #run_command_for_each_arg, #subcommand_aliases, #subcommand_usage, #subcommands, #usage, #verify_access_token!
Constructor Details
this would be cool, we should store all benchmarking results in memory or on disk =o register_subcommands :list, :get, :put, :remove
18
19
20
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 18
def initialize()
end
|
Instance Method Details
#connect(opts) ⇒ Object
22
23
24
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 22
def connect(opts)
end
|
#execute(args) ⇒ Object
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 295
def execute(args)
benchmark_name = nil
options = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[command...]")
opts.on('--name NAME', String, "Name for the benchmark. Default is the command itself.") do |val|
benchmark_name = val
end
build_common_options(opts, options, [:quiet])
opts. = "Benchmark a specified command.\n[command] is required. This is the command to execute\n"
end
optparse.parse!(args)
connect(options)
if args.count < 1
print_error Morpheus::Terminal.angry_prompt
puts_error "wrong number of arguments, expected 1-N and got #{args.count} #{args.join(' ')}\n#{optparse}"
return 1
end
cmd = args.join(' ')
start_benchmark(benchmark_name || cmd)
cmd_result = execute_commands_as_expression(cmd)
exit_code, err = parse_command_result(cmd_result)
benchmark_record = stop_benchmark(exit_code, err)
Morpheus::Logging::DarkPrinter.puts(cyan + dark + benchmark_record.msg) if benchmark_record
return 0
end
|
#handle(args) ⇒ Object
26
27
28
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 26
def handle(args)
handle_subcommand(args)
end
|
#off(args) ⇒ Object
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
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 60
def off(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("")
build_common_options(opts, options, [:quiet])
opts. = "Disable global benchmarking. \nThe default state for this setting is off.\n"
end
optparse.parse!(args)
connect(options)
if args.count != 0
print_error Morpheus::Terminal.angry_prompt
puts_error "wrong number of arguments, expected 0 and got #{args.count} #{args.join(' ')}\n#{optparse}"
return 1
end
benchmark_was_enabled = Morpheus::Benchmarking.enabled
Morpheus::Benchmarking.enabled = false
my_terminal.benchmarking = Morpheus::Benchmarking.enabled
unless options[:quiet]
puts "#{cyan}benchmark: #{dark}off#{reset}"
end
return 0
end
|
#off?(args) ⇒ Boolean
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 116
def off?(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("")
build_common_options(opts, options, [:quiet])
opts. = "Print the value of the global benchmark setting. \nExit 0 if off.\n"
end
optparse.parse!(args)
connect(options)
if args.count != 0
print_error Morpheus::Terminal.angry_prompt
puts_error "wrong number of arguments, expected 0 and got #{args.count} #{args.join(' ')}\n#{optparse}"
return 1
end
unless options[:quiet]
if Morpheus::Benchmarking.enabled?
puts "#{cyan}benchmark: #{green}on#{reset}"
else
puts "#{cyan}benchmark: #{dark}off#{reset}"
end
end
return Morpheus::Benchmarking.enabled? ? 1 : 0
end
|
#on(args) ⇒ Object
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
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 30
def on(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("")
build_common_options(opts, options, [:quiet])
opts. = "Enable global benchmarking. \nThis behaves the same as if you were to add the -B switch to every command.\n"
end
optparse.parse!(args)
connect(options)
if args.count != 0
print_error Morpheus::Terminal.angry_prompt
puts_error "wrong number of arguments, expected 0 and got #{args.count} #{args.join(' ')}\n#{optparse}"
return 1
end
benchmark_was_enabled = Morpheus::Benchmarking.enabled
Morpheus::Benchmarking.enabled = true
my_terminal.benchmarking = Morpheus::Benchmarking.enabled
unless options[:quiet]
puts "#{cyan}benchmark: #{green}on#{reset}"
end
return 0
end
|
#on?(args) ⇒ Boolean
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
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 90
def on?(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("")
build_common_options(opts, options, [:quiet])
opts. = "Print the value of the global benchmark setting. \nExit 0 if on.\n"
end
optparse.parse!(args)
connect(options)
if args.count != 0
print_error Morpheus::Terminal.angry_prompt
puts_error "wrong number of arguments, expected 0 and got #{args.count} #{args.join(' ')}\n#{optparse}"
return 1
end
if Morpheus::Benchmarking.enabled?
puts "#{cyan}benchmark: #{green}on#{reset}" unless options[:quiet]
else
puts "#{cyan}benchmark: #{dark}off#{reset}" unless options[:quiet]
end
return Morpheus::Benchmarking.enabled? ? 0 : 1
end
|
#start(args) ⇒ Object
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 144
def start(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
build_common_options(opts, options, [:quiet])
opts. = "Start recording a benchmark.\n[name] is required. This is just a name for the routine.\nThis allows you to record how long it takes to run a series of commands.\nJust run `benchmark stop` when you are finished.\n"
end
optparse.parse!(args)
connect(options)
benchmark_name = nil
if !args.empty?
benchmark_name = args.join(' ')
end
benchmark_record = Morpheus::Benchmarking.start(benchmark_name)
unless options[:quiet]
if benchmark_record.name
print_green_success "Started benchmark '#{benchmark_record.name}'"
else
print_green_success "Started benchmark"
end
end
return 0
end
|
#status(args) ⇒ Object
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 249
def status(args)
options = {}
params = {}
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
build_common_options(opts, options, [:quiet])
opts. = "Print status of benchmark.\n[name] is optional. This is the name of the benchmark to inspect.\nThe last benchmark is used by default.\n"
end
optparse.parse!(args)
connect(options)
benchmark_name = nil
benchmark_record = nil
if args.empty?
benchmark_record = Morpheus::Benchmarking.last
if benchmark_record.nil?
print_error red,"No benchmark is running",reset,"\n"
return 1
end
else
benchmark_name = args.join(' ')
benchmark_record = Morpheus::Benchmarking.lookup(benchmark_name)
if benchmark_record.nil?
print_error red,"Benchmark not found by name '#{benchmark_name}'",reset,"\n"
return 1
end
end
unless options[:quiet]
Morpheus::Logging::DarkPrinter.puts(cyan + dark + benchmark_record.msg)
end
return 0
end
|
#stop(args) ⇒ Object
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/morpheus/cli/commands/standard/benchmark_command.rb', line 181
def stop(args)
options = {}
params = {}
benchmark_exit_code = nil
benchmark_err = nil
optparse = Morpheus::Cli::OptionParser.new do |opts|
opts.banner = subcommand_usage("[name]")
opts.on('--exit CODE', String, "Exit code to end benchmark with. Default is 0 to indicate success.") do |val|
benchmark_exit_code = val.to_i
end
opts.on('--error ERROR', String, "Error message to include with a benchmark that failed.") do |val|
benchmark_err = val
end
build_common_options(opts, options, [:quiet])
opts. = "Stop recording a benchmark.\n[name] is optional. This is the name of the benchmark to stop. \nThe last benchmark is used by default.\n"
end
optparse.parse!(args)
connect(options)
benchmark_name = nil
benchmark_record = nil
if args.empty?
benchmark_record = Morpheus::Benchmarking.last
if benchmark_record.nil?
print_error red,"Benchmark not found",reset,"\n"
return 1
end
else
benchmark_name = args.join(' ')
benchmark_record = Morpheus::Benchmarking.lookup(benchmark_name)
if benchmark_record.nil?
print_error red,"Benchmark not found by name '#{benchmark_name}'",reset,"\n"
return 1
end
end
if benchmark_record.start_time == nil || benchmark_record.end_time != nil
if benchmark_record.name
print_error red,"Benchmark '#{benchmark_record.name}' is not running",reset,"\n"
else
print_error red,"Benchmark is not running",reset,"\n"
end
return 1
end
benchmark_record.stop(benchmark_exit_code || 0, benchmark_err)
unless options[:quiet]
if benchmark_record.name
print_green_success "Stopped benchmark '#{benchmark_record.name}'"
else
print_green_success "Stopped benchmark"
end
end
Morpheus::Logging::DarkPrinter.puts(cyan + dark + benchmark_record.msg)
return 0
end
|