Top Level Namespace
Defined Under Namespace
Modules: SparkleMotion
Classes: Results, Vector2
Constant Summary
collapse
- MULTI_OPTIONS =
TODO: Try to figure out how to set Curl::CURLOPT_TCP_NODELAY => true TODO: Disable Curl from sending keepalives by trying HTTP/1.0.
{ pipeline: false,
max_connects: (CONFIG["max_connects"] || 3) }
- EASY_OPTIONS =
{ "timeout" => 5,
"connect_timeout" => 5,
"follow_location" => false,
"max_redirects" => 0 }
- CONFIG =
YAML.load(File.read("config.yml"))
- STATS =
[
["requests", :requests, :requests_sec],
["successes", :successes, :successes_sec],
["failures", :failures, :failures_sec],
["hard timeouts", :hard_timeouts, :hard_timeouts_sec],
["soft timeouts", :soft_timeouts, :soft_timeouts_sec],
]
Instance Method Summary
collapse
Instance Method Details
#announce_iteration_config(iters) ⇒ Object
TODO: Namespacing/classes/etc!
2
3
4
5
6
7
8
9
10
|
# File 'lib/sparkle_motion/output.rb', line 2
def announce_iteration_config(iters)
SparkleMotion.logger.unknown do
if iters > 0
"Running for #{iters} iterations."
else
"Running until we're killed. Send SIGHUP to terminate with stats."
end
end
end
|
#dump_debug_data! ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/sparkle_motion/output.rb', line 61
def dump_debug_data!
return unless debugging?
prefix = "%010.0f" % Time.now.to_f
SparkleMotion.logger.unknown { "Dumping debug and/or profiling data to `tmp/#{prefix}_*`." }
stop_ruby_prof!
dump_node_debug_data!(prefix)
dump_output_debug_data!(prefix)
end
|
#dump_node_debug_data!(prefix) ⇒ Object
47
48
49
50
51
|
# File 'lib/sparkle_motion/output.rb', line 47
def dump_node_debug_data!(prefix)
nodes_under_debug.each_with_index do |(name, node), index|
node.snapshot_to!("tmp/%s_%02d_%s.png" % [prefix, index, name.downcase])
end
end
|
#dump_output_debug_data!(prefix) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/sparkle_motion/output.rb', line 53
def dump_output_debug_data!(prefix)
return unless DEBUG_FLAGS["OUTPUT"] && USE_LIGHTS
File.open("tmp/#{prefix}_output.raw", "w") do |fh|
fh.write(SparkleMotion::LazyRequestConfig::GLOBAL_HISTORY.join("\n"))
fh.write("\n")
end
end
|
#env_bool(name) ⇒ Object
14
|
# File 'lib/sparkle_motion/env.rb', line 14
def env_bool(name); (env_int(name, true) || 1) != 0; end
|
#env_float(name) ⇒ Object
9
10
11
12
|
# File 'lib/sparkle_motion/env.rb', line 9
def env_float(name)
return nil unless ENV.key?(name)
ENV[name].to_f
end
|
#env_int(name, allow_zero = false) ⇒ Object
TODO: Namespacing/classes/etc!
2
3
4
5
6
7
|
# File 'lib/sparkle_motion/env.rb', line 2
def env_int(name, allow_zero = false)
return nil unless ENV.key?(name)
tmp = ENV[name].to_i
tmp = nil if tmp == 0 && !allow_zero
tmp
end
|
12
|
# File 'lib/sparkle_motion/output.rb', line 12
def format_float(num); num ? num.round(2) : "-"; end
|
14
|
# File 'lib/sparkle_motion/output.rb', line 14
def format_rate(rate); "#{format_float(rate)}/sec"; end
|
#guard_call(prefix, &block) ⇒ Object
rubocop:disable Lint/RescueException
4
5
6
7
8
9
|
# File 'lib/sparkle_motion/utility.rb', line 4
def guard_call(prefix, &block)
block.call
rescue Exception => e
SparkleMotion.logger.error { "#{prefix}: Exception for #{prefix}: #{e.message}" }
SparkleMotion.logger.error { "#{prefix}:\t#{e.backtrace.join("\n#{prefix}:\t")}" }
end
|
#hue_base(config) ⇒ Object
19
|
# File 'lib/sparkle_motion/http.rb', line 19
def hue_base(config); "#{hue_server(config)}/api/#{config['username']}"; end
|
#hue_group_endpoint(config, group) ⇒ Object
21
|
# File 'lib/sparkle_motion/http.rb', line 21
def hue_group_endpoint(config, group); "#{hue_base(config)}/groups/#{group}/action"; end
|
#hue_light_endpoint(config, light_id) ⇒ Object
20
|
# File 'lib/sparkle_motion/http.rb', line 20
def hue_light_endpoint(config, light_id); "#{hue_base(config)}/lights/#{light_id}/state"; end
|
#hue_server(config) ⇒ Object
easy.header_str.grep(/keep-alive/) Force keepalive off to see if that makes any difference… TODO: Use this: ‘easy.headers = ”` to remove a default header we don’t care about!
18
|
# File 'lib/sparkle_motion/http.rb', line 18
def hue_server(config); "http://#{config['ip']}"; end
|
#print_basic_stats(results) ⇒ Object
28
29
30
31
32
|
# File 'lib/sparkle_motion/output.rb', line 28
def print_basic_stats(results)
STATS.each do |(name, count, rate)|
print_stat(name, results.send(count), results.send(rate))
end
end
|
#print_other_stats(results) ⇒ Object
34
35
36
37
38
|
# File 'lib/sparkle_motion/output.rb', line 34
def print_other_stats(results)
SparkleMotion.logger.unknown { "* #{format_float(results.failure_rate)}% failure rate" }
suffix = " (#{format_float(results.elapsed / ITERATIONS.to_f)}/iteration)" if ITERATIONS > 0
SparkleMotion.logger.unknown { "* #{format_float(results.elapsed)} seconds elapsed#{suffix}" }
end
|
#print_results(results) ⇒ Object
TODO: Show per-bridge and aggregate stats.
#print_stat(name, value, rate) ⇒ Object
16
17
18
|
# File 'lib/sparkle_motion/output.rb', line 16
def print_stat(name, value, rate)
SparkleMotion.logger.unknown { "* #{value} #{name} (#{format_rate(rate)})" }
end
|
#unpack_color(col) ⇒ Object
5
6
7
8
9
10
11
12
13
|
# File 'lib/sparkle_motion/config.rb', line 5
def unpack_color(col)
if col.is_a?(String)
SparkleMotion::LaunchPad::Color.const_get(col.upcase).to_h
else
{ r: ((col >> 16) & 0xFF),
g: ((col >> 8) & 0xFF),
b: (col & 0xFF) }
end
end
|
#unpack_colors_in_place!(cfg) ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'lib/sparkle_motion/config.rb', line 15
def unpack_colors_in_place!(cfg)
cfg.each do |key, val|
if val.is_a?(Array)
cfg[key] = val.map { |vv| unpack_color(vv) }
else
cfg[key] = unpack_color(val)
end
end
end
|
#unpack_vector_in_place!(cfg) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/sparkle_motion/config.rb', line 25
def unpack_vector_in_place!(cfg)
cfg.each do |key, val|
next unless val.is_a?(Array) && val.length == 2
cfg[key] = Vector2.new(x: val[0], y: val[1])
end
end
|
#with_transition_time(data, transition) ⇒ Object
23
24
25
26
|
# File 'lib/sparkle_motion/http.rb', line 23
def with_transition_time(data, transition)
data["transitiontime"] = (transition * 10.0).round(0)
data
end
|