Class: InternetHakai::TimeRegistProcess
- Inherits:
-
Object
- Object
- InternetHakai::TimeRegistProcess
- Defined in:
- lib/internethakai/hakairev/time_register.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(rpipe, wpipe) ⇒ TimeRegistProcess
constructor
A new instance of TimeRegistProcess.
- #on_read(str) ⇒ Object
- #parse(line) ⇒ Object
- #regist(name, time, status, size, err) ⇒ Object
Constructor Details
#initialize(rpipe, wpipe) ⇒ TimeRegistProcess
Returns a new instance of TimeRegistProcess.
74 75 76 77 78 79 |
# File 'lib/internethakai/hakairev/time_register.rb', line 74 def initialize(rpipe, wpipe) @report = ResponseRecord::new @rpipe = rpipe @wpipe = wpipe @rpipe.on_read(&method(:on_read)) end |
Class Method Details
.rpipe ⇒ Object
58 59 60 |
# File 'lib/internethakai/hakairev/time_register.rb', line 58 def self::rpipe @@rpipe end |
.run ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/internethakai/hakairev/time_register.rb', line 61 def self::run @@alive = true @@rpipe, w = ::IO::pipe r, @@wpipe = ::IO::pipe @@wpipe = Rev::IO::new(@@wpipe) @@wpipe.attach(Rev::Loop::default) fork do revio = RWatcher::new(r) revio.attach(Rev::Loop::default) self::new(revio, w) Rev::Loop::default.run end end |
.wpipe ⇒ Object
55 56 57 |
# File 'lib/internethakai/hakairev/time_register.rb', line 55 def self::wpipe @@wpipe end |
Instance Method Details
#on_read(str) ⇒ Object
80 81 82 83 84 |
# File 'lib/internethakai/hakairev/time_register.rb', line 80 def on_read str str.each_line do |l| parse l end end |
#parse(line) ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/internethakai/hakairev/time_register.rb', line 85 def parse line method, name, time, status, size, err = line.chomp.split("\t") case method when 'regist' regist name, time.to_f, status, size.to_i, err.to_i when 'get' Marshal::dump(@report, @wpipe) Rev::Loop::default.stop end end |
#regist(name, time, status, size, err) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/internethakai/hakairev/time_register.rb', line 95 def regist name, time, status, size, err time = time.to_f v = @report[name] v[:size] += size if v[:min].nil? and time != 0 v[:min] = time v[:max] = time elsif time != 0 v[:min] = v[:min] < time ? v[:min] : time end if time != 0 v[:max] = v[:max] > time ? v[:max] : time end v[:totaltime] += time ## 総合時間 v[:accesscount] += 1 if time > 0 v[:errorcount] += err v["status:#{status}"] = v["status:#{status}"].to_i + 1 unless status!=0 v["time:#{((time*1000).to_i/100)*100}"] = v["time:#{((time*1000).to_i/100)*100}"].to_i + 1 end |