FileDocCategorySizeDatePackage
PerfTask.javaAPI DocApache Lucene 2.2.06763Sat Jun 16 22:20:58 BST 2007org.apache.lucene.benchmark.byTask.tasks

PerfTask

public abstract class PerfTask extends Object implements Cloneable
A (abstract) task to be tested for performance.
Every performance task extends this class, and provides its own doLogic() method, which performss the actual task.
Tasks performing some work that should be measured for the task, can overide setup() and/or tearDown() and placed that work there.
Relevant properties: task.max.depth.log.

Fields Summary
private org.apache.lucene.benchmark.byTask.PerfRunData
runData
private String
name
private int
depth
private int
maxDepthLogStart
protected String
params
protected static final String
NEW_LINE
Constructors Summary
private PerfTask()
Should not be used externally


          
    
    name =  Format.simpleName(getClass());
    if (name.endsWith("Task")) {
      name = name.substring(0,name.length()-4);
    }
  
public PerfTask(org.apache.lucene.benchmark.byTask.PerfRunData runData)

    this();
    this.runData = runData;
    this.maxDepthLogStart = runData.getConfig().get("task.max.depth.log",0);
  
Methods Summary
protected java.lang.Objectclone()

    // tasks having non primitive data structures should overide this.
    // otherwise parallel running of a task sequence might not run crrectly. 
    return super.clone();
  
public abstract intdoLogic()
Perform the task once (ignoring repetions specification) Return number of work items done by this task. For indexing that can be number of docs added. For warming that can be number of scanned items, etc.

return
number of work items done by this task.

public intgetDepth()

return
Returns the depth.

    return depth;
  
intgetMaxDepthLogStart()

return
Returns the maxDepthLogStart.

    return maxDepthLogStart;
  
public java.lang.StringgetName()

return
Returns the name.

    if (params==null) {
      return name;
    } 
    return new StringBuffer(name).append('(").append(params).append(')").toString();
  
java.lang.StringgetPadding()

    char c[] = new char[4*getDepth()];
    for (int i = 0; i < c.length; i++) c[i] = ' ";
    return new String(c);
  
public java.lang.StringgetParams()

return
Returns the Params.

    return params;
  
public org.apache.lucene.benchmark.byTask.PerfRunDatagetRunData()

return
Returns the run data.

    return runData;
  
public final intrunAndMaybeStats(boolean reportStats)
Run the task, record statistics.

return
number of work items done by this task.

    if (reportStats && depth <= maxDepthLogStart && !shouldNeverLogAtStart()) {
      System.out.println("------------> starting task: " + getName());
    }
    if (shouldNotRecordStats() || !reportStats) {
      setup();
      int count = doLogic();
      tearDown();
      return count;
    }
    setup();
    Points pnts = runData.getPoints();
    TaskStats ts = pnts.markTaskStart(this,runData.getConfig().getRoundNumber());
    int count = doLogic();
    pnts.markTaskEnd(ts, count);
    tearDown();
    return count;
  
public voidsetDepth(int depth)

param
depth The depth to set.

    this.depth = depth;
  
protected voidsetName(java.lang.String name)

param
name The name to set.

    this.name = name;
  
public voidsetParams(java.lang.String params)
Set the params of this task.

exception
UnsupportedOperationException for tasks supporting command line parameters.

    if (!supportsParams()) {
      throw new UnsupportedOperationException(getName()+" does not support command line parameters.");
    }
    this.params = params;
  
public voidsetup()
Task setup work that should not be measured for that specific task. By default it does nothing, but tasks can implement this, moving work from doLogic() to this method. Only the work done in doLogicis measured for this task. Notice that higher level (sequence) tasks containing this task would then measure larger time than the sum of their contained tasks.

throws
Exception

  
protected booleanshouldNeverLogAtStart()
Tasks that should never log at start can overide this.

return
true if this task should never log when it start.

    return false;
  
protected booleanshouldNotRecordStats()
Tasks that should not record statistics can overide this.

return
true if this task should never record its statistics.

    return false;
  
public booleansupportsParams()
Sub classes that supports parameters must overide this method to return true.

return
true iff this task supports command line params.

    return false;
  
public voidtearDown()
Task tearDown work that should not be measured for that specific task. By default it does nothing, but tasks can implement this, moving work from doLogic() to this method. Only the work done in doLogicis measured for this task. Notice that higher level (sequence) tasks containing this task would then measure larger time than the sum of their contained tasks.

  
public java.lang.StringtoString()

    String padd = getPadding();
    StringBuffer sb = new StringBuffer(padd);
    sb.append(getName());
    return sb.toString();