Class: Gonzui::PerformanceCounter
- Inherits:
-
Object
- Object
- Gonzui::PerformanceCounter
- Defined in:
- lib/gonzui/monitor.rb
Class Method Summary collapse
Instance Method Summary collapse
- #enter ⇒ Object
- #exclude(pc) ⇒ Object
-
#initialize ⇒ PerformanceCounter
constructor
A new instance of PerformanceCounter.
- #leave ⇒ Object
- #rest_summary(label, indent, elapsed) ⇒ Object
- #stime ⇒ Object
- #summary(label, indent, elapsed) ⇒ Object
- #time ⇒ Object
- #utime ⇒ Object
Constructor Details
#initialize ⇒ PerformanceCounter
Returns a new instance of PerformanceCounter.
115 116 117 118 119 120 121 122 123 |
# File 'lib/gonzui/monitor.rb', line 115 def initialize @count = 0 @time_enter = 0 @time_total = 0 @time_subtotal = 0 @times_enter = 0 @times_total = Struct::Tms.new(0, 0, 0, 0) @times_subtotal = Struct::Tms.new(0, 0, 0, 0) end |
Class Method Details
.heading ⇒ Object
156 157 158 159 |
# File 'lib/gonzui/monitor.rb', line 156 def self.heading sprintf("%-32s %8s %6s %6s %6s\n", "", "count", "utime", "stime", "real") end |
Instance Method Details
#enter ⇒ Object
125 126 127 128 129 |
# File 'lib/gonzui/monitor.rb', line 125 def enter @time_enter = Time.now @times_enter = Process.times @count += 1 end |
#exclude(pc) ⇒ Object
150 151 152 153 154 |
# File 'lib/gonzui/monitor.rb', line 150 def exclude(pc) @time_subtotal += pc.time @times_subtotal.utime += pc.utime @times_subtotal.stime += pc.stime end |
#leave ⇒ Object
131 132 133 134 135 136 |
# File 'lib/gonzui/monitor.rb', line 131 def leave @time_total += Time.now - @time_enter times = Process.times @times_total.utime += times.utime - @times_enter.utime @times_total.stime += times.stime - @times_enter.stime end |
#rest_summary(label, indent, elapsed) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/gonzui/monitor.rb', line 168 def rest_summary(label, indent, elapsed) time = @time_total - @time_subtotal utime = @times_total.utime - @times_subtotal.utime stime = @times_total.stime - @times_subtotal.stime sprintf("%-32s %8s %6.2fs %6.2fs %6.2fs (%6.2f%%)\n", " " * indent + label.to_s, '', utime, stime, time, time * 100 / elapsed) end |
#stime ⇒ Object
146 147 148 |
# File 'lib/gonzui/monitor.rb', line 146 def stime @times_total.stime end |
#summary(label, indent, elapsed) ⇒ Object
161 162 163 164 165 166 |
# File 'lib/gonzui/monitor.rb', line 161 def summary(label, indent, elapsed) sprintf("%-32s %8d %6.2fs %6.2fs %6.2fs (%6.2f%%)\n", " " * indent + label, @count, @times_total.utime, @times_total.stime, @time_total, @time_total * 100 / elapsed) end |
#time ⇒ Object
138 139 140 |
# File 'lib/gonzui/monitor.rb', line 138 def time @time_total end |
#utime ⇒ Object
142 143 144 |
# File 'lib/gonzui/monitor.rb', line 142 def utime @times_total.utime end |