Here’s another fun one from the internal support alias.
When you profile with the VS Profiler, you are profiling the Release version of your code (I hope!). As you know from having debugged Release code in the past, sometimes things get a little funky. Well, a good rule of thumb is that anything that is funky in the debugger, is also a little funky in the profiler. After all, we share the same symbol information (i.e., the stuff in the PDBs for native code and the managed metadata in the EXEs and PDBs for managed code.)
One optimization that is particularly tough for the profiler is called COMDAT folding. There’s a good explanation of this from a debugger standpoint here:
The basic concept is that at link time, all identical functions at code generation time are folded in to a single copy of that function. This is particularly useful for limiting the code bloat in template code. You will see COMDAT in action with things like default destructors and simple methods like field accessors. Since there is only one copy of that function in the binary with several source level functions associated with it, if we take a sample in it, there is no way for us to know which is the correct function. So we just pick the first one in the list, just like the debugger.
Hope that helps!