/****************************************************************************** * Copyright (c) 2009 - 2015 IBM Corporation. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *****************************************************************************/ /** * */ package com.ibm.wala.memsat; import com.ibm.wala.memsat.translation.Translation; import com.ibm.wala.memsat.viz.Visualizer; import kodkod.engine.Solution; /** * Contains the results of a Miniatur analysis, consisting * of a counterexample, if any, to an assertion in the analyzed * code, and statistics about various phases of the analysis. * * @specfield translation: Translation<T> // output of the Miniatur translator * @specfield solution: Solution // kodkod solution * @specfield analysisTime: long // time, in miliseconds, taken by call graph extractions, analysis, etc. * @specfield translationTime: long // time, in miliseconds, taken by the Minatur translation to Kodkod * * @author Emina Torlak */ public final class Results<T extends Translation<?>> { private final T translation; private final Solution solution; private final long analysisTime, translationTime; private final Visualizer<String> viz; /** * Constructs new Results out of the given data. * @requires all objects are non-null * @requires all primitives are positive */ Results(T translation, Solution solution, long analysisTime, long translationTime, Visualizer<String> viz) { this.translation = translation; this.solution = solution; this.analysisTime = analysisTime; this.translationTime = translationTime; this.viz = viz; } /** * Returns the translation generated by the Miniatur translator. * @return this.translation */ public T translation() { return translation; } /** * Returns the Kodkod solution of the problem consisting of * this.translation.bounds and the conjuction of this.translation.invariants * with the disjunction of the formulas in this.analyzed. * @return this.solution */ public Solution solution() { return solution; } /** * Returns the time, in miliseconds, taken by * Minatur/Wala to compute call graphs, dependece graphs, etc. * @return analysisTime */ public long analysisTime() { return analysisTime; } /** * Returns the time, in miliseconds, taken by * Minatur to translate the analyzed code to Kodkod. * @return translationTime */ public long translationTime() { return translationTime; } /** * Returns a string view of these results. * @return a string view of these results. */ public String toString() { final StringBuilder s = new StringBuilder(); s.append("--------------Results:--------------\n"); // s.append(" analyzed:\n"); // s.append(Strings.prettyPrint(analyzed,2)+"\n"); // s.append(translation.bounds()+"\n"); s.append("outcome: " + solution.outcome()+ "\n"); s.append("wala analysis time: " + analysisTime + " ms\n"); s.append("miniatur translation time: " + translationTime + " ms\n"); s.append("kodkod translation time: " + solution.stats().translationTime() +" ms\n"); s.append("sat solving time: " + solution.stats().solvingTime() + " ms\n"); s.append("p cnf " + solution.stats().variables() + " " + solution.stats().clauses() + "\n"); s.append("\n"); s.append(viz.visualize()); return s.toString(); } }