001: /*
002: * ChartMaker.java
003: *
004: * Created on October 16, 2002, 10:42 PM
005: */
006:
007: package org.netbeans.performance.impl.analysis;
008:
009: import org.netbeans.performance.spi.*;
010: import org.netbeans.performance.impl.chart.*;
011: import java.util.*; //import org.netbeans.performance.impl.logparsing.*;
012: import java.io.*;
013: import org.apache.tools.ant.*;
014: import org.apache.tools.ant.types.*;
015: import com.jrefinery.data.*;
016: import com.jrefinery.chart.*;
017:
018: /**An ant task to generate some charts.
019: *
020: * @author Tim Boudreau
021: */
022: public class ChartMaker extends Analyzer {
023:
024: /** Creates a new instance of ChartMaker */
025: public ChartMaker() {
026:
027: }
028:
029: public String analyze() throws BuildException {
030: try {
031: DataAggregation data = getData();
032: genCharts();
033: return "Wrote charts to " + outdir;
034: } catch (Exception e) {
035: e.printStackTrace();
036: throw new BuildException(e.getMessage(), e);
037: }
038: }
039:
040: String query = null;
041:
042: public void setQuery(String query) {
043: this .query = query;
044: }
045:
046: private String[] elements = new String[] {};
047:
048: public void setElements(String elements) {
049: StringTokenizer sk = new StringTokenizer(elements, ",");
050: ArrayList al = new ArrayList(elements.length() / 5);
051: while (sk.hasMoreTokens()) {
052: al.add(sk.nextToken().trim());
053: }
054: this .elements = new String[al.size()];
055: this .elements = (String[]) al.toArray(this .elements);
056: }
057:
058: private String xtitle = "X Axis";
059: private String ytitle = "Y Axis";
060: String title = "Chart";
061:
062: public void setXTitle(String s) {
063: xtitle = s;
064: }
065:
066: public void setYTitle(String s) {
067: ytitle = s;
068: }
069:
070: public void setTitle(String s) {
071: title = s;
072: }
073:
074: public void genCharts() throws BuildException {
075: if (query == null)
076: throw new BuildException("No query specified for " + title);
077: if (elements.length == 0)
078: throw new BuildException("No elements specified");
079: try {
080: NbStatisticalDataset nsd = new NbStatisticalDataset(query,
081: elements, getData());
082: NbChart chart = new NbChart(title, xtitle, ytitle, nsd);
083: File f;
084: if (outfile == null) {
085: f = new File(outdir + "/" + title);
086: } else {
087: f = new File(outfile);
088: }
089: if (f.exists())
090: System.out.println("Overwriting " + f);
091: ChartUtilities.saveChartAsPNG(f, chart, nsd
092: .getOptimalWidth(), 680);
093: } catch (Exception e) {
094: throw new BuildException(e);
095: }
096: }
097:
098: public static void main(String[] args) throws Exception {
099: ChartMaker cm = new ChartMaker();
100: cm
101: .setElements("Seconds spent in GC,Seconds in MAJOR GC cycles,Seconds in minor GC cycles");
102: cm.setQuery("/run/GC Tuning*gcinfo");
103: cm.setOutFile("/tmp/testchart.png");
104: cm.setDataFile("/tmp/SerThing.ser");
105: cm.execute();
106: System.out.println("Wrote chart to /tmp/testchart.png");
107: }
108:
109: }
|