commit b107062d2128c8ff8c4e26bcb12189317b79d00d
parent e37ce1ffacb1c4d2b38f06e0db5aabcc577ff70f
Author: Florian Quèze <florian@queze.net>
Date: Tue, 7 Oct 2025 06:56:16 +0000
Bug 1992181 - show 'artifact' markers for files found in the upload dir when stopping the resource monitor, r=ahal.
Differential Revision: https://phabricator.services.mozilla.com/D267454
Diffstat:
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/testing/mozbase/mozsystemmonitor/mozsystemmonitor/resourcemonitor.py b/testing/mozbase/mozsystemmonitor/mozsystemmonitor/resourcemonitor.py
@@ -404,13 +404,16 @@ class SystemResourceMonitor:
self.start_time = time.monotonic()
SystemResourceMonitor.instance = self
- def stop(self):
+ def stop(self, upload_dir=None):
"""Stop measuring system-wide CPU resource utilization.
You should call this if and only if you have called start(). You should
always pair a stop() with a start().
Currently, data is not available until you call stop().
+
+ Args:
+ upload_dir: Optional path to upload directory for artifact markers.
"""
if not self._process:
self._stopped = True
@@ -504,6 +507,27 @@ class SystemResourceMonitor:
SystemResourceUsage.instance = None
self.end_time = time.monotonic()
+ # Add event markers for files in upload directory
+ if upload_dir is None:
+ upload_dir = os.environ.get("UPLOAD_DIR") or os.environ.get(
+ "MOZ_UPLOAD_DIR"
+ )
+ if upload_dir and os.path.isdir(upload_dir):
+ try:
+ for filename in os.listdir(upload_dir):
+ filepath = os.path.join(upload_dir, filename)
+ if os.path.isfile(filepath):
+ stat = os.stat(filepath)
+ timestamp = self.convert_to_monotonic_time(stat.st_mtime)
+ marker_data = {
+ "type": "Artifact",
+ "filename": filename,
+ "size": stat.st_size,
+ }
+ self.events.append((timestamp, "artifact", marker_data))
+ except Exception as e:
+ warnings.warn(f"Failed to scan upload directory: {e}")
+
# Methods to record events alongside the monitored data.
@staticmethod
@@ -1161,6 +1185,23 @@ class SystemResourceMonitor:
],
},
{
+ "name": "Artifact",
+ "tableLabel": "{marker.data.filename} — {marker.data.size}",
+ "display": ["marker-chart", "marker-table"],
+ "data": [
+ {
+ "key": "filename",
+ "label": "Filename",
+ "format": "string",
+ },
+ {
+ "key": "size",
+ "label": "Size",
+ "format": "bytes",
+ },
+ ],
+ },
+ {
"name": "Mem",
"tooltipLabel": "{marker.name}",
"display": [],
diff --git a/testing/mozharness/mozharness/base/python.py b/testing/mozharness/mozharness/base/python.py
@@ -880,12 +880,14 @@ class ResourceMonitoringMixin(PerfherderResourceOptionsMixin):
if not self._resource_monitor:
return
- self._resource_monitor.stop()
+ # Get upload directory to pass to stop() for artifact markers
+ upload_dir = self.query_abs_dirs()["abs_blob_upload_dir"]
+
+ self._resource_monitor.stop(upload_dir=upload_dir)
self._log_resource_usage()
# Upload a JSON file containing the raw resource data.
try:
- upload_dir = self.query_abs_dirs()["abs_blob_upload_dir"]
if not os.path.exists(upload_dir):
os.makedirs(upload_dir)
with open(os.path.join(upload_dir, "resource-usage.json"), "w") as fh: