]> git.saurik.com Git - apple/xnu.git/blame_incremental - tools/lldbmacros/plugins/speedtracer.py
xnu-4570.1.46.tar.gz
[apple/xnu.git] / tools / lldbmacros / plugins / speedtracer.py
... / ...
CommitLineData
1import json, urllib, urllib2
2from urllib2 import Request, urlopen, HTTPError
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['log_content']=result_output
23
24 submiturl = "https://speedtracer.apple.com/api/v2/trace"
25 encoded_data = urllib.urlencode(submitvars)
26 request = urllib2.Request(submiturl, encoded_data)
27 request.add_header("Accept", "application/json")
28 request.add_header("X-ST-GroupName", "core-os")
29 try:
30 response = urllib2.urlopen(request)
31 response_str = response.read()
32 j = json.loads(response_str)
33 outstr += "\nspeedtracer output:\n\n"
34 stacks = j.get("symbolicated_log")
35 if stacks:
36 outstr += stacks
37 else:
38 outstr += json.dumps(j)
39 except HTTPError as e:
40 outstr += "speedtracer replied with\n" + str(e.info())
41 status = False
42
43 return (status, outstr, further_cmds)
44
45def plugin_cleanup():
46 """ A cleanup call from xnu which is a signal to wrap up any open file descriptors etc. """
47 return None
48
49