1

I have a C++ static library .lib that I wrap with cython to create a python extension module. I have been able to build the library and extension module with debug information and attach the Visual Studio Community 2015 debugger to the python process and debug the C++ code.

Now I would like to profile the C++ code using instrumentation. If I chose the VS2015 performance wizard option for instrumentation I can only select projects that are either executables or dlls, I can't select the static library project where my code is. I guess that if I could direct VS to use the python .pyd extension module that may work as it's a dll. However, I don't know how to do that.

I have also tried to find some way of starting the profiler while having the debugger attached to the python process, the same way I do for debugging the C++ code, but I haven't found a way. I can see the PerfTips while stepping through the code, but that's not enough.

Does anybody know how could I profile the C++ code in this static library?

Ultimately, if I can't find a way, I could create another VS2015 executable project and call my lib code from there, then profile the executable project. The only inconvenience with this approach is that I'm passing a few multidimensional arrays from python to the extension module and I would have to first save them from python and then load them in the C++ executable project. I'm not sure how will I do it, but it's doable. It would just be a lot more convenient for me if I was able to profile the C++ lib code when being called from python as I'm going to be doing that multiple times in the future and having to save the python data and then loading it from C++ each time it's a bit of a hassle.

martinako
  • 2,260
  • 1
  • 17
  • 39
  • 1
    Are you looking for ways to speed it up, or just timing it? If you want to speed it up, since you can run the whole thing under VS, [*just do this*](http://stackoverflow.com/a/378024/23771). – Mike Dunlavey Sep 15 '16 at 21:43
  • Thanks. I didn't think of stack sampling because the function takes a fraction of a second only (and I'm not used to use that technique all be said) but I could generate a large amount of data so that it takes a few seconds to execute and then I could take a few more samples. I'll try it. – martinako Sep 16 '16 at 09:30
  • Samples will land in the library in proportion to the fraction of time spent in it. If it finishes too fast, what I sometimes do is put an outer loop around the whole thing. If, even then, no samples land in the library, I would conclude that it's fast enough, so no need to worry about it. – Mike Dunlavey Sep 16 '16 at 12:15

0 Answers0