VS2010: Just My Code

原文地址:http://blogs.msdn.com/b/profiler/archive/2011/05/13/vs2010-just-my-code.aspx


The ‘Just My Code’ feature in the profiler has a few differences to the ‘Just My Code’ feature in the debugger so this post should provide a useful introduction.

Example Program

Here’s a very simple program I’ll use in this post.

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Foo();
        }

        private static void Foo()
        {
            double d = 0;
            for (int i = 0; i < 100000000; ++i)
            {
                d += Math.Sqrt(i);
            }
            Console.WriteLine(d);
        }
    }
}

 

Why ‘Just My Code’?

Typically when profiling you are most interested in optimizing code that you either wrote or you have control over. Sure, sometimes there will be issues in the frameworks that you are using or in other binaries, but even then you often control the calls into those frameworks.  Just My Code or JMC is intended to filter the data that is displayed in profiler reports so that more of the code you control shows up in the reports and the reports are more manageable.

For example, the Call Tree after collecting sampling data for the simple program above, with JMC off, is shown below: 
jmc_off_calltree_1

With the default JMC options, this reduces down to: 
jmc_on_calltree_1

What is ‘My Code’?

There are two conditions for code being considered ‘My Code’ by the profiler and they are both at the Module level (Module Name column in the screenshots above). In the example above, this means the checks are made against the clr.dll, mscoreee.dll, mscoreei.dll and ConsoleApplication1.exe binaries.

Modules considered ‘My Code’:

  1. the copyright string for the module does not contain ‘Microsoft’, OR:
  2. the module name is the same as the module name generated by building any project in the currently open Solution in Visual Studio. 

How do I turn JMC on or off?

You can temporarily toggle JMC on or off on the profiler Summary Page in the Notifications area using ‘Show All Code’ or ‘Hide All Code’ (shown in red below): 
jmc_on1

The default setting may be configured as discussed in the following section.

How do I configure JMC?

Use Tools –> Options –> Performance Tools –> General and set options in the ‘Just My Code’ section: 
jmc_options

The default has JMC on, showing one level of non-user callee functions. In the example above with JMC on, this is why we see the call to COMDouble::Sqrt(dobule) showing up in the call tree.

It is also possible to show one-level of non-user code calling user code, which in the example above would add one level of the non-user code that calls main, as shown below: 
jmc_on_calltree_callers_1

Why is ‘Just My Code’ only available for sampling?

When you instrument binaries for profiling, you have already performed some level of JMC. Only binaries that you instrument and first-level calls into other binaries will show up in the instrumentation report, so JMC is not really necessary.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值