0

I'm using a Physics Toolkit (Geant4) which consists of several thousand C++ header and class files. In order to use the toolkit, you have to write a series of your own class files, that give the toolkit some basic information about what you are trying to model. You then write a main() file which registers these files with the toolkit, 'make' it and then execute the final program. I am using Ubuntu 10.10 as the platform to do this.

I'd like to better understand how the toolkit operates. Specifically, I'd like to find out what functions in what class files, throughout the toolkit, are called and in what order, when the program runs.

One, somewhat brute-force method would be to label each function in each file e.g. insert cout << "File Name, Function Name" << endl as the first statement in each function body and have this all output to a textfile. However, there are some 3000 files I'd need to go through, which would be somewhat... time-consuming.

Is there an easier way of finding out what functions have been called? I've searched through the toolkits manual and, unless I have missed something, I see no way there of doing this via the toolkit. I guess I would need some command at the terminal or an external program?!?

Any help, suggestions or advice would be greatly appreciated!

  • I suggest you use Doxygen and GraphViz to do this for you. Here is an [excellent answer](https://stackoverflow.com/questions/27857/c-c-source-code-visualization/29989#29989) that that should get you started. I hope this is what you are looking for. – Andrew White May 07 '11 at 22:04
  • Ok, thanks for you advice. I have managed to install doxygen and run it to document the source files for Geant4 successfully. Before I go further though... I'm having a doubt as to whether or not this is the right thing... So, this program will give me a complete documentation of this toolkit and the files dependancies, right? The only problem is I don't see that this will tell me how the toolkit runs the program I've created. Surely this just tells me how the toolkit *in general* interacts but it won't tell me what it does when running my specific program? Or am I missing something? – W Webster May 07 '11 at 23:03
  • No, you're right. I wasn't 100% sure if you wanted general flow visualization (the typical) or a per run (much harder to do in C/C++). This is still a valuable tool but looks like it's not exactly what you need. – Andrew White May 08 '11 at 00:06
  • That's fine. Thanks for your input though. You're right; it looks a very useful tool and I probably wouldn't have found it if you hadn't suggested it. I will be doing a lot of coding during my PhD so I've no doubt it will rescue me from the depths of coded frustration sooner or later! :) – W Webster May 08 '11 at 09:28

1 Answers1

2

On ubuntu you'll have a choice of profilers.

I personally love

valgrind --tool=callgrind ./myprogram
kcachegrind

For this because it creates very good callgraphs and statistics (tree map visualizations).

The big FAQ profiler topic is here: How can I profile C++ code running in Linux?

Off the top off my head: gprof (needs instrumentation), oprofile and perf record -g are easy to get started with as well

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633