// We need a way to ensure that our tasks finish before the application // using this class exits because it will just exit without letting our // tasks finish if we don't explicitly wait. This is achieved by hooking // into the ExecutorTerminated event and then waiting on all the tasks we // have. Is there a better way to do this??? private void Wait(Object executor, Executor.ExecutorTerminatedArgs args) { lock (ScheduledTasks) { Task.WaitAll(ScheduledTasks.ToArray()); } }
private void handleExecutorTerminated(Object executor, Executor.ExecutorTerminatedArgs args) { StringBuilder fileName = new StringBuilder("termination_counters"); if (TCounter.TheCountType != TerminationCounter.CountType.ONLY_NON_SPECULATIVE) { fileName.AppendFormat("_{0}", TCounter.TheCountType.ToString()); } // Write GNUPlot data string path = Path.Combine(Directory, fileName.ToString() + ".txt"); Console.WriteLine("Writing termination counts to {0}", path); using (var SW = new StreamWriter(path)) { TCounter.WriteAsGnuPlotData(SW); } path = Path.Combine(Directory, fileName.ToString() + ".yml"); Console.WriteLine("Writing termination counts to {0}", path); // It is necessary to use to "using" blocks because IndentedTextWriter.Dispose() // does not seem to call Dispose() on the underlying stream using (var SW = new StreamWriter(path)) { using (var ITT = new IndentedTextWriter(SW, " ")) { TCounter.WriteAsYAML(ITT); } } }
void HandleExecutorTerminated(object sender, Executor.ExecutorTerminatedArgs e) { var executor = sender as Executor; Debug.Assert(sender is Executor, "Expected Executor"); if (!executor.HasBeenPrepared) { Console.Error.WriteLine("Can't log callgrind output because program was not prepared"); return; } Program clonedProgram = null; using (var SW = new StreamWriter(this.ProgramDestination)) { // FIXME: Duplication isn't ideal here but we don't want to affect the reported error locations // which would happen if we changed the tokens on the Executor's program var duplicator = new DuplicatorResolvingGotoInstructionStatistics(); clonedProgram = (Program)duplicator.Visit(executor.TheProgram); Console.WriteLine("Writing unstructured program to {0}", this.ProgramDestination); ProgramPrinter.Print(clonedProgram, SW, /*pretty=*/ false, ProgramDestination, /*setTokens=*/ true, ProgramPrinter.PrintType.UNSTRUCTURED_ONLY); } // Write out instruction statistics to a callgrind file using (var SW = new StreamWriter(this.CallGrindFileDestintation)) { Console.WriteLine("Writing callgrind file to {0}", this.CallGrindFileDestintation); Debug.Assert(executor.RequestedEntryPoints.Count() > 0, "The executor did not report an entry point"); var entryPointToUse = executor.RequestedEntryPoints.First(); var callGrindFilePrinter = new CallGrindFilePrinter(clonedProgram, Path.GetFileName(this.ProgramDestination), entryPointToUse); callGrindFilePrinter.Print(SW); } }
void HandleExecutorTerminated(object sender, Executor.ExecutorTerminatedArgs e) { var path = Path.Combine(this.Directory, "execution_tree.dot"); var executor = (Executor)sender; if (executor.TreeRoot == null) { Console.Error.WriteLine("Can't create {0}, tree root is null", path.ToString()); return; } using (var SW = new StreamWriter(path)) { ExecutionTreePrinter etp = null; if (AnnotateWithContextChanges) { etp = new ExecutionTreePrinterWithContextChanges(executor.TreeRoot, 2, this.ContextChanges); } else { etp = new ExecutionTreePrinter(executor.TreeRoot); } etp.Print(SW); } }
protected void handleTerminate(Object executor, Executor.ExecutorTerminatedArgs args) { // There is a bug here where the Thread.Sleep() doesn't wake whilst System.Environment.Exit() is being called Run = false; if (MemoryLoggingTask != null) { MemoryLoggingTask.Wait(); } }
void HandleExecutorTerminated(object sender, Executor.ExecutorTerminatedArgs e) { var executor = sender as Executor; // It is necessary to use two "using" blocks because IndentedTextWriter.Dispose() // does not seem to call Dispose() on the underlying stream using (var SW = new StreamWriter(Path.Combine(Directory, "executor_info.yml"))) { using (var ITT = new IndentedTextWriter(SW, " ")) { ITT.WriteLine("# vim: set sw=2 ts=2 softtabstop=2:"); ITT.WriteLine("# Times are in seconds"); executor.WriteAsYAML(ITT); } } }