Closed
Description
Hi there, I'm trying to generate the call graph of the given function. That is, for the following code:
public class Test
{
public void a() {
b();
}
public void b()
{
c();
}
public void c()
{
d();
}
public void d()
{
}
}
I want something like a -> b -> c -> d. Using the suggestion here, I wrote up my first pass, which generates the expected result for my test code. However, the query is extremely inefficient, taking over half an hour running on the demo projects on lgtm.com, and over an hour on the db I want to actually use it on.
class PathCallable extends Callable{
string getPath(Callable sink){
(
this.calls(sink) and
result = this.getName() + "-->" + sink.getName()
) or
exists(
PathCallable next |
this.calls*(sink) and
this.calls(next) and
result = this.getName() + " -->" + next.getPath(sink)
)
}
}
from PathCallable a, Callable d
where
d.hasName("d") and
a.hasName("a") and
a.calls*(d)
select a, d, a.getPath(d)
Any suggestions/ideas on how to cut down on the runtime? I suspect that calls* is the culprit, but not sure if there's any better alternatives or ways to use it more efficiently. Thanks for your help