Skip to content

Commit

Permalink
Created profiling output parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Jul 20, 2011
1 parent e57789b commit cd7f27f
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 1 deletion.
8 changes: 7 additions & 1 deletion net.sf.eclipsefp.haskell.profiler/.project
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<?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>
Expand All @@ -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>
Original file line number Diff line number Diff line change
@@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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.