Skip to content

Commit

Permalink
[tests] replace perf.json total_cycles value when instrument found
Browse files Browse the repository at this point in the history
Signed-off-by: Avimitin <[email protected]>
  • Loading branch information
Avimitin committed Jan 9, 2025
1 parent 65ae0fa commit 5f12f62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 20 additions & 0 deletions nix/t1/run/calculate-cycle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import json

original_total_cycle = 0
with open("perf.json") as f:
original_total_cycle = (json.load(f))["total_cycles"]

with open("mmio-event.jsonl") as f:
events = [json.loads(line) for line in f]
events = list(filter(lambda x: x["event"] == "profile", events))
if len(events) % 2 != 0:
print(original_total_cycle)

total_cycles = 0
for i in range(len(events) // 2):
assert events[2 * i]["value"] == 1
assert events[2 * i + 1]["value"] == 0
duration = events[2 * i + 1]["cycle"] - events[2 * i]["cycle"]
total_cycles += duration

print(total_cycles)
7 changes: 5 additions & 2 deletions nix/t1/run/run-vcs-emu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
, offline-checker
, snps-fhs-env
, writeShellScriptBin
, python3
}:

{ emulator
Expand All @@ -17,7 +18,7 @@ assert lib.assertMsg (!emulator.isRuntimeLoad || (dpilib != null)) "dpilib must

stdenvNoCC.mkDerivation (rec {
name = "${testCase.pname}-vcs-result" + (lib.optionalString emulator.enableTrace "-trace");
nativeBuildInputs = [ zstd jq ];
nativeBuildInputs = [ zstd jq python3 ];
__noChroot = true;

passthru = {
Expand Down Expand Up @@ -123,11 +124,13 @@ stdenvNoCC.mkDerivation (rec {
rm $rtlEventOutPath
if [ -r perf.json ]; then
mv perf.json $out/
cp -v perf.json $out/
fi
# If we find the mmio-event.jsonl file, try to replace the perf total cycle with program instrument.
if [ -r mmio-event.jsonl ]; then
cp -v mmio-event.jsonl $out/
jq ".total_cycles=$(python3 ${./calculate-cycle.py})" perf.json > "$out/perf.json"
fi
${lib.optionalString emulator.enableCover ''
Expand Down

0 comments on commit 5f12f62

Please sign in to comment.