1212module Process
1313 module Metrics
1414 module Command
15+ # Helper module for rendering horizontal progress bars using Unicode block characters.
1516 module Bar
1617 BLOCK = [
1718 " " ,
@@ -25,6 +26,10 @@ module Bar
2526 "█" ,
2627 ]
2728
29+ # Format a fractional value as a horizontal bar.
30+ # @parameter value [Float] A value between 0.0 and 1.0 representing the fill level.
31+ # @parameter width [Integer] The width of the bar in characters.
32+ # @returns [String] A string of Unicode block characters representing the filled bar.
2833 def self . format ( value , width )
2934 blocks = width * value
3035 full_blocks = blocks . floor
@@ -38,6 +43,7 @@ def self.format(value, width)
3843 end
3944 end
4045
46+ # Command that displays a formatted summary of memory usage statistics for processes.
4147 class Summary < Samovar ::Command
4248 self . description = "Display a summary of memory usage statistics."
4349
@@ -48,6 +54,8 @@ class Summary < Samovar::Command
4854 option "--total-memory <integer>" , "Set the total memory relative to the usage (MiB)." , type : Integer
4955 end
5056
57+ # Get the configured terminal for styled output.
58+ # @returns [Console::Terminal] A terminal object with color/style definitions.
5159 def terminal
5260 terminal = Console ::Terminal . for ( $stdout)
5361
@@ -62,6 +70,9 @@ def terminal
6270 return terminal
6371 end
6472
73+ # Format a processor utilization percentage with color-coded bar.
74+ # @parameter value [Float] The CPU utilization percentage (0.0-100.0).
75+ # @parameter terminal [Console::Terminal] The terminal to output styled text.
6576 def format_processor_utilization ( value , terminal )
6677 if value > 80.0
6778 intensity = :high
@@ -78,6 +89,10 @@ def format_processor_utilization(value, terminal)
7889
7990 UNITS = [ "KiB" , "MiB" , "GiB" ]
8091
92+ # Format a memory size value in human-readable units.
93+ # @parameter value [Numeric] The size value in kilobytes.
94+ # @parameter units [Array(String)] The unit labels to use for scaling.
95+ # @returns [String] A formatted string with value and unit (e.g., "512KiB", "1.5MiB").
8196 def format_size ( value , units : UNITS )
8297 unit = 0
8398
@@ -89,6 +104,10 @@ def format_size(value, units: UNITS)
89104 return "#{ value . round ( unit ) } #{ units [ unit ] } "
90105 end
91106
107+ # Format a memory value with a horizontal bar showing utilization relative to total.
108+ # @parameter value [Numeric] The memory value in kilobytes.
109+ # @parameter total [Numeric] The total memory available in kilobytes.
110+ # @parameter terminal [Console::Terminal] The terminal to output styled text.
92111 def format_memory ( value , total , terminal )
93112 if value > ( total * 0.8 )
94113 intensity = :high
@@ -103,6 +122,8 @@ def format_memory(value, total, terminal)
103122 terminal . print ( formatted , intensity , "[" , Bar . format ( value / total . to_f , 60 ) , "]" , :reset )
104123 end
105124
125+ # Get the total memory to use for percentage calculations.
126+ # @returns [Integer] Total memory in kilobytes.
106127 def total_memory
107128 if total_memory = @options [ :total_memory ]
108129 return total_memory * 1024
@@ -111,6 +132,7 @@ def total_memory
111132 end
112133 end
113134
135+ # Execute the summary command, capturing and displaying process metrics.
114136 def call
115137 # Validate required arguments: at least one of --pid or --ppid must be provided:
116138 unless @options [ :pid ] || @options [ :ppid ]
0 commit comments