When you have a performance problem, profiling an application will help you figure out where the bottleneck is. However, most profiling tool have a tendency to slow down the execution by a significant factor and EiffelStudio is unfortunately no different. Nevertheless, we have added a neat class called
PROFILING_SETTING that will enable you to enable/disable the profiler on only some parts of an execution.
To make sure you are using this class properly you should know the following:
- Profiling should be enabled in the project settings
- First executed instruction should be a call to
- Last executed instruction should be a call to
- When profiling a section of code the calls
stop_profiling, they should appear in the same routine, as otherwise the profiler will be confused
With EiffelStudio 6.0, there is also a very handy feature that comes for free with the new project settings structure with libraries. By default libraries do not inherit the `profiling' setting and are therefore excluded from the profiling (thus speeding up the profiling). It simply means that you won't know how much time is spent in a routine from a library, but the time is still accounted for the callers of that routine. If you want to profile a library, you simply need to mark it so in your project configuration.
I've showed that you can profile a certain portion of code, but you can also disable profiling a certain portion too. We use it when profiling the compiler for not tracking the time spent in the parser. Here is an example:
f is local l_prof_setting: PROFILING_SETTING l_is_profiling: BOOLEAN retried: BOOLEAN do if not retried then create l_prof_setting.make l_is_profiling := l_prof_setting.is_profiling l_prof_setting.stop_profiling -- Your code here ... end if l_is_profiling then check l_prof_setting_not_void: l_prof_setting /= Void end l_prof_setting.start_profiling end rescue retried := True retry end
Ok, it looks a little bit more complicated than what you expected. If you do not care about correctness then you know that you can remove:
- the rescue clause if you do not anticipate exceptions
- the `l_is_profiling' local variable if nothing else is enabling/disabling the profiler
Enjoy Eiffel and profiling!