次の方法で共有


@clk

For several releases now, the native debugger has supported a pseudo-register @clk. @clk can be used as a quick and dirty profiler. As you step along, it can give you some sort of guess as to how long each function is taking. Prior to VS 8.0, the simple way to do this was to add a watch item of <'@clk=0'>. However, people often got them selves into trouble by adding watch items with side-effects, so VS8.0 does NOT reevaluate watch items with side effects. So the 8.0 version of the debugger quick-and-dirty profiler needs to be a macro.

Native Debugger Quick-And-Dirty profiler:

    Sub OnBreak(ByVal Reason As EnvDTE.dbgEventReason, byref executeAction as EnvDTE.dbgExecutionAction) Handles DebuggerEvents.OnEnterBreakMode

        If (Reason = dbgEventReason.dbgEventReasonStep) Then

            Dim val As String = DTE.Debugger.GetExpression("@clk").Value

            OutputLine("@clk is " + val)

            DTE.Debugger.GetExpression("@clk=0")

        End If

    End Sub

    Sub OutputLine(ByVal text As String)

        Dim commandWindow As CommandWindow = DTE.Windows.Item(Constants.vsWindowKindCommandWindow).Object

        commandWindow.OutputString(text + vbNewLine)

    End Sub

The way this works is that after each step, @clk is re-evaluated, and the value is dumped to the command window.