C#方法调用的性能检查

C#方法调用的性能检查,c#,reflection,system.diagnostics,C#,Reflection,System.diagnostics,我想创建一个类,该类编写一个文件,其中包含层次结构中的所有方法调用以及程序所需的时间。我不知道如何解决这个问题。我只找到了StackTrace和StackFrame类,但这并不是我真正需要的。我想开始我的程序并做一些动作。在后台,我的类编写一个具有以下或类似结构的文件(例如XML): Method1: 220ms Method2: 180ms Method3: 150ms Method4: 25ms Method5: 20ms Method6: 110ms 有没有一个简

我想创建一个类,该类编写一个文件,其中包含层次结构中的所有方法调用以及程序所需的时间。我不知道如何解决这个问题。我只找到了StackTrace和StackFrame类,但这并不是我真正需要的。我想开始我的程序并做一些动作。在后台,我的类编写一个具有以下或类似结构的文件(例如XML):

Method1: 220ms
  Method2: 180ms
    Method3: 150ms
  Method4: 25ms
    Method5: 20ms
Method6: 110ms
有没有一个简单的方法可以做到这一点?我实际上在System.Diagnostics和System.Reflection名称空间中搜索,但我不知道如何做

到目前为止,我还没有写过一行代码,因为我需要一个好的提示

提前谢谢。

您可以试试。我通常用它来追踪执行时间

然后要跟踪方法,请执行此操作(如文档中的mentioend)-

它有一个很好的界面,可以显示web-

对于基于windows和控制台的应用程序,请使用此处提到的windows扩展-

这里提到了这个过程-


您想做什么?也许你需要的是评测:@OcasoProtal我需要VS2013吗?在我的VS2010上找不到分析菜单:(VS2010:你的帖子感觉像是评论…确保添加实际答案如何自己实现它。
using StackExchange.Profiling;
...
var profiler = MiniProfiler.Current; // it's ok if this is null
using (profiler.Step("Set page title"))
{
    ViewBag.Title = "Home Page";
}
using (profiler.Step("Doing complex stuff"))
{
    using (profiler.Step("Step A"))
    { // something more interesting here
        Thread.Sleep(100);
    }
    using (profiler.Step("Step B"))
    { // and here
        Thread.Sleep(250);
    }
}