Skip to content

Commit

Permalink
Fixes for ISSUE-66: All run.xml should override cycletime/thinktime i…
Browse files Browse the repository at this point in the history
…n benchmark
  • Loading branch information
shanti committed May 8, 2014
1 parent d043ac6 commit 5099095
Show file tree
Hide file tree
Showing 14 changed files with 319 additions and 40 deletions.
2 changes: 2 additions & 0 deletions common/src/com/sun/faban/common/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
*/
public class Utilities {

public static final long TO_NANOS = 1000000L;

/** The file separator on the master. */
public static String masterFileSeparator;

Expand Down
2 changes: 1 addition & 1 deletion driver/build-defaults.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ compiler.debug=on
compiler.generate.no.warnings=off
compiler.args=
compiler.max.memory=128m
compiler.source.version=1.5
compiler.source.version=1.6
junit.jar=/opt/netbeans-6.5/platform9/modules/ext/junit-4.5.jar
2 changes: 1 addition & 1 deletion driver/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

<path id="class.path">
<fileset dir="lib" includes="*.jar"/>
<fileset dir="${env.JDK_HOME}/lib" includes="tools.jar"/>
<!--fileset dir="${env.JDK_HOME}/lib" includes="tools.jar"/-->
</path>

<path id="test.class.path">
Expand Down
6 changes: 3 additions & 3 deletions driver/src/com/sun/faban/driver/engine/AgentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private void doPreRun() {
preRunLatch = null;

earliestStartTime = System.nanoTime() +
runInfo.msBetweenThreadStart * 1000000L;
runInfo.msBetweenThreadStart * Utilities.TO_NANOS;
}
if (runAborted) {
logger.warning(displayName +
Expand All @@ -287,7 +287,7 @@ public void run() {
timer.idleTimerCheck(displayName);

// Create the required number of threads
long nsBetweenThreadStart = runInfo.msBetweenThreadStart * 1000000L;
long nsBetweenThreadStart = runInfo.msBetweenThreadStart * Utilities.TO_NANOS;
try {
// We use System.nanoTime() here directly
// instead of timer.getTime().
Expand Down Expand Up @@ -734,7 +734,7 @@ public void run() {
logger.warning("Null RuntimeStats");
try {
rtm.timestamp = (int) ((System.nanoTime() - startTime) /
1000000l);
Utilities.TO_NANOS);
rtm.sequence = sequence;
master.updateMetrics(rtm);
} catch (RemoteException e) {
Expand Down
57 changes: 55 additions & 2 deletions driver/src/com/sun/faban/driver/engine/Cycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,35 @@
*/
package com.sun.faban.driver.engine;

import com.sun.faban.driver.ConfigurationException;
import com.sun.faban.driver.CycleType;
import com.sun.faban.driver.DefinitionException;
import com.sun.faban.driver.util.Random;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.logging.Logger;

/**
* Super class of all distributions.
*/
public abstract class Cycle implements Serializable, Cloneable {

CycleType cycleType;
CycleType cycleType = CycleType.CYCLETIME;
double cycleDeviation;

protected transient Logger logger;

public Cycle() {
logger = Logger.getLogger(this.getClass().getName());
}

protected Logger getLogger() {
return logger;
}

/**
* Makes a deep copy of this cycle object.
Expand Down Expand Up @@ -149,4 +163,43 @@ static void setCycles(BenchmarkDefinition.Operation[] operations,
* @return The max reasonable delay to be presented in the output histogram.
*/
public abstract double getHistogramMax();
}

public final void configure(Element e) throws ConfigurationException {
NodeList nl = e.getElementsByTagNameNS(
RunInfo.DRIVERURI, "cycleType");
if (nl.getLength() > 1) {
String msg = "Bad cycleType definition; must have only one per cycle Time";
getLogger().severe(msg);
ConfigurationException ce = new ConfigurationException(msg);
getLogger().throwing(getClass().getName(), "configure", ce);
throw ce;
}
if (nl.getLength() == 1) {
String s = nl.item(0).getFirstChild().getNodeValue();
if ("CYCLETIME".equals(s)) {
cycleType = CycleType.CYCLETIME;
} else if ("THINKTIME".equals(s)) {
cycleType = CycleType.THINKTIME;
}
else getLogger().warning("Ignoring unknown cycletype " + s);
}
nl = e.getElementsByTagNameNS(
RunInfo.DRIVERURI, "cycleDeviation");
if (nl.getLength() > 1) {
String msg = "Bad cycleDeviation definition; must have only one per cycle Time";
getLogger().severe(msg);
ConfigurationException ce = new ConfigurationException(msg);
getLogger().throwing(getClass().getName(), "configure", ce);
throw ce;
}
if (nl.getLength() == 1) {
cycleDeviation = Double.parseDouble(nl.item(0).getFirstChild().getNodeValue());
}
configureSubclass(e);
}

protected void configureSubclass(Element e) throws ConfigurationException {
throw new UnsupportedOperationException(this.getClass().getName() +
" does not support overriding configuration information");
}
}
3 changes: 2 additions & 1 deletion driver/src/com/sun/faban/driver/engine/DriverContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.sun.faban.driver.engine;

import com.sun.faban.common.FabanNamespaceContext;
import com.sun.faban.common.Utilities;
import com.sun.faban.driver.CustomMetrics;
import com.sun.faban.driver.CustomTableMetrics;
import com.sun.faban.driver.Timing;
Expand Down Expand Up @@ -503,7 +504,7 @@ public void wakeupAt(long time) {
* @return The relative time steady state starts
*/
public int getSteadyStateStart() {
return (int) (timer.toRelTime(agentThread.endRampUp) / 1000000l);
return (int) (timer.toRelTime(agentThread.endRampUp) / Utilities.TO_NANOS);
}

/**
Expand Down
33 changes: 31 additions & 2 deletions driver/src/com/sun/faban/driver/engine/FixedTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
*/
package com.sun.faban.driver.engine;

import com.sun.faban.common.Utilities;
import com.sun.faban.driver.ConfigurationException;
import com.sun.faban.driver.util.Random;
import com.sun.faban.driver.DefinitionException;
import com.sun.faban.driver.CycleType;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.lang.annotation.Annotation;
import java.io.IOException;

Expand All @@ -38,7 +44,7 @@ public class FixedTime extends Cycle {

private static final long serialVersionUID = 1L;

long cycleTime;
long cycleTime = 1000 * Utilities.TO_NANOS;

/**
* Initializes this cycle according to the annotation.
Expand All @@ -50,7 +56,7 @@ public void init(Annotation a) throws DefinitionException {
(com.sun.faban.driver.FixedTime) a;
cycleType = cycleDef.cycleType();
cycleDeviation = cycleDef.cycleDeviation();
cycleTime = cycleDef.cycleTime() * 1000000l;
cycleTime = cycleDef.cycleTime() * Utilities.TO_NANOS;

// Now check parameters for validity.
if (cycleTime == 0 && cycleType == CycleType.CYCLETIME) {
Expand Down Expand Up @@ -94,4 +100,27 @@ private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
}

/**
* Configure the cycle based on an XML fragment from the configuration
* file. The format of the fragment is:
*
* <pre>
* <cycleTime>min</cycleTime>
* </pre>
*/
protected void configureSubclass(Element e) throws ConfigurationException {
NodeList nl = e.getElementsByTagNameNS(
RunInfo.DRIVERURI, "cycleTime");
if (nl.getLength() > 1) {
String msg = "Bad cycleTime definition; must have only one per cycleTime";
getLogger().severe(msg);
ConfigurationException ce = new ConfigurationException(msg);
getLogger().throwing(getClass().getName(), "configure", ce);
throw ce;
}
if (nl.getLength() == 1) {
cycleTime = Long.parseLong(nl.item(0).getFirstChild().getNodeValue()) * Utilities.TO_NANOS;
}
}
}
1 change: 0 additions & 1 deletion driver/src/com/sun/faban/driver/engine/FlatMix.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public Object clone() {
*/
public void configure(Element driverConfigNode)
throws ConfigurationException {

/* The format is as follows:
<operationMix>
<name>operationF</name><r>40</r>
Expand Down
2 changes: 1 addition & 1 deletion driver/src/com/sun/faban/driver/engine/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ public void recordDelayTime() {
* further processing.
*/
public void wrap() {
endTime = (endTimeNanos - thread.agent.startTime) / 1000000l;
endTime = (endTimeNanos - thread.agent.startTime) / Utilities.TO_NANOS;
}

/**
Expand Down
82 changes: 82 additions & 0 deletions driver/src/com/sun/faban/driver/engine/Mix.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
import com.sun.faban.driver.ConfigurationException;
import com.sun.faban.driver.DefinitionException;
import com.sun.faban.driver.util.Random;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import java.io.Serializable;
import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -239,4 +241,84 @@ public abstract static class Selector {
*/
public abstract void reset();
}


/**
* Allows the cycle times for each operation in the mix to be overridden
* by the configuration file. It is assumed that the cycle times for the
* operations have already been initialized (from the annotations, when
* the init method was called).
*
* Ideally this could be part of the configure() method, but the
* implementation here is common to all Mix classes, while the configure
* method is specific to each Mix.
*
* The format is as follows:
* <pre>
* <cycleTime>
* <classname>fully-qualified class name</classname>
* <values>
* ... xml fields to set specific value for mix ...
* </values>
* <name>operation name</name>
* ... can have 0 or more names ...
* ... if no name is specified, apply to all operations ...
* </cycleTime>
* .. can have 0 or more cycle times ...
* </pre>
*/
public void configureCycles(Element driverConfigNode) throws ConfigurationException {
NodeList cycleTimes = driverConfigNode.getElementsByTagNameNS(
RunInfo.DRIVERURI,
"cycleTime");
int nCycles = cycleTimes.getLength();
for (int i = 0; i < nCycles; i++) {
Element cycleTime = (Element) cycleTimes.item(i);
NodeList nl = cycleTime.getElementsByTagNameNS(
RunInfo.DRIVERURI, "classname");
if (nl.getLength() != 1) {
String msg = "Badly configured cycle time; you must have one and only one classname";
getLogger().severe(msg);
ConfigurationException ce = new ConfigurationException(msg);
getLogger().throwing(className, "configure", ce);
throw ce;
}
Cycle cycle;
try {
String className = nl.item(0).getFirstChild().getNodeValue();
Class clazz = Class.forName(className);
cycle = (Cycle) clazz.newInstance();
cycle.configure(cycleTime);
} catch (Exception e) {
String msg = "Can't create cycle";
getLogger().severe(msg);
ConfigurationException ce = new ConfigurationException(msg, e);
getLogger().throwing(className, "configure", ce);
throw ce;
}
NodeList names = cycleTime.getElementsByTagNameNS(
RunInfo.DRIVERURI, "name");
int nNames = names.getLength();
if (nNames == 0) {
// Apply to all operations
for (int curOp = 0; curOp < operations.length; curOp++) {
operations[curOp].cycle = cycle;
}
}
else for (int curName = 0; curName < nNames; curName++) {
String name = names.item(curName).getFirstChild().getNodeValue();
boolean found = false;
for (int curOp = 0; curOp < operations.length; curOp++) {
if (operations[curOp].name.equals(name)) {
found = true;
operations[curOp].cycle = cycle;
break;
}
}
if (!found) {
getLogger().warning("No benchmark operation found for " + name);
}
}
}
}
}
Loading

0 comments on commit 5099095

Please sign in to comment.