Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ require: rubocop-rspec
RSpec/BeforeAfterAll:
Enabled: false
RSpec/MultipleExpectations:
Max: 4
Max: 10
RSpec/ExampleLength:
Max: 15
RSpec/ContextWording:
Enabled: false
RSpec/FilePath:
SpecSuffixOnly: true
RSpec/SpecFilePathFormat:
Enabled: false
RSpec/InstanceVariable:
Enabled: false

Expand Down Expand Up @@ -51,12 +53,16 @@ Layout/FirstArrayElementIndentation:
Enabled: false
Layout/CaseIndentation:
IndentOneStep: true
Layout/LeadingCommentSpace:
Enabled: false
Layout/SpaceBeforeBlockBraces:
Enabled: false
Layout/SpaceInsideHashLiteralBraces:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
IgnoredMethods: ['describe', 'context']
AllowedMethods: ['describe', 'context']
Metrics/ClassLength:
Enabled: false
Metrics/MethodLength:
Expand Down
8 changes: 4 additions & 4 deletions lib/aix/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ class Error < StandardError; end

public

ProcTableStruct = Struct.new("ProcTableStruct", *@fields) do
ProcTableStruct = Struct.new('ProcTableStruct', *@fields) do
alias comm fname
end

ProcTableMapStruct = Struct.new("ProcTableMapStruct", *@map_fields)
ProcTableMapStruct = Struct.new('ProcTableMapStruct', *@map_fields)

# In block form, yields a ProcTableStruct for each process entry that you
# have rights to. This method returns an array of ProcTableStruct's in
Expand All @@ -212,7 +212,7 @@ def self.ps(**kwargs)
array = block_given? ? nil : []
struct = nil

Dir.foreach("/proc") do |file|
Dir.foreach('/proc') do |file|
next if file =~ /\D/ # Skip non-numeric entries under /proc

# Only return information for a given pid, if provided
Expand Down Expand Up @@ -340,7 +340,7 @@ def self.ps(**kwargs)
caller
end

envp = fd.sysread(4).unpack("L")[0]
envp = fd.sysread(4).unpack('L')[0]
break if envp.zero?
np = fd.sysseek(envp, IO::SEEK_SET)
data = fd.sysread(1024)[/^[^\0]*/] # Null strip
Expand Down
16 changes: 8 additions & 8 deletions lib/bsd/sys/freebsd/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,14 @@ def self.fields

def self.get_state(int)
case int
when SIDL; "idle"
when SRUN; "run"
when SSLEEP; "sleep"
when SSTOP; "stop"
when SZOMB; "zombie"
when SWAIT; "waiting"
when SLOCK; "locked"
else; "unknown"
when SIDL; 'idle'
when SRUN; 'run'
when SSLEEP; 'sleep'
when SSTOP; 'stop'
when SZOMB; 'zombie'
when SWAIT; 'waiting'
when SLOCK; 'locked'
else; 'unknown'
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bsd/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
when /dragonfly/i
require_relative 'dragonfly/sys/proctable'
else
raise "Unsupported version of BSD"
raise 'Unsupported version of BSD'
end
4 changes: 2 additions & 2 deletions lib/darwin/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ class ProcTaskAllInfo < FFI::Struct
]

# Add a couple aliases to make it similar to Linux
ProcTableStruct = Struct.new("ProcTableStruct", *@fields) do
ProcTableStruct = Struct.new('ProcTableStruct', *@fields) do
alias_method :vsize, :virtual_size
alias_method :rss, :resident_size
end

private_constant :ProcTableStruct

ThreadInfoStruct = Struct.new("ThreadInfo", :user_time, :system_time,
ThreadInfoStruct = Struct.new('ThreadInfo', :user_time, :system_time,
:cpu_usage, :policy, :run_state, :flags, :sleep_time, :curpri,
:priority, :maxpriority, :name
)
Expand Down
14 changes: 7 additions & 7 deletions lib/linux/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Error < StandardError; end
# There is no constructor
private_class_method :new

@mem_total = File.read("/proc/meminfo")[/MemTotal.*/].split[1].to_i * 1024 rescue nil
@boot_time = File.read("/proc/stat")[/btime.*/].split.last.to_i rescue nil
@mem_total = File.read('/proc/meminfo')[/MemTotal.*/].split[1].to_i * 1024 rescue nil
@boot_time = File.read('/proc/stat')[/btime.*/].split.last.to_i rescue nil

@fields = [
'cmdline', # Complete command line
Expand Down Expand Up @@ -121,7 +121,7 @@ def self.ps(**kwargs)

raise TypeError if pid && !pid.is_a?(Numeric)

Dir.foreach("/proc") do |file|
Dir.foreach('/proc') do |file|
next if file =~ /\D/ # Skip non-numeric directories
next if pid && file.to_i != pid

Expand All @@ -144,7 +144,7 @@ def self.ps(**kwargs)
struct.environ = {}

begin
File.read("/proc/#{file}/environ").force_encoding("UTF-8").split("\0").each do |str|
File.read("/proc/#{file}/environ").force_encoding('UTF-8').split("\0").each do |str|
key, value = str.split('=')
struct.environ[key] = value
end
Expand Down Expand Up @@ -188,7 +188,7 @@ def self.ps(**kwargs)
# are true for a file in the /proc fileystem but raises a Errno:EACCESS
# when your try to read it without permissions.
unless smaps == false
smaps_contents = File.read("/proc/#{file}/smaps") rescue ""
smaps_contents = File.read("/proc/#{file}/smaps") rescue ''
struct.smaps = Smaps.new(file, smaps_contents)
end

Expand Down Expand Up @@ -309,7 +309,7 @@ def self.get_pctmem(rss)
return nil unless @mem_total
page_size = 4096
rss_total = rss * page_size
format("%3.2f", (rss_total.to_f / @mem_total) * 100).to_f
format('%3.2f', (rss_total.to_f / @mem_total) * 100).to_f
end

private_class_method :get_pctmem
Expand All @@ -321,7 +321,7 @@ def self.get_pctcpu(utime, start_time)
hertz = 100.0
utime = (utime * 10000).to_f
stime = (start_time.to_f / hertz) + @boot_time
format("%3.2f", (utime / 10000.0) / (Time.now.to_i - stime)).to_f
format('%3.2f', (utime / 10000.0) / (Time.now.to_i - stime)).to_f
end

private_class_method :get_pctcpu
Expand Down
8 changes: 4 additions & 4 deletions lib/sunos/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class PRUsage < FFI::Struct

public

ProcTableStruct = Struct.new("ProcTableStruct", *@fields) do
ProcTableStruct = Struct.new('ProcTableStruct', *@fields) do
alias comm fname
end

Expand Down Expand Up @@ -245,7 +245,7 @@ def self.ps(**kwargs)
array = block_given? ? nil : []
struct = nil

Dir.foreach("/proc") do |file|
Dir.foreach('/proc') do |file|
next if file =~ /\D/ # Skip non-numeric entries under /proc

# Only return information for a given pid, if provided
Expand Down Expand Up @@ -315,7 +315,7 @@ def self.ps(**kwargs)
begin
File.open("/proc/#{file}/as") do |fd|
fd.sysseek(struct.argv, IO::SEEK_SET)
address = fd.sysread(struct.argc * 4).unpack("L")[0]
address = fd.sysread(struct.argc * 4).unpack('L')[0]

struct.cmd_args = []

Expand All @@ -331,7 +331,7 @@ def self.ps(**kwargs)

fd.sysseek(struct.envp, IO::SEEK_SET)

env_address = fd.sysread(128).unpack("L")[0]
env_address = fd.sysread(128).unpack('L')[0]

# TODO: Optimization potential here.
loop do
Expand Down
2 changes: 1 addition & 1 deletion lib/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
when /mswin|win32|dos|cygwin|mingw|windows/i
require_relative '../windows/sys/proctable'
else
raise "Unsupported platform"
raise 'Unsupported platform'
end
4 changes: 2 additions & 2 deletions lib/windows/sys/proctable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Error < StandardError; end
write_transfer_count
]

ProcTableStruct = Struct.new("ProcTableStruct", *@fields)
ProcTableStruct = Struct.new('ProcTableStruct', *@fields)

# call-seq:
# ProcTable.fields
Expand Down Expand Up @@ -108,7 +108,7 @@ def self.ps(**kwargs)
rescue WIN32OLERuntimeError => err
raise Error, err # Re-raise as ProcTable::Error
else
wmi.InstancesOf("Win32_Process").each do |wproc|
wmi.InstancesOf('Win32_Process').each do |wproc|
if pid && wproc.ProcessId != pid
next
end
Expand Down
Loading