// The ExecutionLog class. /****************************************************************************** CHANGE LOG. 23 Nov 98: Creation. [pike] ******************************************************************************/ import java.io.PrintStream; import java.io.FileOutputStream; class ExecutionLog { BoxedList_String strings; PrintStream local out; boolean timestampByDefault; long time0; int loggingLevel; static final int defaultLevel = 1; public ExecutionLog() { init(defaultLevel); } public ExecutionLog(int ll) { init(ll); } private local void init(int ll) { loggingLevel = ll; strings = new BoxedList_String(); timestampByDefault = true; time0 = System.currentTimeMillis(); begin("log"); } public void rawappend(int ll, String s) { if (ll <= loggingLevel) strings.push(s); } public void append(String s) { append(defaultLevel, s); } public void append(int ll, String s) { if (ll > loggingLevel) return; if (timestampByDefault) s = (System.currentTimeMillis() - time0) + ": " + s; s = Ti.thisProc() + ": " + s; rawappend(ll, s); } public void begin(String phase) { append("begin " + phase); } public void end(String phase) { append("end " + phase); } public static void printArray(PrintStream local out, String [1d] a) { for (int i = a.domain().min()[1]; i <= a.domain().max()[1]; i++) out.println(a[i]); } public static void printReverseOrder(BoxedList_String s, PrintStream local out) { printArray(out, s.toReversedArray()); } public local void dump(BoxedList_String s) { // System.out.println("Dumping ExecutionLog from proc " + Ti.thisProc()); printReverseOrder(s, out); } static single void end(ExecutionLog local e) { int single n = Ti.numProcs(); int me = Ti.thisProc(); boolean die = false; if ((broadcast e.loggingLevel from 0) == 0) return; e.end("log"); if (Ti.thisProc() == 0 && e.out == null) try { e.out = new PrintStream(new FileOutputStream("log")); } catch (Throwable x) { die = true; } if (broadcast die from 0) return; for (int single i = 0; i < n; i++) { BoxedList_String s = broadcast e.strings from i; if (me == 0) e.dump(s); } } single local void end() { end(this); } // Methods below may be called from native code for logging purposes. static private long xtime; static private Histogram_long local [1d] local h; static private int xkind; static final private int xkinds = 3; static void xbegin(int kind) { xtime = System.currentTimeMillis(); } static void xend(int kind) { xtime -= System.currentTimeMillis(); if (h == null) { if (Ti.thisProc() == 0) System.out.println("Creating histogram of message times."); h = new Histogram_long local [[0 : xkinds - 1]]; foreach (p in h.domain()) h[p] = new Histogram_long(); } h[kind].add(xtime); } static sglobal void histDump() { int single n = Ti.numProcs(); int me = Ti.thisProc(); for (int single i = 0; i < n; i++) { Ti.barrier(); if (i == me && h != null) foreach (p in h.domain()) h[p].dump("Histogram " + p + " for proc " + me); } } }