Forget static callgraphs – Use Python & DTrace!October 20th, 2011 • Comments Off on Forget static callgraphs – Use Python & DTrace!
Forget about static analyzed callgrahs! No more running the code closing it and then looking at the callgraph. With DTrace you can attach yourself to any (running) process on the (running/production) system and get life up to date information about what the programm is doing. No need to restart the application or anything. This works for most programming languages which have DTrace providers (like C, Java and Python :-)). All you need to know is the pid.
Based on the information you get from DTrace (using the Python consumer) you can draw life updating callgraphs of what is currently happening in the program. Not only is it possible to look at the callgraph but you can also look at the time it took to reach a certain piece of code to analyze bottle necks and the flow of the program:
$ pgrep python # get the pid of the process you want to trace 123456 $ ./callgraph.py 123456 # trace the program and create a callgraph
So if you would have the following Python code:
class A(object): def sayHello(self): return 'I am A' class B(object): def __init__(self): self.a = A() def sayHello(self): return self.a.sayHello() if __name__ == '__main__': print B().sayHello()
You would get the following life generated callgraph – the GUI can start, stop and restart tracing and get live updates as the DTrace probes fires:
The following screenshot was taken while looking into the printer manager:
DTrace for the win!
[Updated] Updated the screenshots.