forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1662706 - add a fuzzy runner r=sparky,necko-reviewers,rstewart DO…
…NTBUILD Differential Revision: https://phabricator.services.mozilla.com/D89123
- Loading branch information
Showing
19 changed files
with
387 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[perftest_browser_xhtml_dom.js] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,7 +149,7 @@ DIRS += [ | |
'build', | ||
'config', | ||
'python', | ||
'testing/mozbase', | ||
'testing', | ||
'third_party/python', | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[perftest_http3_cloudflareblog.js] | ||
[perftest_http3_facebook_scroll.js] | ||
[perftest_http3_google_image.js] | ||
[perftest_http3_google_search.js] | ||
[perftest_http3_lucasquicfetch.js] | ||
[perftest_http3_youtube_watch.js] | ||
[perftest_http3_youtube_watch_scroll.js] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[test_http3_perf.js] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
import os | ||
import sys | ||
import subprocess | ||
from pathlib import Path | ||
import json | ||
|
||
from mozterm import Terminal | ||
from mozboot.util import get_state_dir | ||
from mozbuild.util import ensure_subprocess_env | ||
from distutils.spawn import find_executable | ||
|
||
|
||
HERE = Path(__file__).parent.resolve() | ||
SRC_ROOT = (HERE / ".." / ".." / ".." / "..").resolve() | ||
PREVIEW_SCRIPT = HERE / "preview.py" | ||
FZF_HEADER = """ | ||
Please select a performance test to execute. | ||
{shortcuts} | ||
""".strip() | ||
|
||
fzf_shortcuts = { | ||
"ctrl-t": "toggle-all", | ||
"alt-bspace": "beginning-of-line+kill-line", | ||
"?": "toggle-preview", | ||
} | ||
|
||
fzf_header_shortcuts = [ | ||
("select", "tab"), | ||
("accept", "enter"), | ||
("cancel", "ctrl-c"), | ||
("cursor-up", "up"), | ||
("cursor-down", "down"), | ||
] | ||
|
||
|
||
def run_fzf(cmd, tasks): | ||
env = dict(os.environ) | ||
env.update( | ||
{"PYTHONPATH": os.pathsep.join([p for p in sys.path if "requests" in p])} | ||
) | ||
proc = subprocess.Popen( | ||
cmd, | ||
stdout=subprocess.PIPE, | ||
stdin=subprocess.PIPE, | ||
env=ensure_subprocess_env(env), | ||
universal_newlines=True, | ||
) | ||
out = proc.communicate("\n".join(tasks))[0].splitlines() | ||
selected = [] | ||
query = None | ||
if out: | ||
query = out[0] | ||
selected = out[1:] | ||
return query, selected | ||
|
||
|
||
def format_header(): | ||
terminal = Terminal() | ||
shortcuts = [] | ||
for action, key in fzf_header_shortcuts: | ||
shortcuts.append( | ||
"{t.white}{action}{t.normal}: {t.yellow}<{key}>{t.normal}".format( | ||
t=terminal, action=action, key=key | ||
) | ||
) | ||
return FZF_HEADER.format(shortcuts=", ".join(shortcuts), t=terminal) | ||
|
||
|
||
def autodetect(path): | ||
from mozperftest.script import ScriptInfo | ||
|
||
return ScriptInfo.detect_type(path).name | ||
|
||
|
||
def select(test_objects): | ||
mozbuild_dir = Path(Path.home(), ".mozbuild") | ||
os.makedirs(str(mozbuild_dir), exist_ok=True) | ||
cache_file = Path(mozbuild_dir, ".perftestfuzzy") | ||
|
||
with cache_file.open("w") as f: | ||
f.write(json.dumps(test_objects)) | ||
|
||
def _display(task): | ||
flavor = autodetect(task["path"]) | ||
path = task["path"].replace(str(SRC_ROOT), "") | ||
return f"[{flavor}] {path}" | ||
|
||
candidate_tasks = [_display(t) for t in test_objects] | ||
fzf_bin = find_executable("fzf", str(Path(get_state_dir(), "fzf", "bin"))) | ||
key_shortcuts = [k + ":" + v for k, v in fzf_shortcuts.items()] | ||
|
||
base_cmd = [ | ||
fzf_bin, | ||
"-m", | ||
"--bind", | ||
",".join(key_shortcuts), | ||
"--header", | ||
format_header(), | ||
"--preview-window=right:50%", | ||
"--print-query", | ||
"--preview", | ||
sys.executable + ' {} -t "{{+f}}"'.format(str(PREVIEW_SCRIPT)), | ||
] | ||
query_str, tasks = run_fzf(base_cmd, sorted(candidate_tasks)) | ||
return tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this | ||
# file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
""" | ||
This file is executed by fzf through the command line and needs to | ||
work in a standalone way on any Python 3 environment. | ||
This is why it alters PATH,making the assumption it's executed | ||
from within a source tree. Do not add dependencies unless they | ||
are in the source tree and added in SEARCH_PATHS. | ||
""" | ||
import argparse | ||
import sys | ||
import json | ||
from pathlib import Path | ||
import importlib.util | ||
|
||
|
||
HERE = Path(__file__).parent.resolve() | ||
SRC_ROOT = (HERE / ".." / ".." / ".." / "..").resolve() | ||
# make sure esprima is in the path | ||
SEARCH_PATHS = [ | ||
("third_party", "python", "esprima"), | ||
] | ||
|
||
for path in SEARCH_PATHS: | ||
path = Path(SRC_ROOT, *path) | ||
if path.exists(): | ||
sys.path.insert(0, str(path)) | ||
|
||
|
||
def get_test_objects(): | ||
"""Loads .perftestfuzzy and returns its content. | ||
The cache file is produced by the main fzf script and is used | ||
as a way to let the preview script grab test_objects from the | ||
mach command | ||
""" | ||
cache_file = Path(Path.home(), ".mozbuild", ".perftestfuzzy") | ||
with cache_file.open() as f: | ||
return json.loads(f.read()) | ||
|
||
|
||
def plain_display(taskfile): | ||
"""Preview window display. | ||
Returns the reST summary for the perf test script. | ||
""" | ||
# Lame way to catch the ScriptInfo class without loading mozperftest | ||
script_info = HERE / ".." / "script.py" | ||
spec = importlib.util.spec_from_file_location( | ||
name="script.py", location=str(script_info) | ||
) | ||
module = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(module) | ||
ScriptInfo = module.ScriptInfo | ||
|
||
with open(taskfile) as f: | ||
tasklist = [line.strip() for line in f] | ||
script_name = tasklist[0].split(" ")[-1] | ||
for ob in get_test_objects(): | ||
if ob["path"].endswith(script_name): | ||
print(ScriptInfo(ob["path"])) | ||
return | ||
|
||
|
||
def process_args(args): | ||
"""Process preview arguments.""" | ||
argparser = argparse.ArgumentParser() | ||
argparser.add_argument( | ||
"-t", | ||
"--tasklist", | ||
type=str, | ||
default=None, | ||
help="Path to temporary file containing the selected tasks", | ||
) | ||
return argparser.parse_args(args=args) | ||
|
||
|
||
def main(args=None): | ||
if args is None: | ||
args = sys.argv[1:] | ||
args = process_args(args) | ||
plain_display(args.tasklist) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.