class Process::Metrics::Command::Summary

Constants

UNITS

Public Instance Methods

call() click to toggle source
# File lib/process/metrics/command/summary.rb, line 121
def call
        terminal = self.terminal
        
        summary = Process::Metrics::General.capture(pid: @options[:pid], ppid: @options[:ppid])
        
        format_memory_usage = self.method(:format_memory_usage).curry
        memory_usage = 0
        proportional = true
        
        summary.each do |pid, general|
                terminal.print_line(:pid, pid, :reset, " ", :command, general[:command])
                
                terminal.print(:key, "Processor Usage: ".rjust(20), :reset)
                format_pcpu(general.pcpu, terminal)
                terminal.print_line
                
                if memory = general.memory
                        memory_usage += memory.proportional_size
                        
                        terminal.print_line(
                                :key, "Memory (PSS): ".rjust(20), :reset,
                                format_memory_usage[memory.proportional_size]
                        )
                        
                        terminal.print_line(
                                :key, "Private (USS): ".rjust(20), :reset,
                                format_memory_usage[memory.unique_size]
                        )
                else
                        memory_usage += general.rss
                        proportional = false
                        
                        terminal.print_line(
                                :key, "Memory (RSS): ".rjust(20), :reset,
                                format_memory_usage[general.rss]
                        )
                end
        end
        
        terminal.print_line("Summary")
        
        if proportional
                terminal.print_line(
                        :key, "Memory (PSS): ".rjust(20), :reset,
                        format_memory_usage[memory_usage]
                )
        else
                terminal.print_line(
                        :key, "Memory (RSS): ".rjust(20), :reset,
                        format_memory_usage[memory_usage]
                )
        end
end
format_memory_usage(value, terminal, scale: @options[:memory_scale]) click to toggle source
# File lib/process/metrics/command/summary.rb, line 107
def format_memory_usage(value, terminal, scale: @options[:memory_scale])
        if value > (1024.0 * scale * 0.8)
                intensity = :high
        elsif value > (1024.0 * scale * 0.5)
                intensity = :medium
        else
                intensity = :low
        end
        
        formatted = (format_size(value) + ' ').rjust(10)
        
        terminal.print(formatted, intensity, "[", Bar.format(value / (1024.0 * scale), 60), "]", :reset)
end
format_pcpu(value, terminal) click to toggle source
# File lib/process/metrics/command/summary.rb, line 80
def format_pcpu(value, terminal)
        if value > 80.0
                intensity = :high
        elsif value > 50.0
                intensity = :medium
        else
                intensity = :low
        end
        
        formatted = "%5.1f%% " % value
        
        terminal.print(formatted.rjust(10), intensity, "[", Bar.format(value / 100.0, 60), "]", :reset)
end
format_size(value, units: UNITS) click to toggle source
# File lib/process/metrics/command/summary.rb, line 96
def format_size(value, units: UNITS)
        unit = 0
        
        while value > 1024.0 && unit < units.size
                value /= 1024.0
                unit += 1
        end
        
        return "#{value.round(unit)}#{units[unit]}"
end
terminal() click to toggle source
# File lib/process/metrics/command/summary.rb, line 66
def terminal
        terminal = Console::Terminal.for($stdout)
        
        # terminal[:pid] = terminal.style(:blue)
        terminal[:command] = terminal.style(nil, nil, :bold)
        terminal[:key] = terminal.style(:cyan)
        
        terminal[:low] = terminal.style(:green)
        terminal[:medium] = terminal.style(:yellow)
        terminal[:high] = terminal.style(:red)
        
        return terminal
end