6

We use quite a lot of C++11 lambdas in our code, but found that it leads to difficulties with profiling and debugging tools. For instance the MSVC profiler will show lambdas as:

`anonymous namespace'::<lambda0>::operator()(void)const     
`anonymous namespace'::<lambda1>::operator()(double,double)const    
...

This does not really help to identify the lambda at first glance in a stacktrace or profiler summary.

Is there any way to give the lambda a name for debugging purposes (it should be the mangled name of the scope in which it is defined, IMHO)? I am okay with platform specific solutions (#pragma?) and hacks.

Special namespaces could work but it would require jumping to some hoops from our regular namespace.

Christopher Oezbek
  • 23,994
  • 6
  • 61
  • 85
  • 1
    There is a simple way to give a lambda a name! Make it a function! – Dietmar Kühl Dec 29 '16 at 20:09
  • If you use [*this method*](http://stackoverflow.com/a/378024/23771), doesn't it give you line number information in the stack trace? That should tell you what function it is in, without having to know the function name. – Mike Dunlavey Dec 29 '16 at 21:13
  • @DietmarKühl Sure, that works, but separates code that belongs together (that is why most of these lambdas are used). – Christopher Oezbek Dec 29 '16 at 22:10
  • @MikeDunlavey For profiling you can switch it on in an extra column, but the debugger in stacktrace view is not so friendly. Still it is more tedious. – Christopher Oezbek Dec 29 '16 at 22:11
  • @ChristopherOezbek: You can get line numbers in the stacktrace, and if the goal is to get measurements then, absolutely, it is tedious. OTOH, if the goal is to find out how time is being wasted so you can make it run faster, many people find it the opposite of tedious, because it gives much more detail about what is happening. Anything wasting enough time to be worth fixing is obvious in a small number of samples, like less than 10. I seldom need more than 20. Here's [*why it works*](http://scicomp.stackexchange.com/a/2719/1262). – Mike Dunlavey Dec 29 '16 at 22:22

0 Answers0