1# Copyright 2022 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from __future__ import annotations 6 7import abc 8import datetime as dt 9from typing import TYPE_CHECKING, Tuple, Type 10 11from crossbench.benchmarks.jetstream.jetstream import (JetStreamBenchmark, 12 JetStreamProbe) 13from crossbench.stories.press_benchmark import PressBenchmarkStory 14 15if TYPE_CHECKING: 16 from crossbench.runner.run import Run 17 18 19class JetStream2Probe(JetStreamProbe, metaclass=abc.ABCMeta): 20 """ 21 JetStream2-specific Probe. 22 Extracts all JetStream2 times and scores. 23 """ 24 25 26class JetStream2Story(PressBenchmarkStory, metaclass=abc.ABCMeta): 27 URL_LOCAL: str = "http://localhost:8000/" 28 SUBSTORIES: Tuple[str, ...] = ( 29 "WSL", 30 "UniPoker", 31 "uglify-js-wtb", 32 "typescript", 33 "tsf-wasm", 34 "tagcloud-SP", 35 "string-unpack-code-SP", 36 "stanford-crypto-sha256", 37 "stanford-crypto-pbkdf2", 38 "stanford-crypto-aes", 39 "splay", 40 "segmentation", 41 "richards-wasm", 42 "richards", 43 "regexp", 44 "regex-dna-SP", 45 "raytrace", 46 "quicksort-wasm", 47 "prepack-wtb", 48 "pdfjs", 49 "OfflineAssembler", 50 "octane-zlib", 51 "octane-code-load", 52 "navier-stokes", 53 "n-body-SP", 54 "multi-inspector-code-load", 55 "ML", 56 "mandreel", 57 "lebab-wtb", 58 "json-stringify-inspector", 59 "json-parse-inspector", 60 "jshint-wtb", 61 "HashSet-wasm", 62 "hash-map", 63 "gcc-loops-wasm", 64 "gbemu", 65 "gaussian-blur", 66 "float-mm.c", 67 "FlightPlanner", 68 "first-inspector-code-load", 69 "espree-wtb", 70 "earley-boyer", 71 "delta-blue", 72 "date-format-xparb-SP", 73 "date-format-tofte-SP", 74 "crypto-sha1-SP", 75 "crypto-md5-SP", 76 "crypto-aes-SP", 77 "crypto", 78 "coffeescript-wtb", 79 "chai-wtb", 80 "cdjs", 81 "Box2D", 82 "bomb-workers", 83 "Basic", 84 "base64-SP", 85 "babylon-wtb", 86 "Babylon", 87 "async-fs", 88 "Air", 89 "ai-astar", 90 "acorn-wtb", 91 "3d-raytrace-SP", 92 "3d-cube-SP", 93 ) 94 95 @property 96 def substory_duration(self) -> dt.timedelta: 97 return dt.timedelta(seconds=2) 98 99 def setup(self, run: Run) -> None: 100 with run.actions("Setup") as actions: 101 actions.show_url(self.get_run_url(run)) 102 if self._substories != self.SUBSTORIES: 103 actions.wait_js_condition(("return JetStream && JetStream.benchmarks " 104 "&& JetStream.benchmarks.length > 0;"), 0.1, 105 10) 106 actions.js( 107 """ 108 let benchmarks = arguments[0]; 109 JetStream.benchmarks = JetStream.benchmarks.filter( 110 benchmark => benchmarks.includes(benchmark.name)); 111 """, 112 arguments=[self._substories]) 113 actions.wait_js_condition( 114 """ 115 return document.querySelectorAll("#results>.benchmark").length > 0; 116 """, 1, self.duration + dt.timedelta(seconds=30)) 117 118 def run(self, run: Run) -> None: 119 with run.actions("Running") as actions: 120 actions.js("JetStream.start()") 121 actions.wait(self.fast_duration) 122 with run.actions("Waiting for completion") as actions: 123 actions.wait_js_condition( 124 """ 125 let summaryElement = document.getElementById("result-summary"); 126 return (summaryElement.classList.contains("done")); 127 """, 128 0.5, 129 self.slow_duration, 130 delay=self.substory_duration) 131 132 133ProbeClsTupleT = Tuple[Type[JetStream2Probe], ...] 134 135 136class JetStream2Benchmark(JetStreamBenchmark): 137 pass 138