Skip to content

Optimizing calls*() for generating call graph in C# #9944

Closed
@chanely99

Description

@chanely99

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions