xref: /xnu-10063.141.1/tools/lldbmacros/plugins/iosspeedtracer.py (revision d8b80295118ef25ac3a784134bcf95cd8e88109f) !
1*d8b80295SApple OSS Distributions# Feed user stacks to ios/speedtracer
2*d8b80295SApple OSS Distributions
3*d8b80295SApple OSS Distributionsdef plugin_init(kernel_target, config, lldb_obj, isConnected):
4*d8b80295SApple OSS Distributions    """ initialize the common data as required by plugin """
5*d8b80295SApple OSS Distributions    return None
6*d8b80295SApple OSS Distributions
7*d8b80295SApple OSS Distributionsdef plugin_execute(command_name, result_output):
8*d8b80295SApple OSS Distributions    """ The xnu framework will call this function with output of a command.
9*d8b80295SApple OSS Distributions        The options for returning are as follows
10*d8b80295SApple OSS Distributions        returns:  (status, outstr, further_cmds)
11*d8b80295SApple 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*d8b80295SApple OSS Distributions           outstr: str - string output for user to be printed at the prompt
13*d8b80295SApple OSS Distributions           further_cmds: [] of str - this holds set of commands to execute at the lldb prompt. Empty array if nothing is required.
14*d8b80295SApple OSS Distributions    """
15*d8b80295SApple OSS Distributions    import subprocess,os
16*d8b80295SApple OSS Distributions    status = True
17*d8b80295SApple OSS Distributions    outstr = ''
18*d8b80295SApple OSS Distributions    further_cmds = []
19*d8b80295SApple OSS Distributions
20*d8b80295SApple OSS Distributions    if command_name != 'showtaskuserstacks' :
21*d8b80295SApple OSS Distributions        status = False
22*d8b80295SApple OSS Distributions    else:
23*d8b80295SApple 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*d8b80295SApple OSS Distributions
25*d8b80295SApple OSS Distributions        outstr += ios_process.communicate(input=result_output)[0]
26*d8b80295SApple OSS Distributions
27*d8b80295SApple OSS Distributions    return (status, outstr, further_cmds)
28*d8b80295SApple OSS Distributions
29*d8b80295SApple OSS Distributionsdef plugin_cleanup():
30*d8b80295SApple OSS Distributions    """ A cleanup call from xnu which is a signal to wrap up any open file descriptors etc. """
31*d8b80295SApple OSS Distributions    return None
32*d8b80295SApple OSS Distributions
33*d8b80295SApple OSS Distributions
34