File: darwin.py

package info (click to toggle)
llvm-toolchain-6.0 1%3A6.0.1-10
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 598,080 kB
  • sloc: cpp: 3,046,253; ansic: 595,057; asm: 271,965; python: 128,926; objc: 106,554; sh: 21,906; lisp: 10,191; pascal: 6,094; ml: 5,544; perl: 5,265; makefile: 2,227; cs: 2,027; xml: 686; php: 212; csh: 117
file content (46 lines) | stat: -rw-r--r-- 1,661 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Provides a pre-kill method to run on macOS."""
from __future__ import print_function

# system imports
import subprocess
import sys

# third-party module imports
import six


def do_pre_kill(process_id, runner_context, output_stream, sample_time=3):
    """Samples the given process id, and puts the output to output_stream.

    @param process_id the local process to sample.

    @param runner_context a dictionary of details about the architectures
    and platform on which the given process is running.  Expected keys are
    archs (array of architectures), platform_name, platform_url, and
    platform_working_dir.

    @param output_stream file-like object that should be used to write the
    results of sampling.

    @param sample_time specifies the time in seconds that should be captured.
    """

    # Validate args.
    if runner_context is None:
        raise Exception("runner_context argument is required")
    if not isinstance(runner_context, dict):
        raise Exception("runner_context argument must be a dictionary")

    # We will try to run sample on the local host only if there is no URL
    # to a remote.
    if "platform_url" in runner_context and (
            runner_context["platform_url"] is not None):
        import pprint
        sys.stderr.write(
            "warning: skipping timeout pre-kill sample invocation because we "
            "don't know how to run on a remote yet. runner_context={}\n"
            .format(pprint.pformat(runner_context)))

    output = subprocess.check_output(['sample', six.text_type(process_id),
                                      str(sample_time)])
    output_stream.write(output)