From 7348999caf3ce1e0be64697319581d52f1d7f8ea Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 13 Mar 2024 22:12:59 +0900 Subject: perf: log instruction metrics --- src/Execution/Runtime.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php index 40d7703..3617de2 100644 --- a/src/Execution/Runtime.php +++ b/src/Execution/Runtime.php @@ -21,8 +21,13 @@ use Nsfisis\Waddiwasi\Structure\Types\TableIdx; use Nsfisis\Waddiwasi\Structure\Types\ValType; use Nsfisis\Waddiwasi\Structure\Types\ValTypes; -final readonly class Runtime +final class Runtime { + /** + * @var array + */ + private array $instrMetrics = []; + private function __construct( public readonly Store $store, public readonly Stack $stack, @@ -151,6 +156,15 @@ final readonly class Runtime return null; } + /** + * @return array + */ + public function getInstrMetrics(): array + { + ksort($this->instrMetrics); + return $this->instrMetrics; + } + /** * @param list $vals * @return list @@ -314,6 +328,9 @@ final readonly class Runtime static $debug = 0; // if ($debug >= 3) echo "Exec: " . $instr::opName() . "\n"; + // $this->instrMetrics[$instr::opName()] ??= 0; + // $this->instrMetrics[$instr::opName()]++; + return match ($instr::class) { Instrs\Numeric\F32Abs::class => $this->execInstrNumericF32Abs($instr), Instrs\Numeric\F32Add::class => $this->execInstrNumericF32Add($instr), -- cgit v1.2.3-70-g09d2