Merge lp:~ben-hutchings/ensoft-sextant/query-fix into lp:ensoft-sextant

Proposed by Robert
Status: Merged
Approved by: Robert
Approved revision: 69
Merged at revision: 40
Proposed branch: lp:~ben-hutchings/ensoft-sextant/query-fix
Merge into: lp:ensoft-sextant
Prerequisite: lp:~ben-hutchings/ensoft-sextant/exception-fix
Diff against target: 178 lines (+30/-51)
3 files modified
src/sextant/__main__.py (+16/-22)
src/sextant/export.py (+3/-5)
src/sextant/query.py (+11/-24)
To merge this branch: bzr merge lp:~ben-hutchings/ensoft-sextant/query-fix
Reviewer Review Type Date Requested Status
Robert Approve
Review via email: mp+245127@code.launchpad.net

This proposal supersedes a proposal from 2014-12-12.

Commit message

Fixed the 'sextant query ...' commands and updated so that it is possible to limit to internal calls/specify the maximum call depth from the commandline. Output can look quite pretty in yEd.

Description of the change

Fixed the 'sextant query ...' commands and updated so that it is possible to limit to internal calls/specify the maximum call depth from the commandline. Output can look quite pretty in yEd.

To post a comment you must log in.
Revision history for this message
Robert (rjwills) :
review: Approve
Revision history for this message
Martin Morrison (isoschiz) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/sextant/__main__.py'
2--- src/sextant/__main__.py 2014-11-18 16:54:17 +0000
3+++ src/sextant/__main__.py 2014-12-18 15:16:16 +0000
4@@ -158,28 +158,18 @@
5 try:
6 arg1 = args.funcs[0]
7 arg2 = args.funcs[1]
8- except TypeError:
9- pass
10- except IndexError:
11- pass
12-
13- try:
14- program_name = args.program[0]
15- except TypeError:
16- program_name = None
17-
18- try:
19- suppress_common = args.suppress_common[0]
20- except TypeError:
21- suppress_common = False
22-
23- query.query(remote_neo4j=args.remote_neo4j,
24+ except (TypeError, IndexError):
25+ pass
26+
27+ query.query(connection,
28 display_neo4j=_displayable_url(args),
29 input_query=args.query,
30- program_name=program_name,
31+ program_name=args.program,
32 argument_1=arg1,
33 argument_2=arg2,
34- suppress_common=suppress_common)
35+ suppress_common=args.suppress_common,
36+ limit_internal=args.limit_internal,
37+ limit_call_depth=args.limit_call_depth)
38
39 # End of functions which invoke Sextant
40
41@@ -243,13 +233,17 @@
42 parsers['query'].add_argument('--program', metavar="PROG_NAME",
43 help="name of program as stored in the database; "
44 "required for all queries except 'programs'",
45- type=str, nargs=1)
46+ type=str)
47 parsers['query'].add_argument('--funcs', metavar='FUNCS',
48 help='functions to pass to the query',
49 type=str, nargs='+')
50- parsers['query'].add_argument('--suppress-common', metavar='BOOL',
51- help='suppress commonly called functions (True or False)',
52- type=str, nargs=1)
53+ parsers['query'].add_argument('--suppress-common', action='store_true',
54+ help='suppress commonly called functions (True or False)')
55+ parsers['query'].add_argument('--limit-internal', action='store_true',
56+ help='limit call graph walking to internal function calls')
57+ parsers['query'].add_argument('--limit-call-depth', metavar='CALL_DEPTH',
58+ type=int, help='limit the maximum call depth, 0 for unlimited',
59+ default=0)
60
61 parsers['web'] = subparsers.add_parser('web', help="start the web server")
62 parsers['web'].add_argument('--port', metavar='PORT', type=int,
63
64=== modified file 'src/sextant/export.py'
65--- src/sextant/export.py 2014-11-19 11:37:11 +0000
66+++ src/sextant/export.py 2014-12-18 15:16:16 +0000
67@@ -111,7 +111,7 @@
68 display_func = ProgramConverter.get_display_name(func)
69 if func.type == "stub":
70 colour = "#ff00ff"
71- elif func.type == "function_pointer":
72+ elif func.type == "pointer":
73 colour = "#99ffff"
74 elif func.is_common:
75 colour = "#00FF00"
76@@ -141,7 +141,6 @@
77 </node>\n""".format(func.name, 20, len(display_func)*8, colour, display_func)
78
79 functions_called = func.functions_i_call
80- print(functions_called)
81 if remove_self_calls is True:
82 #remove calls where a function calls itself
83 for func_called, is_internal, in functions_called:
84@@ -149,18 +148,17 @@
85 functions_called.remove(func_called)
86
87 for callee, is_internal in functions_called:
88- print(callee, is_internal)
89 color = "#000000" if is_internal else "#ff0000"
90 if callee not in commonly_called:
91 if not(suppress_common_nodes and callee.is_common):
92 output_str += """<edge source="{}" target="{}"> <data key="d9">
93 <y:PolyLineEdge>
94- <y:LineStyle color="#ff0000" type="line" width="1.0"/>
95+ <y:LineStyle color="{}" type="line" width="1.0"/>
96 <y:Arrows source="none" target="standard"/>
97 <y:BendStyle smoothed="false"/>
98 </y:PolyLineEdge>
99 </data>
100- </edge>\n""".format(func.name, callee.name)
101+ </edge>\n""".format(func.name, callee.name, color)
102
103 output_str += '</graph>\n<data key="d0"> <y:Resources/> </data>\n</graphml>'
104 return output_str
105
106=== modified file 'src/sextant/query.py'
107--- src/sextant/query.py 2014-10-10 16:34:37 +0000
108+++ src/sextant/query.py 2014-12-18 15:16:16 +0000
109@@ -14,8 +14,9 @@
110 from .export import ProgramConverter
111
112
113-def query(connection, display_neo4j='', program_name=None,
114- argument_1=None, argument_2=None, suppress_common=False):
115+def query(connection, input_query, display_neo4j='', program_name=None,
116+ argument_1=None, argument_2=None, suppress_common=False,
117+ limit_internal=False, limit_call_depth=0):
118 """
119 Run a query against the database at remote_neo4j.
120
121@@ -36,24 +37,6 @@
122
123 """
124
125- # if display_neo4j:
126- # display_url = display_neo4j
127- # else:
128- # display_url = remote_neo4j
129-
130- # try:
131- # db = db_api.SextantConnection(remote_neo4j)
132- # except requests.exceptions.ConnectionError as err:
133- # logging.error("Could not connect to Neo4J server {}. Are you sure it is running?".format(display_url))
134- # logging.error(str(err))
135- # return 2
136- # #Not supported in python 2
137- # #except (urllib.exceptions.MaxRetryError):
138- # # logging.error("Connection was refused to {}. Are you sure the server is running?".format(remote_neo4j))
139- # # return 2
140- # except Exception as err:
141- # logging.exception(str(err))
142- # return 2
143
144 prog = None
145 names_list = None
146@@ -66,24 +49,28 @@
147 if argument_1 is None:
148 print('Supply one function name to functions-calling.')
149 return 1
150- prog = connection.get_all_functions_calling(program_name, argument_1)
151+ prog = connection.get_all_functions_calling(program_name, argument_1,
152+ limit_internal, limit_call_depth)
153 elif input_query == 'functions-called-by':
154 if argument_1 is None:
155 print('Supply one function name to functions-called-by.')
156 return 1
157- prog = connection.get_all_functions_called(program_name, argument_1)
158+ prog = connection.get_all_functions_called(program_name, argument_1,
159+ limit_internal, limit_call_depth)
160 elif input_query == 'all-call-paths':
161 if argument_1 is None and argument_2 is None:
162 print('Supply two function names to calls-between.')
163 return 1
164- prog = connection.get_call_paths(program_name, argument_1, argument_2)
165+ prog = connection.get_call_paths(program_name, argument_1, argument_2,
166+ limit_internal, limit_call_depth)
167 elif input_query == 'whole-program':
168 prog = connection.get_whole_program(program_name)
169 elif input_query == 'shortest-call-path':
170 if argument_1 is None and argument_2 is None:
171 print('Supply two function names to shortest-path.')
172 return 1
173- prog = connection.get_shortest_path_between_functions(program_name, argument_1, argument_2)
174+ prog = connection.get_shortest_path_between_functions(program_name, argument_1, argument_2,
175+ limit_internal, limit_call_depth)
176 elif input_query == 'functions':
177 if program_name is not None:
178 func_names = connection.get_function_names(program_name)

Subscribers

People subscribed via source and target branches