1# A basic Plugin that creates performance reports from zprint output
2import urllib, urllib2
3
4kern_version = None
5def plugin_init(kernel_target, config, lldb_obj, isConnected):
6    """ initialize the common data as required by plugin """
7    global kern_version
8    kern_version = str(kernel_target.version)
9
10def plugin_execute(command_name, result_output):
11    """ The xnu framework will call this function with output of a command.
12        The options for returning are as follows
13        returns:  (status, outstr, further_cmds)
14           status: Boolean - specifying whether plugin execution succeeded(True) or failed. If failed then xnu will stop doing any further work with this command.
15           outstr: str - string output for user to be printed at the prompt
16           further_cmds: [] of str - this holds set of commands to execute at the lldb prompt. Empty array if nothing is required.
17    """
18    status = True
19    outstr = ''
20    further_cmds = []
21    submitvars = {}
22    submitvars['type']="text"
23    submitvars['log']=result_output
24
25    submiturl = "http://speedtracer.apple.com/trace/analyze?format=xml"
26    encoded_data = urllib.urlencode(submitvars)
27    request = urllib2.Request(submiturl, encoded_data, {"Accept":"application/xml"})
28    response = urllib2.urlopen(request)
29
30    status = response.info()['status']
31    if status == 201 or status == '201':
32        outstr += "CrashTracer data found at " + response.info()['location']
33        newurl = response.info()['location']
34        import webbrowser
35        webbrowser.open(newurl)
36        status = True
37    else:
38        outstr += "unknown response from server \n" + str(response.info())
39        status = False
40
41    return (status, outstr, further_cmds)
42
43def plugin_cleanup():
44    """ A cleanup call from xnu which is a signal to wrap up any open file descriptors etc. """
45    return None
46
47
48