rbbt-util 5.13.0 → 5.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rbbt/util/log.rb +3 -1
- data/lib/rbbt/util/log/progress.rb +53 -15
- data/lib/rbbt/util/misc/concurrent_stream.rb +3 -1
- data/lib/rbbt/util/open.rb +3 -2
- data/lib/rbbt/workflow/accessor.rb +3 -1
- data/lib/rbbt/workflow/step/run.rb +7 -5
- data/share/rbbt_commands/benchmark/throughput +3 -15
- data/test/rbbt/util/log/test_progress.rb +13 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a03adabca2810fb92c9771c98c6cee6126fec535
|
4
|
+
data.tar.gz: 173c80fd823140c2d7cb5443ae034fa61d89b74a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43fa5b928dd62ddb3627d44255ec4497eba7ad61f2d16236df36e2cdb1f2243182b92ca4e11c4c279f2db6ea91d68e514530f9ff64abbc27a6ea93b2c145acf6
|
7
|
+
data.tar.gz: 4c9c7b955f6157b9ed7c0640454be5e92eef62c2e831bcfe1ea1fc16621d6c80c5bf48f72cf0233e8213582a06fd9ec58ac87005b1f1ef7d7f3fc21572352b84
|
data/lib/rbbt/util/log.rb
CHANGED
@@ -94,6 +94,7 @@ module Log
|
|
94
94
|
end
|
95
95
|
|
96
96
|
LOG_MUTEX = Mutex.new
|
97
|
+
LAST = "log"
|
97
98
|
def self.log(message = nil, severity = MEDIUM, &block)
|
98
99
|
return if severity < self.severity
|
99
100
|
message ||= block.call if block_given?
|
@@ -103,13 +104,14 @@ module Log
|
|
103
104
|
|
104
105
|
sev_str = severity.to_s
|
105
106
|
|
106
|
-
prefix = time << "[" << color(severity) << sev_str << color(0)
|
107
|
+
prefix = time << "[" << color(severity) << sev_str << color(0)<<"]"
|
107
108
|
message = "" << highlight << message << color(0) if severity >= INFO
|
108
109
|
str = prefix << " " << message
|
109
110
|
|
110
111
|
LOG_MUTEX.synchronize do
|
111
112
|
STDERR.puts str
|
112
113
|
logfile.puts str unless logfile.nil?
|
114
|
+
Log::LAST.replace "log"
|
113
115
|
end
|
114
116
|
end
|
115
117
|
|
@@ -2,7 +2,7 @@ require 'rbbt/util/log'
|
|
2
2
|
module Log
|
3
3
|
class ProgressBar
|
4
4
|
|
5
|
-
attr_accessor :depth, :num_reports, :desc, :io, :severity
|
5
|
+
attr_accessor :depth, :num_reports, :desc, :io, :severity, :history
|
6
6
|
|
7
7
|
# Creates a new instance. Max is the total number of iterations of the
|
8
8
|
# loop. The depth represents how many other loops are above this one,
|
@@ -38,8 +38,7 @@ module Log
|
|
38
38
|
@last_report=percent
|
39
39
|
end
|
40
40
|
else
|
41
|
-
@last_report
|
42
|
-
if Time.now - @last_report >= 1.0
|
41
|
+
if @last_report == -1 or Time.now - @last_report >= 1.0
|
43
42
|
throughput
|
44
43
|
end
|
45
44
|
end
|
@@ -66,11 +65,11 @@ module Log
|
|
66
65
|
|
67
66
|
|
68
67
|
def up_lines(depth)
|
69
|
-
"\033[#{depth +
|
68
|
+
"\033[#{depth + 1}F\033[2K"
|
70
69
|
end
|
71
70
|
|
72
71
|
def down_lines(depth)
|
73
|
-
"\n\033[#{depth +
|
72
|
+
"\n\033[#{depth + 2}E"
|
74
73
|
end
|
75
74
|
|
76
75
|
def report_msg
|
@@ -91,47 +90,85 @@ module Log
|
|
91
90
|
used = [used/3600, used/60 % 60, used % 60].map{|t| "%02i" % t }.join(':')
|
92
91
|
|
93
92
|
if progress == 1
|
94
|
-
indicator << Log.color(:green, " done
|
95
|
-
|
96
|
-
|
93
|
+
indicator << Log.color(:green, " done")
|
97
94
|
indicator << Log.color(:blue, " #{used}")
|
98
95
|
else
|
99
|
-
indicator << "
|
96
|
+
indicator << " #{Log.color(:blue, percent.to_s << "%")}"
|
100
97
|
|
101
98
|
eta = self.eta
|
102
99
|
eta = [eta/3600, eta/60 % 60, eta % 60].map{|t| "%02i" % t }.join(':')
|
103
100
|
|
104
|
-
indicator << "
|
101
|
+
indicator << " #{Log.color :yellow, used} used #{Log.color :yellow, eta} left"
|
105
102
|
end
|
106
103
|
|
107
104
|
end
|
108
105
|
|
109
|
-
def
|
110
|
-
|
106
|
+
def thr
|
107
|
+
@history ||= []
|
108
|
+
@last_report = Time.now if @last_report == -1
|
111
109
|
time = Time.now - @last_report
|
112
110
|
thr = (@current / time).to_i
|
111
|
+
|
112
|
+
@history << thr
|
113
|
+
@history.shift if @history.length > 10
|
114
|
+
|
115
|
+
thr
|
116
|
+
end
|
117
|
+
|
118
|
+
def mean
|
119
|
+
@mean_max ||= 0
|
120
|
+
if @history.length > 3
|
121
|
+
mean = Misc.mean(@history[1..-1])
|
122
|
+
@mean_max = mean if mean > @mean_max
|
123
|
+
end
|
124
|
+
mean
|
125
|
+
end
|
126
|
+
|
127
|
+
def throughput_msg
|
128
|
+
thr = self.thr
|
129
|
+
|
130
|
+
mean = self.mean
|
131
|
+
|
132
|
+
indicator = Log.color(:magenta, @desc)
|
113
133
|
indicator << " #{ Log.color :blue, thr } per second"
|
134
|
+
|
135
|
+
indicator << " -- #{ Log.color :yellow, mean.to_i } avg. #{ Log.color :yellow, @mean_max.to_i} max." if mean
|
136
|
+
|
114
137
|
indicator
|
115
138
|
end
|
116
139
|
|
140
|
+
def print(io, str)
|
141
|
+
LOG_MUTEX.synchronize do
|
142
|
+
STDERR.print str
|
143
|
+
Log.logfile.puts str unless Log.logfile.nil?
|
144
|
+
Log::LAST.replace "progress"
|
145
|
+
end
|
146
|
+
end
|
117
147
|
# Prints de progress report. It backs up as many lines as the meters
|
118
148
|
# depth. Prints the progress as a line of dots, a percentage, time
|
119
149
|
# spent, and time left. And then goes moves the cursor back to its
|
120
150
|
# original line. Everything is printed to stderr.
|
121
151
|
def report(io = STDERR)
|
122
|
-
|
152
|
+
if Log::LAST != "progress"
|
153
|
+
BARS.length.times{print(io, "\n")}
|
154
|
+
end
|
155
|
+
print(io, up_lines(@depth) << report_msg << down_lines(@depth)) if severity >= Log.severity
|
156
|
+
@last_report = Time.now if @last_report == -1
|
123
157
|
end
|
124
158
|
|
125
159
|
def throughput(io = STDERR)
|
126
|
-
|
160
|
+
if Log::LAST != "progress"
|
161
|
+
BARS.length.times{print(io, "\n")}
|
162
|
+
end
|
163
|
+
print(io, up_lines(@depth) << throughput_msg << down_lines(@depth)) if severity >= Log.severity
|
127
164
|
@last_report = Time.now
|
128
165
|
@current = 0
|
129
166
|
end
|
130
167
|
BAR_MUTEX = Mutex.new
|
131
168
|
BARS = []
|
132
169
|
def self.new_bar(max, options = {})
|
133
|
-
options = Misc.add_defaults options, :depth => BARS.length
|
134
170
|
BAR_MUTEX.synchronize do
|
171
|
+
options = Misc.add_defaults options, :depth => BARS.length
|
135
172
|
BARS << (bar = ProgressBar.new(max, options))
|
136
173
|
bar
|
137
174
|
end
|
@@ -148,6 +185,7 @@ module Log
|
|
148
185
|
end
|
149
186
|
BARS.pop
|
150
187
|
end
|
188
|
+
Log::LAST.replace "removeprogress"
|
151
189
|
end
|
152
190
|
end
|
153
191
|
|
@@ -104,13 +104,15 @@ module ConcurrentStream
|
|
104
104
|
@callback = nil
|
105
105
|
end
|
106
106
|
|
107
|
-
def
|
107
|
+
def super(*args)
|
108
108
|
if autojoin
|
109
109
|
begin
|
110
110
|
super(*args)
|
111
111
|
rescue
|
112
|
+
Log.exception $!
|
112
113
|
self.abort
|
113
114
|
self.join
|
115
|
+
raise $!
|
114
116
|
ensure
|
115
117
|
self.join if self.closed? or self.eof?
|
116
118
|
end
|
data/lib/rbbt/util/open.rb
CHANGED
@@ -379,6 +379,7 @@ module Open
|
|
379
379
|
rescue
|
380
380
|
io.abort if io.respond_to? :abort
|
381
381
|
io.join if io.respond_to? :join
|
382
|
+
raise $!
|
382
383
|
ensure
|
383
384
|
io.join if io.respond_to? :join
|
384
385
|
end
|
@@ -439,8 +440,8 @@ module Open
|
|
439
440
|
begin
|
440
441
|
File.open(file, mode) do |f|
|
441
442
|
f.flock(File::LOCK_EX)
|
442
|
-
while
|
443
|
-
f.write
|
443
|
+
while block = content.read(2014)
|
444
|
+
f.write block
|
444
445
|
end
|
445
446
|
f.flock(File::LOCK_UN)
|
446
447
|
end
|
@@ -46,6 +46,8 @@ class Step
|
|
46
46
|
begin
|
47
47
|
return @info_cache if @info_cache and File.mtime(info_file) < @info_cache_time
|
48
48
|
rescue Exception
|
49
|
+
Log.exception $!
|
50
|
+
raise $!
|
49
51
|
end
|
50
52
|
|
51
53
|
begin
|
@@ -64,8 +66,8 @@ class Step
|
|
64
66
|
end
|
65
67
|
rescue Exception
|
66
68
|
Log.debug{"Error loading info file: " + info_file}
|
69
|
+
#self.abort_pid
|
67
70
|
Open.write(info_file, INFO_SERIALIAZER.dump({:status => :error, :messages => ["Info file lost"]}))
|
68
|
-
self.abort
|
69
71
|
raise $!
|
70
72
|
end
|
71
73
|
end
|
@@ -344,7 +344,11 @@ class Step
|
|
344
344
|
|
345
345
|
def join
|
346
346
|
|
347
|
-
|
347
|
+
until done? or result or error? or aborted? or streaming?
|
348
|
+
sleep 1
|
349
|
+
end
|
350
|
+
|
351
|
+
join_stream if status == :streaming
|
348
352
|
|
349
353
|
return self if not Open.exists? info_file
|
350
354
|
|
@@ -356,9 +360,8 @@ class Step
|
|
356
360
|
end
|
357
361
|
|
358
362
|
begin
|
359
|
-
if pid.nil?
|
363
|
+
if pid.nil? or Process.pid == pid
|
360
364
|
dependencies.each{|dep| dep.join }
|
361
|
-
self
|
362
365
|
else
|
363
366
|
begin
|
364
367
|
Log.debug{"Waiting for pid: #{pid}"}
|
@@ -368,11 +371,10 @@ class Step
|
|
368
371
|
end if Misc.pid_exists? pid
|
369
372
|
pid = nil
|
370
373
|
dependencies.each{|dep| dep.join }
|
371
|
-
self
|
372
374
|
end
|
375
|
+
self
|
373
376
|
ensure
|
374
377
|
set_info :joined, true
|
375
378
|
end
|
376
|
-
self
|
377
379
|
end
|
378
380
|
end
|
@@ -23,20 +23,8 @@ max = 0
|
|
23
23
|
avg = 0
|
24
24
|
all = []
|
25
25
|
scale = 5
|
26
|
+
bar = Log::ProgressBar.new_bar nil
|
27
|
+
|
26
28
|
while line = STDIN.gets
|
27
|
-
|
28
|
-
last ||= Time.now
|
29
|
-
if Time.now - last >= 1.0 / scale
|
30
|
-
Log.clear_line
|
31
|
-
puts "Reading #{ Log.color :blue, count*scale } per second. Max #{ Log.color :blue, max*scale }. Average #{Log.color :blue, avg*scale}"
|
32
|
-
max = count > max ? count : max
|
33
|
-
last = Time.now
|
34
|
-
all << count
|
35
|
-
avg = Misc.mean(all).to_i if all.length > 3
|
36
|
-
count = 0
|
37
|
-
end
|
29
|
+
bar.tick
|
38
30
|
end
|
39
|
-
|
40
|
-
all << count
|
41
|
-
|
42
|
-
puts "Total #{Log.color :blue, Misc.sum(all).to_i} in #{Log.color :blue, (Time.now - start).to_i} seconds -- #{Log.color :green, (Misc.sum(all).to_f / (Time.now - start)).to_i } per second. Max #{Log.color :blue, max*scale}. Average #{Log.color :green, avg*scale}"
|
@@ -2,22 +2,26 @@ require File.join(File.expand_path(File.dirname(__FILE__)), '../../..', 'test_he
|
|
2
2
|
require 'rbbt/util/log/progress'
|
3
3
|
|
4
4
|
class TestProgress < Test::Unit::TestCase
|
5
|
-
def
|
5
|
+
def test_bar
|
6
6
|
t1 = Thread.new do
|
7
|
-
Log::ProgressBar.with_bar(20) do |bar|
|
7
|
+
Log::ProgressBar.with_bar(20, :desc => "Bar 1") do |bar|
|
8
8
|
20.times do
|
9
9
|
bar.tick
|
10
10
|
sleep 0.3
|
11
11
|
end
|
12
|
+
Log.debug "Done progress"
|
13
|
+
assert_equal 100, bar.percent
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
17
|
t2 = Thread.new do
|
16
|
-
Log::ProgressBar.with_bar(20) do |bar|
|
18
|
+
Log::ProgressBar.with_bar(20, :desc => "Bar 2") do |bar|
|
17
19
|
20.times do
|
18
20
|
bar.tick
|
19
21
|
sleep 0.2
|
20
22
|
end
|
23
|
+
Log.debug "Done progress"
|
24
|
+
assert_equal 100, bar.percent
|
21
25
|
end
|
22
26
|
end
|
23
27
|
t1.join
|
@@ -26,20 +30,24 @@ class TestProgress < Test::Unit::TestCase
|
|
26
30
|
|
27
31
|
def test_bar_no_size
|
28
32
|
t1 = Thread.new do
|
29
|
-
Log::ProgressBar.with_bar(nil) do |bar|
|
33
|
+
Log::ProgressBar.with_bar(nil, :desc => "Bar 1") do |bar|
|
30
34
|
20.times do
|
31
35
|
bar.tick
|
32
36
|
sleep 0.3
|
33
37
|
end
|
38
|
+
Log.debug "Done progress"
|
39
|
+
assert bar.history.length > 0
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
37
43
|
t2 = Thread.new do
|
38
|
-
Log::ProgressBar.with_bar(nil) do |bar|
|
44
|
+
Log::ProgressBar.with_bar(nil, :desc => "Bar 2") do |bar|
|
39
45
|
20.times do
|
40
46
|
bar.tick
|
41
47
|
sleep 0.2
|
42
48
|
end
|
49
|
+
Log.debug "Done progress"
|
50
|
+
assert bar.history.length > 0
|
43
51
|
end
|
44
52
|
end
|
45
53
|
t1.join
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbbt-util
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.13.
|
4
|
+
version: 5.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|