Class: OsCtl::Cli::Ps::Columns

Inherits:
Object
  • Object
show all
Includes:
Utils::Humanize
Defined in:
lib/osctl/cli/ps/columns.rb

Constant Summary collapse

COLS =
%i(
  pool
  ctid
  pid
  ctpid
  ruid
  rgid
  euid
  egid
  ctruid
  ctrgid
  cteuid
  ctegid
  vmsize
  rss
  state
  start
  time
  command
  name
)
DEFAULT =
%i(
  pid
  ctpid
  cteuid
  vmsize
  rss
  state
  start
  time
  command
)
ALIGN_RIGHT =
%i(
  pid
  ruid
  rgid
  euid
  egid
  ctruid
  ctrgid
  cteuid
  ctegid
  vmsize
  rss
  time
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Humanize

#break_interval, #format_long_duration, #format_percent, #format_short_duration, #humanize_data, #humanize_time_ns, #parse_data

Constructor Details

#initialize(os_proc, precise) ⇒ Columns

Returns a new instance of Columns

Parameters:

  • os_proc (OsCtl::Lib::OsProcess)
  • precise (Boolean)


86
87
88
89
# File 'lib/osctl/cli/ps/columns.rb', line 86

def initialize(os_proc, precise)
  @os_proc = os_proc
  @precise = precise
end

Instance Attribute Details

#os_procObject (readonly, protected)

Returns the value of attribute os_proc



168
169
170
# File 'lib/osctl/cli/ps/columns.rb', line 168

def os_proc
  @os_proc
end

Class Method Details

.generate(process_list, cols, precise) ⇒ Array<Hash>

Parameters:

  • process_list (OsCtl::Lib::ProcessList)
  • cols (Array<Symbol>)
  • precise (Boolean)

Returns:

  • (Array<Hash>)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/osctl/cli/ps/columns.rb', line 58

def self.generate(process_list, cols, precise)
  spec = cols.map do |c|
    {
      name: c,
      label: c.to_s.upcase,
      align: ALIGN_RIGHT.include?(c) ? :right : :left,
    }
  end

  data = []

  process_list.each do |os_proc|
    row = new(os_proc, precise)

    begin
      data << Hash[cols.map { |c| [c, row.send(c)] }]
    rescue OsCtl::Lib::Exceptions::OsProcessNotFound
      next
    end
  end

  [spec, data]
end

Instance Method Details

#commandObject



159
160
161
# File 'lib/osctl/cli/ps/columns.rb', line 159

def command
  os_proc.cmdline
end

#ctegidObject



135
136
137
# File 'lib/osctl/cli/ps/columns.rb', line 135

def ctegid
  os_proc.ct_egid
end

#cteuidObject



131
132
133
# File 'lib/osctl/cli/ps/columns.rb', line 131

def cteuid
  os_proc.ct_euid
end

#ctidObject



95
96
97
# File 'lib/osctl/cli/ps/columns.rb', line 95

def ctid
  os_proc.ct_id[1]
end

#ctpidObject



103
104
105
# File 'lib/osctl/cli/ps/columns.rb', line 103

def ctpid
  os_proc.ct_pid
end

#ctrgidObject



127
128
129
# File 'lib/osctl/cli/ps/columns.rb', line 127

def ctrgid
  os_proc.ct_rgid
end

#ctruidObject



123
124
125
# File 'lib/osctl/cli/ps/columns.rb', line 123

def ctruid
  os_proc.ct_ruid
end

#egidObject



119
120
121
# File 'lib/osctl/cli/ps/columns.rb', line 119

def egid
  os_proc.egid
end

#euidObject



115
116
117
# File 'lib/osctl/cli/ps/columns.rb', line 115

def euid
  os_proc.euid
end

#format_time(v) ⇒ Object (protected)



182
183
184
185
186
187
188
189
190
# File 'lib/osctl/cli/ps/columns.rb', line 182

def format_time(v)
  now = Time.now

  if now - v > 24*60*60
    v.strftime('%b%d')
  else
    v.strftime('%H:%M')
  end
end

#nameObject



163
164
165
# File 'lib/osctl/cli/ps/columns.rb', line 163

def name
  os_proc.name
end

#pidObject



99
100
101
# File 'lib/osctl/cli/ps/columns.rb', line 99

def pid
  os_proc.pid
end

#poolObject



91
92
93
# File 'lib/osctl/cli/ps/columns.rb', line 91

def pool
  os_proc.ct_id[0]
end

#precise?Boolean (protected)

Returns:

  • (Boolean)


192
193
194
# File 'lib/osctl/cli/ps/columns.rb', line 192

def precise?
  @precise
end

#present_data(v) ⇒ Object (protected)



170
171
172
# File 'lib/osctl/cli/ps/columns.rb', line 170

def present_data(v)
  OsCtl::Lib::Cli::Presentable.new(v, formatted: precise? ? nil : humanize_data(v))
end

#present_duration(v) ⇒ Object (protected)



178
179
180
# File 'lib/osctl/cli/ps/columns.rb', line 178

def present_duration(v)
  OsCtl::Lib::Cli::Presentable.new(v, formatted: precise? ? nil : format_short_duration(v))
end

#present_time(v) ⇒ Object (protected)



174
175
176
# File 'lib/osctl/cli/ps/columns.rb', line 174

def present_time(v)
  OsCtl::Lib::Cli::Presentable.new(v, formatted: precise? ? nil : format_time(v))
end

#rgidObject



111
112
113
# File 'lib/osctl/cli/ps/columns.rb', line 111

def rgid
  os_proc.rgid
end

#rssObject



143
144
145
# File 'lib/osctl/cli/ps/columns.rb', line 143

def rss
  present_data(os_proc.rss)
end

#ruidObject



107
108
109
# File 'lib/osctl/cli/ps/columns.rb', line 107

def ruid
  os_proc.ruid
end

#startObject



151
152
153
# File 'lib/osctl/cli/ps/columns.rb', line 151

def start
  present_time(os_proc.start_time)
end

#stateObject



147
148
149
# File 'lib/osctl/cli/ps/columns.rb', line 147

def state
  os_proc.state
end

#timeObject



155
156
157
# File 'lib/osctl/cli/ps/columns.rb', line 155

def time
  present_duration(os_proc.user_time + os_proc.sys_time)
end

#vmsizeObject



139
140
141
# File 'lib/osctl/cli/ps/columns.rb', line 139

def vmsize
  present_data(os_proc.vmsize)
end