xref: /xnu-12377.41.6/tools/lldbmacros/plugins/zprint_perf_log.py (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions# A basic Plugin that creates performance reports from zprint output
2*bbb1b6f9SApple OSS Distributionskern_version = None
3*bbb1b6f9SApple OSS Distributions
4*bbb1b6f9SApple OSS Distributionsdef plugin_init(kernel_target, config, lldb_obj, isConnected):
5*bbb1b6f9SApple OSS Distributions    """ initialize the common data as required by plugin """
6*bbb1b6f9SApple OSS Distributions    global kern_version
7*bbb1b6f9SApple OSS Distributions    kern_version = str(kernel_target.version)
8*bbb1b6f9SApple OSS Distributions
9*bbb1b6f9SApple OSS Distributionsdef plugin_execute(command_name, result_output):
10*bbb1b6f9SApple OSS Distributions    """ The xnu framework will call this function with output of a command.
11*bbb1b6f9SApple OSS Distributions        The options for returning are as follows
12*bbb1b6f9SApple OSS Distributions        returns:  (status, outstr, further_cmds)
13*bbb1b6f9SApple 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.
14*bbb1b6f9SApple OSS Distributions           outstr: str - string output for user to be printed at the prompt
15*bbb1b6f9SApple OSS Distributions           further_cmds: [] of str - this holds set of commands to execute at the lldb prompt. Empty array if nothing is required.
16*bbb1b6f9SApple OSS Distributions    """
17*bbb1b6f9SApple OSS Distributions    status = True
18*bbb1b6f9SApple OSS Distributions    outstr = 'Nothing to be done here'
19*bbb1b6f9SApple OSS Distributions    further_cmds = []
20*bbb1b6f9SApple OSS Distributions    further_cmds.append("memstats -- --plugin zprint_perf_log ")
21*bbb1b6f9SApple OSS Distributions
22*bbb1b6f9SApple OSS Distributions    if command_name != 'zprint' :
23*bbb1b6f9SApple OSS Distributions        status = False
24*bbb1b6f9SApple OSS Distributions    else:
25*bbb1b6f9SApple OSS Distributions        num_zones = len(result_output.split("\n")) -1
26*bbb1b6f9SApple OSS Distributions        outstr += "Num of zones analyzed =" + str(num_zones) + "\n"
27*bbb1b6f9SApple OSS Distributions    return (status, outstr, further_cmds)
28*bbb1b6f9SApple OSS Distributions
29*bbb1b6f9SApple OSS Distributionsdef plugin_cleanup():
30*bbb1b6f9SApple OSS Distributions    """ A cleanup call from xnu which is a signal to wrap up any open file descriptors etc. """
31*bbb1b6f9SApple OSS Distributions    return None
32