use of org.apache.stanbol.enhancer.servicesapi.helper.execution.ChainExecution in project stanbol by apache.
the class EnhancementJobHandler method logExecutionTimes.
/**
* Helper method that logs the execution time for the Chain and all the
* Enhancement Engines on DEBUG level
* @param logger The logger used for logging
* @param job the job to log. This expects that
* <code>{@link EnhancementJob#isFinished()} == true</code>
*/
protected static void logExecutionTimes(Logger logger, EnhancementJob job) {
if (logger.isInfoEnabled()) {
try {
ExecutionMetadata em = ExecutionMetadata.parseFrom(job.getExecutionMetadata(), job.getContentItem().getUri());
ChainExecution ce = em.getChainExecution();
long cd = ce.getDuration();
StringBuilder message = new StringBuilder("> processed ContentItem ").append(job.getContentItem().getUri()).append(" with Chain '").append(ce.getChainName()).append("' in ").append(ce.getDuration()).append("ms | ");
List<Execution> ees = new ArrayList<Execution>(em.getEngineExecutions().values());
//sort by start date (execution order)
Collections.sort(ees, new Comparator<Execution>() {
@Override
public int compare(Execution e1, Execution e2) {
return e1.getStarted().compareTo(e2.getStarted());
}
});
message.append("chain:[");
long eds = 0;
boolean first = true;
for (Execution ee : ees) {
if (first) {
first = false;
} else {
message.append(", ");
}
long ed = ee.getDuration();
eds = eds + ed;
int edp = Math.round(ed * 100 / (float) cd);
message.append(ee.getExecutionNode().getEngineName()).append(": ").append(ed).append("ms (").append(edp).append("%)");
}
float cf = eds / cd;
int cfp = Math.round((cf - 1) * 100);
message.append("], concurrency: ").append(cf).append(" (").append(cfp).append("%)");
logger.info(message.toString());
} catch (RuntimeException e) {
log.warn("Exception while logging ExecutionTimes for Chain: '" + job.getChainName() + " and ContentItem " + job.getContentItem().getUri() + " to Logger " + logger.getName(), e);
}
}
}
Aggregations