Visual Studio 打开 "record CPU Profile" 以通过分析 CPU 使用情况来衡量应用程序性能,但结果为空

Visual Studio open "record CPU Profile" to measure application performance by analyzing CPU usage but get empty result

我关注微软文档Measure application performance by analyzing CPU usage

打开"record CPU Profile"

我试过了,但没有像医生那样的预期结果

我的Visual Studio信息

Microsoft Visual Studio Community 2019
Version 16.9.4

我的测试代码

    class Program
    {
        static void Main(string[] args)
        {
            Test1();
        }

        public static void Test1()
        {
            for (int i = 0; i < 10000*1; i++)
                i.ToString();
            Test2();
        }

        public static void Test2()
        {
            for (int i = 0; i < 10000 * 10; i++)
                i.ToString();
            Test3();
        }

        public static void Test3()
        {
            for (int i = 0; i < 10000 * 100; i++)
                i.ToString();
            Test4();
        }

        public static void Test4()
        {
            for (int i = 0; i < 10000 * 10000; i++)
                i.ToString();
        }
    }

为什么我这样做,因为我想知道每个方法浪费时间。


更新:

动图:

我通过Debug \ Performance Profiler

解决了问题

和selectInstrumentation

然后点击Start系统可以return方法执行时间


我注意到它无法显示 project reference 方法执行时间摘要


更新:

可以显示参考执行时间,由select多个项目


更新:

我注意到项目必须使用相同的 TargetFramework 版本,否则它会抛出以下异常