开发者

Count Function Calls

开发者 https://www.devze.com 2023-03-05 04:41 出处:网络
I would like to count the number of times the following methods executed since application startup. How can I do tha开发者_如何学JAVAt?

I would like to count the number of times the following methods executed since application startup. How can I do tha开发者_如何学JAVAt?

System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)


AQtime does that with no difficulty.


I can think of two ways. One is to use a profiler, which may be the simplest.

The other is to wrap the calls in a function that counts it for you. Find and replace will do the rest.

private int invokeCount = 0;

public static Graphics FromHdcInternalWrapped(IntPtr hdc)
{
     invokeCount++;
     return Graphics.FromHdcInternal(hdc);
}

Personally, I'd stick with the profiler.


The canonical, easiest way would probably be to simply use a profiler application. Personally I have good experiences with jetBrains dotTrace, but there are more out there.

Basically what you do is you let the profiler fire up your app, and it will keep track of all method calls in your code. It will then show you how much time was spent executing those methods, and how many times they are called.

Assuming your reason for wanting to know this is actually performance, I think it's a good idea to look at a profiler. You can try to optimize your code by doing an educated guess to where the bottlenecks are, but if you use a profiler you can actually measure that. And we all know, measure twice, cut once ;-)

0

精彩评论

暂无评论...
验证码 换一张
取 消