40
40
import java .io .File ;
41
41
import java .io .FileWriter ;
42
42
import java .io .IOException ;
43
+ import java .nio .file .Files ;
44
+ import java .nio .file .Paths ;
43
45
import java .text .SimpleDateFormat ;
44
46
import java .util .*;
45
47
import java .util .Map .Entry ;
@@ -58,7 +60,7 @@ public class Measurement {
58
60
private long seed ;
59
61
private int maxNode ;
60
62
61
- public static void main (String [] strs ) {
63
+ public static void main (String [] strs ) throws IOException {
62
64
CmdArgs cmdArgs = CmdArgs .read (strs );
63
65
int repeats = cmdArgs .getInt ("measurement.repeats" , 1 );
64
66
for (int i = 0 ; i < repeats ; ++i )
@@ -67,24 +69,29 @@ public static void main(String[] strs) {
67
69
68
70
// creates properties file in the format key=value
69
71
// Every value is one y-value in a separate diagram with an identical x-value for every Measurement.start call
70
- void start (CmdArgs args ) {
72
+ void start (CmdArgs args ) throws IOException {
71
73
final String graphLocation = args .get ("graph.location" , "" );
72
74
final boolean useJson = args .getBool ("measurement.json" , false );
73
75
boolean cleanGraph = args .getBool ("measurement.clean" , false );
74
76
String summaryLocation = args .get ("measurement.summaryfile" , "" );
75
77
final String timeStamp = new SimpleDateFormat ("yyyy-MM-dd_HH_mm_ss" ).format (new Date ());
76
78
put ("measurement.timestamp" , timeStamp );
77
- String propLocation = args .get ("measurement.location" , "" );
78
- if (isEmpty (propLocation )) {
79
+ String propFolder = args .get ("measurement.folder" , "" );
80
+ if (!propFolder .isEmpty ()) {
81
+ Files .createDirectories (Paths .get (propFolder ));
82
+ }
83
+ String propFilename = args .get ("measurement.filename" , "" );
84
+ if (isEmpty (propFilename )) {
79
85
if (useJson ) {
80
86
String gitInfo = Constants .GIT_INFO ;
81
87
// if we start from IDE or otherwise jar was not built using maven the git commit id will be unknown
82
- String prefix = gitInfo .startsWith ("${git.commit.id}" ) ? "unknown" : gitInfo .split ("\\ |" )[0 ].substring (0 , 8 );
83
- propLocation = prefix + "_" + timeStamp + ".json" ;
88
+ String id = gitInfo .startsWith ("${git.commit.id}" ) ? "unknown" : gitInfo .split ("\\ |" )[0 ].substring (0 , 8 );
89
+ propFilename = "measurement_" + id + "_" + timeStamp + ".json" ;
84
90
} else {
85
- propLocation = "measurement" + timeStamp + ".properties" ;
91
+ propFilename = "measurement" + timeStamp + ".properties" ;
86
92
}
87
93
}
94
+ final String propLocation = Paths .get (propFolder ).resolve (propFilename ).toString ();
88
95
seed = args .getLong ("measurement.seed" , 123 );
89
96
put ("measurement.gitinfo" , args .get ("measurement.gitinfo" , "" ));
90
97
int count = args .getInt ("measurement.count" , 5000 );
@@ -594,9 +601,10 @@ private void storeJson(String graphLocation, String jsonLocation) {
594
601
result .put ("gitinfo" , gitInfoMap );
595
602
result .put ("metrics" , properties );
596
603
try {
604
+ File file = new File (jsonLocation );
597
605
new ObjectMapper ()
598
606
.writerWithDefaultPrettyPrinter ()
599
- .writeValue (new File ( jsonLocation ) , result );
607
+ .writeValue (file , result );
600
608
} catch (IOException e ) {
601
609
logger .error ("Problem while storing json " + graphLocation + ", " + jsonLocation , e );
602
610
}
0 commit comments