org.activiti.engine.test.profiler.CommandStats Maven / Gradle / Ivy
The newest version!
package org.activiti.engine.test.profiler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*/
public class CommandStats {
protected long getTotalCommandTime = 0L;
protected List commandExecutionTimings = new ArrayList();
protected List databaseTimings = new ArrayList();
protected Map dbSelects = new HashMap();
protected Map dbInserts = new HashMap();
protected Map dbUpdates = new HashMap();
protected Map dbDeletes = new HashMap();
public CommandStats(List executions) {
for (CommandExecutionResult execution : executions) {
getTotalCommandTime += execution.getTotalTimeInMs();
commandExecutionTimings.add(execution.getTotalTimeInMs());
databaseTimings.add(execution.getDatabaseTimeInMs());
addToDbOperation(execution.getDbSelects(), dbSelects);
addToDbOperation(execution.getDbInserts(), dbInserts);
addToDbOperation(execution.getDbUpdates(), dbUpdates);
addToDbOperation(execution.getDbDeletes(), dbDeletes);
}
}
protected void addToDbOperation(Map executionMap, Map globalMap) {
for (String key : executionMap.keySet()) {
if (!globalMap.containsKey(key)) {
globalMap.put(key, 0L);
}
Long oldValue = globalMap.get(key);
globalMap.put(key, oldValue + executionMap.get(key));
}
}
public long getCount() {
return commandExecutionTimings.size();
}
public long getGetTotalCommandTime() {
return getTotalCommandTime;
}
public double getAverageExecutionTime() {
long total = 0;
for (Long timing : commandExecutionTimings) {
total += timing.longValue();
}
double average = (double) total / (double) commandExecutionTimings.size();
return Math.round(average * 100.0) / 100.0;
}
public double getAverageDatabaseExecutionTimePercentage() {
double totalAvg = getAverageExecutionTime();
double databaseAvg = getAverageDatabaseExecutionTime();
double percentage = 100.0 * (databaseAvg / totalAvg);
return Math.round(percentage * 100.0) / 100.0;
}
public double getAverageDatabaseExecutionTime() {
long total = 0;
for (Long timing : databaseTimings) {
total += timing.longValue();
}
double average = (double) total / (double) commandExecutionTimings.size();
return Math.round(average * 100.0) / 100.0;
}
public Map getDbSelects() {
return dbSelects;
}
public void setDbSelects(Map dbSelects) {
this.dbSelects = dbSelects;
}
public Map getDbInserts() {
return dbInserts;
}
public void setDbInserts(Map dbInserts) {
this.dbInserts = dbInserts;
}
public Map getDbUpdates() {
return dbUpdates;
}
public void setDbUpdates(Map dbUpdates) {
this.dbUpdates = dbUpdates;
}
public Map getDbDeletes() {
return dbDeletes;
}
public void setDbDeletes(Map dbDeletes) {
this.dbDeletes = dbDeletes;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy