Skip to content

Commit

Permalink
Merge pull request #108 from jialinsun/0.3.3.0
Browse files Browse the repository at this point in the history
Fix issue #20
  • Loading branch information
ywang19 committed Aug 26, 2013
2 parents c4f7520 + 8a99a2f commit 84af2c6
Show file tree
Hide file tree
Showing 29 changed files with 252 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<field name="config" type="string">
<bind-xml name="config" node="attribute" />
</field>

<field name="id" type="string">
<bind-xml name="id" node="attribute" />
</field>

</class>

Expand Down
11 changes: 11 additions & 0 deletions dev/cosbench-config/src/com/intel/cosbench/config/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class Operation {
private int ratio = 100;
private String division;
private String config;
private String id = "none"; /* will be inited in workloadProcessor.initStageOpId() */

public Operation() {
/* empty */
Expand Down Expand Up @@ -80,6 +81,16 @@ public void setConfig(String config) {
/* configuration might be empty */
this.config = config;
}


public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}


public void validate() {
setType(getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<field name="config" type="string">
<bind-xml name="config" node="attribute" />
</field>

<field name="id" type="string">
<bind-xml name="id" node="attribute" />
</field>

</class>

Expand Down
2 changes: 1 addition & 1 deletion dev/cosbench-controller-web/WEB-INF/freemarker/metrics.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</tr>
<#list allMetrics as mInfo>
<tr>
<td>${mInfo.opType}<#if mInfo.opType != mInfo.sampleType>-${mInfo.sampleType}</#if></td>
<td>${mInfo.opName}<#if mInfo.opName != mInfo.sampleType>-${mInfo.sampleType}</#if></td>
<td>
<#assign op = mInfo.sampleCount >
<#if (op >= 1000) >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,21 @@ private void createStages() {
}

private static StageContext createStageContext(String id, Stage stage) {
initStageOpId(stage);
StageContext context = new StageContext();
context.setId(id);
context.setStage(stage);
context.setState(StageState.WAITING);
return context;
}

private static void initStageOpId(Stage stage) {
int index = 0;
for (Work work : stage.getWorks()) {
for (Operation op : work.getOperations())
op.setId("op" + String.valueOf(++index));
}
}

private void createExecutor() {
executor = Executors.newFixedThreadPool(2);
Expand Down
31 changes: 26 additions & 5 deletions dev/cosbench-core/src/com/intel/cosbench/bench/Mark.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class Mark implements Cloneable, Item {

private String opType; /* operation type */
private String sampleType; /* sample type */
private String opName; /* operation name */
private String opId; /* operation id */

private int opCount; /* number of successful operations */
private int sampleCount; /* number of successful samples */
Expand Down Expand Up @@ -61,6 +63,22 @@ public String getOpType() {
public void setOpType(String opType) {
this.opType = opType;
}

public void setOpName(String opName){
this.opName = opName;
}

public String getOpName(){
return opName;
}

public void setOpId(String opId) {
this.opId = opId;
}

public String getOpId() {
return opId;
}

public String getSampleType() {
return sampleType;
Expand Down Expand Up @@ -144,16 +162,19 @@ public void addOperation(Result result) {
totalOpCount += 1;
}

public static String getMarkType(String opType, String sampleType) {
return opType + "-" + sampleType;
}
public static String getMarkType(String opId, String opType,
String sampleType, String opName) {
return opId + "-" + opType + "-" + sampleType + "-" + opName;
}

public static Mark newMark(String type) {
String[] types = type.split("-");
Mark mark = new Mark();
mark.setName(type);
mark.setOpType(types[0]);
mark.setSampleType(types[1]);
mark.setOpId(types[0]);
mark.setOpType(types[1]);
mark.setSampleType(types[2]);
mark.setOpName(types[3]);
return mark;
}
}
32 changes: 27 additions & 5 deletions dev/cosbench-core/src/com/intel/cosbench/bench/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class Metrics implements Item, Cloneable {

private String opType; /* operation type */
private String sampleType; /* sample type */
private String opName; /* operation name*/
private String opId; /* operation id */

/* Status */

Expand Down Expand Up @@ -79,6 +81,22 @@ public String getSampleType() {
public void setSampleType(String sampleType) {
this.sampleType = sampleType;
}

public String getOpName(){
return opName;
}

public void setOpName(String opName){
this.opName = opName;
}

public String getOpId() {
return opId;
}

public void setOpId(String opId) {
this.opId = opId;
}

public int getSampleCount() {
return sampleCount;
Expand Down Expand Up @@ -153,16 +171,19 @@ public Metrics clone() {
return this;
}

public static String getMetricsType(String opType, String sampleType) {
return opType + "-" + sampleType;
public static String getMetricsType(String opId, String opType,
String sampleType, String opName) {
return opId + "-" + opType + "-" + sampleType + "-" + opName;
}

public static Metrics newMetrics(String type) {
String[] types = type.split("-");
Metrics metrics = new Metrics();
metrics.setName(type);
metrics.setOpType(types[0]);
metrics.setSampleType(types[1]);
metrics.setOpId(types[0]);
metrics.setOpType(types[1]);
metrics.setSampleType(types[2]);
metrics.setOpName(types[3]);
return metrics;
}

Expand All @@ -171,7 +192,8 @@ public static Metrics convert(Mark mark, long window) {
int tsps = mark.getTotalSampleCount();
long rtSum = mark.getRtSum();
long bytes = mark.getByteCount();
String type = getMetricsType(mark.getOpType(), mark.getSampleType());
String type = getMetricsType(mark.getOpId(), mark.getOpType(),
mark.getSampleType(), mark.getOpName());
Metrics metrics = newMetrics(type);
metrics.setSampleCount(sps);
metrics.setTotalSampleCount(tsps);
Expand Down
31 changes: 20 additions & 11 deletions dev/cosbench-core/src/com/intel/cosbench/bench/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ public class Result {
private boolean succ;
private String opType;
private String sampleType;

public Result(Date timestamp, String opType, boolean succ) {
this(timestamp, opType, opType, succ);
}

public Result(Date timestamp, String opType, String sampleType, boolean succ) {
this.timestamp = timestamp;
this.succ = succ;
this.opType = opType;
this.sampleType = sampleType;
}
private String opName;
private String opId;

public Result(Date timestamp, String opId, String opType,
String sampleType, String opName, boolean succ) {
this.timestamp = timestamp;
this.succ = succ;
this.opType = opType;
this.sampleType = sampleType;
this.opName = opName;
this.opId = opId;
}

public Date getTimestamp() {
return timestamp;
Expand Down Expand Up @@ -75,5 +76,13 @@ public String getSampleType() {
public void setSampleType(String sampleType) {
this.sampleType = sampleType;
}

public String getOpName(){
return opName;
}

public String getOpId() {
return opId;
}

}
36 changes: 25 additions & 11 deletions dev/cosbench-core/src/com/intel/cosbench/bench/Sample.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,44 @@ public class Sample {

private Date timestamp;

private String opName;
private boolean succ;
private String opType;
private String opId;
private String sampleType;

private long time; /* response time */
private long bytes; /* bytes transferred */

public Sample(Date timestamp, String opType, boolean succ) {
this(timestamp, opType, succ, 0L, 0L);
public Sample(Date timestamp, String opId, String opType,
String sampleType, String opName, boolean succ) {
this(timestamp, opId, opType, sampleType, opName, succ, 0L, 0L);
}

public Sample(Date timestamp, String opType, boolean succ, long time,
long bytes) {
this.timestamp = timestamp;
this.succ = succ;
this.time = time;
this.bytes = bytes;
this.opType = opType;
this.sampleType = opType;
}
public Sample(Date timestamp, String opId, String opType,
String sampleType, String opName, boolean succ, long time,
long bytes) {
this.timestamp = timestamp;
this.succ = succ;
this.time = time;
this.bytes = bytes;
this.opType = opType;
this.sampleType = sampleType;
this.opName = opName;
this.opId = opId;
}

public Date getTimestamp() {
return timestamp;
}

public String getOpName() {
return opName;
}

public String getOpId() {
return opId;
}

public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ protected void writeHeader(Writer writer) throws IOException {
}

private static void writeOpType(StringBuilder buffer, Metrics metrics) {
String opt = metrics.getOpType();
String opt = metrics.getOpName();
String spt = metrics.getSampleType();
if (spt.equals(opt))
buffer.append(opt);
else
buffer.append(opt + '-' + spt);
buffer.append(opt + '-' + spt);
buffer.append(',').append("(%)").append(',');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ protected void writeMetrics(Writer writer, StageInfo stage,
StringBuilder buffer = new StringBuilder();
String uuid = workload.getId() + '-' + stage.getId() + '-' + idx;
buffer.append(uuid).append(',');
String opt = metrics.getOpType();
String opt = metrics.getOpName();
String spt = metrics.getSampleType();
if (spt.equals(opt))
buffer.append(opt);
else
buffer.append(opt + '-' + spt);
buffer.append(opt + '-' + spt);
buffer.append(',');
buffer.append(metrics.getSampleCount()).append(',');
buffer.append(metrics.getByteCount()).append(',');
Expand Down Expand Up @@ -113,7 +113,7 @@ private static void writeConfigInfo(StringBuilder buffer, StageInfo stage,
Metrics metrics) throws IOException {
for (Work work : stage.getStage())
for (Operation op : work) {
if (op.getType().equals(metrics.getOpType())) {
if (op.getId().equals(metrics.getOpId())) {
buffer.append(op.getRatio()).append('%').append(' ');
String config = op.getConfig();
config = config.replaceAll(",", "-").replaceAll(";", " ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.*;
import java.util.Arrays;

import org.apache.commons.lang.StringUtils;

import com.intel.cosbench.bench.*;

/**
Expand Down Expand Up @@ -53,8 +55,13 @@ protected void writeHeader(Writer writer) throws IOException {
for (int i = 0; i < 6; i++)
// 6 metrics
for (Metrics metrics : snapshots[0].getReport())
buffer.append(metrics.getSampleType()).append(',');
buffer.append("Min-Version").append(',');
buffer.append(
StringUtils.join(new Object[] {
(metrics.getOpName().equals(
metrics.getSampleType()) ? null
: metrics.getOpName() + "-"),
metrics.getSampleType() })).append(',');
buffer.append("Min-Version").append(',');
buffer.append("Version").append(',');
buffer.append("Max-Version").append('\n');
writer.write(buffer.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected void writeHeader(Writer writer) throws IOException {
protected void writeMetrics(Writer writer, Metrics metrics)
throws IOException {
StringBuilder buffer = new StringBuilder();
String opt = metrics.getOpType();
String opt = metrics.getOpName();
String spt = metrics.getSampleType();
if (spt.equals(opt))
buffer.append(opt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static interface Item {

}

private Map<String, T> registry;
protected Map<String, T> registry;

public MapRegistry() {
Map<String, T> registry = new LinkedHashMap<String, T>();
Expand Down
2 changes: 1 addition & 1 deletion dev/cosbench-driver-web/WEB-INF/freemarker/metrics.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</tr>
<#list allMetrics as mInfo>
<tr>
<td>${mInfo.opType}<#if mInfo.opType != mInfo.sampleType>-${mInfo.sampleType}</#if></td>
<td>${mInfo.opName}<#if mInfo.opName != mInfo.sampleType>-${mInfo.sampleType}</#if></td>
<td>
<#assign op = mInfo.sampleCount >
<#if (op >= 1000) >
Expand Down
Loading

0 comments on commit 84af2c6

Please sign in to comment.