在vb.net中跟踪函数调用的持续时间 [英] Tracking duration of functions calls in vb.net

查看:370
本文介绍了在vb.net中跟踪函数调用的持续时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的VB6应用程序中,我们添加了一些实用功能,用于跟踪功能中花费的时间。我们这样做是为了跟踪性能瓶颈。

In our VB6 applications, we added a few utility functions for tracking the amount of time spent in a function. We did this to track performance bottlenecks.

基本上,它的工作原理是有两个实用功能:StartTickCount()和EndTickCount()。您将传递每个函数的名称,并且函数将使用字典来获取StartTickCount()被调用时的刻度计数,然后在调用EndTickCount()时减去计数。这不是完美的,因为当然没有考虑到拨打电话需要时间等等,但基本上它是为了我们的目的。对接部分的痛苦是确保在每个退出点的每个函数开始处调用StartTickCount()和EndTickCount():

Basically, how it worked was there were two utility functions: StartTickCount() and EndTickCount(). You would pass the name of the function in each, and the functions would use a dictionary to get the tick count when StartTickCount() was called, and then subtract the tick count when EndTickCount() was called. This wasn't perfect because it didn't of course take into consideration that calls to get tick count takes time, etc, but basically it worked for our purposes. The pain in the butt part was making sure to call StartTickCount() at the beginning of each function and EndTickCount() at each exit point:

Private Function SomeFuction() as String
    ' indicate the function started
    StartTickCount("MyClass.SomeFunction")


    ' some logic that causes the function to end
    If (some logic) Then
        EndTickCount("MyClass.SomeFunction")
        Return "Hello!"
    End If

    ' final exit point
    EndTickCount("MyClass.SomeFunction")
    Return "World"
End Function

无论如何,通过VS 2010调试器或 System.Reflection内置任何功能命名空间,在VB.NET中做类似的事情?

Anyway, is there any functionality built in, either through the VS 2010 debugger or in the System.Reflection namespace, to do something similar in VB.NET?

基本上,我想要的是记录每个函数调用的次数,在该函数中花费的总时间,平均花费的秒数功能,以及在该函数中单次调用中花费的最长时间。

Basically, what I want is to log the number of times each function is called, the total amount to time spent in that function, the average number of seconds spent in that function, and the maximum amount of time spent in a single call in that function.

我可以手动写这个(因为我们已经在VB6中做过一次),但是如果现有的工具使其更容易,我宁愿使用它们。

I can certainly write this by hand (since we already did once in VB6), but if there are existing tools to make it easier, I'd rather use them.

推荐答案

我会看看秒表类 - 它是为这种类型的东西设计的。

I'd have a look at the stopwatch class - it's designed for this type of thing.

然而,还有一个梦幻般的工具,已经做到这一点,它实际上做的更好,工作很少的工作。它也有10天的免费试用版。

However there is also a fantastic tool out there to do this already and it actually does a better job with very little work. It has a 10-day free trial as well.

http://www.jetbrains.com/profiler/

(我不工作,不隶属于喷气式飞机 - 但我希望我是因为他们使一些非常酷的产品)

(I don't work for and am not affiliated with jetbrains - but I wish I was because they make some really cool products)

这篇关于在vb.net中跟踪函数调用的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆