// statistics.beh -- Collect statistics about traversal generation // $Id: statistics.beh,v 1.2 2002/09/26 05:19:42 dougo Exp $ Program { {{ int travs, total_sgnodes, total_sgedges, total_tgnodes, total_tgedges; }} /** Collect statistics for a traversal, writing per-traversal statistics to a file. */ void collectStatistics(ClassName clname, TraversalName name, ClassGraph cg, StrategyGraph sg, TraversalGraph tg) {{ travs++; openOutputFile(new File(gendir, name + "_" + clname + ".trv")); out.println("Statistics:"); int sgnodes = sg.getNumNodes(), sgedges = sg.numEdges(); total_sgnodes += sgnodes; total_sgedges += sgedges; out.println(" sg: " + amountString(sgnodes, "node") + ", " + amountString(sgedges, "edge") + ", " + amountString(size(sg.getVertices()), "class", "es") + ", " + amountString(sg.getNumConstraints(), "constraint")); int tgnodes = size(tg.vertices()), tgedges = size(tg.edges()); total_tgnodes += tgnodes; total_tgedges += tgedges; out.println(" cg slice: " + amountString(tgnodes, "node") + ", " + amountString(tgedges, "edge")); out.println("Strategy graph:"); out.println(sg); out.println("Class graph slice:"); Enumeration vertices = tg.vertices(); while (vertices.hasMoreElements()) { ClassName cl = (ClassName) vertices.nextElement(); ClassDef def = cg.findClassDef(cl); if (def != null) { def.printTraversalEdges(tg, out); } } closeOutputFile(); }} void saveStatistics() {{ openOutputFile(new File(gendir, "statistics")); out.println("Traversals: " + travs); out.println("Total strategy graph nodes: " + total_sgnodes); out.println("Total strategy graph edges: " + total_sgedges); out.println("Average strategy graph nodes: " + (double) total_sgnodes / travs); out.println("Average strategy graph edges: " + (double) total_sgedges / travs); out.println("Total class graph slice nodes: " + total_tgnodes); out.println("Total class graph slice edges: " + total_tgedges); out.println("Average class graph slice nodes: " + (double) total_tgnodes / travs); out.println("Average class graph slice edges: " + (double) total_tgedges / travs); out.println("Class graph nodes: " + size(classdefs())); out.println("Class graph edges: " + getNumEdges()); closeOutputFile(); }} int getNumEdges() to { Part, Superclass, Interface, Subclass } { before { Part, Superclass, Interface, Subclass } {{ return_val++; }} } static String amountString(int amount, String name) {{ return amountString(amount, name, "s"); }} static String amountString(int amount, String name, String suffix) {{ return amount + " " + name + (amount == 1 ? "" : suffix); }} static int size(Enumeration e) {{ int i = 0; while (e.hasMoreElements()) { i++; e.nextElement(); } return i; }} } StrategyGraph { int getNumNodes() bypassing { -> *,sources,*, -> *,targets,*, -> *,constraint,* } to ClassGlobSpec { {{ HashSet nodes = new HashSet(); }} before ClassGlobSpec {{ nodes.add(host); }} return {{ nodes.size() }} } int getNumConstraints() to NegativeConstraint { before NegativeConstraint {{ return_val++; }} } }