Module: Kernel

Defined in:
lib/roebe/core/kernel.rb

Overview

#

require ‘roebe/core/kernel.rb’

#

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

#

print_resource_usage

Prints memory and cpu footprint of the server (uses ps in a subshell, portability is therefore limited)

Usage example:

Kernel.print_resource_usage
#


20
21
22
23
24
25
26
27
# File 'lib/roebe/core/kernel.rb', line 20

def print_resource_usage
  ps_out = `ps -o vsz,rss,%cpu,%mem -p #{$$}`
  vsz, rss, cpu, pmem = ps_out.scan(/\d+(?:[.,]\d+)?/).map { |e|
    e.gsub(/,/,'.').to_f
  } # ps on 10.5.1 outputs ',' instead of '.' for MEM%
  virtual, real = (vsz-rss).div(1024), rss.div(1024)
  $stdout.printf "%dMB real, %dMB virtual, %.1f%% CPU, %.1f%% MEM\n", real, virtual, cpu, pmem
end

.require_directory(this_directory) ⇒ Object

#

Kernel.require_directory

Usage example:

Kernel.require_directory('/home/x/DATA/PROGRAMMING_LANGUAGES/RUBY/src/ascii_paradise/lib/ascii_paradise/')
#


37
38
39
40
41
42
43
44
45
46
# File 'lib/roebe/core/kernel.rb', line 37

def self.require_directory(this_directory)
  all_files = Dir[(this_directory+'/*').squeeze('/')]
  # ======================================================================= #
  # Next, select only .rb files for now.
  # ======================================================================= #
  all_files.select! {|entry| entry.end_with? '.rb' }
  all_files.each {|this_file|
    require this_file
  }
end

Instance Method Details

#require(this_file) ⇒ Object

#

require

A patch to require symbols.

require %w( yaml pp )
require 'yaml','pp'

def require(*args)
  args.each { |file| require_orig(file) }
end
#


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/roebe/core/kernel.rb', line 66

def require(this_file)
  if this_file.is_a? Symbol
    require 'beautiful_url/requires/failsafe_require_of_beautiful_url.rb'
    this_file = BeautifulUrl.parse(this_file).url?
  end
  require_orig(this_file)
  # The next code is debug-code.
  # begin
  #   failsave_require(this_file)
  # rescue Exception => e
  #   # puts e
  #   # puts this_file
  #   # puts 'rescued ... but you should fix it! :P'
  # end
end

#require_origObject

#

Keep a reference-copy next:

#


51
# File 'lib/roebe/core/kernel.rb', line 51

alias require_orig require