11package com .tagtraum .perf .gcviewer ;
22
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-
103import com .tagtraum .perf .gcviewer .ctrl .impl .GCViewerGuiController ;
114import com .tagtraum .perf .gcviewer .exp .DataWriter ;
125import com .tagtraum .perf .gcviewer .exp .DataWriterType ;
1710import com .tagtraum .perf .gcviewer .model .GCResource ;
1811import com .tagtraum .perf .gcviewer .view .SimpleChartRenderer ;
1912
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+
2020/**
2121 * Main class of GCViewer. Parses command line parameters if there are any and either remains
2222 * in command line mode or starts the gui (depending on parameters).
@@ -26,13 +26,24 @@ public class GCViewer {
2626 private static final int EXIT_OK = 0 ;
2727 private static final int EXIT_EXPORT_FAILED = -1 ;
2828 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+ }
2940
30- public static void main (final String [] args ) throws InvocationTargetException , InterruptedException {
41+ public static void main (final String [] args ) throws InvocationTargetException , InterruptedException {
3142 new GCViewer ().doMain (args );
3243 }
3344
3445 public void doMain (String [] args ) throws InvocationTargetException , InterruptedException {
35- GCViewerArgsParser argsParser = new GCViewerArgsParser () ;
46+ GCViewerArgsParser argsParser = gcViewerArgsParser ;
3647 try {
3748 argsParser .parseArguments (args );
3849 }
@@ -47,14 +58,14 @@ public void doMain(String[] args) throws InvocationTargetException, InterruptedE
4758 }
4859 else if (argsParser .getArgumentCount () >= 2 ) {
4960 LOGGER .info ("GCViewer command line mode" );
50- String gcfile = argsParser .getGcfile ();
61+ GCResource gcResource = argsParser .getGcResource ();
5162 String summaryFilePath = argsParser .getSummaryFilePath ();
5263 String chartFilePath = argsParser .getChartFilePath ();
5364 DataWriterType type = argsParser .getType ();
5465
5566 //export summary:
5667 try {
57- export (gcfile , summaryFilePath , chartFilePath , type );
68+ export (gcResource , summaryFilePath , chartFilePath , type );
5869 LOGGER .info ("export completed successfully" );
5970 System .exit (EXIT_OK );
6071 }
@@ -64,22 +75,22 @@ else if (argsParser.getArgumentCount() >= 2) {
6475 }
6576 }
6677 else {
67- new GCViewerGuiController () .startGui (argsParser .getArgumentCount () == 1 ? argsParser .getGcfile () : null );
78+ gcViewerGuiController .startGui (argsParser .getArgumentCount () == 1 ? argsParser .getGcResource () : null );
6879 }
6980 }
7081
71- private void export (String gcFilename , String summaryFilePath , String chartFilePath , DataWriterType type )
82+ private void export (GCResource gcResource , String summaryFilePath , String chartFilePath , DataWriterType type )
7283 throws IOException , DataReaderException {
7384
7485 DataReaderFacade dataReaderFacade = new DataReaderFacade ();
75- GCModel model = dataReaderFacade .loadModel (new GCResource ( gcFilename ) );
86+ GCModel model = dataReaderFacade .loadModel (gcResource );
7687
7788 exportType (model , summaryFilePath , type );
7889 if (chartFilePath != null )
7990 renderChart (model , chartFilePath );
8091 }
8192
82- private void exportType (GCModel model , String summaryFilePath , DataWriterType type ) throws IOException {
93+ private void exportType (GCModel model , String summaryFilePath , DataWriterType type ) throws IOException {
8394 try (DataWriter summaryWriter = DataWriterFactory .getDataWriter (new File (summaryFilePath ), type )) {
8495 summaryWriter .write (model );
8596 }
@@ -90,13 +101,16 @@ private void renderChart(GCModel model, String chartFilePath) throws IOException
90101 renderer .render (model , new FileOutputStream (new File (chartFilePath )));
91102 }
92103
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" );
95106 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" );
96108 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>]" );
100114 }
101115
102116}
0 commit comments