Displaying build times in Visual Studio
Asked Answered
C

14

199

Our build server is taking too long to build one of our C++ projects. It uses Visual Studio 2008, running devenv.com MyApp.sln /Build -- see devenv command-line switches (although that's for a newer version of VS). Is there a way to get devenv.com to log the time taken to build each project in the solution, so that I know where to focus my efforts?

Improved hardware is not an option in this case.

I've tried setting the output verbosity (under menu ToolsOptionsProjects and SolutionsBuild and RunMSBuild project build output verbosity). This doesn't seem to have any effect in the IDE.

When running MSBuild from the command line (and, for Visual Studio 2008, it needs to be MSBuild v3.5), it displays the total time elapsed at the end, but not in the IDE.

I really wanted a time-taken report for each project in the solution, so that I could figure out where the build process was taking its time.

Chalcedony answered 17/9, 2008 at 11:20 Comment(1)
devenv.com is not a web site, but the COM file devenvLabrador
X
229

Menu ToolsOptionsProjects and SolutionsVC++ Project SettingsBuild Timing should work.

Xylem answered 25/9, 2008 at 10:34 Comment(7)
One would think it's under "Build and Run", but nooooo, that would have been to simpleFeatured
If they would have put it there, someone else would have complained that it is not where they would expect it to be. The most obvious place to put it is different for different users.Xylem
What's the output of this?Fistic
@AndreasBonini: Under Build and Run you'll find MSBuild project build output v̱erbosity which you can set above Minimal to get timings, too.Wizen
This is good for profiling individual tasks within a build stage, but doesnt give summaries of the whole build.Woodham
To get any timing information it is necessary to change setting "MSBuild project build output verbosity" from "Minimal" (the installation default) to "Normal" (in menu ToolsOptionsProjects and SolutionsBuild and Run). Perhaps you can add this information to your answer?Labrador
@PeterMortensen Not really. With parallel builds, you get the "user time" per-project, but not the "wall time". Seems so natural and easy to indicate the "wall time" at the end of a build, the fact it's not there is really strange (and annoying)Kolkhoz
T
107

Go to menu ToolsOptionsProjects and SolutionsBuild and RunMSBuild project build output verbosity. Set to "Normal" or "Detailed", and the build time will appear in the output window.

Transportation answered 17/9, 2008 at 11:22 Comment(4)
Prior to Visual Studio 2010, Visual C++ projects don't use MSBuild, so this setting has no effect. Works fine for other project types, though.Chalcedony
set to "Normal" instead of "Detailed" is enough :)Schizont
Setting this to Normal is indeed what most would want because VC++ Project Settings -> Build Timing shows way too much detailsMelly
This is exactly what most people want - total time, and not that ClCompile took 22424ms in one of the projects. Ctrl+Q, build and run <Enter>, and change first "minimal" to "normal".Fanciful
L
43

Visual Studio 2012 - 2019

  • For MSBuild Projects (e.g., all .NET projects): Click ToolsOptions and then select Projects and SolutionsBuild and Run. Change MSBuild project build output verbosity to Normal. So it will display Time Elapsed in every Solution Project it builds. But there is unfortunately no Elapsed Time Sum over all projects. You will also see the Build started Timestamp

  • For C/C++ Projects:

Click ToolsOptions and then select Projects and SolutionsVC++ Project Settings.

Change Build Timing to Yes.

Laris answered 8/8, 2014 at 12:38 Comment(2)
The solution you offered works for me on VS 2015 for a C++ project too. Also, I choose to use this solution instead of Build Timing since it displays the total time only.Dino
No change with VS2019. The total "time elapsed" is shown for all MSBuild Projects (including C/C++).Dzoba
P
26

I have created an extension to measure the build times and present the order of events in a graph: Visual Studio Build Timer.

Enter image description here

It is available on the Visual Studio market place and works for Visual Studio 2015, Visual Studio 2017 and Visual Studio 2019.

Apart from showing which projects take longer, the chart displays effective dependencies between them, i.e., projects that need to wait for others, which helps figuring out what dependencies need to break to increase the parallelization of your build.

Plemmons answered 11/1, 2019 at 10:49 Comment(6)
Could you please upgrade it to support VS 2019Polystyrene
I am a bit busy these days, but it's in my plans.Plemmons
I think this should be the preferred answer. It installs and just works beautifully (VS2019 version 16.10.3). The accepted answer which is Tools->Options->... is inferior IMHO to the results this plug in provides. A log to file option on the plug in might be nice... but jotting this into EXCEL is easily done.Pubes
It would be nice if you had the time to support CS 2022 :)Hydnocarpate
Please upgrade Visual Studio Build Timer extension to VS2022, it is really neat! Btw I mention it in this blog post blog.ndepend.com/improve-visual-studio-build-performanceElectrotonus
@Plemmons Someone create pull request to support Visual Studio 2022. Can you please review it as an author? bitbucket.org/odyxanthi/vs_buildtimer/pull-requests/6Sufflate
B
8

Menu ToolsOptionsProjects and SolutionsBuild and Run

Set "MSBuild project build output verbosity" from "Minimal" to "Normal".

Brandenbrandenburg answered 16/1, 2013 at 12:14 Comment(0)
U
8

For Visual Studio 2012 you could use the Build Monitor extension.

Ugric answered 8/7, 2013 at 12:16 Comment(1)
You could use it for Visual Studio 2013 and 2015 as well.Lineament
T
6

Since your question involves using DevEnv from the command line, I would also suggest using MSBuild (which can build .sln files without modification).

msbuild /fl /flp:Verbosity=diagnostic Your.sln

msbuild /? will show you other useful options for the filelogger.

Transportation answered 17/9, 2008 at 11:36 Comment(0)
O
6

If you're stuck on VS2005 you could use the vs-build-timer plugin. At the completion of a build it shows the total time taken and a (optional) summary of each of the project durations.

Disclaimer; I wrote it. And yes, I need to create an installer...one day!

Outclass answered 7/4, 2010 at 4:29 Comment(3)
Is your installer availableCostume
Did you create it? 12 years should be enough time.Labrador
Afraid not - haven't used Visual Studio actively for probably a decade! Feel free to create one ;)Outclass
G
6

If you want to visualize your build, you can use Incredibuild. Incredibuild's now available in standalone-mode (not distributed, but for use only on 8 cores on your local machine) for free as part of Visual Studio 2015 Update 1.

Disclaimer: I work for Incredibuild

Gallman answered 6/12, 2015 at 14:38 Comment(1)
Loved incredibuild... could not justify getting a licensed copy so had to abandon it. I work in a remote location and don't have enough local CPU's for abuild farm. But were my situation slightly different I'd be able to justify it. Worked great on ancient VS6.0 and VS2013 when I benchmarked it years ago. Impressive product.Pubes
M
4

I ended up here because I just wanted the date and time included in the build output. Should others be searching for something similar it's as simple as adding echo %date% %time% to the Pre-build and/or Post-build events under project, PropertiesCompileBuild Events.

Meza answered 19/3, 2015 at 14:2 Comment(0)
N
4

Do a build first and see which project is appearing first in the build output (Ctrl + Home in the output window). Right click that project → Project PropertiesCompileBuild EventsPre-build. And echo ###########%date% %time%#############.

So every time you see build results (or during build) do Ctrl + Home in the output window. And somewhere in that area the time and date stares at your face!

Oh and you might end up adding these details to many projects as the build order can change :)


I found a better solution! ###

ToolsOptionsProjects & SolutionsBuild and RunMSBuild project build output verbosity = Normal (or above Minimal). This adds the time in the beginning/top of output window. Ctrl + Home in the output window should do.

If we want to see how much time each projects take then Projects & SolutionsVC++ Project SettingsBuild Timing = yes. It is applicable to all projects; "VC++" is misleading.

Nall answered 5/8, 2015 at 8:34 Comment(0)
G
2

Parallel Builds Monitor is a nice extension for Visual Studio, it works for VS 2022 while most other extensions does not.

Glimpse answered 17/1, 2023 at 19:52 Comment(0)
B
1

If you want to invoke an external program that can track your total build times, you can use the following solution for Visual Studio 2010 (and maybe older). The code below uses CTime by Casey Muratori. Of course, you can also use it to simply print the build time.

Open up the macro explorer, and paste the following before 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

The answer was taken from here and here.

Banderilla answered 10/5, 2016 at 12:49 Comment(1)
What is this mythical CTime you speak of?Labrador
M
1

Options -> Projects and Solutions -> VC++ Project Settings -> Build Timing

enter image description here

Mariano answered 3/7, 2018 at 10:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.