Class: RokuBuilder::Profiler

Inherits:
Util
  • Object
show all
Extended by:
Plugin
Defined in:
lib/roku_builder/plugins/profiler.rb

Overview

Scene Graph Profiler

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

commands, dependencies, parse_options, validate

Methods inherited from Util

#initialize

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Class Method Details

.commandsObject



9
10
11
12
13
14
15
16
# File 'lib/roku_builder/plugins/profiler.rb', line 9

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

.parse_options(parser:, options:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/roku_builder/plugins/profiler.rb', line 18

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
  parser.on("--node-tracking [INTERVAL]", "Take snapshots of the current nodes and print difference since last snapshot") do |interval|
    options[:node_tracking] = true
    options[:node_tracking_interval] = interval
  end
  parser.separator "Options:"
  parser.on("--add-ids", "Add ids to stats command") do
    options[:add_ids] = true
  end
end

Instance Method Details

#devlog(options:) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/roku_builder/plugins/profiler.rb', line 102

def devlog(options:)
  telnet_config = nil
  get_device(no_lock: true) do |device|
    telnet_config ={
      'Host' => device.ip,
      'Port' => 8080
    }
  end
  connection = Net::Telnet.new(telnet_config)
  connection.puts("enhanced_dev_log #{options[:devlog]} #{options[:devlog_function]}\n")
end

#node_tracking(options:) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/roku_builder/plugins/profiler.rb', line 114

def node_tracking(options:)
  @options = options
  @connection = nil
  begin
    current_nodes = nil
    previous_nodes = nil
    while true
      current_nodes = get_stats
      diff = diff_node_stats(current_nodes, previous_nodes)
      print_stats(stats: diff)
      previous_nodes = current_nodes
      current_nodes = nil
      STDIN.read(1)
    end
  rescue SystemExit, Interrupt
    @connection.close if @connection
  end
end

#profile(options:) ⇒ Object

Run the profiler commands

Parameters:

  • command (Symbol)

    The profiler command to run



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/roku_builder/plugins/profiler.rb', line 42

def profile(options:)
  @options = options
  @connection = nil
  case options[:profile].to_sym
  when :stats
    print_all_node_stats
  when :all
    print_all_nodes
  when :roots
    print_root_nodes
  when :images
    print_image_information
  when :memmory
    print_memmory_usage
  when :textures
    print_texture_information
  else
    print_nodes_by_id(options[:profile])
  end
  @connection.close if @connection
end

#sgperf(options:) ⇒ Object



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
# File 'lib/roku_builder/plugins/profiler.rb', line 64

def sgperf(options:)
  telnet_config = nil
  get_device(no_lock: true) do |device|
    telnet_config ={
      'Host' => device.ip,
      'Port' => 8080
    }
  end
  @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, 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 or options[:verbose]
        prev_lines += 1
        puts "Thread #{i}: c:#{line[0]} u:#{line[1]} r:#{line[2]}%"
      end
    end
  end
  rescue SystemExit, Interrupt
    @connection.close if @connection
  end
end