Skip to content

Commit

Permalink
add additional profiler commands
Browse files Browse the repository at this point in the history
  • Loading branch information
greeneca committed Jul 5, 2017
1 parent 1624314 commit 386e46c
Show file tree
Hide file tree
Showing 4 changed files with 265 additions and 22 deletions.
12 changes: 12 additions & 0 deletions intergration/roku_builder/test_profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ def test_profile_all
output = `#{roku} --profile all`
assert_match(/RectangleExample/, output)
end
def test_profile_roots
`#{roku} --sideload --working`
assert_log @uuid
output = `#{roku} --profile roots`
assert_match(/Default/, output)
end
def test_profile_node
`#{roku} --sideload --working`
assert_log @uuid
output = `#{roku} --profile exampleRectangle`
assert_match(/name="exampleRectangle"/, output)
end
def test_profile_images
`#{roku} --sideload --working`
assert_log @uuid
Expand Down
7 changes: 4 additions & 3 deletions lib/roku_builder/plugins/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def init_readline
end

commands = [
"bsc", "bscs", "brkd", "bt", "classes", "cont", "cont", "down", "d",
"exit", "gc", "help", "last", "list", "next", "print", "p", "?", "step",
"s", "t", "over", "out", "up", "u", "var", "q"
"bsc", "bscs", "brkd", "bt", "c", "classes", "cont", "cont", "down", "d",
"exit", "gc", "help", "l", "last", "list", "n", "next", "o", "print",
"p", "?", "s", "stats", "step", "t", "th", "thread", "threads", "ths",
"over", "out", "up", "u", "q", "v", "var"
].sort
commands.collect { |i| i + ' ' } if libedit

Expand Down
92 changes: 82 additions & 10 deletions lib/roku_builder/plugins/profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ class Profiler < Util
extend Plugin

def self.commands
{profile: {device: true}}
{
profile: {device: true},
sgperf: {device: true},
devlog: {device: true}
}
end

def self.parse_options(parser:, options:)
parser.separator "Commands:"
parser.on("--profile COMMAND", "Run various profiler options") do |c|
options[:profile] = c
end
parser.on("--sgperf", "Run scenegraph profiler") do
options[:sgperf] = true
end
parser.on("--devlog FUNCTION [TYPE]", "Run scenegraph profiler") do |f, t|
options[:devlog] = t || "rendezvous"
options[:devlog_function] = f
end
end

# Run the profiler commands
Expand All @@ -25,13 +36,61 @@ def profile(options:)
print_stats
when :all
print_all_nodes
when :roots
print_root_nodes
when :images
print_image_information
when :textures
print_texture_information
else
print_nodes_by_id(options[:profile])
end
end

def sgperf(options:)
telnet_config ={
'Host' => @roku_ip_address,
'Port' => 8080
}
connection = Net::Telnet.new(telnet_config)
connection.puts("sgperf clear\n")
connection.puts("sgperf start\n")
start_reg = />thread/
end_reg = /#{SecureRandom.uuid}/
prev_lines = 0
begin
while true
lines = get_command_response(command: "sgperf report", start_reg: start_reg,
end_reg: end_reg, unique: true, connection: connection, ignore_warnings: true)
results = []
lines.each do |line|
match = /thread node calls: create\s*(\d*) \+ op\s*(\d*)\s*@\s*(\d*\.\d*)% rendezvous/.match(line)
results.push([match[1].to_i, match[2].to_i, match[3].to_f])
end
print "\r" + ("\e[A\e[K"*prev_lines)
prev_lines = 0
results.each_index do |i|
line = results[i]
if line[0] > 0 or line[1] > 0
prev_lines += 1
puts "Thread #{i}: c:#{line[0]} u:#{line[1]} r:#{line[2]}%"
end
end
end
rescue SystemExit, Interrupt
#Exit
end
end

def devlog(options:)
telnet_config ={
'Host' => @roku_ip_address,
'Port' => 8080
}
connection = Net::Telnet.new(telnet_config)
connection.puts("enhanced_dev_log #{options[:devlog]} #{options[:devlog_function]}\n")
end

private

# Print the node stats
Expand Down Expand Up @@ -67,6 +126,18 @@ def print_all_nodes
lines = get_command_response(command: "sgnodes all", start_reg: start_reg, end_reg: end_reg)
lines.each {|line| print line}
end
def print_root_nodes
start_reg = /<Root_Nodes>/
end_reg = /<\/Root_Nodes>/
lines = get_command_response(command: "sgnodes roots", start_reg: start_reg, end_reg: end_reg)
lines.each {|line| print line}
end
def print_nodes_by_id(id)
start_reg = /<#{id}>/
end_reg = /<\/#{id}>/
lines = get_command_response(command: "sgnodes #{id}", start_reg: start_reg, end_reg: end_reg)
lines.each {|line| print line}
end
def print_image_information
start_reg = /RoGraphics instance/
end_reg = /Available memory/
Expand All @@ -82,17 +153,18 @@ def print_texture_information

# Retrive list of all nodes
# @return [Array<String>] Array of lines
def get_command_response(command:, start_reg:, end_reg:, unique: false)
def get_command_response(command:, start_reg:, end_reg:, unique: false, connection: nil, ignore_warnings: false)
waitfor_config = {
'Match' => /.+/,
'Timeout' => 5
}
telnet_config ={
'Host' => @roku_ip_address,
'Port' => 8080
'Timeout' => 1
}

connection = Net::Telnet.new(telnet_config)
unless connection
telnet_config ={
'Host' => @roku_ip_address,
'Port' => 8080
}
connection = Net::Telnet.new(telnet_config)
end

@lines = []
@all_txt = ""
Expand All @@ -105,7 +177,7 @@ def get_command_response(command:, start_reg:, end_reg:, unique: false)
handle_text(txt: txt, start_reg: start_reg, end_reg: end_reg, unique: unique)
end
rescue Net::ReadTimeout
@logger.warn "Timed out reading profiler information"
@logger.warn "Timed out reading profiler information" unless ignore_warnings
@done = true
end
end
Expand Down
Loading

0 comments on commit 386e46c

Please sign in to comment.