Visual Studio 2008 调试窗口显示时间戳?

发布于 2024-08-11 02:31:08 字数 346 浏览 9 评论 0原文

我希望能够在 Visual Studio 的调试窗口中的每条跟踪的开头看到时间戳。

 [此处的时间戳] 线程“Win32 Thread”(0xcd0) 已退出,代码为 0 (0x0)。

 [此处的时间戳] => CLR ProvideAssembly:AppDomainId:1,参考:'msvcm90d ...

例如 sysinternals 应用程序 - DebugView。问题是我无法进行 Visual Studio 调试,并同时使用 DebugView 进行监听,并且我不习惯将时间戳手动添加到跟踪器中。

I want to be able to see a time stamp in the beginning of every trace in the debug window in Visual studio.

 [Time stamp here] The thread 'Win32 Thread' (0xcd0) has exited with code 0 (0x0).

 [Time stamp here] => CLR ProvideAssembly: AppDomainId: 1, Ref: 'msvcm90d...

Example of this is the sysinternals application - DebugView. The problem is that I can't have Visual Studio debugging, and listening with DebugView at the same time, and I am not comfortable with adding the time stamp manually to my tracers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

悲歌长辞 2024-08-18 02:31:08

由于输出窗口文本一旦写入就是只读的,因此没有一种简单的方法可以准确地执行您想要执行的操作。但是,执行类似的操作很容易:在将新文本写入输出窗口之后附加时间戳行。这将使输出窗口变得更加混乱,但你会得到你的计时。

其工作原理如下:首先,创建一个 Visual Studio 外接程序或宏,用于挂钩 PaneUpdated 事件。 (请参阅此线程了解如何使用宏方法来做到这一点)。确保在事件处理程序中检查 pane.Name == "Debug" 并忽略其他窗格。其次,当您在调试输出窗格中检测到新文本时,附加一个时间戳行,如下所示:

public void AddTimestamp(DTE2 dte)
{
    // Retrieve and show the Output window.
    OutputWindow outWin = dte.ToolWindows.OutputWindow;

    pane = outWin.OutputWindowPanes.Item("Debug");
    }
    catch
    {
        pane = outWin.OutputWindowPanes.Add("Debug");
    }

    pane.OutputString("[timestamp: " + DateTime.Now.ToString() + "]\n");
}

也可以在每行前面附加一个时间戳,但这要困难得多。您无法更改“输出”窗口中已有的文本(它是只读的),但您可以清除该窗口并添加文本。因此,您可以使用上面相同的事件处理程序方法来检测文本更改,但您可以复制当前文本,将时间戳添加到任何还没有时间戳的行,清除窗口,然后重新添加 now,而不是附加- 带时间戳的文本。一旦输出窗口变大,就会出现性能问题。因此,您可能必须实现一种“惰性标记”,在后台进行清除和插入,以避免在短时间内发出 100 行调试输出(这是常见的)时杀死您的 IDE 。此外,当您清除并重新添加时,如果您当前正在输出窗口中选择文本,则您的选择将会丢失。

就我个人而言,我只会做简​​单的事情并附加时间戳行,而不是更困难的预挂起方法。由于如果不滚动就很难看到行末尾的内容,因此我可能会确保时间戳之前有一个换行符,因此用户会看到每批一个或多个输出行,后跟一个时间戳行。

可能有一种方法可以在显示文本之前挂钩输出窗口,但我在 VS Extensibility API 中找不到任何此类扩展点。

还有一个想法:您始终可以滚动自己的工具窗口,例如“Ivan 的调试输出”,它侦听来自真实输出窗口的事件,并将新行(带有时间戳)回显到您自己的工具窗口。这可能是最难的选择,但应该完全符合您的要求。

Since the output window text is read-only once written, there's not an easy way to do exactly what you want to do. However, it's easy to do something similar: append a timestamp line after new text is written to the output window. This will make the output window a lot more messy, but you'll get your timings.

Here's how this would work: First, create a Visual Studio Add-in or Macro which hooks the PaneUpdated event of the Outlook Window's active pane. (See this thread for how to do this with a Macro approach). Make sure to check, in the event handler, that pane.Name == "Debug" and ignore other panes. Second, when you detect new text in the debug output pane, append a timestamp line, like this:

public void AddTimestamp(DTE2 dte)
{
    // Retrieve and show the Output window.
    OutputWindow outWin = dte.ToolWindows.OutputWindow;

    pane = outWin.OutputWindowPanes.Item("Debug");
    }
    catch
    {
        pane = outWin.OutputWindowPanes.Add("Debug");
    }

    pane.OutputString("[timestamp: " + DateTime.Now.ToString() + "]\n");
}

It's also possible to pre-pend a timestamp to each line, but it's a lot harder. You can't change text already in the Output window (it's read-only), but you can clear the window and you can add text. So you could use the same event-handler approach above to detect text changes, but instead of appending you could copy the current text, prepend timestamps to any lines which don't have timestamps already, clear the window, and re-add the now-with-timestamps text. The problem with this is performance once your output window gets large. So you'd probably have to implement a kind of "lazy stamping" which does the clear and insert in the background, in order to avoid killing your IDE when (as is common) 100's of lines of debug output get emitted in a short time. Also, when you clear and re-add, if you're currently selecting text in the output window, your selection is lost.

Personally, I'd just do the easy thing and append timestamp lines rather than the harder pre-pend approach. Since stuff at the end of the line is hard to see without scrolling, I'd probably ensure there was a newline before the timestamp, so the user would see each batch of one or more output lines followed by one timestamp line.

It's possible there may be a way to hook the output window before text is displayed, but I couldn't find any such extensibility point in the VS Extensibility APIs.

One more idea: you could always roll your own tool window, e.g. "Ivan's Debug Output" which listens to events coming from the real output window, and echoes new lines (with timestamps) to your own tool window. This is probably the hardest option, but should do exactly what you want.

可是我不能没有你 2024-08-18 02:31:08

要为ANCIENT问题添加新答案,生产力工具 2013 扩展生产力工具 2015 扩展,将时间戳边距添加到输出窗口,无需任何代码。

to add a new answer to an ANCIENT question, there's an feature in the productivity power tools 2013 extension and productivity power tools 2015 extension that add a timestamp margin to the output window, no code required.

不如归去 2024-08-18 02:31:08

我一直在寻找相同的功能。我的同事在消息字段中提出了 $TICK 宏,打印出“当前”CPU 时钟周期。

看看Simon Chapman 的这些提示,也是。

I was looking for the same functionality. Colleague of mine came up with the $TICK macro in the message field, printing out the 'current' cpu ticks.

Take a look at these tips from Simon Chapman, too.

对你再特殊 2024-08-18 02:31:08

在 Visual Studio 2022 17.4 及更高版本中,您可以使用此选项

2022 17.4 发行说明 新内容

在输出窗口中有一个带时钟的按钮。

输入图片此处描述

更多信息:

https://davecallan.com/timestamps-add-output-窗口视觉工作室/

In Visual Studio 2022 17.4 and higher you have this option

2022 17.4 Release Notes What's new

In the output windows there is a button with clock.

enter image description here

More info:

https://davecallan.com/timestamps-added-output-window-visual-studio/

梦魇绽荼蘼 2024-08-18 02:31:08

我也想要这个功能,所以最终我编写了一个扩展来实现它(很像贾斯汀·格兰特在接受的答案中建议的那样)。使用了一段时间后,我认为相对时间戳在调试时对我更有用。如果人们想要绝对时间戳,我相信我可以重新添加该功能。无论如何,如果您有兴趣,可以在 niahtextfilter.com

并显示 Visual Studio 调试会话中正在运行的相对时间戳:
Niah 文本过滤调试输出

I wanted this functionality too, so eventually I wrote an extension to do it (much like Justin Grant suggested in the accepted answer). After using it for a while, I decided that relative timestamps were even more useful to me when debugging. If folks wanted absolute timestamps, I'm sure I could add that functionality back in. Anyway, if you're interested you can check it out at niahtextfilter.com.

And to show the relative timestamps in action in a Visual Studio debug session:
Niah Text Filter debug output

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文