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
Re: performance profiler for CPU usage in visual studio
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;
Re: performance profiler for CPU usage in visual studio
Thankyou very much kaud and Victor.
I'll try your suggestions.
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::duration<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
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 ::duration - so looks ok.
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).