tools/mac/power/driver.py
def Profile(self, scenario_config, profile_mode):
    """Cover the running of the scenario with DTrace and save the
    results.

    Args:
      profile_mode: A string describing the Profile mode between "wakeups"
      and "cpu_time".

    Raises:
      TimeoutExpired: When a DTrace process takes more than 30 seconds to
      terminate after the end of the scenario.
    """

    if scenario_config["browser"] != "Chromium":
      logging.error("Only Chromium can be profiled! Skipping.")
      return

    script_process = self.RunScenario(scenario_config)
    browser_process = self.FindBrowserProcess(scenario_config["browser"])

    # Set up the environment for correct dtrace execution.
    dtrace_env = os.environ.copy()
    dtrace_env["DYLD_SHARED_REGION"] = "avoid"

    pid_to_subprocess = {}

    with open('./dtrace_log.txt', "w") as dtrace_log:
      # Keep looking for child processes as long as the scenario is running.
      while script_process.poll() is None:

        # Let some time pass to limit the overhead of this script.
        time.sleep(0.100)
        logging.info("Looking for child processes")

        # Watch for new processes and follow those too.
        for pid in self.GetAllPids(browser_process):
          if profile_mode == "wakeups":
            probe_def = \
              f"mach_kernel::wakeup/pid == {pid}/ " \
              "{{ @[ustack(32)] = count(); }}"
          else:
            probe_def = \
              f"profile-1001/pid == {pid}/ {{ @[ustack(32)] = count(); }}"

          dtrace_args = [
              'sudo', 'dtrace', '-p', f"{pid}", "-o",
              f"{self.__output_dir}/{pid}.txt", '-n', probe_def
          ]

          if pid not in pid_to_subprocess:
            logging.info(f"Found new child!:{pid}")
            # No need to add |process| to |self._started_processeds| as it's
            # explicitly waited on later.
            process = subprocess.Popen(dtrace_args,
                    env=dtrace_env,
                    stdout=dtrace_log,
                    stderr=dtrace_log)
            pid_to_subprocess[pid] = process

    script_process.wait()

    # Cleanup executed before waiting for the DTrace processes so that they
    # see that the browse is gone.
    self.Teardown()

    for pid, dtrace_process in pid_to_subprocess.items():
      logging.info(f"Waiting for dtrace hooked on {pid} to exit")
      dtrace_process.wait(30)
Cover the running of the scenario with DTrace and save the
    results.

    Args:
      profile_mode: A string describing the Profile mode between "wakeups"
      and "cpu_time".

    Raises:
      TimeoutExpired: When a DTrace process takes more than 30 seconds to
      terminate after the end of the scenario.
    
Cover the running of the scenario with DTrace and save the
results.

A string describing the Profile mode between "wakeups"
and "cpu_time".

When a DTrace process takes more than 30 seconds to
terminate after the end of the scenario.
Cover the running of the scenario with DTrace and save the results . A string describing the Profile mode between " wakeups " and " cpu_time " . When a DTrace process takes more than 30 seconds to terminate after the end of the scenario .
def Profile(self, scenario_config, profile_mode):
    if scenario_config["browser"] != "Chromium":
      logging.error("Only Chromium can be profiled! Skipping.")
      return
    script_process = self.RunScenario(scenario_config)
    browser_process = self.FindBrowserProcess(scenario_config["browser"])
    dtrace_env = os.environ.copy()
    dtrace_env["DYLD_SHARED_REGION"] = "avoid"
    pid_to_subprocess = {}
    with open('./dtrace_log.txt', "w") as dtrace_log:
      while script_process.poll() is None:
        time.sleep(0.100)
        logging.info("Looking for child processes")
        for pid in self.GetAllPids(browser_process):
          if profile_mode == "wakeups":
            probe_def = \
              f"mach_kernel::wakeup/pid == {pid}/ " \
              "{{ @[ustack(32)] = count(); }}"
          else:
            probe_def = \
              f"profile-1001/pid == {pid}/ {{ @[ustack(32)] = count(); }}"
          dtrace_args = [
              'sudo', 'dtrace', '-p', f"{pid}", "-o",
              f"{self.__output_dir}/{pid}.txt", '-n', probe_def
          ]
          if pid not in pid_to_subprocess:
            logging.info(f"Found new child!:{pid}")
            process = subprocess.Popen(dtrace_args,
                    env=dtrace_env,
                    stdout=dtrace_log,
                    stderr=dtrace_log)
            pid_to_subprocess[pid] = process
    script_process.wait()
    self.Teardown()
    for pid, dtrace_process in pid_to_subprocess.items():
      logging.info(f"Waiting for dtrace hooked on {pid} to exit")
      dtrace_process.wait(30)
def Profile ( self , scenario_config , profile_mode ) : if scenario_config [ "browser" ] != "Chromium" : logging . error ( "Only Chromium can be profiled! Skipping." ) return script_process = self . RunScenario ( scenario_config ) browser_process = self . FindBrowserProcess ( scenario_config [ "browser" ] ) dtrace_env = os . environ . copy ( ) dtrace_env [ "DYLD_SHARED_REGION" ] = "avoid" pid_to_subprocess = { } with open ( './dtrace_log.txt' , "w" ) as dtrace_log : while script_process . poll ( ) is None : time . sleep ( 0.100 ) logging . info ( "Looking for child processes" ) for pid in self . GetAllPids ( browser_process ) : if profile_mode == "wakeups" : probe_def = f"mach_kernel::wakeup/pid == {pid}/ " "{{ @[ustack(32)] = count(); }}" else : probe_def = f"profile-1001/pid == {pid}/ {{ @[ustack(32)] = count(); }}" dtrace_args = [ 'sudo' , 'dtrace' , '-p' , f"{pid}" , "-o" , f"{self.__output_dir}/{pid}.txt" , '-n' , probe_def ] if pid not in pid_to_subprocess : logging . info ( f"Found new child!:{pid}" ) process = subprocess . Popen ( dtrace_args , env = dtrace_env , stdout = dtrace_log , stderr = dtrace_log ) pid_to_subprocess [ pid ] = process script_process . wait ( ) self . Teardown ( ) for pid , dtrace_process in pid_to_subprocess . items ( ) : logging . info ( f"Waiting for dtrace hooked on {pid} to exit" ) dtrace_process . wait ( 30 )
Cover the running of the scenario with DTrace and save the
results.
Cover the running of the scenario with DTrace and save the results .
"""Cover the running of the scenario with DTrace and save the
    results.

    Args:
      profile_mode: A string describing the Profile mode between "wakeups"
      and "cpu_time".

    Raises:
      TimeoutExpired: When a DTrace process takes more than 30 seconds to
      terminate after the end of the scenario.
    """ # Set up the environment for correct dtrace execution. # Keep looking for child processes as long as the scenario is running. # Let some time pass to limit the overhead of this script. # Watch for new processes and follow those too. # No need to add |process| to |self._started_processeds| as it's # explicitly waited on later. # Cleanup executed before waiting for the DTrace processes so that they # see that the browse is gone.
self
scenario_config
profile_mode