tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 6848892b8f03f70911d3114636890f54ed4efa1e
parent 1e0691112bac90a0b89f5539e9bfa5bc6b17bf80
Author: Florian Quèze <florian@queze.net>
Date:   Tue,  4 Nov 2025 14:03:23 +0000

Bug 1998095 - Produce resource usage profiles for mach lint commands, r=jcristau.

Differential Revision: https://phabricator.services.mozilla.com/D271194

Diffstat:
Mpython/sites/lint.txt | 1+
Mtaskcluster/kinds/source-test/mozlint.yml | 3+++
Mtools/lint/mach_commands.py | 25++++++++++++++++++++++++-
3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/python/sites/lint.txt b/python/sites/lint.txt @@ -11,6 +11,7 @@ pypi:fluent.pygments==1.0 pypi:imagesize==1.4.1 pypi:more-itertools==7.2.0 pypi:pluggy==0.13.1 +pypi:psutil==5.9.4 pypi:py==1.11.0 pypi:pytz==2022.7.1 pypi:rstcheck==6.2.4 diff --git a/taskcluster/kinds/source-test/mozlint.yml b/taskcluster/kinds/source-test/mozlint.yml @@ -18,6 +18,9 @@ task-defaults: - type: file name: public/code-review/mozlint.json path: /builds/worker/mozlint.json + - type: file + name: public/profile_resource-usage.json + path: /builds/worker/profile_resource-usage.json run: using: mach use-caches: [checkout, pip, uv] diff --git a/tools/lint/mach_commands.py b/tools/lint/mach_commands.py @@ -4,11 +4,13 @@ import argparse import copy +import json import os from mach.decorators import Command, CommandArgument from mozbuild.base import BuildEnvironmentNotFoundException from mozbuild.base import MachCommandConditions as conditions +from mozsystemmonitor.resourcemonitor import SystemResourceMonitor here = os.path.abspath(os.path.dirname(__file__)) EXCLUSION_FILES = [ @@ -103,7 +105,28 @@ def lint(command_context, *runargs, **lintargs): setupargs = { "mach_command_context": command_context, } - return cli.run(*runargs, setupargs=setupargs, **lintargs) + + monitor = SystemResourceMonitor(poll_interval=0.1) + monitor.start() + + try: + ret = cli.run(*runargs, setupargs=setupargs, **lintargs) + finally: + monitor.stop() + + if os.environ.get("MOZ_AUTOMATION") == "1": + profile_path = "/builds/worker/profile_resource-usage.json" + else: + command_context._ensure_state_subdir_exists(".") + profile_path = command_context._get_state_filename( + "profile_build_resources.json" + ) + + with open(profile_path, "w", encoding="utf-8", newline="\n") as f: + to_write = json.dumps(monitor.as_profile(), separators=(",", ":")) + f.write(to_write) + + return ret @Command(