Reputation:
Do i have to add entry and exit logs in all the C functions?
If, so are there any possible ways to write the entry and exit of a function automatically (Similar to Automatic Entry/Exit using Aspect oriented Programming in java).
The application that I'm writing is time critical and adding entry/exit statements for each function might delay the performance and also makes the code non-readable.
Upvotes: 1
Views: 1759
Reputation: 23714
You might get some mileage out of the FUNCTION and some macros. You'd still have to add entry and exit macros to each function. But at least you don't need to retype the function name.
If you are ok with C++ RAII, then you only need an entry macro in each function.
Upvotes: 0
Reputation:
Check out AspectC, a variant of C extended with aspect-oriented features (just like AspectJ is a variant of Java with aspect-oriented features).
Upvotes: 0
Reputation: 399703
C does not support any form of introspection or doing stuff automatically through magic in the runtime or on the virtual machine; there is no virtual machine, and the runtime support is basically just libraries of "dead" code that provide standard functionality.
And as Subtwo pointed out, if you want to do something (like log entry/exit), it will have to be done and thus take time. You can't just "hide" that penalty, there is very little overhead to put it in.
A standard profiler might give you some insight, by sampling your program statistically to see which functions execute, but that will not give you the call order, just random locations where your program was executing code at the time it was sampled.
You could perhaps turn to some preprocessor trickery, this is a common way to do "boilerplate" stuff like logging, by for instance defining some macros that you then put at the entry/exit points of each function. Still, you'd have to remember including the macros, and any performance penalty from doing the logging will of course be present.
Upvotes: 2
Reputation: 3796
First of all. If you want to log something it will take time, no matter how you accomplish it. That being by aspect programming or something else. If your application is time critical you should have some switch to turn on/off debugging.
Update: Checkout http://perfinsp.sourceforge.net/hookit_linux.html
Upvotes: 1