Commit 855f2dc9 authored by Johannes Roith's avatar Johannes Roith

Plugin statistics.

parent de639fb8
package de.tum.in.www2.cupplugin.controller;
import java.util.Date;
/**
*
*/
public class ControllerStatistics {
private long parserRuns;
private long parserRunFailures;
private long parserRunFailures; // TODO!
private long lastParserRunNanos;
private long lastParserRunDate;
private Date lastParserRunDate;
private long lalrRuns;
private long lalrRunFailures;
private long lalrRunFailures; // TODO!
private long lastLALRRunNanos;
private long lastLALRRunDate;
private Date lastLALRRunDate;
public long getParserRuns () { return parserRuns; }
public long getParserRunFailures () { return parserRunFailures; }
public long getLastParserRunNanos () { return lastParserRunNanos; }
public Date getLastParserRunDate () { return lastParserRunDate; }
public long getLalrRuns () { return lalrRuns; }
public long getLalrRunFailures () { return lalrRunFailures; }
public long getLastLALRRunNanos () { return lastLALRRunNanos; }
public Date getLastLALRRunDate () { return lastLALRRunDate; }
public void addParserRun(long nanos) {
public void addParserRun(long nanos, Date dt) {
parserRuns++;
lastParserRunNanos = nanos;
lastParserRunNanos = nanos;
lastParserRunDate = dt;
}
public void addTableRun(long nanos) {
public void addTableRun(long nanos, Date dt) {
lalrRuns++;
lastParserRunNanos = nanos;
lastLALRRunNanos = nanos;
lastLALRRunDate = dt;
}
@Override
public Object clone() {
ControllerStatistics res = new ControllerStatistics();
res.parserRuns = parserRuns;
res.parserRunFailures = parserRunFailures;
res.lastParserRunNanos = lastParserRunNanos;
if (lastParserRunDate != null)
res.lastParserRunDate = (Date) lastParserRunDate.clone();
res.lalrRuns = lalrRuns;
res.lalrRunFailures = lalrRunFailures;
res.lastLALRRunNanos = lastLALRRunNanos;
if (lastLALRRunDate != null)
res.lastLALRRunDate = (Date) lastLALRRunDate.clone();
return res;
}
}
......@@ -5,6 +5,7 @@ import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Date;
import java.util.EnumSet;
import java.util.List;
......@@ -79,6 +80,8 @@ public class DocumentDidChangeJob extends Job {
if (editor == null || editor.getDocument() == null)
return Status.CANCEL_STATUS;
Date parserDate = null;
Date lalrDate = null;
long parseTimeNano = -1;
long tableTimeNano = -1;
......@@ -94,6 +97,7 @@ public class DocumentDidChangeJob extends Job {
parser = new CupParser(errorReporter, in);
result = null;
try {
parserDate = new Date();
long before = tmxb.getCurrentThreadCpuTime();
result = parser.parse();
parseTimeNano = tmxb.getCurrentThreadCpuTime() - before;
......@@ -134,6 +138,7 @@ public class DocumentDidChangeJob extends Job {
lalrResult = null;
try {
if (parser != null && !parser.hasParseErrors()) {
lalrDate = new Date();
long before = tmxb.getCurrentThreadCpuTime();
lalrResult = LALRResult.Compute(context, context.start_production);
tableTimeNano = tmxb.getCurrentThreadCpuTime() - before;
......@@ -180,10 +185,11 @@ public class DocumentDidChangeJob extends Job {
documentEvents.clear();
jobs.clear();
controllerStats = (ControllerStatistics) controllerStats.clone();
if (parseTimeNano != -1)
controllerStats.addParserRun(parseTimeNano);
controllerStats.addParserRun(parseTimeNano, parserDate);
if (tableTimeNano != -1)
controllerStats.addTableRun(tableTimeNano);
controllerStats.addTableRun(tableTimeNano, lalrDate);
currentlyRunning = false;
CallbackJob cb = new CallbackJob(editor, jobStatusList, controllerStats);
......
package de.tum.in.www2.cupplugin.views;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
......@@ -23,6 +25,7 @@ import de.in.tum.www2.cup.ast.ParserResult;
import de.tum.in.www2.cupplugin.Pair;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
import de.tum.in.www2.cupplugin.controller.Controller;
import de.tum.in.www2.cupplugin.controller.ControllerStatistics;
import de.tum.in.www2.cupplugin.controller.IRegisterForControllerChanges;
import de.tum.in.www2.cupplugin.controller.JobStatus;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
......@@ -41,6 +44,10 @@ public class CupOverviewView extends FailableView
ICupParserASTChangeObserver,
ICupStatisticsChangeObserver {
private Statistics stats;
private ControllerStatistics controllerStats;
class SimpleTable {
private List<Label> labels;
private List<Label> values;
......@@ -48,6 +55,18 @@ public class CupOverviewView extends FailableView
public void setRowValue(int index, int val) {
values.get(index).setText("" + val);
}
public void setRowValue(int index, long val) {
values.get(index).setText("" + val);
}
public void setRowValue(int index, Date val) {
values.get(index).setText(new SimpleDateFormat("HH:mm:ss").format(val));
}
public void setRowValue(int index, double val) {
values.get(index).setText(String.format("%1$,.1f", val));
}
public void setRowValue(int index, String val) {
values.get(index).setText(val);
......@@ -68,7 +87,16 @@ public class CupOverviewView extends FailableView
}
}
private static final int ERROR_ROW = 0;
private static final int ANALYSIS_ERROR_ROW = 0;
private static final int PLUGIN_STATS_PARSER_RUNS = 0;
private static final int PLUGIN_STATS_PARSER_RUN_FAILURES = 1;
private static final int PLUGIN_STATS_PARSER_RUN_NANOS = 2;
private static final int PLUGIN_STATS_PARSER_RUN_LAST = 3;
private static final int PLUGIN_STATS_LALR_RUNS = 4;
private static final int PLUGIN_STATS_LALR_RUN_FAILURES = 5;
private static final int PLUGIN_STATS_LALR_RUN_NANOS = 6;
private static final int PLUGIN_STATS_LALR_RUN_LAST = 7;
private static final int OUTER_MARGIN = 10;
private static final int INNER_MARGIN = 10;
......@@ -83,6 +111,7 @@ public class CupOverviewView extends FailableView
private static final String SECTION_CONFLICTS_DESCRIPTION_TEMPLATE = "Number of conflicts, etc.";
private Pair<Composite,SimpleTable> analysisSection;
private Pair<Composite,SimpleTable> pluginSection;
boolean visible = false;
......@@ -95,7 +124,7 @@ public class CupOverviewView extends FailableView
super(realParent);
Composite parent = getMain();
setupForm(parent, title);
this.editor = editor;
......@@ -103,9 +132,8 @@ public class CupOverviewView extends FailableView
Model.getInstanceForDocument(doc).registerModelObserver(this);
analysisSection = createTableSection("Analysis", "", false, 3);
analysisSection.getSecond().setRowLabel(ERROR_ROW, "Errors:");
analysisSection.getSecond().setRowLabel(ANALYSIS_ERROR_ROW, "Errors:");
createSection(SECTION_PARSE_TABLES,
SECTION_PARSE_TABLES_DESCRIPTION_TEMPLATE, false);
createSection(SECTION_CONTENT,
......@@ -114,6 +142,17 @@ public class CupOverviewView extends FailableView
SECTION_GRAMMAR_DESCRIPTION_TEMPLATE, false);
createSection(SECTION_CONFLICTS,
SECTION_CONFLICTS_DESCRIPTION_TEMPLATE, false);
pluginSection = createTableSection("Plugin Statistics", "", false, 8);
pluginSection.getSecond().setRowLabel(PLUGIN_STATS_PARSER_RUNS, "Parser runs:");
pluginSection.getSecond().setRowLabel(PLUGIN_STATS_PARSER_RUN_FAILURES, "Parser failures:");
pluginSection.getSecond().setRowLabel(PLUGIN_STATS_PARSER_RUN_NANOS, "Last parser time (ms):");
pluginSection.getSecond().setRowLabel(PLUGIN_STATS_PARSER_RUN_LAST, "Last parser run:");
pluginSection.getSecond().setRowLabel(PLUGIN_STATS_LALR_RUNS, "Table runs:");
pluginSection.getSecond().setRowLabel(PLUGIN_STATS_LALR_RUN_FAILURES, "Table failures:");
pluginSection.getSecond().setRowLabel(PLUGIN_STATS_LALR_RUN_NANOS, "Last table time (ms):");
pluginSection.getSecond().setRowLabel(PLUGIN_STATS_LALR_RUN_LAST, "Last table run:");
}
private Pair<Composite,SimpleTable> createTableSection(String title, String description, boolean doSpan, int rowCount) {
......@@ -190,6 +229,7 @@ public class CupOverviewView extends FailableView
public void willBecomeVisible() {
System.out.println("CupOverviewView will become visible.");
updateStatistics();
visible = true;
}
......@@ -209,18 +249,48 @@ public class CupOverviewView extends FailableView
// do nothing
}
*/
private void updateStatistics(Statistics statistics) {
if (statistics == null)
return;
analysisSection.getSecond().setRowValue(ERROR_ROW, statistics.getErrorCount());
private void updateStatistics() {
if (this.stats != null) {
SimpleTable tbl = analysisSection.getSecond();
tbl.setRowValue(ANALYSIS_ERROR_ROW, stats.getErrorCount());
this.stats = null;
analysisSection.getFirst().layout();
}
if (this.controllerStats != null) {
SimpleTable tbl = pluginSection.getSecond();
tbl.setRowValue(PLUGIN_STATS_PARSER_RUNS, controllerStats.getParserRuns());
tbl.setRowValue(PLUGIN_STATS_PARSER_RUN_FAILURES, controllerStats.getParserRunFailures());
tbl.setRowValue(PLUGIN_STATS_PARSER_RUN_NANOS, controllerStats.getLastParserRunNanos()/1000000.0);
Date parserDate = controllerStats.getLastParserRunDate();
if (parserDate != null)
tbl.setRowValue(PLUGIN_STATS_PARSER_RUN_LAST, parserDate);
else
tbl.setRowValue(PLUGIN_STATS_PARSER_RUN_LAST, "-");
tbl.setRowValue(PLUGIN_STATS_LALR_RUNS, controllerStats.getLalrRuns());
tbl.setRowValue(PLUGIN_STATS_LALR_RUN_FAILURES, controllerStats.getLalrRunFailures());
tbl.setRowValue(PLUGIN_STATS_LALR_RUN_NANOS, controllerStats.getLastLALRRunNanos()/1000000.0);
Date lalrDate = controllerStats.getLastLALRRunDate();
if (lalrDate != null)
tbl.setRowValue(PLUGIN_STATS_LALR_RUN_LAST, controllerStats.getLastLALRRunDate());
else
tbl.setRowValue(PLUGIN_STATS_LALR_RUN_LAST, "-");
pluginSection.getFirst().layout();
}
}
@Override
public void modelChanged(Model model) {
if (model == null)
return;
updateStatistics(model.getStatistics());
this.stats = model.getStatistics();
this.controllerStats = model.getControllerStatistics();
if (visible)
updateStatistics();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment