// Loop through each of the procedures and measure how accurate we are in our predictions
for (TransactionTrace xact : args.workload.getTransactions()) {
LOG.info(xact.debug(args.catalog_db));
Procedure catalog_proc = xact.getCatalogItem(args.catalog_db);
if (skip.contains(catalog_proc.getName())) continue;
int partition = HStoreConstants.NULL_PARTITION_ID;
try {
partition = p_estimator.getBasePartition(catalog_proc, xact.getParams(), true);
} catch (Exception ex) {
ex.printStackTrace();
assert(false);
}
assert(partition >= 0);
totals.get(catalog_proc).incrementAndGet();
MarkovGraph markov = m.get(partition).getFromParams(xact.getTransactionId(), partition, xact.getParams(), catalog_proc);
if (markov == null) {
LOG.warn(String.format("No MarkovGraph for %s at partition %d", catalog_proc.getName(), partition));
continue;
}
// Check whether we predict the same path
List<MarkovVertex> actual_path = markov.processTransaction(xact, p_estimator);
MarkovEstimate est = MarkovPathEstimator.predictPath(markov, t_estimators.get(partition), xact.getParams());
assert(est != null);
List<MarkovVertex> predicted_path = est.getMarkovPath();
if (actual_path.equals(predicted_path)) correct_path_txns.get(catalog_proc).incrementAndGet();
LOG.info("MarkovEstimate:\n" + est);
// Check whether we predict the same partitions
PartitionSet actual_partitions = MarkovUtil.getTouchedPartitions(actual_path);
PartitionSet predicted_partitions = MarkovUtil.getTouchedPartitions(predicted_path);
if (actual_partitions.equals(predicted_partitions)) correct_partitions_txns.get(catalog_proc).incrementAndGet();
if (actual_partitions.size() > 1) multip_txns.get(catalog_proc).incrementAndGet();
// System.err.println(xact.debug(args.catalog_db));
// System.err.println(StringUtil.repeat("=", 120));
// System.err.println(GraphUtil.comparePaths(markov, actual_path, predicted_path));
//
// String dotfile = "/home/pavlo/" + catalog_proc.getName() + ".dot";
// GraphvizExport<Vertex, Edge> graphviz = MarkovUtil.exportGraphviz(markov, actual_path);
// FileUtil.writeStringToFile(dotfile, graphviz.export(catalog_proc.getName()));
//// skip.add(catalog_proc.getName());
// System.err.println("\n\n");
} // FOR
// if (args.hasParam(ArgumentsParser.PARAM_MARKOV_OUTPUT)) {
// markovs.save(args.getParam(ArgumentsParser.PARAM_MARKOV_OUTPUT));
// }
System.err.println("Procedure\t\tTotal\tSingleP\tPartitions\tPaths");
for (Entry<Procedure, AtomicInteger> entry : totals.entrySet()) {
Procedure catalog_proc = entry.getKey();
int total = entry.getValue().get();
if (total == 0) continue;
int valid_partitions = correct_partitions_txns.get(catalog_proc).get();
double valid_partitions_p = (valid_partitions / (double)total) * 100;
int valid_paths = correct_path_txns.get(catalog_proc).get();
double valid_paths_p = (valid_paths / (double)total) * 100;
int singlep = total - multip_txns.get(catalog_proc).get();
double singlep_p = (singlep / (double)total) * 100;
System.err.println(String.format("%-25s %d\t%.02f\t%.02f\t%.02f", catalog_proc.getName(),
total,
singlep_p,
valid_partitions_p,
valid_paths_p
));