mbt-gen 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mbt-gen.rb +2058 -1958
- data/lib/progress.rb +53 -5
- data/lib/solver-lib.rb +572 -433
- metadata +6 -3
data/lib/progress.rb
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/ruby
|
|
2
2
|
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
3
5
|
class Progress
|
|
4
6
|
|
|
5
|
-
def initialize()
|
|
7
|
+
def initialize(logfilename)
|
|
6
8
|
@last_line = ""
|
|
9
|
+
dir = File.dirname(logfilename)
|
|
10
|
+
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
|
11
|
+
@logfile = File.open(logfilename, "w")
|
|
7
12
|
end
|
|
8
13
|
|
|
9
14
|
def update_last_line(last_line)
|
|
@@ -13,27 +18,70 @@ class Progress
|
|
|
13
18
|
end
|
|
14
19
|
|
|
15
20
|
def print_line(line)
|
|
21
|
+
@logfile.puts(line)
|
|
22
|
+
@logfile.flush()
|
|
16
23
|
print "\033[M#{line}\n#{@last_line}"
|
|
17
24
|
$stdout.flush()
|
|
18
25
|
end
|
|
19
26
|
end
|
|
20
27
|
|
|
28
|
+
class VoidProgress < Progress
|
|
29
|
+
def initialize()
|
|
30
|
+
super("tmp.log")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
21
34
|
class ProgressBar < Progress
|
|
22
|
-
def initialize(max)
|
|
35
|
+
def initialize(max, logfilename)
|
|
36
|
+
super(logfilename)
|
|
23
37
|
@max = max.to_f
|
|
24
38
|
end
|
|
25
39
|
|
|
40
|
+
def set_max(value)
|
|
41
|
+
@max = value.to_f
|
|
42
|
+
end
|
|
43
|
+
|
|
26
44
|
def render_bar(current, length)
|
|
27
45
|
bars = (current.to_f * length.to_f).floor
|
|
28
46
|
"=" * bars + ">" + " " * (length - bars)
|
|
29
47
|
end
|
|
30
48
|
|
|
31
|
-
def
|
|
49
|
+
def processing_time(start_time, prior_processessing_time)
|
|
50
|
+
total_sec = prior_processessing_time + (Time.now().to_i - start_time)
|
|
51
|
+
sec = total_sec
|
|
52
|
+
days = sec / (3600*24)
|
|
53
|
+
sec -= days * (3600*24)
|
|
54
|
+
hours = sec / 3600
|
|
55
|
+
sec -= hours * 3600
|
|
56
|
+
min = sec / 60
|
|
57
|
+
sec -= min * 60
|
|
58
|
+
if days > 0 then
|
|
59
|
+
return format("%d:%02d:%02d:%02d", days, hours, min, sec)
|
|
60
|
+
else
|
|
61
|
+
if hours > 0 then
|
|
62
|
+
return format("%02d:%02d:%02d", hours, min, sec)
|
|
63
|
+
else
|
|
64
|
+
return format("%02d:%02d", min, sec)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def report_progress(progress, start_time, prior_processessing_time, num_docs)
|
|
70
|
+
time_str = processing_time(start_time, prior_processessing_time)
|
|
32
71
|
if progress then
|
|
33
72
|
current = (progress.to_f / @max)
|
|
34
|
-
update_last_line("[#{render_bar(current, 40)}] combinations covered: #{progress}/#{@max} (#{format("%.8f", current * 100.0)}%)")
|
|
73
|
+
update_last_line("#{time_str} [#{render_bar(current, 40)}] combinations covered: #{progress}/#{@max} (#{format("%.8f", current * 100.0)}%), docs generated: #{num_docs}")
|
|
35
74
|
else
|
|
36
|
-
update_last_line("[... ? ... ? ... ? ...] combinations covered: ?/∞ (?%)")
|
|
75
|
+
update_last_line("#{time_str} [... ? ... ? ... ? ...] combinations covered: ?/∞ (?%), docs generated: #{num_docs}")
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def self.logging(max, logfile, &block)
|
|
80
|
+
progress = ProgressBar.new(max, logfile)
|
|
81
|
+
begin
|
|
82
|
+
block.call(progress)
|
|
83
|
+
ensure
|
|
84
|
+
progress.print_line("Output written to #{logfile}")
|
|
37
85
|
end
|
|
38
86
|
end
|
|
39
87
|
end
|