Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86f847e55e | ||
|
|
d77751cff6 | ||
|
|
8b327f5e24 | ||
|
|
d75e005862 |
No files matched your search
@@ -0,0 +1,91 @@
|
||||
# same-site-diag.yml - hunt scaffolding, never merged. Runs only on a push to a `hunt/same-site**` branch.
|
||||
#
|
||||
# tests/test_fission_strategy1_bench.py::test_same_site_other_port_stays_in_process was red in 14 of 30 runs of the whole
|
||||
# e2e suite ("a same-site frame changed the processes of the sites: [P] -> [P, P2]") and never when run alone. This job
|
||||
# repeats a copy of it that records what P2 is: whose child, when it was born against the instants of the test, and what the
|
||||
# engine logged when it started it. Four workers on this file alone gave 0 red runs of 40; with other e2e tests running beside it, 9 of 40: that phase gave the table of the processes and the engine's log.
|
||||
# Now: one page opened by a retail Firefox of the same version and by ours, started the same way, with the
|
||||
# processes named by site.
|
||||
name: same-site diag
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ['hunt/same-site**']
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
|
||||
jobs:
|
||||
diag:
|
||||
name: what is the second process
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 60
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
steps:
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||
with: { fetch-depth: 1 }
|
||||
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
|
||||
with: { python-version: '3.11' }
|
||||
- name: Install wrapper + test deps (+ pinned Playwright)
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install ".[dev]"
|
||||
python -m pip install "playwright==$(cat scripts/playwright_pin.txt)"
|
||||
- name: System deps (xvfb + Firefox runtime libs)
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y xvfb
|
||||
sudo "$(which python)" -m playwright install-deps firefox
|
||||
- name: Fetch the published firefox binary
|
||||
run: echo "FF=$(python -m invisible_playwright fetch | tail -1)" >> "$GITHUB_ENV"
|
||||
- name: Retail Firefox of the same version
|
||||
run: |
|
||||
set -eu
|
||||
mkdir -p retail evidence/probe
|
||||
curl -fsSL --retry 3 -o retail/firefox.tar.xz "https://ftp.mozilla.org/pub/firefox/releases/159.0/linux-x86_64/en-US/firefox-159.0.tar.xz"
|
||||
sha256sum retail/firefox.tar.xz | tee evidence/probe/retail.sha256
|
||||
tar -xJf retail/firefox.tar.xz -C retail
|
||||
grep -E "^(Version|BuildID)=" retail/firefox/application.ini | tee evidence/probe/retail.version
|
||||
grep -E "^(Version|BuildID)=" "$(dirname "$FF")/application.ini" | tee evidence/probe/ours.version
|
||||
echo "RETAIL=$PWD/retail/firefox/firefox" >> "$GITHUB_ENV"
|
||||
- name: Which content processes one page starts, retail and ours
|
||||
env:
|
||||
PYTHONUNBUFFERED: "1"
|
||||
run: |
|
||||
set -u
|
||||
probe() { # label firefox extra args...
|
||||
label="$1"; bin="$2"; shift 2
|
||||
for n in 1 2 3; do
|
||||
xvfb-run -a python scripts/second_process_probe.py --firefox "$bin" --label "$label" \
|
||||
--out "evidence/probe/${label}_${n}.json" --seconds 18 "$@" 2>&1 | tee -a evidence/probe/probe.log || true
|
||||
done
|
||||
}
|
||||
probe retail_site "$RETAIL" --pool 0
|
||||
probe retail_blank "$RETAIL" --pool 0 --blank
|
||||
probe ours_bare_site "$FF" --pool 0
|
||||
probe ours_lib_site "$FF" --pool 0 --via-wrapper
|
||||
probe ours_lib_site_newtab_off "$FF" --pool 0 --via-wrapper --pref browser.newtabpage.enabled=false
|
||||
probe ours_lib_site_preload_off "$FF" --pool 0 --via-wrapper --pref browser.newtab.preload=false
|
||||
probe ours_lib_site_crossword_off "$FF" --pool 0 --via-wrapper --pref browser.newtabpage.activity-stream.widgets.system.crossword.enabled=false
|
||||
probe ours_lib_site_widgets_off "$FF" --pool 0 --via-wrapper --pref browser.newtabpage.activity-stream.widgets.system.enabled=false
|
||||
{
|
||||
echo "## One page, which content processes (kind tab), names by site"
|
||||
echo
|
||||
echo '```'
|
||||
cat evidence/probe/retail.version evidence/probe/ours.version
|
||||
cat evidence/probe/probe.log
|
||||
echo '```'
|
||||
} >> "$GITHUB_STEP_SUMMARY"
|
||||
- name: Upload all the evidence
|
||||
if: always()
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
|
||||
with:
|
||||
name: same-site-diag-${{ github.run_id }}
|
||||
path: evidence
|
||||
if-no-files-found: warn
|
||||
retention-days: 14
|
||||
@@ -0,0 +1,85 @@
|
||||
"""Hunt scaffolding (never merged): reads the records of tests/test_fission_strategy1_bench.py::test_diag_same_site.
|
||||
|
||||
python scripts/same_site_diag_report.py DIR
|
||||
|
||||
Prints, in markdown, how many runs changed the set of the processes of the sites, and for each one that did: the process that
|
||||
appeared, its parent (the browser of the test or another one), when it was born against the instants of the test, whether it
|
||||
was still there ten seconds later, and what the engine logged about starting it.
|
||||
"""
|
||||
import collections
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
ABOUT_PROCESSES = re.compile(r"webIsolated|Launch|launch|GetNewOrUsed|remoteType|Isolat|Prealloc|process switch|ProcessSwitch")
|
||||
|
||||
|
||||
def main(argv):
|
||||
folder = argv[1]
|
||||
recs = []
|
||||
for path in sorted(glob.glob(os.path.join(folder, "rec_*.json"))):
|
||||
with open(path, encoding="utf-8") as fh:
|
||||
recs.append(json.load(fh))
|
||||
by_arm = collections.Counter((r["arm"], bool(r.get("changed"))) for r in recs)
|
||||
print("## Same-site control, %s: %d runs\n" % (os.path.basename(os.path.normpath(folder)), len(recs)))
|
||||
print("| arm | runs | changed |\n|---|---|---|")
|
||||
for arm in sorted({r["arm"] for r in recs}):
|
||||
print("| %s | %d | %d |" % (arm, by_arm[(arm, True)] + by_arm[(arm, False)], by_arm[(arm, True)]))
|
||||
print()
|
||||
shown_green = 0
|
||||
for r in recs:
|
||||
if not r.get("changed"):
|
||||
if shown_green >= 2 or not glob.glob(os.path.join(folder, "moz_%s*" % r["tag"])):
|
||||
continue
|
||||
shown_green += 1
|
||||
t = r["t"]
|
||||
print("#### %s (%s): instants and names" % (r["tag"], "RED" if r.get("changed") else "green, for comparison"))
|
||||
print("- instants from start: %s" % {k: round(v - t["start"], 2) for k, v in t.items()})
|
||||
print("- names over time (pid, name, seen at, born at): %s"
|
||||
% [(n["pid"], n["name"], round(n["t"] - t["start"], 2), round(n["born"] - t["start"], 2)) for n in r.get("names", [])])
|
||||
rows = r["tables"].get("after", [])
|
||||
after = {row["pid"]: row for row in rows}
|
||||
parents = [row for row in rows if row["kind"] == "parent"]
|
||||
r.setdefault("before", [])
|
||||
r.setdefault("after", [])
|
||||
print("### %s: %s -> %s\n" % (r["tag"], r["before"], r["after"]))
|
||||
print("- browsers below the worker at the second read: %s"
|
||||
% [(p["pid"], "born %+.1f s" % (p["born"] - t["start"])) for p in parents])
|
||||
own = {after[p]["ppid"] for p in r["before"] if p in after}
|
||||
for pid in sorted(set(r["after"]) - set(r["before"])):
|
||||
row = after.get(pid)
|
||||
if not row:
|
||||
print("- pid %d: not in the table" % pid)
|
||||
continue
|
||||
whose = "the browser of the page's process" if row["ppid"] in own else "ANOTHER browser"
|
||||
print("- NEW pid %d: parent %d (%s), name %r, born at start%+.2f s; goto done %+.2f, first read %+.2f, "
|
||||
"frame added %+.2f, leaf reported %+.2f, second read %+.2f; threads %s, rss %s MB; still there 10 s later: %s"
|
||||
% (pid, row["ppid"], whose, row["name"], row["born"] - t["start"], t["goto_done"] - t["start"],
|
||||
t["before_read"] - t["start"], t["frame_added"] - t["start"], t["leaf_reported"] - t["start"],
|
||||
t["after_read"] - t["start"], row["threads"], row["rss_mb"], pid in r.get("later", [])))
|
||||
print(" - args: %s" % " ".join(row["args"]))
|
||||
for pid in sorted(set(r["before"]) - set(r["after"])):
|
||||
print("- GONE pid %d" % pid)
|
||||
print("- frames after: %s" % r.get("frames"))
|
||||
print("- content processes at the second read: %s"
|
||||
% [(x["pid"], x["name"], "born %+.2f" % (x["born"] - t["start"])) for x in rows if x["kind"] != "parent"])
|
||||
logs = sorted(glob.glob(os.path.join(folder, "moz_%s*" % r["tag"])))
|
||||
print("- engine log files: %s" % [os.path.basename(p) for p in logs])
|
||||
for path in logs:
|
||||
if ".child-" in os.path.basename(path):
|
||||
continue
|
||||
with open(path, encoding="utf-8", errors="replace") as fh:
|
||||
keep = [line.rstrip() for line in fh if ABOUT_PROCESSES.search(line)]
|
||||
print("\n<details><summary>%s: %d lines about processes (first 260)</summary>\n\n```"
|
||||
% (os.path.basename(path), len(keep)))
|
||||
for line in keep[:260]:
|
||||
print(line[:420])
|
||||
print("```\n</details>\n")
|
||||
print()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
||||
@@ -0,0 +1,245 @@
|
||||
"""Hunt scaffolding (never merged): which content processes a Firefox starts for ONE page of one site, over time.
|
||||
|
||||
python scripts/second_process_probe.py --firefox PATH --label NAME --out FILE [--seconds 20] [--pool N] [--blank]
|
||||
|
||||
Starts the given Firefox by itself (no driver, no library: `firefox --headless --profile DIR URL`) on a new profile, with a
|
||||
local page of the site `a.test` (or, with --blank, `about:blank`), and samples the names of its content processes every
|
||||
100 ms. The profile sets `fission.processSiteNames`, with which a content process that hosts a site is named by that site
|
||||
(ContentChild::SetProcessName), so the table says for which site each process is, and when it got it. Linux only: no other
|
||||
system names a process.
|
||||
|
||||
The question it answers: the same-site control of the wrapper's suite saw a second "Isolated Web Content" process appear
|
||||
a few seconds after the first, in every run, with nothing asked by the page. Does a retail Firefox do the same?
|
||||
"""
|
||||
import argparse
|
||||
import hashlib
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
|
||||
PREFS = {
|
||||
"fission.autostart": True,
|
||||
"fission.webContentIsolationStrategy": 1,
|
||||
"dom.ipc.processCount.webIsolated": 4,
|
||||
"fission.processSiteNames": True,
|
||||
"network.dns.localDomains": "a.test,b.test,c.test",
|
||||
# a new profile shows no first-run page; the New Tab page and its preloading are left as the browser ships them
|
||||
"browser.shell.checkDefaultBrowser": False,
|
||||
"browser.aboutwelcome.enabled": False,
|
||||
"startup.homepage_welcome_url": "",
|
||||
"startup.homepage_welcome_url.additional": "",
|
||||
"startup.homepage_override_url": "",
|
||||
"browser.startup.homepage_override.mstone": "ignore",
|
||||
"datareporting.policy.dataSubmissionEnabled": False,
|
||||
"datareporting.policy.dataSubmissionPolicyBypassNotification": True,
|
||||
"toolkit.telemetry.reportingpolicy.firstRun": False,
|
||||
"termsofuse.bypassNotification": True,
|
||||
"browser.preonboarding.enabled": False,
|
||||
"app.update.enabled": False,
|
||||
"browser.sessionstore.resume_from_crash": False,
|
||||
}
|
||||
|
||||
|
||||
def pref_line(name, value):
|
||||
return "user_pref(%s, %s);" % (json.dumps(name), json.dumps(value))
|
||||
|
||||
|
||||
def serve():
|
||||
class Handler(http.server.BaseHTTPRequestHandler):
|
||||
hits = []
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
def do_GET(self):
|
||||
Handler.hits.append({"t": round(time.time(), 3), "host": self.headers.get("Host"), "path": self.path})
|
||||
body = b"<!doctype html><title>plain</title><p>plain" if self.path == "/plain" else b""
|
||||
self.send_response(200 if body else 404)
|
||||
self.send_header("Content-Type", "text/html; charset=utf-8")
|
||||
self.send_header("Content-Length", str(len(body)))
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
||||
server.daemon_threads = True
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
return server, Handler.hits
|
||||
|
||||
|
||||
def sha256(path):
|
||||
digest = hashlib.sha256()
|
||||
with open(path, "rb") as fh:
|
||||
for chunk in iter(lambda: fh.read(1 << 20), b""):
|
||||
digest.update(chunk)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def sample_into(names, seen, children, started):
|
||||
import psutil
|
||||
|
||||
for child in children:
|
||||
try:
|
||||
cmd = child.cmdline()
|
||||
if "-contentproc" not in cmd:
|
||||
continue
|
||||
key = (child.name(), cmd[-1])
|
||||
if seen.get(child.pid) != key:
|
||||
seen[child.pid] = key
|
||||
names.append({"at": round(time.time() - started, 2), "pid": child.pid, "name": key[0], "kind": key[1],
|
||||
"born": round(child.create_time() - started, 2),
|
||||
"rss_mb": round(child.memory_info().rss / 1e6, 1)})
|
||||
except (psutil.Error, IndexError):
|
||||
continue
|
||||
|
||||
|
||||
def final_table(seen, started):
|
||||
import psutil
|
||||
|
||||
final = []
|
||||
for pid, (name, kind) in sorted(seen.items()):
|
||||
try:
|
||||
child = psutil.Process(pid)
|
||||
final.append({"pid": pid, "name": child.name(), "kind": kind, "born": round(child.create_time() - started, 2),
|
||||
"rss_mb": round(child.memory_info().rss / 1e6, 1)})
|
||||
except psutil.Error:
|
||||
final.append({"pid": pid, "name": name, "kind": kind, "gone": True})
|
||||
return final
|
||||
|
||||
|
||||
def remote_types(log_base):
|
||||
"""pid -> the remote types the engine's log says that process was given, in order."""
|
||||
import glob
|
||||
import re
|
||||
|
||||
types = {}
|
||||
line = re.compile(r"Setting remoteType of process (\d+) to (\S+)|Changing remoteType of process (\d+) from \S+ to (\S+)")
|
||||
for path in glob.glob(log_base + "*"):
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="replace") as fh:
|
||||
for text in fh:
|
||||
m = line.search(text)
|
||||
if m:
|
||||
pid, kind = (m.group(1), m.group(2)) if m.group(1) else (m.group(3), m.group(4))
|
||||
types.setdefault(int(pid), []).append(kind)
|
||||
except OSError:
|
||||
continue
|
||||
return types
|
||||
|
||||
|
||||
def report(args, url, names, final, hits, started, extra=None):
|
||||
types = remote_types(os.path.splitext(args.out)[0] + ".moz")
|
||||
for row in final:
|
||||
row["remote_type"] = " -> ".join(types.get(row["pid"], [])) or None
|
||||
record = {"label": args.label, "firefox": args.firefox, "firefox_sha256": sha256(args.firefox), "url": url, "pool": args.pool,
|
||||
"prefs": args.pref, "via_wrapper": args.via_wrapper, "seconds": args.seconds, "names": names, "final": final,
|
||||
"hits": [dict(h, t=round(h["t"] - started, 2)) for h in hits]}
|
||||
record.update(extra or {})
|
||||
with open(args.out, "w", encoding="utf-8") as fh:
|
||||
json.dump(record, fh, indent=1)
|
||||
tabs = [f for f in final if f["kind"] == "tab" and not f.get("gone")]
|
||||
print("%-26s url=%-12s pool=%-2s %s page asked at %s; tab processes at the end: %s" % (
|
||||
args.label, url.split("/")[-1][:12], args.pool, " ".join(args.pref), [h["t"] for h in hits if h["path"] == "/plain"][:1],
|
||||
[(f["remote_type"] or f["name"], "born %+.2f" % f["born"], "%s MB" % f["rss_mb"]) for f in tabs]))
|
||||
print(" names over time: %s" % [(n["at"], n["pid"], n["name"]) for n in names if n["kind"] == "tab"])
|
||||
return 0
|
||||
|
||||
|
||||
def via_wrapper(args, prefs, url, server, hits):
|
||||
"""The engine started by the library, as the suite does it; the page opened with page.goto."""
|
||||
import psutil
|
||||
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
keep = ("fission.", "dom.ipc.", "network.dns.localDomains")
|
||||
extra_prefs = {k: v for k, v in prefs.items() if k.startswith(keep)}
|
||||
for item in args.pref: # a pref named on the command line always reaches the engine
|
||||
name, _, value = item.partition("=")
|
||||
extra_prefs[name] = json.loads(value)
|
||||
names, seen, marks = [], {}, {}
|
||||
os.environ["MOZ_LOG"] = "Process:5,ProcessIsolation:5,timestamp,sync"
|
||||
os.environ["MOZ_LOG_FILE"] = os.path.splitext(args.out)[0] + ".moz"
|
||||
started = time.time()
|
||||
try:
|
||||
with InvisiblePlaywright(seed=42, binary_path=args.firefox, humanize=False, headless=True,
|
||||
extra_prefs=extra_prefs) as browser:
|
||||
marks["launched"] = round(time.time() - started, 2)
|
||||
page = browser.new_context().new_page()
|
||||
marks["page_open"] = round(time.time() - started, 2)
|
||||
if not args.blank:
|
||||
page.goto(url)
|
||||
marks["goto_done"] = round(time.time() - started, 2)
|
||||
while time.time() - started < args.seconds:
|
||||
sample_into(names, seen, psutil.Process(os.getpid()).children(recursive=True), started)
|
||||
page.wait_for_timeout(100)
|
||||
final = final_table(seen, started)
|
||||
finally:
|
||||
server.shutdown()
|
||||
print(" instants: %s" % marks)
|
||||
return report(args, url, names, final, hits, started, {"instants": marks})
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
import psutil
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--firefox", required=True)
|
||||
ap.add_argument("--label", required=True)
|
||||
ap.add_argument("--out", required=True)
|
||||
ap.add_argument("--seconds", type=float, default=20.0)
|
||||
ap.add_argument("--pool", type=int, default=0, help="dom.ipc.processPrelaunch.fission.number; -1 leaves the default")
|
||||
ap.add_argument("--blank", action="store_true", help="open about:blank and no page of a site")
|
||||
ap.add_argument("--pref", action="append", default=[], help="name=json value, added to the profile (repeatable)")
|
||||
ap.add_argument("--via-wrapper", action="store_true",
|
||||
help="start the engine with the library (InvisiblePlaywright) and open the page with page.goto")
|
||||
args = ap.parse_args(argv)
|
||||
|
||||
server, hits = serve()
|
||||
url = "about:blank" if args.blank else "http://a.test:%d/plain" % server.server_address[1]
|
||||
profile = tempfile.mkdtemp(prefix="probe_profile_")
|
||||
prefs = dict(PREFS)
|
||||
if args.pool >= 0:
|
||||
prefs["dom.ipc.processPrelaunch.fission.number"] = args.pool
|
||||
for item in args.pref:
|
||||
name, _, value = item.partition("=")
|
||||
prefs[name] = json.loads(value)
|
||||
if args.via_wrapper:
|
||||
return via_wrapper(args, prefs, url, server, hits)
|
||||
with open(os.path.join(profile, "user.js"), "w", encoding="utf-8") as fh:
|
||||
fh.write("\n".join(pref_line(k, v) for k, v in prefs.items()) + "\n")
|
||||
log_base = os.path.splitext(args.out)[0] + ".moz"
|
||||
env = dict(os.environ, MOZ_LOG="Process:5,ProcessIsolation:5,timestamp,sync", MOZ_LOG_FILE=log_base,
|
||||
MOZ_CRASHREPORTER_DISABLE="1")
|
||||
started = time.time()
|
||||
proc = subprocess.Popen([args.firefox, "--headless", "--no-remote", "--profile", profile, url], env=env,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
names, seen = [], {}
|
||||
try:
|
||||
while time.time() - started < args.seconds:
|
||||
try:
|
||||
children = psutil.Process(proc.pid).children(recursive=True)
|
||||
except psutil.Error:
|
||||
children = []
|
||||
sample_into(names, seen, children, started)
|
||||
time.sleep(0.1)
|
||||
final = final_table(seen, started)
|
||||
finally:
|
||||
try:
|
||||
for child in psutil.Process(proc.pid).children(recursive=True):
|
||||
child.kill()
|
||||
except psutil.Error:
|
||||
pass
|
||||
proc.kill()
|
||||
proc.wait(10)
|
||||
server.shutdown()
|
||||
shutil.rmtree(profile, ignore_errors=True)
|
||||
return report(args, url, names, final, hits, started)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -460,3 +460,123 @@ def test_the_frames_have_their_urls_when_goto_returns(browser, cross_site_loop,
|
||||
empty.append((i, urls))
|
||||
page.context.close()
|
||||
assert not empty, "frames with no url right after goto, in %d of 50 runs: %s" % (len(empty), empty[:3])
|
||||
|
||||
|
||||
# ── hunt scaffolding (never merged): what is the second process of the same-site control? ─────────────────────
|
||||
# The control above was red in 14 of 30 suite runs with "[P] -> [P, P2]". These copies of it record, for every run, the
|
||||
# table of the engine's processes below the worker (pid, parent, name, birth), the instants of the test, and (arm `log`)
|
||||
# the engine's own log of why it starts a content process (MOZ_LOG Process and ProcessIsolation, parent process).
|
||||
|
||||
DIAG_DIR = os.environ.get("DIAG_DIR") or ""
|
||||
DIAG_REPS = int(os.environ.get("DIAG_REPS") or 0)
|
||||
|
||||
|
||||
def process_table(engine_dir):
|
||||
import psutil
|
||||
|
||||
rows = []
|
||||
try:
|
||||
procs = psutil.Process(os.getpid()).children(recursive=True)
|
||||
except psutil.Error:
|
||||
return rows
|
||||
for proc in procs:
|
||||
try:
|
||||
if not os.path.normcase(proc.exe()).startswith(os.path.normcase(engine_dir)):
|
||||
continue
|
||||
cmd = proc.cmdline()
|
||||
rows.append({"pid": proc.pid, "ppid": proc.ppid(), "name": proc.name(), "born": round(proc.create_time(), 3),
|
||||
"kind": (cmd[-1] if "-contentproc" in cmd else "parent"),
|
||||
"args": [a[:48] for a in cmd[1:] if not a.startswith("/")][:24],
|
||||
"threads": proc.num_threads(), "rss_mb": round(proc.memory_info().rss / 1e6, 1)})
|
||||
except (psutil.Error, ValueError, IndexError):
|
||||
continue
|
||||
return sorted(rows, key=lambda r: r["born"])
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.parametrize("rep", range(DIAG_REPS))
|
||||
def test_diag_cross_site_load(rep, page, cross_site_loop, engine_dir):
|
||||
"""The test that runs just before the control in the suite, as load and as its predecessor."""
|
||||
test_cross_site_iframe_gets_its_own_process(page, cross_site_loop, engine_dir)
|
||||
|
||||
|
||||
@pytest.mark.e2e
|
||||
@pytest.mark.parametrize("rep", range(DIAG_REPS))
|
||||
@pytest.mark.parametrize("arm", (os.environ.get("DIAG_ARMS") or "log,nolog").split(","))
|
||||
def test_diag_same_site(arm, rep, firefox_binary, cross_site_loop, engine_dir, monkeypatch):
|
||||
from invisible_playwright import InvisiblePlaywright
|
||||
|
||||
tag = "%s_%02d_%s" % (arm, rep, os.environ.get("PYTEST_XDIST_WORKER", "gw"))
|
||||
log_base = os.path.join(DIAG_DIR, "moz_" + tag)
|
||||
if arm == "log":
|
||||
monkeypatch.setenv("MOZ_LOG", "Process:5,ProcessIsolation:5,timestamp,sync")
|
||||
monkeypatch.setenv("MOZ_LOG_FILE", log_base)
|
||||
rec = {"tag": tag, "arm": arm, "worker_pid": os.getpid(), "t": {}, "tables": {}}
|
||||
|
||||
def mark(key):
|
||||
rec["t"][key] = round(time.time(), 3)
|
||||
|
||||
mark("start")
|
||||
names, stop = [], threading.Event()
|
||||
|
||||
def sample(): # every content process below the worker, each time its name changes (a process is renamed by its type)
|
||||
import psutil
|
||||
|
||||
seen = {}
|
||||
while not stop.is_set():
|
||||
try:
|
||||
for proc in psutil.Process(os.getpid()).children(recursive=True):
|
||||
try:
|
||||
cmd = proc.cmdline()
|
||||
if "-contentproc" in cmd and cmd[-1] == "tab" and seen.get(proc.pid) != proc.name():
|
||||
seen[proc.pid] = proc.name()
|
||||
names.append({"t": round(time.time(), 3), "pid": proc.pid, "name": seen[proc.pid],
|
||||
"born": round(proc.create_time(), 3)})
|
||||
except (psutil.Error, IndexError):
|
||||
continue
|
||||
except psutil.Error:
|
||||
pass
|
||||
stop.wait(0.05)
|
||||
|
||||
sampler = threading.Thread(target=sample, daemon=True)
|
||||
sampler.start()
|
||||
try:
|
||||
with InvisiblePlaywright(seed=42, binary_path=firefox_binary, humanize=False, headless=True,
|
||||
extra_prefs=dict(FISSION_ON, **{"dom.ipc.processPrelaunch.fission.number": 0})) as browser:
|
||||
page = browser.new_context().new_page()
|
||||
page.set_default_timeout(3000)
|
||||
page.set_default_navigation_timeout(20000)
|
||||
mark("page_open")
|
||||
page.goto(cross_site_loop["plain"])
|
||||
mark("goto_done")
|
||||
before = quiet(engine_dir)
|
||||
mark("before_read")
|
||||
rec["tables"]["before"] = process_table(engine_dir)
|
||||
page.evaluate("(u) => { const f = document.createElement('iframe'); f.id = 's'; f.src = u;"
|
||||
" document.body.appendChild(f); }", cross_site_loop["leaf"])
|
||||
mark("frame_added")
|
||||
rec["leaf_reported"] = wait_for(page, lambda: any(r["path"] == "/report/loaded" and r["query"]["path"] == ["/leaf"]
|
||||
for r in cross_site_loop["reports"]))
|
||||
mark("leaf_reported")
|
||||
after = quiet(engine_dir)
|
||||
mark("after_read")
|
||||
rec["tables"]["after"] = process_table(engine_dir)
|
||||
rec["before"], rec["after"], rec["changed"] = sorted(before), sorted(after), after != before
|
||||
if after != before:
|
||||
page.wait_for_timeout(10000)
|
||||
mark("ten_seconds_later")
|
||||
rec["tables"]["ten_seconds_later"] = process_table(engine_dir)
|
||||
rec["later"] = sorted(site_processes(engine_dir))
|
||||
rec["frames"] = [frame.url for frame in page.frames]
|
||||
finally:
|
||||
mark("closed")
|
||||
stop.set()
|
||||
sampler.join(2)
|
||||
rec["names"] = names
|
||||
if DIAG_DIR:
|
||||
Path(DIAG_DIR, "rec_%s.json" % tag).write_text(json.dumps(rec, indent=1), encoding="utf-8")
|
||||
if not rec.get("changed") and rep >= 3: # keep the engine's log of the red runs and of two green ones
|
||||
for path in Path(DIAG_DIR).glob("moz_%s*" % tag):
|
||||
path.unlink()
|
||||
assert rec["leaf_reported"]
|
||||
assert not rec["changed"], "a same-site frame changed the processes of the sites: %s -> %s" % (rec["before"], rec["after"])
|
||||
Reference in new issue
Block a user