opreport seems to report the wrong template instantiation

22 Views Asked by At

I am currently trying to profile a shared library. Unfortunately, sprof does not seem to work on my system so I am using oprofile.

However, when I investigate the profiling data, most of the time is indicated to be spent in a templated method. This is to be expected, since most of the number computation is in that method. However, opreport indicates that time is spent in a certain specialization of this template. This might explain, why the computation seems slower than it should be. Some of these specializations include optimized code, whereas others don't, and opreport indicates time is spent in a less optimized version. The shared object includes both versions instantiated, but I have to know if the code that decides which one is taken works correctly.

I added some couts to the templates, and these seem to indicate that the correct specialization is taken, but I am still puzzled by the opreport output.

EDIT:

Here are some more details on what I am doing. The code have needs to be able to run for any length of input, but I can optimize it, if I know the size. So I am doing something like this:

template<size_t N>
struct simulator {
  static void run(...) // optimized version for known N
};

template<>
struct simulator<0> {
   static void run(...) // unoptimized version for any size
};

void simulate(....) {
   switch(n) {
      case(1):
         simulator<1>::run(...);
         break;
      case(2):
         simulator<2>::run(...);
         break;
      ...
      default:
         simulator<0>::run(...);
   }
}

In the actual code I use some template magic to allow the maximal number for which the code is optimized as #define, but the idea is the same. Now I need to ensure, that the simulator<0>::run() is really never called, when it shouldn't be. But opreport indicates only this one is run, but no other (cout disagrees).

0

There are 0 best solutions below