jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1179651 - in /incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf: PerfMain.scala PerfUnit.scala PerfUnitLib.scala
Date Thu, 06 Oct 2011 14:42:42 GMT
Author: andy
Date: Thu Oct  6 14:42:41 2011
New Revision: 1179651

URL: http://svn.apache.org/viewvc?rev=1179651&view=rev
Log: (empty)

Modified:
    incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfMain.scala
    incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnit.scala
    incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnitLib.scala

Modified: incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfMain.scala
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfMain.scala?rev=1179651&r1=1179650&r2=1179651&view=diff
==============================================================================
--- incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfMain.scala
(original)
+++ incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfMain.scala
Thu Oct  6 14:42:41 2011
@@ -33,8 +33,8 @@ object PerfMain {
 
     val reporter = new ReporterPrint()
     
-    if ( false )
-        enact(new ActionProcessorPrint(), manifest.build)
+    if ( true )
+      enact(new ActionProcessorPrint(), manifest)
     
     //val procMon = new ActionProcessorMonitor(proc)
 
@@ -53,10 +53,16 @@ object PerfMain {
   
 
   // --- Performing
-  def enact(proc:ActionProcessor, action:Action): Unit = {
-    val executor = new ActionExecutor(proc)
-    executor.exec(action)
+  def enact(proc:ActionVisitor, manifest:ActionBuilderManifest): Unit = {
+    println("-- Warmup")
+    enact(proc, manifest.actionWarmUp)
+    println("-- Main run")
+    enact(proc, manifest.actionTimedRun)
   }
+  
+  
+  def enact(proc:ActionVisitor, action:Action): Unit = action.visit(proc)
+
   // ---- Reporting
   def report(reporter: Reporter, collector: Collector): Unit = reporter.report(collector)
   

Modified: incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnit.scala
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnit.scala?rev=1179651&r1=1179650&r2=1179651&view=diff
==============================================================================
--- incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnit.scala
(original)
+++ incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnit.scala
Thu Oct  6 14:42:41 2011
@@ -2,6 +2,8 @@ package org.apache.jena.perf
 import java.util.Date
 import java.util.concurrent.atomic.AtomicInteger
 
+/** Define the abstractions that go to make up this performance framework */
+
 class PerfUnit {
 
 }
@@ -9,7 +11,17 @@ class PerfUnit {
 //---- Actions
 
 sealed abstract class Action {
-    val name:String
+  val name: String
+  def visit(visitor: ActionVisitor) = {
+    visitor.beginVisit(this)
+    this match {
+      case a1: ActionStep =>
+        visitor.visit(a1)
+      case a2: ActionN =>
+        visitor.visit(a2)
+    }
+    visitor.endVisit(this)
+  }
 }
 
 class ActionN(val actions:Seq[Action]) extends Action {
@@ -22,24 +34,11 @@ abstract class ActionStep extends Action
   def enact(): Outcome
 }
 
-trait ActionProcessor {
-  def startAction(action:Action) : Unit = {}
-  def exec(action:ActionStep) : Unit
-  def exec(action:ActionN) : Unit = { }
-  def finishAction(action:Action) : Unit = {}
-}
-
-class ActionExecutor(runner:ActionProcessor) {
-  def exec(action:Action):Unit = {
-    runner.startAction(action)
-    action match {
-      case a:ActionStep => 
-        runner.exec(a)
-      case actions:ActionN =>
-        actions.actions.foreach(a => exec(a))
-    }
-    runner.finishAction(action)
-  }
+trait ActionVisitor {
+  def beginVisit(action:Action) : Unit = { }
+  def visit(action:ActionStep) : Unit
+  def visit(action:ActionN) : Unit     = action.actions.foreach( _.visit(this) )  
+  def endVisit(action:Action) : Unit   = { }
 }
 
 // ---- Reporter

Modified: incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnitLib.scala
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnitLib.scala?rev=1179651&r1=1179650&r2=1179651&view=diff
==============================================================================
--- incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnitLib.scala
(original)
+++ incubator/jena/Experimental/JenaPerf/trunk/src/main/scala/org/apache/jena/perf/PerfUnitLib.scala
Thu Oct  6 14:42:41 2011
@@ -40,16 +40,17 @@ class Collector {
   }
 }
 
-// ---- Action Processors
+// ---- Action Visitors
 
-class ActionProcessorEnact extends ActionProcessor {
-  def exec(action:ActionStep) : Unit = action.enact()
+object ActionExecutor extends ActionVisitor {
+  def visit(action:ActionStep) : Unit  = action.enact()
+  //def visit(action:ActionN) : Unit     = action.actions.foreach( _.visit(this) )
 }
 
-class ActionProcessorCollector(collector:Collector, monitor:ResultMonitor) extends ActionProcessor
{
+class ActionProcessorCollector(collector:Collector, monitor:ResultMonitor) extends ActionVisitor
{
   val counter = new AtomicInteger(0)
 
-  def exec(action:ActionStep) : Unit = {
+  def visit(action:ActionStep) : Unit  = {
     val id = counter.incrementAndGet()
     val start = System.currentTimeMillis()
     
@@ -69,24 +70,28 @@ object actionMonitorPrint extends Result
 }
 
 
-class ActionProcessorPrint extends ActionProcessor {
-  def exec(action:ActionStep) : Unit = println(action)
-}
-
-class ActionProcessorPrintAnd(proc:ActionProcessor) extends ActionProcessor {
-  def exec(action:ActionStep) : Unit = { println(action) ; proc.exec(action) ; }
+class ActionProcessorPrint extends ActionVisitor {
+  var indent = ""
+  override def visit(action:ActionN)    : Unit = {
+    val indent0 = indent ;
+    indent = indent + "  "
+    action.actions.foreach( _.visit(this) )
+    indent = indent0
+  }
+    
+  override def visit(action:ActionStep) : Unit = { print(indent) ; println(action) }
 }
 
-class ActionProcessorWrapper(proc:ActionProcessor) extends ActionProcessor {
-  override def startAction(action:Action) : Unit    = { proc.startAction(action) }
-  override def exec(action:ActionStep) : Unit       = { proc.exec(action) }
-  override def exec(action:ActionN) : Unit          = { proc.exec(action) }
-  override def finishAction(action:Action) : Unit   = { proc.finishAction(action) }
+class ActionVisitorWrapper(proc:ActionVisitor) extends ActionVisitor {
+  override def beginVisit(action:Action) : Unit     = { proc.beginVisit(action) }
+  override def visit(action:ActionStep) : Unit      = { proc.visit(action) }
+  override def visit(action:ActionN) : Unit         = { proc.visit(action) }
+  override def endVisit(action:Action) : Unit       = { proc.endVisit(action) }
 }
 
-class ActionProcessorMonitor(proc:ActionProcessor) extends ActionProcessorWrapper(proc) {
-  override def startAction(action:Action) : Unit    = { println("> "+action.name) ; super.startAction(action)
}
-  override def finishAction(action:Action) : Unit   = { super.finishAction(action) ; println("<
"+action.name) ; }
+class ActionProcessorMonitor(proc:ActionVisitor) extends ActionVisitorWrapper(proc) {
+  override def beginVisit(action:Action) : Unit = { println("> "+action.name) ; super.beginVisit(action)
}
+  override def endVisit(action:Action) : Unit   = { super.endVisit(action) ; println("<
"+action.name) ; }
 }
 
 // ---- Results



Mime
View raw message