locked
Problems profiling code

    Pregunta

  • I wrote a C# application that is used to test one of my company's public C/C++ APIs. I wanted to use the profiler in VS 2010 Ultimate SP1 to profile the API. This API is built by an official build system using make files, so while I have the pdb files, VS itself doesn't compile the code locally and this may be part of the problems I'm seeing. I've been trying to set up the C/C++ projects in VS so that VS can build them locally, however this is a very complex project with many dependencies and so far I have not had luck doing that. For now let's say I'm stuck with the DLLs and pdb files built by the make system.

    The issues I run into are:

    1. I can only do Sampling profiling. When I try to do Instrumentation, it doesn't include the C/C++ functions in the results. Is there a way to do Instrumentation on the C/C++ code?
    2. When using Sampling mode, I'm a bit confused by the results. The results are in % values, yet for instance I know a particular C++ function is taking almost all of the time (it is blocked on network IO), yet the results show it is using 10%. I think the results are skewed by number of threads, which in my case is fluctuating so I have no idea how to convert that 10% to a meaningful value.

      For instance, let's say I have 4 threads, where 3 are in Sleep and a 4th is doing a lengthy calculation and is using 100% CPU. The profiler will show that the function doing the calculations is getting 25% of the samples. Yes this tells me the function is really using all CPU time since I know I have 4 threads. But what if I don't know the exact number of threads, and thead count is fluctuating through the application lifetime.

      Ideally, I want to convert the % value to a time value, for instance each call to the function takes 3.7ms, or just an actual % value of overall time, or something similar to by using the Sampling method?

      Or am I just misinterpreting the results to begin with?

    Any help appreciated, thanks.


    • Editado BitFlipper martes, 03 de abril de 2012 15:54
    martes, 03 de abril de 2012 15:51

Respuestas

Todas las respuestas

  • OK thinking about this more, I realized that the thread count should not make any difference to the % values. I think my initial test result of 10% is correct but that the time is spent somewhere else.

    However I still have the issues mentioned in point #1, and would appreciate anyone's input on solving this issue.

    martes, 03 de abril de 2012 16:43
  • Hi BitFlipper,

    Thank you for posting in the MSDN forum.

    I’m not very sure about this issue. Do you mean that you could do the Sampling profiling but not do Instrumentation? If you create a simple C++ app, whether you could get the result?

    Did you get any message when you do Instrumentation profiling? If have, please share it to us.

    As my understanding, the Visual Studio Profiler could be launch the Instrumentation mode with both native C++ code or managed code.

    You could try to profile it using Command line, for detailed steps, see Roahn Luo’s reply in this thread: Using profiler in instrumentation mode -- cannot find part of path to instrumented binary.

    In addition, I find two threads about Profiling in VC++, if possible, please refer them:

    Visual C++ 2010 premium - cannot profile with instrumentation

    How to do Code Profiling in VC++

    If there's any concern, please feel free to let us know.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    jueves, 05 de abril de 2012 7:59
  • Jack,

    Thanks for the reply. As for your questions...

    Specifically, I want to Instrument mixed managed/unmanaged code. This works with the Sampling mode, but when I use Instrumentation, I only get results for the C# code. There is no error, it is just that I am not seeing any C/C++ functions in the results as I'm getting with the Sampling mode.

    I have a feeling that maybe because the C/C++ code is built using make instead of inside VS, that maybe it cannot instrument the unmanaged DLLs, but I could be wrong. This is the part that isn't clear to me, so I'm trying to understand it better, and to find a way to make it work.

    As for Sampling mode... The results I'm getting is still somewhat confusing to me. I understand how the sampling mode works, and that I can't for instance tell how many times a function was called, just how many of the "snapshots" were inside the function, etc. However, for the % value to be useful to me, I need to know how long the overall run was. This might be shown somewhere in the results but I'm not finding it. I could manually time the overall test but it seems inaccurate. A possible way to do this could be to look at the Marks results and take the timestamp of the "End of Program" entry and convert to overall time based on the sampling interval.

    I will try the command line mode and see if that helps.


    • Editado BitFlipper jueves, 05 de abril de 2012 18:24
    jueves, 05 de abril de 2012 18:21
  • When I using Instrumentation and specify one of the unmanaged DLLs, I get this output:

    Profiling started.
    Instrumenting C:\...some path...\types.dll in place
    Info VSP3049: Small functions will be excluded from instrumentation.
    Microsoft (R) VSInstr Post-Link Instrumentation 10.0.40219 x86
    Copyright (C) Microsoft Corp. All rights reserved.
    Error VSP1011: Unable to obtain debug information. Link with the /Profile linker switch.
    PRF0002: Instrumentation failed with these options: /u "...some path...\types.dll"   /excludesmallfuncs.  Please check the output window for additional details.
    Data written to ...some path...\somefile.vsp.
    Profiling finished.
    File contains no data buffers
    File contains no data buffers
    Analysis failed
    Profiling complete.

    Note I hid the paths because they show which product I'm working on which I don't want to disclose.

    Since the DLLs are built using make (although I do have the pdb files), how can I resolve this issue?


    • Editado BitFlipper jueves, 05 de abril de 2012 21:01
    jueves, 05 de abril de 2012 21:00
  • Hi BitFlipper,

    Glad to receive your reply.

    As my previous reply, if you create a simple app, whether you could get the result?

    Error VSP1011: Unable to obtain debug information. Link with the /Profile linker switch.

    I did some research about this issue, it seems that we need to specify "/link /Profile" when linking our binary. You could enable this linker option by doing the following steps:

    1. In "Solution Explorer", right-click your project, select "Properties"
    2. Go to "Configuration Properties" -> "Linker" -> "Advanced"
    3. In the property grid, set "Profile" to "Yes (/PROFILE)"
    4. Recompile your application
    5. Try profiling again

    Since it is hard for me to repro this issue, if possible, please attach your Visual Studio project or a similar simple project, you can upload it to the sky driver, and then share the download link in your post. Please also attach a screenshot image about your results in your post. We will try to profile it.

    If there's any concern, please feel free to let me know.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us


    viernes, 06 de abril de 2012 6:31
  • Jack,

    I realize what the error message says but as I mentioned previously, the C/C++ code is built externally by make and hence these DLLs are not being generated by a VS project. Therefore I cannot follow your suggested steps.

    I guess in this case there is no simple answer. If I really want to do Instrumentation on the C/C++ DLLs I'll need to set them up as VS projects and then specify the Profile option. However I tried to set some of these up as VS projects on a previous occasion but gave up. This is a very complex project with multiple dependencies. Just building it with make takes more than 2 hours and it generates about 30 DLLs.

    I'm not very familiar with make files, but I guess an option could be to figure out how to specify the /PROFILE option in the make files. I can build these DLLs locally on my dev system using make so that allows me to experiment a bit I guess.

    Thanks

    viernes, 06 de abril de 2012 16:22
  • Hi BitFlipper,

    This is a very complex project with multiple dependencies. Just building it with make takes more than 2 hours and it generates about 30 DLLs.

    Since it is hard for us to repro this project, if you couldn’t share us a sample, I’m afraid that I don’t have more idea about this issue. But you could submit this feedback to Microsoft Connect feedback portal: http://connect.microsoft.com, Microsoft engineers will evaluate them seriously. Thanks for your understanding. If this issue is urgent, please contact support at http://support.microsoft.com. Thanks for your understanding.

    Have a nice day,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us


    lunes, 09 de abril de 2012 2:51
  • This is Andre with the VSU Profiler Team.

    Yes you will need to figure out a way to add the /Profile option to the command line. If after instrumentin the binaries you are still unable to get the information you seek, please reply to this post and we  can investigate this issue further.

    martes, 24 de abril de 2012 23:14