-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/console mode #95
base: master
Are you sure you want to change the base?
Changes from 17 commits
d3834c7
d90a25f
6757a13
d1d30a1
3a38eb6
b0fd4bf
d7dde91
0890d08
51bd259
dc34f53
810b2ba
cec3644
4004367
c7e2224
9190a05
52adcbb
687eefb
34c68c2
1b6aae3
8a602f4
7f93028
4e91c98
012e824
0d33144
225f532
5919c80
88695a0
4f069f8
09cfa0d
9ebe51d
9e19416
a1caf27
546fd17
b069100
028506b
43a0b50
a39c4bb
91d6efd
a16205e
0a5817c
107623b
b7e8cb2
975f4b0
3b065b7
e5eb850
2905662
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,15 @@ | |
|
||
package net.atomique.ksar; | ||
|
||
import net.atomique.ksar.export.FileCSV; | ||
import net.atomique.ksar.export.FilePDF; | ||
import net.atomique.ksar.export.FilePNG; | ||
import net.atomique.ksar.graph.Graph; | ||
import net.atomique.ksar.graph.List; | ||
import net.atomique.ksar.ui.Desktop; | ||
import net.atomique.ksar.ui.ParentNodeInfo; | ||
import net.atomique.ksar.ui.SortedTreeNode; | ||
import net.atomique.ksar.ui.TreeNodeInfo; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -18,13 +26,22 @@ | |
public class Main { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(Main.class); | ||
|
||
private static boolean gui = true; | ||
static Config config = null; | ||
static GlobalOptions globaloptions = null; | ||
static ResourceBundle resource = ResourceBundle.getBundle("net/atomique/ksar/Language/Message"); | ||
|
||
public static void usage() { | ||
show_version(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have you removed this version info? |
||
log.info("-input : input sar statistics file \n"); | ||
log.info("-n : toggles nongui mode for exporting\n"); | ||
log.info("-outputCSV : location of parsed CSV file\n"); | ||
log.info("-outputPDF : location of output pdf file\n"); | ||
log.info("-outputIMG : prefix for output images\n"); | ||
log.info("-width : width for output png charts\n"); | ||
log.info("-heigth : heigth for output png charts"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think PS. Something like https://github.com/airlift/airline or https://github.com/tatsuhiro-t/argparse4j might make sense to parse the options There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was refering to previous version of kSar where console mode was working It was following BTW there is full output for help in older version -version: show kSar version number |
||
log.info("-tags : comma separated list of nodes for export. ex: 'CPU all,Load'"); | ||
log.info("-dateFormat : date time format. Example: MM/DD/YYYY 23:59:59"); | ||
System.exit(0); | ||
} | ||
|
||
public static void show_version() { | ||
|
@@ -36,7 +53,8 @@ private static void set_lookandfeel() { | |
if (Config.getLandf().equals(laf.getName())) { | ||
try { | ||
UIManager.setLookAndFeel(laf.getClassName()); | ||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { | ||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | ||
| UnsupportedLookAndFeelException ex) { | ||
log.error("lookandfeel Exception", ex); | ||
} | ||
} | ||
|
@@ -78,7 +96,6 @@ public static void main(String[] args) { | |
config = Config.getInstance(); | ||
globaloptions = GlobalOptions.getInstance(); | ||
|
||
|
||
if (args.length > 0) { | ||
while (i < args.length && args[i].startsWith("-")) { | ||
arg = args[i++]; | ||
|
@@ -102,16 +119,183 @@ public static void main(String[] args) { | |
} | ||
continue; | ||
} | ||
if ("-outputCSV".equals(arg)) { | ||
// This will be CSV file to export by deafault | ||
if (i < args.length) { | ||
GlobalOptions.setOutCSV(args[i++]); | ||
} else { | ||
exit_error(resource.getString("INPUT_REQUIRE_ARG")); | ||
} | ||
continue; | ||
} | ||
|
||
if ("-outputPDF".equals(arg)) { | ||
// This will be CSV file to export by deafault | ||
if (i < args.length) { | ||
GlobalOptions.setOutPDF(args[i++]); | ||
} else { | ||
exit_error(resource.getString("INPUT_REQUIRE_ARG")); | ||
} | ||
continue; | ||
} | ||
|
||
// prefix for chart image files | ||
if ("-outputIMG".equals(arg)) { | ||
// This will be CSV file to export by deafault | ||
if (i < args.length) { | ||
GlobalOptions.setOutIMG(args[i++]); | ||
} else { | ||
exit_error(resource.getString("INPUT_REQUIRE_ARG")); | ||
} | ||
continue; | ||
} | ||
|
||
// node names for export comma separated | ||
if ("-tags".equals(arg)) { | ||
// This will be CSV file to export by deafault | ||
if (i < args.length) { | ||
GlobalOptions.setOutTags(args[i++]); | ||
} else { | ||
exit_error(resource.getString("INPUT_REQUIRE_ARG")); | ||
} | ||
continue; | ||
} | ||
|
||
if ("-width".equals(arg)) { | ||
// This will be CSV file to export by deafault | ||
if (i < args.length) { | ||
GlobalOptions.setWidth(Integer.parseInt(args[i++])); | ||
} else { | ||
exit_error(resource.getString("INPUT_REQUIRE_ARG")); | ||
} | ||
continue; | ||
} | ||
|
||
if ("-heigth".equals(arg)) { | ||
// This will be CSV file to export by deafault | ||
if (i < args.length) { | ||
GlobalOptions.setWidth(Integer.parseInt(args[i++])); | ||
} else { | ||
exit_error(resource.getString("INPUT_REQUIRE_ARG")); | ||
} | ||
continue; | ||
} | ||
|
||
if ("-dateFormat".equals(arg)) { | ||
// This will be CSV file to export by deafault | ||
if (i < args.length) { | ||
Config.setLinuxDateFormat(args[i++]); | ||
Config.save(); | ||
} else { | ||
exit_error(resource.getString("INPUT_REQUIRE_ARG")); | ||
} | ||
continue; | ||
} | ||
|
||
if ("-n".equals(arg)) { | ||
// This means nongui mode (same as in jmeter) | ||
gui = false; | ||
continue; | ||
} | ||
|
||
} | ||
} | ||
|
||
make_ui(); | ||
if (gui) { | ||
make_ui(); | ||
} else { | ||
nongui(); | ||
} | ||
|
||
} | ||
|
||
public static void exit_error(final String message) { | ||
log.error(message); | ||
System.exit(1); | ||
} | ||
|
||
public static void validateTags(SortedTreeNode node) { | ||
int num = node.getChildCount(); | ||
if (num > 0) { | ||
Object obj1 = node.getUserObject(); | ||
if (obj1 instanceof ParentNodeInfo) { | ||
ParentNodeInfo tmpnode = (ParentNodeInfo) obj1; | ||
List nodeobj = tmpnode.getNode_object(); | ||
} | ||
for (int i = 0; i < num; i++) { | ||
SortedTreeNode l = (SortedTreeNode) node.getChildAt(i); | ||
validateTags(l); | ||
} | ||
} else { | ||
Object obj1 = node.getUserObject(); | ||
if (obj1 instanceof TreeNodeInfo) { | ||
TreeNodeInfo tmpnode = (TreeNodeInfo) obj1; | ||
Graph nodeobj = tmpnode.getNode_object(); | ||
nodeobj.printSelected = false; | ||
for (String nodename : GlobalOptions.getOutTags().split(",")) { | ||
if (nodeobj.getTitle().equals(nodename)) { | ||
nodeobj.printSelected = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void nongui() { | ||
kSar ks = new kSar(); | ||
if (GlobalOptions.getCLfilename() == null) { | ||
exit_error("No any input file path specified"); | ||
} | ||
System.out.println("running nongui with " + GlobalOptions.getCLfilename()); | ||
ks.do_fileread(GlobalOptions.getCLfilename()); | ||
while (ks.launched_action.isAlive()) { | ||
try { | ||
Thread.sleep(1); | ||
} catch (InterruptedException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
// filter out graph nodes for given tags | ||
if (GlobalOptions.getOutTags() != null) { | ||
validateTags(ks.graphtree); | ||
} | ||
|
||
log.trace("File parsing completed. Starting export"); | ||
if (GlobalOptions.getOutCSV() != null) { | ||
Runnable t = new FileCSV(GlobalOptions.getOutCSV(), ks); | ||
Thread th = new Thread(t); | ||
th.start(); | ||
while (th.isAlive()) { | ||
try { | ||
Thread.sleep(1); | ||
} catch (InterruptedException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
log.trace("CSV Export completed"); | ||
} | ||
|
||
if (GlobalOptions.getOutPDF() != null) { | ||
Runnable t = new FilePDF(GlobalOptions.getOutPDF(), ks); | ||
Thread th = new Thread(t); | ||
th.start(); | ||
while (th.isAlive()) { | ||
try { | ||
Thread.sleep(1); | ||
} catch (InterruptedException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
log.trace("PDF Export completed"); | ||
} | ||
if (GlobalOptions.getOutIMG() != null) { | ||
FilePNG.drawCharts(ks.graphtree, ks); | ||
log.trace("IMG Export completed"); | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refrain from moving things around in the same commit/PR as the feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved declarations back