Frage

I just profiled my program with gprof and got this:

100.01      0.01     0.01    23118     0.43     0.43  std::vector<int, std::allocator<int> >::operator=(std::vector<int, std::allocator<int> > const&)

Which confuses me, as it says that it is using 100.01% of the time using the = operator. Am i right guessing that this means it is just copying data all along and is there a limit of how much memory a program is allowed to use?

War es hilfreich?

Lösung

It looks like you profiled too short a run to get any useful data.

The way gprof works is that it periodically interrupts your code to see what function you were in at that instant. If the code isn't running very long, it may only collect a small number of data points. In contrast, callgrind instruments your code and tracks each function call and return and checks how much time was spent between hooks. This gives it a much fuller view, even if the run is short. This has a downside, it slows the program down quite a bit.

Another advantage of callgrind is that you can stop, start, and save its data collection. So if you don't want to monitor your program's startup or want to catch only the time it's doing a particular thing, you can. Plus, there's a tool called kcachegrind that can give you a great graphical view of the data you collected.

If you can tolerate slowing your program down by a factor of four while you're running it for testing, use callgrind instead -- it's part of valgrind.

If you're using Linux, your distribution probably has a valgrind package and a package that includes kcachegrind (which may be called kdesdk or something else). It's worth the time invested to learn how to use them (they are not as easy to get started with as gprof). I think you'll find the kcachegrind's GUI impressive (look at this screenshot). And, as its name suggests, it can analyze cachegrind output too.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top