Profiling with instruments/shark - Time % seem to be placed wrong.

Dear all

I decided to try out osx profiling tools to profile OpenFOAM. I downloaded freefoam from [1] and compiled it for debugging. Then I ran a custom solver with shark and instruments. First it seemed to work well, but when I looked at the code something seems to be deeply wrong. Both shark and instruments for example attached time % to lines which just contain comments [2].

I'm wondering if anybody has experienced similar problems.

[1] http://sourceforge.net/projects/freefoam/
[2] http://emerging-patterns.com/tmp/instruments_wtf.png

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Those are very expensive

Those are very expensive comments =)

I don't have much experience with Instruments, so I'm drawing a blank there. For Shark, start by making sure you have the latest version installed. Download the latest version of the "CHUD Tools" to update Shark (and make sure to run CHUD Remover before installing).

If the problem persists, or even if it doesn't, please file a bug report.

Of course I have the newest

Of course I have the newest version installed.. But I think the problem lies elsewhere.. for example the OF code is quite complex and uses macros and inline functions..

Profiling with instruments/shark

Shark (and I presume instruments) do not always mark the correct line where the instruction taking the time is located in the source. You _may_ have to shift by one or two lines down. You can check the assembly (side-by-side) to align the percentages with the proper lines in the code, as well.

As Stephen said, file a bug report. But in the meantime if you are not certain which lines to look at, just shift down one (maybe two lines). It will still get you in the general vicinity of where you are spending time.

Dave

Thx for your replays. Sent

Thx for your replays. Sent feedback to apple.

I also tried out valgrind with kcachegrind on my Linux box. There seems to be no line confusion.. but I would like to be able to do everything on my Mac ;)

Here, too

I am also seeing this (time attached to comments) and other strange behavior when using high optimization levels (-O2, -O3). For instance, I also noticed identical function calls that take very different amount of time, or "hotspots" at operations that should take (almost) no time.

My code (C++) is heavily templated and uses lots of inline functions, and I think this kind of behavior is to be expected for such a code. If you take a look at the corresponding assembler code, you'll see that one line of source code is very often scattered over a large part of of the assembler code. The optimizations performed by the compiler sometimes involve quite heavy transformation of your source code, so it gets very difficult, if not impossible, to relate time spend in a bunch of assembler instructions back to your original code.

I just got an E-Mail from

I just got an E-Mail from Apple. They confirmed that the problem is just with optimized builds. Also it's a gcc problem: GCC does not manage to keep track of the source lines if you have code with lots of macros (and if you compile it with optimization)

If you want to have the time percentages attached to the correct line, then you have to use an unoptimized build (which can differ quite a lot from the optimized build with regard to perfomance)

To verify this I recompiled freefoam w/o optimization and now the time percentages are attached to the correct line.

Unfortunately I can confirm

Unfortunately I can confirm this is a long-standing problem. I seem to remember hearing hints that this is much improved under clang/llvm, but I can't confirm first hand until C++ support is improved and I can migrate my code to that compiler system.

I find Shark's source code time profile to be often entirely useless, but I recommend trying to understand the assembly code time profile. This is not actually too hard for maths-heavy inner loops, and can often give you the detailed information you need to understand what is holding the code back.

One very specific issue that you *can* work around (radar bug# 4723147) occurs if you open two traces for the same program, each containing different versions of the same embedded source files. This completely throws Shark and it will report utter rubbish. The workaround is simply to open one such trace, quit and relaunch shark, and then open the second trace.

I have too. But the problem

I have too. But the problem is not solved yet...( Shark and instruments
resume attached time % to lines and other problems. What to do? Try to find out the problem from different term papers but couldn`t find the answer(

I did not work too much with

I did not work too much with osx profiling tools to profile OpenFOAM. For Shark, I also start by making sure you have the latest version installed. I find and download the latest version of the "CHUD Tools" to update Shark. Do not forget to run CHUD Remover before installing.If the problem persists, or even if it doesn't, I file a bug report.There are also audio tutorials on this topic at web mp3 sources . It might be useful for those who are concrened about OpenFOAM.

Hi guys, Just wondering if

Hi guys,
Just wondering if any progress has been made on fixing this bug that was found a couple of months back?
Just curious if anyone can comment on whether it's ever going to come back.
Thanks,
Matt

Haven't tried it out, maybe

Haven't tried it out, maybe you want to have a look at the developer preview of Xcode 4. IIRC it also comes with new profiling tools.