Module: DangoUtilModule

Includes:
ErrorMessage
Included in:
DangoRakeUtil
Defined in:
lib/dango/framework_base.rb

Overview

ユーティティ

Instance Method Summary collapse

Methods included from ErrorMessage

#error_message

Instance Method Details

#array_random(arr, num = 2) ⇒ Object

配列をランダムに並べ替え arrは順番を入れ替えたい配列 numは入れ替え回数(省略時2、大きな数を入れると確実にランダムになるが時間が掛かる)



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/dango/framework_base.rb', line 78

def array_random(arr, num = 2)
  arr.sort_by{rand}.deep_dup

#    ret_arr = arr.deep_dup
#    (ret_arr.size * num).times do # メンバー数のnum倍の回数、入れ替え
#      idx = rand(ret_arr.size)
#      id = ret_arr.delete_at(idx)
#      ret_arr.push(id)
#    end
#    ret_arr
end

#get_process_info(pid_orig = nil) ⇒ Object

プロセス情報取得



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/dango/framework_base.rb', line 90

def get_process_info(pid_orig = nil) # プロセス情報取得
  if pid_orig
    pid = pid_orig.deep_dup
  else
    pid = Process.pid
  end
  
  ret = ""
  ret += "=== get_process_info ===\n"
  ret += "DangoUtilModule::pid = #{pid}\n"
  ret += "DangoUtilModule::RUBY_VERSION      = #{RUBY_VERSION}\n"
  ret += "DangoUtilModule::RUBY_RELEASE_DATE = #{RUBY_RELEASE_DATE}\n"
  ret += "DangoUtilModule::RUBY_PLATFORM     = #{RUBY_PLATFORM}\n"
  
  if RUBY_PLATFORM == 'i386-mswin32'
    
  else
    proc_process_dir = "/proc/#{pid}"
    begin
      if File.directory?(proc_process_dir)
        # 開始時間
        ret += "DangoUtilModule::process start time=#{File.mtime(proc_process_dir).to_ss}\n"
        
        # /proc/#{pid}/statusを読み込む
        proc_process_status = "/proc/#{pid}/status"
        
        if File.file?(proc_process_status) && File.readable?(proc_process_status)
          if RUBY_PLATFORM != 'i386-cygwin' # cygwinだとなぜか落ちるので分離
            open(proc_process_status, "rb") do |fh|
              ret += "DangoUtilModule::get_process_info:proc_process_status\n#{fh.read}\n"
            end
          end
        end
        
        # /proc/#{pid}/fdの中の一覧を取得
        proc_process_fd = "/proc/#{pid}/fd"
        if File.directory?(proc_process_fd) && File.executable?(proc_process_fd)
          ret += "DangoUtilModule::get_process_info:proc_process_fd:#{proc_process_fd}\n"
          Dir.foreach(proc_process_fd) do |file|
            file_fullpath = "#{proc_process_fd}/#{file}"
            if File.symlink?(file_fullpath)
              ret += "    #{file_fullpath} -> #{File.readlink(file_fullpath)}\n"
            else
              ret += "    #{file_fullpath}\n"
            end
          end
        end
      else
        ret += "DangoUtilModule::#{proc_process_dir} is not exist"
      end
    rescue
      ret += "DangoUtilModule:: #{error_message($!, 'u')}"
    end
  end
  
  ret
end