Welcome to my personal web page
Code profiling is a very important aspect of computer programming - almost every software engineer knows that well. It helps finding bottlenecks in your code, finding which parts need improvement, which cause trouble etc. I'm sure everyone knows of this already. There are many tools for this purpose available around the internet. This short post lists a few of them, as well as a brief introduction to a really simple and naive solution I made in the past.
Here are some tools helpful in application profiling:
In the past, while working on the Flatconf project for ASN, I needed to do some fast but non-complicated time-profiling for my application. Since I was mostly interested in just knowing the average time spent in selected functions and I somehow couldn't make the existing tools do what I want - I wrote a really simple library for the time profiling I needed.
The timeprof profiler uses the instrumentation callbacks offered by the gcc. The library itself isn't very interesting, since it has been written in a short period of time just to count the time usage of called functions, but it shows nicely the use of the -finstrument-functions flag. You can find the library in its respective ASN Labs git repository here.
The instrumentation handlers can be used for any specific analysis of function behaviour in a program. All that is needed is specifying the flag during compilation and providing the __cyg_profile_func_enter() and __cyg_profile_func_exit() callbacks definitions as needed. We can inform the compiler which functions we do not wish to analyse by declaring them with the __attribute__((no_instrument_function)) attribute.
The instrument-functions mechanism is rather well documented, so there's no use in duplicating information. But it's really useful to know about its existence when specific analysis or debugging is required. Consult the timeprof source code to see an example of its usage.
On a side note - lately many different, interesting things happened, that is why today's post is a rather short one. But I'll return soon and hopefully explain the reasons why. Thanks!