Browse files

Created profiling output parser.

  • Loading branch information...
1 parent e57789b commit cd7f27fe12fc4a962aac80215c69a4298e9b6b52 @serras serras committed Jul 20, 2011
View
8 net.sf.eclipsefp.haskell.profiler/.project
@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>net.sf.eclipsefp.haskell.profiler</name>
- <comment></comment>
+ <comment>JavaCC Nature</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
+ <name>sf.eclipse.javacc.javaccbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
@@ -24,5 +29,6 @@
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>sf.eclipse.javacc.javaccnature</nature>
</natures>
</projectDescription>
View
110 ...l.profiler/src/net/sf/eclipsefp/haskell/profiler/internal/parser/ProfilingOutputParser.jj
@@ -0,0 +1,110 @@
+/**
+ * JavaCC template file created by SF JavaCC plugin 1.5.17+ wizard for JavaCC 1.5.0+
+ */ options { JDK_VERSION = "1.5";
+ FORCE_LA_CHECK = true; static = false; } PARSER_BEGIN(ProfilingOutputParser) package net.sf.eclipsefp.haskell.profiler.internal.parser;
+
+import net.sf.eclipsefp.haskell.profiler.model.*;
+
+public class ProfilingOutputParser { } PARSER_END(ProfilingOutputParser) SKIP : { " " | "\r" | "\t" | "\n" }
+
+TOKEN :
+{ < JOB : "JOB" >
+| < DATE : "DATE" >
+| < SAMPLE_UNIT : "SAMPLE_UNIT" >
+| < VALUE_UNIT : "VALUE_UNIT" >
+| < BEGIN_SAMPLE : "BEGIN_SAMPLE" >
+| < END_SAMPLE : "END_SAMPLE" >
+}
+
+TOKEN :
+{
+ < #DIGIT : [ "0"-"9" ] >
+| < FLOAT : (< DIGIT >)+ "." (< DIGIT >)+ >
+| < INTEGER : (< DIGIT >)+ > | < IDENTIFIER : (~[" ", "\n", "\r", "\""])+ >
+| < QUOTEDSTRING : "\"" (~["\"", "\n", "\r"])* "\"" >
+}
+
+Job job() :
+{ String name;
+ String date;
+ String sampleUnit;
+ String valueUnit;
+ Job j;
+ Sample s;
+}
+{ < JOB >
+ name = quotedString()
+ < DATE >
+ date = quotedString()
+ < SAMPLE_UNIT >
+ sampleUnit = quotedString()
+ < VALUE_UNIT >
+ valueUnit = quotedString()
+ { j = new Job(name, date, sampleUnit, valueUnit);
+ }
+ ( s = sample()
+ { j.addSample(s);
+ }
+ )+
+ { return j;
+ }
+}
+
+Sample sample() :
+{ float time;
+ Sample s;
+ String ident;
+ long value;
+}
+{ < BEGIN_SAMPLE >
+ time = floatNumber()
+ { s = new Sample(time);
+ }
+ ( ident = identifier()
+ value = integerNumber()
+ {
+ s.addEntry(ident, value); }
+ )*
+ < END_SAMPLE >
+ floatNumber()
+ { return s;
+ }
+}
+
+float floatNumber() :
+{ Token string;
+}
+{ string = < FLOAT >
+ { return Float.valueOf(string.image);
+ }
+}
+
+long integerNumber() :
+{
+ Token string;
+}
+{
+ string = < INTEGER >
+ {
+ return Long.valueOf(string.image);
+ }
+}
+
+String identifier() :
+{
+ Token string;
+}
+{
+ string = < IDENTIFIER >
+ {
+ return string.image;
+ }
+}
+
+String quotedString() :
+{ Token string;
+}
+{ string = < QUOTEDSTRING >
+ { return string.image.substring(1, string.image.length() - 1);
+ }
+}
View
65 net.sf.eclipsefp.haskell.profiler/src/net/sf/eclipsefp/haskell/profiler/model/Job.java
@@ -0,0 +1,65 @@
+package net.sf.eclipsefp.haskell.profiler.model;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import net.sf.eclipsefp.haskell.profiler.internal.parser.ParseException;
+import net.sf.eclipsefp.haskell.profiler.internal.parser.ProfilingOutputParser;
+
+public class Job {
+ String name;
+ String date;
+ String sampleUnit;
+ String valueUnit;
+ LinkedHashMap<Float, Sample> samples;
+
+ public Job(String name, String date, String sampleUnit, String valueUnit) {
+ this.name = name;
+ this.date = date;
+ this.sampleUnit = sampleUnit;
+ this.valueUnit = valueUnit;
+ this.samples = new LinkedHashMap<Float, Sample>();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDate() {
+ return date;
+ }
+
+ public String getSampleUnit() {
+ return sampleUnit;
+ }
+
+ public String getValueUnit() {
+ return valueUnit;
+ }
+
+ public Set<Map.Entry<Float, Sample>> getSamplesAndTimes() {
+ return samples.entrySet();
+ }
+
+ public Collection<Sample> getSamples() {
+ return samples.values();
+ }
+
+ public void addSample(Sample sample) {
+ samples.put(sample.getTime(), sample);
+ }
+
+ public static Job parse(InputStream stream) throws ParseException {
+ ProfilingOutputParser parser = new ProfilingOutputParser(stream);
+ return parser.job();
+ }
+
+ public static Job parse(Reader stream) throws ParseException {
+ ProfilingOutputParser parser = new ProfilingOutputParser(stream);
+ return parser.job();
+ }
+}
View
27 net.sf.eclipsefp.haskell.profiler/src/net/sf/eclipsefp/haskell/profiler/model/Sample.java
@@ -0,0 +1,27 @@
+package net.sf.eclipsefp.haskell.profiler.model;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class Sample {
+ float time;
+ LinkedHashMap<String, Long> entries;
+
+ public Sample(float time) {
+ this.time = time;
+ this.entries = new LinkedHashMap<String, Long>();
+ }
+
+ public float getTime() {
+ return time;
+ }
+
+ public void addEntry(String name, long value) {
+ entries.put(name, value);
+ }
+
+ public Set<Map.Entry<String, Long>> getEntries() {
+ return entries.entrySet();
+ }
+}

0 comments on commit cd7f27f

Please sign in to comment.