Skip to content

Commit

Permalink
Improve /timing
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasAlaif committed Jan 13, 2025
1 parent 9506ffc commit f5700f3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
19 changes: 11 additions & 8 deletions source/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ void taskLoadZ3LogFile(string logFile)
}
}
});
while (!stop) {
stop = true;
if (task.Wait(TimeSpan.FromMilliseconds(1000))) {
stop = false;
break;
}
if (!task.Wait(TimeSpan.FromMilliseconds(300))) {
do {
stop = true;
if (task.Wait(TimeSpan.FromMilliseconds(1000))) {
stop = false;
break;
}
} while (!stop);
}
if (stop)
isCancelled = true;
Expand All @@ -201,8 +203,9 @@ void taskLoadZ3LogFile(string logFile)
}
statusUpdate(1000);
if (!config.timing) return;
if (isCancelled) Console.WriteLine("[Parse] Err " + oldperc + "‰");
else Console.WriteLine("[Parse] " + parseMs + "ms");
Console.Write("[Parse] ");
if (isCancelled) Console.Write("Err " + oldperc + "‰ ");
Console.WriteLine(parseMs + "ms");
Console.WriteLine("[Graph] " + analysisMs + "ms");
}

Expand Down
17 changes: 14 additions & 3 deletions source/ScriptingSupport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public static bool RunScriptingTasks(Model model, ScriptingTasks tasks, bool tim
var trueLoops = new List<List<Quantifier>>();
var falseLoops = new List<List<Quantifier>>();
var error = "";
var watch = new System.Diagnostics.Stopwatch();
try
{
var watch = System.Diagnostics.Stopwatch.StartNew();
// Output basic information
var basicFileExists = false;
if (tasks.ShowNumChecks)
Expand All @@ -58,6 +58,7 @@ public static bool RunScriptingTasks(Model model, ScriptingTasks tasks, bool tim
}
}
}
watch.Start();

// Check logest paths for potential loops
var pathsToCheck = model.instances.Where(inst => inst.Depth == 1)
Expand All @@ -66,17 +67,21 @@ public static bool RunScriptingTasks(Model model, ScriptingTasks tasks, bool tim
.Select(inst => deepestPathStartingFrom(inst)).ToList();
if (pathsToCheck.Any())
{
watch.Stop();
using (var writer = new StreamWriter(basePath + ".loops", false))
{
writer.WriteLine("# repetitions,repeating pattern");
watch.Start();
foreach (var path in pathsToCheck)
{
var cycleDetection = new CycleDetection.CycleDetection(path.getInstantiations(), 3);
var gen = cycleDetection.getGeneralization();
if (gen != null)
{
var quantifiers = cycleDetection.getCycleQuantifiers();
watch.Stop();
writer.WriteLine(cycleDetection.GetNumRepetitions() + "," + string.Join(" -> ", quantifiers.Select(quant => quant.PrintName)) + "," + gen.TrueLoop);
watch.Start();
if (gen.TrueLoop) {
if (!trueLoops.Contains(quantifiers))
trueLoops.Add(quantifiers);
Expand All @@ -91,13 +96,16 @@ public static bool RunScriptingTasks(Model model, ScriptingTasks tasks, bool tim
break;
}
}
watch.Stop();
}
watch.Start();
}

// High branching analysis
var highBranchingInsts = model.instances.Where(inst => inst.DependantInstantiations.Count() >= tasks.FindHighBranchingThreshold).ToList();
if (highBranchingInsts.Any())
{
watch.Stop();
using (var writer = new StreamWriter(basePath + ".branching"))
{
writer.WriteLine($"Quantifier,# instances with ≥ {tasks.FindHighBranchingThreshold} direct children");
Expand All @@ -106,12 +114,14 @@ public static bool RunScriptingTasks(Model model, ScriptingTasks tasks, bool tim
writer.WriteLine(quant.Key.PrintName + "," + quant.Count());
}
}
watch.Start();
}
watch.Stop();
tasksMs = watch.ElapsedMilliseconds;
}
catch (Exception e)
{
watch.Stop();
error = e.Message;
const int ERROR_HANDLE_DISK_FULL = 0x27;
const int ERROR_DISK_FULL = 0x70;
Expand All @@ -125,10 +135,11 @@ public static bool RunScriptingTasks(Model model, ScriptingTasks tasks, bool tim
}
}
if (timing) {
Console.Write("[Analysis] ");
if (tasksMs == long.MaxValue)
Console.WriteLine("[Analysis] Err " + error);
Console.WriteLine("Err " + watch.ElapsedMilliseconds + "ms " + error);
else
Console.WriteLine("[Analysis] " + tasksMs + "ms");
Console.WriteLine(tasksMs + "ms");
Console.WriteLine("[Loops] " + trueLoops.Count + " true, " + falseLoops.Count + " false");
}

Expand Down

0 comments on commit f5700f3

Please sign in to comment.