Skip to content

Commit 791042b

Browse files
committed
add --perf option to measure performance
1 parent 3dd7f15 commit 791042b

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

src/main/java/com/pdiff/Introspection.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,27 @@ public static String versionString() {
1919
}
2020
}
2121

22-
public static OutputRun outputImage(final Path outputPathPng, final String text) throws Exception {
22+
public static OutputRun outputImage(final Path outputPathPng, final String text, boolean onlyPerf)
23+
throws Exception {
2324

2425
final Class<?> readerClass = Class.forName("net.sourceforge.plantuml.SourceStringReader");
26+
final Class<?> fileFormatClass = Class.forName("net.sourceforge.plantuml.FileFormat");
27+
final Class<?> fileFormatOptionClass = Class.forName("net.sourceforge.plantuml.FileFormatOption");
28+
29+
final Enum fileFormatPng = onlyPerf ? Enum.valueOf((Class<Enum>) fileFormatClass, "PNG_EMPTY")
30+
: Enum.valueOf((Class<Enum>) fileFormatClass, "PNG");
31+
final Constructor<?> fileFormatOptionConstructor = fileFormatOptionClass.getConstructor(fileFormatClass);
32+
final Object fileFormatOptionInstance = fileFormatOptionConstructor.newInstance(fileFormatPng);
2533

2634
final Constructor<?> readerConstructor = readerClass.getConstructor(String.class);
2735
final Object readerInstance = readerConstructor.newInstance(text);
2836

29-
final Method outputImageMethod = readerClass.getMethod("outputImage", OutputStream.class);
37+
final Method outputImageMethod = readerClass.getMethod("outputImage", OutputStream.class, int.class,
38+
fileFormatOptionClass);
3039

3140
try (OutputStream png = Files.newOutputStream(outputPathPng)) {
32-
final Object result = outputImageMethod.invoke(readerInstance, png);
41+
final Object result = outputImageMethod.invoke(readerInstance, png, 0, fileFormatOptionInstance);
42+
3343
final Method getDescriptionMethod = result.getClass().getMethod("getDescription");
3444
final String description = (String) getDescriptionMethod.invoke(result);
3545

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public class RunCommand {
3535
@Parameter(names = { "-s", "--slot" }, description = "Specifies the number of parallel slots", required = false)
3636
private int slot = Runtime.getRuntime().availableProcessors();
3737

38+
@Parameter(names = { "-p", "--perf" }, description = "Do not generate output files", required = false)
39+
private boolean onlyPerf = false;
40+
41+
3842
private AtomicInteger done = new AtomicInteger();
3943

4044
private int minimalPrefix;
@@ -49,7 +53,7 @@ private Predicate<? super DbFileBeforeRun> getFilter() {
4953
}
5054

5155
public void doit() throws IOException, InterruptedException {
52-
56+
5357
final DbCollection dbCollection = new DbCollection();
5458
this.minimalPrefix = dbCollection.getMinimalPrefix();
5559

@@ -110,7 +114,7 @@ private void processFile(DbFileBeforeRun dbFile) throws Exception {
110114
magicOutput.updateLivingPart(workerId, workerId + " " + dbFile.getFileName(minimalPrefix));
111115
magicOutput.updateLivingPart(slot, remainingTime.updateCountAndGetStatus(done.incrementAndGet()));
112116

113-
dbFile.convertMe(this.minimalPrefix);
117+
dbFile.convertMe(this.minimalPrefix, onlyPerf);
114118
magicOutput.updateLivingPart(workerId, "");
115119

116120
}

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

Lines changed: 2 additions & 2 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) throws Exception {
46+
public void convertMe(int minimalPrefix, boolean onlyPerf) throws Exception {
4747
List<String> all = Files.readAllLines(getPumlPath());
4848
all = all.subList(DbCollection.getStartingLine(all), all.size());
4949

@@ -53,7 +53,7 @@ public void convertMe(int minimalPrefix) throws Exception {
5353
Files.createDirectories(outputPathPng.getParent());
5454

5555
final long start = System.currentTimeMillis();
56-
final OutputRun outputRun = Introspection.outputImage(outputPathPng, text);
56+
final OutputRun outputRun = Introspection.outputImage(outputPathPng, text, onlyPerf);
5757

5858
final long duration = System.currentTimeMillis() - start;
5959

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ private ImageSignature(BufferedImage im, boolean ignoreFirstPoint) {
3737
this.height = im.getHeight();
3838
this.crc = crc.getValue();
3939
}
40+
41+
private void updateCRC(CRC32 crc, int c) {
42+
final int r = (c & 0xFF0000) >> 16;
43+
final int g = (c & 0x00FF00) >> 8;
44+
final int b = (c & 0x0000FF);
45+
crc.update(r);
46+
crc.update(g);
47+
crc.update(b);
48+
}
4049

4150
public static ImageSignature fromImage(BufferedImage im) {
4251
return new ImageSignature(im, false);
@@ -81,14 +90,7 @@ public boolean equals(Object arg) {
8190
// return fromImage(im, ignoreFirstPoint);
8291
// }
8392

84-
private void updateCRC(CRC32 crc, int c) {
85-
final int r = (c & 0xFF0000) >> 16;
86-
final int g = (c & 0x00FF00) >> 8;
87-
final int b = (c & 0x0000FF);
88-
crc.update(r);
89-
crc.update(g);
90-
crc.update(b);
91-
}
93+
9294

9395
public final long getCrc() {
9496
return crc;

0 commit comments

Comments
 (0)