xref: /xnu-10002.1.13/tools/lldbmacros/plugins/iosspeedtracer.py (revision 1031c584a5e37aff177559b9f69dbd3c8c3fd30a)
1*1031c584SApple OSS Distributions# Feed user stacks to ios/speedtracer
2*1031c584SApple OSS Distributions
3*1031c584SApple OSS Distributionsdef plugin_init(kernel_target, config, lldb_obj, isConnected):
4*1031c584SApple OSS Distributions    """ initialize the common data as required by plugin """
5*1031c584SApple OSS Distributions    return None
6*1031c584SApple OSS Distributions
7*1031c584SApple OSS Distributionsdef plugin_execute(command_name, result_output):
8*1031c584SApple OSS Distributions    """ The xnu framework will call this function with output of a command.
9*1031c584SApple OSS Distributions        The options for returning are as follows
10*1031c584SApple OSS Distributions        returns:  (status, outstr, further_cmds)
11*1031c584SApple OSS Distributions           status: Boolean - specifying whether plugin execution succeeded(True) or failed. If failed then xnu will stop doing any further work with this command.
12*1031c584SApple OSS Distributions           outstr: str - string output for user to be printed at the prompt
13*1031c584SApple OSS Distributions           further_cmds: [] of str - this holds set of commands to execute at the lldb prompt. Empty array if nothing is required.
14*1031c584SApple OSS Distributions    """
15*1031c584SApple OSS Distributions    import subprocess,os
16*1031c584SApple OSS Distributions    status = True
17*1031c584SApple OSS Distributions    outstr = ''
18*1031c584SApple OSS Distributions    further_cmds = []
19*1031c584SApple OSS Distributions
20*1031c584SApple OSS Distributions    if command_name != 'showtaskuserstacks' :
21*1031c584SApple OSS Distributions        status = False
22*1031c584SApple OSS Distributions    else:
23*1031c584SApple OSS Distributions        ios_process = subprocess.Popen([os.path.join(os.path.dirname(os.path.abspath(__file__)), "iosspeedtracer.sh")], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
24*1031c584SApple OSS Distributions
25*1031c584SApple OSS Distributions        outstr += ios_process.communicate(input=result_output)[0]
26*1031c584SApple OSS Distributions
27*1031c584SApple OSS Distributions    return (status, outstr, further_cmds)
28*1031c584SApple OSS Distributions
29*1031c584SApple OSS Distributionsdef plugin_cleanup():
30*1031c584SApple OSS Distributions    """ A cleanup call from xnu which is a signal to wrap up any open file descriptors etc. """
31*1031c584SApple OSS Distributions    return None
32*1031c584SApple OSS Distributions
33*1031c584SApple OSS Distributions
34