Skip to content

Commit f30171d

Browse files
committed
print total PNG files size
1 parent cb098d6 commit f30171d

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/main/java/com/pdiff/RunCommand.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.concurrent.Executors;
1111
import java.util.concurrent.TimeUnit;
1212
import java.util.concurrent.atomic.AtomicInteger;
13+
import java.util.concurrent.atomic.AtomicLong;
1314
import java.util.function.Predicate;
1415
import java.util.stream.Collectors;
1516

@@ -38,13 +39,13 @@ public class RunCommand {
3839
@Parameter(names = { "-p", "--perf" }, description = "Do not generate output files", required = false)
3940
private boolean onlyPerf = false;
4041

41-
4242
private AtomicInteger done = new AtomicInteger();
4343

4444
private int minimalPrefix;
4545

4646
private MagicOutput magicOutput;
4747
private RemainingTime remainingTime;
48+
private final AtomicLong totalSize = new AtomicLong();
4849

4950
private Predicate<? super DbFileBeforeRun> getFilter() {
5051
if (filter == null)
@@ -53,7 +54,7 @@ private Predicate<? super DbFileBeforeRun> getFilter() {
5354
}
5455

5556
public void doit() throws IOException, InterruptedException {
56-
57+
5758
final DbCollection dbCollection = new DbCollection();
5859
this.minimalPrefix = dbCollection.getMinimalPrefix();
5960

@@ -104,17 +105,31 @@ public void doit() throws IOException, InterruptedException {
104105
}
105106
System.out.print(Ansi.ansi().eraseLine());
106107
System.out.println("Done!");
108+
}
107109

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+
}
108118
}
109119

110120
private void processFile(DbFileBeforeRun dbFile) throws Exception {
111121
final String threadName = Thread.currentThread().getName();
112122
final int workerId = Integer.parseInt(threadName.split("-")[1]);
113123

114124
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);
116132

117-
dbFile.convertMe(this.minimalPrefix, onlyPerf);
118133
magicOutput.updateLivingPart(workerId, "");
119134

120135
}

src/main/java/com/pdiff/core/DbFileBeforeRun.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private DbFileAfterRun getDbFileAfterRun() {
4343
return res.get();
4444
}
4545

46-
public void convertMe(int minimalPrefix, boolean onlyPerf) throws Exception {
46+
public long convertMe(int minimalPrefix, boolean onlyPerf) throws Exception {
4747
List<String> all = Files.readAllLines(getPumlPath());
4848
all = all.subList(DbCollection.getStartingLine(all), all.size());
4949

@@ -55,6 +55,8 @@ public void convertMe(int minimalPrefix, boolean onlyPerf) throws Exception {
5555
final long start = System.currentTimeMillis();
5656
final OutputRun outputRun = Introspection.outputImage(outputPathPng, text, onlyPerf);
5757

58+
final long sizeInBytes = Files.size(outputPathPng);
59+
5860
final long duration = System.currentTimeMillis() - start;
5961

6062
final BufferedImage bufferedImage = ImageIO.read(outputPathPng.toFile());
@@ -69,11 +71,14 @@ public void convertMe(int minimalPrefix, boolean onlyPerf) throws Exception {
6971
png.addProperty("width", bufferedImage.getWidth());
7072
png.addProperty("height", bufferedImage.getHeight());
7173
png.addProperty("crc", imageSignature.getCrc());
74+
png.addProperty("sizeInBytes", sizeInBytes);
7275

7376
jsonObject.add("png", png);
7477

7578
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
7679
Files.write(outputPathJson, List.of(gson.toJson(jsonObject)));
80+
81+
return sizeInBytes;
7782

7883
}
7984

@@ -82,8 +87,10 @@ private static String getOtherLink(DbFileBeforeRun other) {
8287
return "../" + name.substring(0, 2) + "/" + name;
8388
}
8489

85-
public void createStandaloneHtml(int minimalPrefix, DbFileBeforeRun prev, DbFileBeforeRun next/*,
86-
List<DbFileAfterRun> allAfterRuns*/) throws IOException {
90+
public void createStandaloneHtml(int minimalPrefix, DbFileBeforeRun prev,
91+
DbFileBeforeRun next/*
92+
* , List<DbFileAfterRun> allAfterRuns
93+
*/) throws IOException {
8794
final Path outputPathHtml = transformPath(getPumlPath(), ".html");
8895

8996
List<String> all = Files.readAllLines(getPumlPath());

0 commit comments

Comments
 (0)