CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    May 2015
    Posts
    500

    performance profiler for CPU usage in visual studio

    Hello,

    There is some issue reported by our test team that this release is bit slow in one of the operations.

    So i was told to run the profiler. This is the first time i am running the profiler

    I wanted to check particular function, so i put the breakpoint in the beginning and end of that function. Then run the profiler for the CPU usage. But strangely, the operation which is suspected to be issue, ( i.e the function with the breakpoints) is performed, but breakpoint is not hit. Profiler shows some part of the code, which i am not interested.

    How to get the timing b/w the two breakpoints in the profiler.
    Thankyou very much
    pdk

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: performance profiler for CPU usage in visual studio

    If you want to debug the release build see:
    https://docs.microsoft.com/en-us/cpp...d?view=vs-2019
    Some info about using profiling tools:
    https://docs.microsoft.com/en-us/vis...r?view=vs-2019
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: performance profiler for CPU usage in visual studio

    If you want to easily time a particular piece of code takes, then a simple solution if you have a console available is:

    Code:
    #include <chrono>
    ...
    const auto startr = std::chrono::high_resolution_clock::now();
    
    // code for time to be measured here
    
    const auto diffr = std::chrono::high_resolution_clock::now() - startr;
    std::cout << "xyz took " << std::chrono::duration<double, std::milli>(diffr).count() << " ms" << std::endl;
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    May 2015
    Posts
    500

    Re: performance profiler for CPU usage in visual studio

    Thankyou very much kaud and Victor.
    I'll try your suggestions.

  5. #5
    Join Date
    May 2015
    Posts
    500

    Re: performance profiler for CPU usage in visual studio

    I tried using the kaud's suggestion, as there was a log output ..

    The log format looks some what like printf/scanf format from c:
    LogMessage(false, true, "%s Date File : %s. Compression = %.0f%%%", loadsave, per.GetFileName(), flRatio);

    So I tried to convert the output to long double
    LogMessage(false, true, " PRIYA file save took : %lf", std::chrono:uration<long double, std::milli>(diffr).count());

    Im getting value of 5064.434000 ms. Not sure if i used the %lf properly .. Because there is possibility of overflow errors etc

    Please comment and kindly help me

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: performance profiler for CPU usage in visual studio

    5064.434ms is just over 5 seconds. Is that about what the time taken for the save seems to be?

    %lf means long double which is the type specified in :uration - so looks ok.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    May 2015
    Posts
    500

    Re: performance profiler for CPU usage in visual studio

    Thanks a lot kaud. The timer method actually helped. I could get the precise time. Actually with the profiler running in debug mode, we can put two breakpoints , which gives the time it took for b/w the two breakpoints. But the disadv is that, profiler needs to be run in debug mode ( and may not be having same timing as run in release mode).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured