1
1
package com .tagtraum .perf .gcviewer ;
2
2
3
- import java .io .File ;
4
- import java .io .FileOutputStream ;
5
- import java .io .IOException ;
6
- import java .lang .reflect .InvocationTargetException ;
7
- import java .util .logging .Level ;
8
- import java .util .logging .Logger ;
9
-
10
3
import com .tagtraum .perf .gcviewer .ctrl .impl .GCViewerGuiController ;
11
4
import com .tagtraum .perf .gcviewer .exp .DataWriter ;
12
5
import com .tagtraum .perf .gcviewer .exp .DataWriterType ;
17
10
import com .tagtraum .perf .gcviewer .model .GCResource ;
18
11
import com .tagtraum .perf .gcviewer .view .SimpleChartRenderer ;
19
12
13
+ import java .io .File ;
14
+ import java .io .FileOutputStream ;
15
+ import java .io .IOException ;
16
+ import java .lang .reflect .InvocationTargetException ;
17
+ import java .util .logging .Level ;
18
+ import java .util .logging .Logger ;
19
+
20
20
/**
21
21
* Main class of GCViewer. Parses command line parameters if there are any and either remains
22
22
* in command line mode or starts the gui (depending on parameters).
@@ -26,13 +26,24 @@ public class GCViewer {
26
26
private static final int EXIT_OK = 0 ;
27
27
private static final int EXIT_EXPORT_FAILED = -1 ;
28
28
private static final int EXIT_ARGS_PARSE_FAILED = -2 ;
29
+ private GCViewerGuiController gcViewerGuiController ;
30
+ private GCViewerArgsParser gcViewerArgsParser ;
31
+
32
+ public GCViewer () {
33
+ this (new GCViewerGuiController (), new GCViewerArgsParser ());
34
+ }
35
+
36
+ public GCViewer (GCViewerGuiController gcViewerGuiController , GCViewerArgsParser gcViewerArgsParser ) {
37
+ this .gcViewerGuiController = gcViewerGuiController ;
38
+ this .gcViewerArgsParser = gcViewerArgsParser ;
39
+ }
29
40
30
- public static void main (final String [] args ) throws InvocationTargetException , InterruptedException {
41
+ public static void main (final String [] args ) throws InvocationTargetException , InterruptedException {
31
42
new GCViewer ().doMain (args );
32
43
}
33
44
34
45
public void doMain (String [] args ) throws InvocationTargetException , InterruptedException {
35
- GCViewerArgsParser argsParser = new GCViewerArgsParser () ;
46
+ GCViewerArgsParser argsParser = gcViewerArgsParser ;
36
47
try {
37
48
argsParser .parseArguments (args );
38
49
}
@@ -47,14 +58,14 @@ public void doMain(String[] args) throws InvocationTargetException, InterruptedE
47
58
}
48
59
else if (argsParser .getArgumentCount () >= 2 ) {
49
60
LOGGER .info ("GCViewer command line mode" );
50
- String gcfile = argsParser .getGcfile ();
61
+ GCResource gcResource = argsParser .getGcResource ();
51
62
String summaryFilePath = argsParser .getSummaryFilePath ();
52
63
String chartFilePath = argsParser .getChartFilePath ();
53
64
DataWriterType type = argsParser .getType ();
54
65
55
66
//export summary:
56
67
try {
57
- export (gcfile , summaryFilePath , chartFilePath , type );
68
+ export (gcResource , summaryFilePath , chartFilePath , type );
58
69
LOGGER .info ("export completed successfully" );
59
70
System .exit (EXIT_OK );
60
71
}
@@ -64,22 +75,22 @@ else if (argsParser.getArgumentCount() >= 2) {
64
75
}
65
76
}
66
77
else {
67
- new GCViewerGuiController () .startGui (argsParser .getArgumentCount () == 1 ? argsParser .getGcfile () : null );
78
+ gcViewerGuiController .startGui (argsParser .getArgumentCount () == 1 ? argsParser .getGcResource () : null );
68
79
}
69
80
}
70
81
71
- private void export (String gcFilename , String summaryFilePath , String chartFilePath , DataWriterType type )
82
+ private void export (GCResource gcResource , String summaryFilePath , String chartFilePath , DataWriterType type )
72
83
throws IOException , DataReaderException {
73
84
74
85
DataReaderFacade dataReaderFacade = new DataReaderFacade ();
75
- GCModel model = dataReaderFacade .loadModel (new GCResource ( gcFilename ) );
86
+ GCModel model = dataReaderFacade .loadModel (gcResource );
76
87
77
88
exportType (model , summaryFilePath , type );
78
89
if (chartFilePath != null )
79
90
renderChart (model , chartFilePath );
80
91
}
81
92
82
- private void exportType (GCModel model , String summaryFilePath , DataWriterType type ) throws IOException {
93
+ private void exportType (GCModel model , String summaryFilePath , DataWriterType type ) throws IOException {
83
94
try (DataWriter summaryWriter = DataWriterFactory .getDataWriter (new File (summaryFilePath ), type )) {
84
95
summaryWriter .write (model );
85
96
}
@@ -90,13 +101,16 @@ private void renderChart(GCModel model, String chartFilePath) throws IOException
90
101
renderer .render (model , new FileOutputStream (new File (chartFilePath )));
91
102
}
92
103
93
- private static void usage () {
94
- System .out .println ("Welcome to GCViewer with cmdline" );
104
+ private static void usage () {
105
+ System .out .println ("Welcome to GCViewer with cmdline" );
95
106
System .out .println ("java -jar gcviewer.jar [<gc-log-file|url>] -> opens gui and loads given file" );
107
+ System .out .println ("java -jar gcviewer.jar [<gc-log-file|url>];[<gc-log-file|url>];[...] -> opens gui and loads given files as series of rotated logfiles" );
96
108
System .out .println ("java -jar gcviewer.jar [<gc-log-file>] [<export.csv>] -> cmdline: writes report to <export.csv>" );
97
- System .out .println ("java -jar gcviewer.jar [<gc-log-file>] [<export.csv>] [<chart.png>] " +
98
- "-> cmdline: writes report to <export.csv> and renders gc chart to <chart.png>" );
99
- System .out .println ("java -jar gcviewer.jar [<gc-log-file>] [<export.csv>] [<chart.png>] [-t <SUMMARY, CSV, CSV_TS, PLAIN, SIMPLE>]" );
109
+ System .out .println ("java -jar gcviewer.jar [<gc-log-file|url>];[<gc-log-file|url>];[...] [<export.csv>] -> cmdline: loads given files as series of rotated logfiles and writes report to <export.csv>" );
110
+ System .out .println ("java -jar gcviewer.jar [<gc-log-file>] [<export.csv>] [<chart.png>] -> cmdline: writes report to <export.csv> and renders gc chart to <chart.png>" );
111
+ System .out .println ("java -jar gcviewer.jar [<gc-log-file|url>];[<gc-log-file|url>];[...] [<export.csv>] [<chart.png>] -> cmdline: loads given files as series of rotated logfiles and writes report to <export.csv> and renders gc chart to <chart.png>" );
112
+ System .out .println ("java -jar gcviewer.jar [<gc-log-file|url>] [<export.csv>] [<chart.png>] [-t <SUMMARY, CSV, CSV_TS, PLAIN, SIMPLE>]" );
113
+ System .out .println ("java -jar gcviewer.jar [<gc-log-file|url>];[<gc-log-file|url>];[...] [<export.csv>] [<chart.png>] [-t <SUMMARY, CSV, CSV_TS, PLAIN, SIMPLE>]" );
100
114
}
101
115
102
116
}
0 commit comments