10
10
import java .util .concurrent .Executors ;
11
11
import java .util .concurrent .TimeUnit ;
12
12
import java .util .concurrent .atomic .AtomicInteger ;
13
+ import java .util .concurrent .atomic .AtomicLong ;
13
14
import java .util .function .Predicate ;
14
15
import java .util .stream .Collectors ;
15
16
@@ -38,13 +39,13 @@ public class RunCommand {
38
39
@ Parameter (names = { "-p" , "--perf" }, description = "Do not generate output files" , required = false )
39
40
private boolean onlyPerf = false ;
40
41
41
-
42
42
private AtomicInteger done = new AtomicInteger ();
43
43
44
44
private int minimalPrefix ;
45
45
46
46
private MagicOutput magicOutput ;
47
47
private RemainingTime remainingTime ;
48
+ private final AtomicLong totalSize = new AtomicLong ();
48
49
49
50
private Predicate <? super DbFileBeforeRun > getFilter () {
50
51
if (filter == null )
@@ -53,7 +54,7 @@ private Predicate<? super DbFileBeforeRun> getFilter() {
53
54
}
54
55
55
56
public void doit () throws IOException , InterruptedException {
56
-
57
+
57
58
final DbCollection dbCollection = new DbCollection ();
58
59
this .minimalPrefix = dbCollection .getMinimalPrefix ();
59
60
@@ -104,17 +105,31 @@ public void doit() throws IOException, InterruptedException {
104
105
}
105
106
System .out .print (Ansi .ansi ().eraseLine ());
106
107
System .out .println ("Done!" );
108
+ }
107
109
110
+ public static String formatSize (long bytes ) {
111
+ if (bytes < 1024 ) {
112
+ return bytes + " bytes" ;
113
+ } else if (bytes < 1024 * 1024 ) {
114
+ return String .format ("%.1f K" , bytes / 1024.0 );
115
+ } else {
116
+ return String .format ("%.1f M" , bytes / (1024.0 * 1024 ));
117
+ }
108
118
}
109
119
110
120
private void processFile (DbFileBeforeRun dbFile ) throws Exception {
111
121
final String threadName = Thread .currentThread ().getName ();
112
122
final int workerId = Integer .parseInt (threadName .split ("-" )[1 ]);
113
123
114
124
magicOutput .updateLivingPart (workerId , workerId + " " + dbFile .getFileName (minimalPrefix ));
115
- magicOutput .updateLivingPart (slot , remainingTime .updateCountAndGetStatus (done .incrementAndGet ()));
125
+ final String status = remainingTime .updateCountAndGetStatus (done .incrementAndGet ());
126
+
127
+ magicOutput .updateLivingPart (slot , "(" + formatSize (totalSize .get ()) + ") " + status );
128
+
129
+ final long sizeInBytes = dbFile .convertMe (this .minimalPrefix , onlyPerf );
130
+ final long newSize = totalSize .addAndGet (sizeInBytes );
131
+ magicOutput .updateLivingPart (slot , "(" + formatSize (newSize ) + ") " + status );
116
132
117
- dbFile .convertMe (this .minimalPrefix , onlyPerf );
118
133
magicOutput .updateLivingPart (workerId , "" );
119
134
120
135
}
0 commit comments