• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 datetime as dt
8from typing import TYPE_CHECKING
9
10from crossbench.probes.polling import PollingProbe
11from crossbench.probes.probe import ProbeValidationError
12
13if TYPE_CHECKING:
14  from crossbench.browsers.browser import Browser
15  from crossbench.env import HostEnvironment
16
17
18class SystemStatsProbe(PollingProbe):
19  """
20  General-purpose probe to periodically collect system-wide CPU and memory
21  stats on unix systems.
22  """
23  NAME = "system.stats"
24  CMD = ("ps", "-a", "-e", "-o", "pcpu,pmem,args", "-r")
25  IS_GENERAL_PURPOSE = True
26
27  def __init__(
28      self, interval: dt.timedelta = dt.timedelta(seconds=0.1)) -> None:
29    super().__init__(self.CMD, interval)
30
31  def validate_browser(self, env: HostEnvironment, browser: Browser) -> None:
32    super().validate_browser(env, browser)
33    if not (browser.platform.is_linux or browser.platform.is_macos):
34      raise ProbeValidationError(self, "Only supported on macOS and linux.")
35