Skip to content

Commit

Permalink
Fix Compile Stopwatch
Browse files Browse the repository at this point in the history
This helped validate that the previous fixes actually improved compile
times

CPU.cs
* Modify compileWatch reset and addition to check if stopwatch is
running
* When we moved compiling to a separate thread, this wasn't modified to
know that the compile may cross multiple updates

YieldFinishedCompile.cs
* Fixed call to stop the compile stopwatch so that it stops after any
completed compilation.
  • Loading branch information
hvacengi committed Nov 17, 2017
1 parent 1bf93c7 commit 48c8151
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/kOS.Safe/Execution/CPU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,8 +1205,10 @@ public void KOSFixedUpdate(double deltaTime)
updateWatch.Reset();
executionWatch.Reset();
instructionWatch.Reset();
compileWatch.Stop();
compileWatch.Reset();
if (!compileWatch.IsRunning)
{
compileWatch.Reset();
}
updateWatch.Start();
}

Expand Down Expand Up @@ -1272,7 +1274,10 @@ public void KOSFixedUpdate(double deltaTime)
totalUpdateTime += updateElapsed;
executionElapsed = executionWatch.ElapsedTicks * 1000D / Stopwatch.Frequency;
totalExecutionTime += executionElapsed;
totalCompileTime += compileWatch.ElapsedTicks * 1000D / Stopwatch.Frequency;
if (!compileWatch.IsRunning)
{
totalCompileTime += compileWatch.ElapsedTicks * 1000D / Stopwatch.Frequency;
}
if (maxMainlineInstructionsSoFar < numMainlineInstructions)
maxMainlineInstructionsSoFar = numMainlineInstructions;
if (maxUpdateTime < updateElapsed)
Expand Down
2 changes: 1 addition & 1 deletion src/kOS.Safe/Execution/YieldFinishedCompile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public override void ThreadFinish()
{
case CompileMode.RUN:
programContext.AddParts(codeParts);
shared.Cpu.StopCompileStopwatch();
break;
case CompileMode.LOAD:
int programAddress = programContext.AddObjectParts(codeParts, path.ToString());
Expand All @@ -74,6 +73,7 @@ public override void ThreadFinish()
default:
break;
}
shared.Cpu.StopCompileStopwatch();
}

public static YieldFinishedCompile RunScript(GlobalPath scriptPath, int lineNumber, string fileContent, string contextIdentifier, CompilerOptions compilerOptions)
Expand Down

0 comments on commit 48c8151

Please sign in to comment.