9
9
import java .util .*;
10
10
import java .util .concurrent .atomic .AtomicLong ;
11
11
import java .util .stream .Collectors ;
12
+ import java .util .stream .Stream ;
12
13
13
14
/**
14
15
* Class offering a {@link #main(String[])} method that compares builds in a given folder with each other and creates
15
16
* files with patch sizes.
16
17
*
17
18
* @author Daniel Tischner {@literal <zabuza.dev@gmail.com>}
18
19
*/
19
- @ SuppressWarnings ("UseOfSystemOutOrSystemErr" )
20
- final class PatchBenchmark {
20
+ @ SuppressWarnings ({ "UseOfSystemOutOrSystemErr" , "MagicNumber" })
21
+ enum PatchBenchmark {
22
+ ;
23
+
21
24
/**
22
25
* Starts the application.
23
26
*
24
27
* @param args One arguments, the path to the builds to benchmark.
28
+ *
29
+ * @throws IOException If an IOException occurred
25
30
*/
26
31
public static void main (final String [] args ) throws IOException {
27
32
if (args .length != 1 ) {
28
33
throw new IllegalArgumentException (
29
34
"Expected one arguments denoting the path to the folder containing the builds to benchmark." );
30
35
}
31
36
32
- Path basePath = Path .of (args [0 ]);
33
- List <String > builds = Files .list (basePath )
34
- .filter (Files ::isDirectory )
35
- .map (Path ::getFileName )
36
- .map (Path ::toString )
37
- .sorted ()
38
- .collect (Collectors .toList ());
37
+ final Path basePath = Path .of (args [0 ]);
38
+ final List <String > builds ;
39
+ try (final Stream <Path > stream = Files .list (basePath )) {
40
+ builds = stream .filter (Files ::isDirectory )
41
+ .map (Path ::getFileName )
42
+ .map (Path ::toString )
43
+ .sorted ()
44
+ .collect (Collectors .toList ());
45
+ }
39
46
40
- List <Map .Entry <String , String >> buildsToCompare = new ArrayList <>();
47
+ final List <Map .Entry <String , String >> buildsToCompare = new ArrayList <>();
41
48
for (int i = 0 ; i < builds .size () - 1 ; i ++) {
42
- String previous = builds .get (i );
43
- String current = builds .get (i + 1 );
49
+ final String previous = builds .get (i );
50
+ final String current = builds .get (i + 1 );
44
51
45
52
buildsToCompare .add (Map .entry (previous , current ));
46
53
}
47
54
48
55
System .out .printf ("Comparing %d patch scenarios%n" , buildsToCompare .size ());
49
56
50
- List <String > patchDataLines = new ArrayList <>();
57
+ final Collection <String > patchDataLines = new ArrayList <>();
51
58
patchDataLines .add ("patch,name,fsc2mb,fastcdc2mb,fastcdc8kb" );
52
59
// patchDataLines.add("patch,name,rtpal262kb");
53
- List <String > buildDataLines = new ArrayList <>();
60
+ final Collection <String > buildDataLines = new ArrayList <>();
54
61
buildDataLines .add ("version,name,size" );
55
62
int i = 1 ;
56
- for (Map .Entry <String , String > comparison : buildsToCompare ) {
63
+ for (final Map .Entry <String , String > comparison : buildsToCompare ) {
64
+ //noinspection HardcodedFileSeparator
57
65
System .out .printf ("====================== %d / %d patch scenarios ======================%n" , i ,
58
66
buildsToCompare .size ());
59
67
@@ -76,11 +84,11 @@ public static void main(final String[] args) throws IOException {
76
84
comparison .getValue ());
77
85
System .out .println ();
78
86
79
- List <Long > patchSizes = new ArrayList <>();
80
- AtomicLong previousBuildSize = new AtomicLong ();
81
- AtomicLong currentBuildSize = new AtomicLong ();
87
+ final Collection <Long > patchSizes = new ArrayList <>();
88
+ final AtomicLong previousBuildSize = new AtomicLong ();
89
+ final AtomicLong currentBuildSize = new AtomicLong ();
82
90
descriptionToChunker .forEach ((description , chunker ) -> {
83
- PatchSummary summary = PatchSummary .computePatchSummary (chunker , previousBuild , currentBuild );
91
+ final PatchSummary summary = PatchSummary .computePatchSummary (chunker , previousBuild , currentBuild );
84
92
85
93
patchSizes .add (summary .getPatchSize ());
86
94
@@ -90,24 +98,22 @@ public static void main(final String[] args) throws IOException {
90
98
.getTotalSize ());
91
99
});
92
100
93
- StringJoiner patchSizesJoiner = new StringJoiner ("," );
101
+ final StringJoiner patchSizesJoiner = new StringJoiner ("," );
94
102
patchSizesJoiner .add (String .valueOf (i + 1 ));
95
- patchSizesJoiner .add (previousBuild .getFileName ()
96
- .toString () + "-" + currentBuild .getFileName ()
97
- .toString ());
103
+ patchSizesJoiner .add (previousBuild .getFileName () + "-" + currentBuild .getFileName ());
98
104
patchSizes .forEach (size -> patchSizesJoiner .add (String .valueOf (size )));
99
105
patchDataLines .add (patchSizesJoiner .toString ());
100
106
101
107
if (i == 1 ) {
102
- StringJoiner buildDataJoiner = new StringJoiner ("," );
108
+ final StringJoiner buildDataJoiner = new StringJoiner ("," );
103
109
buildDataJoiner .add ("1" );
104
110
buildDataJoiner .add (previousBuild .getFileName ()
105
111
.toString ());
106
112
buildDataJoiner .add (String .valueOf (previousBuildSize .get ()));
107
113
buildDataLines .add (buildDataJoiner .toString ());
108
114
}
109
115
110
- StringJoiner buildDataJoiner = new StringJoiner ("," );
116
+ final StringJoiner buildDataJoiner = new StringJoiner ("," );
111
117
buildDataJoiner .add (String .valueOf (i + 1 ));
112
118
buildDataJoiner .add (currentBuild .getFileName ()
113
119
.toString ());
@@ -116,8 +122,8 @@ public static void main(final String[] args) throws IOException {
116
122
117
123
i ++;
118
124
119
- Path buildDataPath = Path .of ("benchmark_build_data.csv" );
120
- Path patchDataPath = Path .of ("benchmark_patch_data.csv" );
125
+ final Path buildDataPath = Path .of ("benchmark_build_data.csv" );
126
+ final Path patchDataPath = Path .of ("benchmark_patch_data.csv" );
121
127
Files .write (buildDataPath , buildDataLines );
122
128
Files .write (patchDataPath , patchDataLines );
123
129
System .out .println ("Updated benchmark build data: " + buildDataPath );
0 commit comments