Skip to content
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

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d3834c7
Adding Autodetect time format in drop-down list that toggles linux ti…
May 15, 2017
d90a25f
CSV output fix, date value was missing
May 15, 2017
6757a13
Revert "CSV output fix, date value was missing"
May 15, 2017
d1d30a1
Revert "Adding Autodetect time format in drop-down list that toggles …
May 15, 2017
3a38eb6
csv_export_fix
May 15, 2017
b0fd4bf
console mode
May 15, 2017
d7dde91
style fix
May 15, 2017
0890d08
autodetect option
May 15, 2017
51bd259
remove_trailing
May 15, 2017
dc34f53
adding graph fix
May 15, 2017
810b2ba
fix of format
May 15, 2017
cec3644
fix of format
May 15, 2017
4004367
fix of format
May 15, 2017
c7e2224
fix of format
May 15, 2017
9190a05
fix of format
May 15, 2017
52adcbb
Merge pull request #2 from elkrieg/csv_export_fix
elkrieg May 18, 2017
687eefb
fix of missing else clause
May 18, 2017
34c68c2
unittests
May 18, 2017
1b6aae3
style fixes
May 18, 2017
8a602f4
style fixes
May 18, 2017
7f93028
style fixes
May 18, 2017
4e91c98
style fixes
May 18, 2017
012e824
add format selection in console mode
May 18, 2017
0d33144
add format selection in console mode
May 18, 2017
225f532
Merge pull request #3 from elkrieg/AutoDateFormat
elkrieg May 22, 2017
5919c80
add unittests
Jul 7, 2017
88695a0
add unittests
Jul 7, 2017
4f069f8
Merge branch 'master' into console_feature
elkrieg Jul 7, 2017
09cfa0d
format
Jul 7, 2017
9ebe51d
format
Jul 7, 2017
9e19416
Update AllParser.java
elkrieg Jul 7, 2017
a1caf27
Update AllParser.java
elkrieg Jul 7, 2017
546fd17
Update AllParser.java
elkrieg Jul 7, 2017
b069100
123
Jul 19, 2017
028506b
return version to usage
elkrieg Aug 7, 2017
43a0b50
height typo fix
elkrieg Aug 7, 2017
a39c4bb
Update Main.java
elkrieg Aug 7, 2017
91d6efd
Update Linux.java
elkrieg Aug 7, 2017
a16205e
moved vars declaration back to the end of file
elkrieg Aug 7, 2017
0a5817c
format fixes
elkrieg Aug 7, 2017
107623b
Update AllParser.java
elkrieg Aug 7, 2017
b7e8cb2
Merge pull request #4 from vlsi/master
elkrieg Aug 7, 2017
975f4b0
Merge remote-tracking branch 'upstream/master'
Apr 28, 2018
3b065b7
merge
Apr 28, 2018
e5eb850
format issues
Apr 28, 2018
2905662
Merge branch 'console_feature' of https://github.com/elkrieg/ksar int…
Apr 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions src/main/java/net/atomique/ksar/AllParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@

public abstract class AllParser {

protected String sarStartDate = null;
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved declarations back

protected String sarEndDate = null;

protected LocalDateTime startofgraph = null;
protected LocalDateTime endofgraph = null;
protected TreeSet<LocalDateTime> DateSamples = new TreeSet<LocalDateTime>();
protected int firstdatacolumn = 0;

abstract public String getInfo();

abstract public void parse_header(String s);

abstract public void updateUITitle();

protected kSar mysar = null;
protected OSConfig myosconfig = null;
protected String ParserName = null;

protected LocalTime parsetime = null;
protected LocalDate parsedate = null;

protected String currentStat = "NONE";
protected String dateFormat = "MM/dd/yy";
protected String timeFormat = "HH:mm:ss";
protected int timeColumn = 1;

private static final Logger log = LoggerFactory.getLogger(AllParser.class);
private static final Map<String, String> DATE_FORMAT_REGEXPS = new HashMap<String, String>() {
{
Expand Down Expand Up @@ -87,7 +113,6 @@ public boolean setDate(String s) {
} else {
formatter = DateTimeFormatter.ofPattern(dateFormat);
}

currentDate = LocalDate.parse(s, formatter);

parsedate = currentDate;
Expand Down Expand Up @@ -133,30 +158,4 @@ public static String determineDateFormat(String dateString) {
}
return null; // Unknown format.
}

protected String sarStartDate = null;
protected String sarEndDate = null;

protected LocalDateTime startofgraph = null;
protected LocalDateTime endofgraph = null;
protected TreeSet<LocalDateTime> DateSamples = new TreeSet<LocalDateTime>();
protected int firstdatacolumn = 0;

abstract public String getInfo();

abstract public void parse_header(String s);

abstract public void updateUITitle();

protected kSar mysar = null;
protected OSConfig myosconfig = null;
protected String ParserName = null;

protected LocalTime parsetime = null;
protected LocalDate parsedate = null;

protected String currentStat = "NONE";
protected String dateFormat = "MM/dd/yy";
protected String timeFormat = "HH:mm:ss";
protected int timeColumn = 1;
}
54 changes: 54 additions & 0 deletions src/main/java/net/atomique/ksar/GlobalOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,54 @@ static void saveHistory() {

}

public static String getOutCSV() {
return outCSV;
}

public static void setOutCSV(String outCSV) {
GlobalOptions.outCSV = outCSV;
}

public static String getOutPDF() {
return outPDF;
}

public static void setOutPDF(String outPDF) {
GlobalOptions.outPDF = outPDF;
}

public static String getOutIMG() {
return outIMG;
}

public static void setOutIMG(String outIMG) {
GlobalOptions.outIMG = outIMG;
}

public static String getOutTags() {
return outTags;
}

public static void setOutTags(String outTags) {
GlobalOptions.outTags = outTags;
}

public static int getWidth() {
return width;
}

public static void setWidth(int width) {
GlobalOptions.width = width;
}

public static int getHeigth() {
return heigth;
}

public static void setHeigth(int heigth) {
GlobalOptions.heigth = heigth;
}

private static Desktop UI = null;
private static Properties systemprops;
private static String userhome;
Expand All @@ -259,4 +307,10 @@ static void saveHistory() {
private static String CLfilename = null;
private static HashMap<String, Class> ParserMap;
private static boolean firstrun = true;
private static String outCSV;
private static String outPDF;
private static String outIMG;
private static String outTags;
private static int width = 600;
private static int heigth = 400;
}
194 changes: 189 additions & 5 deletions src/main/java/net/atomique/ksar/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Copy link
Owner

Choose a reason for hiding this comment

The 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");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

height should be spelled as height.
Of course naming is hard, however it looks odd to have width and height options dedicated to png.
What if we require pdf page width/height?

I think imgWidth would be better.

PS. Something like https://github.com/airlift/airline or https://github.com/tatsuhiro-t/argparse4j might make sense to parse the options

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
-width : make JPG/PNG with specified width size (default: 800)
-height : make JPG/PNG with specified height size (default: 600)

BTW there is full output for help in older version

-version: show kSar version number
-help: show this help
-input : argument must be either ssh://user@host/command or cmd://command o
r file://path/to/file or just /path/to/file
-graph : space separated list of graph you want to be outputed
-showCPUstacked: will make the CPU used graph as stacked
-showMEMstacked: will make the Memory graph as stacked (linux only)
-cpuFixedAxis: will graph CPU used with fixed axis from 0% to 100%
-showIntrListstacked : will make the Interrupt List graph as stacked
-showTrigger: will show trigger on graph (disabled by default)
-noEmptyDisk: will not export disk with no data
-tile: will tile window
-userPrefs: will use the userPrefs for outputing graphs (last export of this hos
t)
-showOnlygraphName: will only print graph name available for that data (to be us
e for -graph)
-addHTML: will create an html page with PNG/JPG image
-outputPDF : output the pdf report to the pdf file
-outputPNG : output the graphs to PNG file using argument as bas
e filename
-outputJPG : output the graphs to JPG file using argument as bas
e filename
-outputCSV : output the CSV file
-width : make JPG/PNG with specified width size (default: 800)
-height : make JPG/PNG with specified height size (default: 600)
-startdate : will graph the range begining at that time
-enddate : will graph the range until that date
-solarisPagesize : will set solaris pagesize
-wizard: open with unified login popup
-replaceShortcut : replace all shortcut with those in the xml file
-addShortcut : add shortcut from the xml file
-startup: open window marked for opening at startup

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() {
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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++];
Expand All @@ -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");
}

}
}
Loading