在Visual Studio中显示构建时间

199

我们的构建服务器在构建一个C++项目时花费的时间太长了。它使用的是Visual Studio 2008,运行命令devenv.com MyApp.sln /Build -- 参见devenv命令行开关(尽管此文档适用于较新版本的VS)。有没有办法让devenv.com记录构建解决方案中每个项目所花费的时间,以便我知道应该在哪里集中精力?

在这种情况下,改进硬件不是一个选项。

我已经尝试过设置输出详细级别(在菜单 工具选项项目和解决方案生成和运行MSBuild项目生成输出日志级别 下)。但这似乎对IDE没有任何影响。

当从命令行运行MSBuild时(对于Visual Studio 2008,需要使用MSBuild v3.5),它会在结束时显示总耗时,但在IDE中则不会。

我真的希望能够获得解决方案中每个项目所花费的时间报告,以便我可以找出构建过程在哪里消耗时间。


devenv.com 不是一个网站,而是 COM 文件 devenv - Peter Mortensen
14个回答

4
首先执行构建操作并查看构建输出中出现的第一个项目(在输出窗口中按Ctrl+Home)。右键单击该项目 → 项目属性编译生成事件预生成。然后,输入echo ###########%date% %time%#############
因此,每次查看构建结果时(或在构建过程中),您可以在输出窗口中按Ctrl+Home。并且某个地方会显示时间和日期!
哦,由于构建顺序可能会更改,您可能需要将这些详细信息添加到许多项目中 :)
我发现了更好的解决方案!### 工具选项项目和解决方案生成和运行MSBuild 项目生成输出详细程度= 正常(或高于最小值)。这将在输出窗口的顶部添加时间。在输出窗口中按Ctrl+Home即可。
如果我们想要查看每个项目花费了多少时间,则在项目和解决方案VC++ 项目设置中选择构建时间 = yes。这适用于所有项目;"VC++"可能会让人误解。

1

选项 -> 项目和解决方案 -> VC++ 项目设置 -> 构建时间

enter image description here


1
如果您想调用一个可以跟踪您的总构建时间的外部程序,您可以使用以下解决方案Visual Studio 2010(可能还包括旧版本)。下面的代码使用了Casey Muratori的CTime。当然,您也可以使用它来简单地打印构建时间。
打开宏资源管理器,在End Module之前粘贴以下内容:
Dim buildStart As Date

Private Sub RunCtime(ByVal StartRatherThanEnd As Boolean)
    Dim Arg As String
    Dim psi As New System.Diagnostics.ProcessStartInfo("ctime.exe")
    If StartRatherThanEnd Then
        psi.Arguments = "-begin"
    Else
        psi.Arguments = "-end"
    End If
    psi.Arguments += " c:\my\path\build.ctm"
    psi.RedirectStandardOutput = False
    psi.WindowStyle = ProcessWindowStyle.Hidden
    psi.UseShellExecute = False
    psi.CreateNoWindow = True
    Dim process As System.Diagnostics.Process
    process = System.Diagnostics.Process.Start(psi)
    Dim myOutput As System.IO.StreamReader = process.StandardOutput
    process.WaitForExit(2000)
    If process.HasExited Then
        Dim output As String = myOutput.ReadToEnd
        WriteToBuildWindow("CTime output: " + output)
    End If
End Sub

Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
    WriteToBuildWindow("Build started!")
    buildStart = Date.Now
    RunCtime(True)
End Sub

Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
    Dim buildTime = Date.Now - buildStart
    WriteToBuildWindow(String.Format("Total build time: {0} seconds", buildTime.ToString))
    RunCtime(False)
End Sub

Private Sub WriteToBuildWindow(ByVal message As String)
    Dim win As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
    Dim ow As OutputWindow = CType(win.Object, OutputWindow)
    If (Not message.EndsWith(vbCrLf)) Then
        message = message + vbCrLf
    End If
    ow.OutputWindowPanes.Item("Build").OutputString(message)
End Sub

这个答案摘自这里这里

你所说的神秘 CTime 是什么?(https://github.com/ThisDrunkDane/otime) - Peter Mortensen

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接