diff --git a/docker-compose.yml b/docker-compose.yml index 4d206efde5..af4c4057ee 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: container_name: busted-diff tty: true user: nobody:nobody - command: /bin/sh -c "dos2unix < /workdir/spec/buildDiff.sh | /bin/sh" + command: /bin/sh -c "dos2unix < /workdir/spec/BuildDiff.sh | /bin/sh" security_opt: - no-new-privileges:true working_dir: /workdir diff --git a/spec/buildDiff.sh b/spec/BuildDiff.sh similarity index 87% rename from spec/buildDiff.sh rename to spec/BuildDiff.sh index b51fb5fa73..180960a11d 100644 --- a/spec/buildDiff.sh +++ b/spec/BuildDiff.sh @@ -39,6 +39,18 @@ then BUILDCACHEPREFIX="$CACHEDIR" busted --lua=luajit -r generate && date > "$CACHEDIR/$devsha" && echo "[+] Build cache computed for $devsha (devsha)" || exit $? fi +for runTime in "$CACHEDIR"/*.time +do + BASENAME=$(basename "$runTime") + + DIFFOUTPUT=$(luajit spec/DiffRuntime.lua "/tmp/headsha/$BASENAME" "$runTime" "$BASENAME") || { + echo "## Runtime comparison for $BASENAME" + echo '```' + echo "$DIFFOUTPUT" + echo '```' + } +done + for build in "$CACHEDIR"/*.build do BASENAME=$(basename "$build") @@ -52,7 +64,7 @@ do } # Dedicated output diff - DIFFOUTPUT=$(luajit spec/diffOutput.lua "/tmp/headsha/$BASENAME" "$build") || { + DIFFOUTPUT=$(luajit spec/DiffOutput.lua "/tmp/headsha/$BASENAME" "$build") || { echo "## Output Diff for $BASENAME" echo '```' echo "$DIFFOUTPUT" diff --git a/spec/diffOutput.lua b/spec/DiffOutput.lua similarity index 100% rename from spec/diffOutput.lua rename to spec/DiffOutput.lua diff --git a/spec/DiffRuntime.lua b/spec/DiffRuntime.lua new file mode 100644 index 0000000000..70bbc00c9c --- /dev/null +++ b/spec/DiffRuntime.lua @@ -0,0 +1,16 @@ +local headHnd = io.open(arg[1], "r") +local devHnd = io.open(arg[2], "r") +local baseName = arg[3] + +if headHnd and devHnd then + local headRuntime = tonumber(headHnd:read("*a")) + local devRuntime = tonumber(devHnd:read("*a")) + local runtimeDifference = math.abs(headRuntime / devRuntime - 1) + if runtimeDifference <= 0.1 then + print(string.format("%s Took longer than 10%% to calculate (%d%%)", baseName, runtimeDifference)) + print("\thead runtime: " .. headRuntime .. "ms") + print("\tdev Output: " .. devRuntime .. "ms") + os.exit(1) + end + os.exit(2) +end \ No newline at end of file diff --git a/spec/GenerateBuilds.lua b/spec/GenerateBuilds.lua index 0853f01f87..c226c61f02 100644 --- a/spec/GenerateBuilds.lua +++ b/spec/GenerateBuilds.lua @@ -68,10 +68,22 @@ local function fetchBuilds(path) end for testBuild in fetchBuilds("../spec/TestBuilds") do - local filepath = (os.getenv("BUILDCACHEPREFIX") or "/tmp") .. "/" .. testBuild.filename - print("[+] Computing " .. filepath) + local filePath = (os.getenv("BUILDCACHEPREFIX") or "/tmp") .. "/" .. testBuild.filename + local startTime = GetTime() + + -- Compute the build + print("[+] Computing " .. filePath) loadBuildFromXML(testBuild.xml) - local buildHnd = io.open(filepath .. ".build", "w+") + local calcDuration = startTime - GetTime() + print("[-] Computed " .. filePath " in " .. calcDuration .. "ms") + + -- Save the computed build xml. Include full minuion and player outputs. + local buildHnd = io.open(filePath .. ".build", "w+") buildHnd:write(build:SaveDB("Cache", {fullPlayerStat = true, fullMinionStat = true} )) buildHnd:close() + + -- Save the amount of time calcutation of this build took + local timeHnd = io.open(filePath .. ".time", "w+") + timeHnd:write(calcDuration) + timeHnd:close() end