Skip to content

Commit

Permalink
Opt Into Perf Logging (#6274)
Browse files Browse the repository at this point in the history
  • Loading branch information
benvillalobos committed Apr 15, 2021
1 parent 478f12f commit 369631b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions eng/cibuild_bootstrapped_msbuild.ps1
Expand Up @@ -53,6 +53,7 @@ $RepoRoot = [System.IO.Path]::GetFullPath($RepoRoot).TrimEnd($([System.IO.Path]:
$ArtifactsDir = Join-Path $RepoRoot "artifacts"
$Stage1Dir = Join-Path $RepoRoot "stage1"
$Stage1BinDir = Join-Path $Stage1Dir "bin"
$PerfLogDir = Join-Path $ArtifactsDir "log\$Configuration\PerformanceLogs"

if ($msbuildEngine -eq '')
{
Expand Down Expand Up @@ -123,6 +124,9 @@ try {
# Ensure that debug bits fail fast, rather than hanging waiting for a debugger attach.
$env:MSBUILDDONOTLAUNCHDEBUGGER="true"

# Opt into performance logging. https://github.com/dotnet/msbuild/issues/5900
$env:DOTNET_PERFLOG_DIR=$PerfLogDir

# When using bootstrapped MSBuild:
# - Turn off node reuse (so that bootstrapped MSBuild processes don't stay running and lock files)
# - Do run tests
Expand Down
4 changes: 4 additions & 0 deletions eng/cibuild_bootstrapped_msbuild.sh
Expand Up @@ -39,6 +39,7 @@ done
RepoRoot="$ScriptRoot/.."
ArtifactsDir="$RepoRoot/artifacts"
Stage1Dir="$RepoRoot/stage1"
PerfLogDir="$ArtifactsDir/log/$configuration/PerformanceLogs"

. "$ScriptRoot/common/tools.sh"
InitializeDotNetCli true
Expand Down Expand Up @@ -86,6 +87,9 @@ mv $ArtifactsDir $Stage1Dir
# Ensure that debug bits fail fast, rather than hanging waiting for a debugger attach.
export MSBUILDDONOTLAUNCHDEBUGGER=true

# Opt into performance logging.
export DOTNET_PERFLOG_DIR=$PerfLogDir

# Prior to 3.0, the Csc task uses this environment variable to decide whether to run
# a CLI host or directly execute the compiler.
export DOTNET_HOST_PATH="$_InitializeDotNetCli/dotnet"
Expand Down
4 changes: 2 additions & 2 deletions src/MSBuild.UnitTests/PerfLog_Tests.cs
Expand Up @@ -74,7 +74,7 @@ public void TestPerfLogEnabledProducedLogFile()
}

[Fact]
public void TestPerfLogDirectoryDoesNotExist()
public void TestPerfLogDirectoryGetsCreated()
{
using (TestEnvironment testEnv = TestEnvironment.Create(_output))
{
Expand All @@ -101,7 +101,7 @@ public void TestPerfLogDirectoryDoesNotExist()
RunnerUtilities.ExecMSBuild(msbuildParameters, out bool successfulExit);
successfulExit.ShouldBeTrue();

Directory.Exists(perfLogPath).ShouldBeFalse();
Directory.Exists(perfLogPath).ShouldBeTrue();
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/MSBuild/PerformanceLogEventListener.cs
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Text;
using Microsoft.Build.Eventing;
using Microsoft.Build.Shared;

namespace Microsoft.Build.CommandLine
{
Expand Down Expand Up @@ -51,7 +52,8 @@ internal static PerformanceLogEventListener Create()

// Check to see if we should enable the event listener.
string logDirectory = Environment.GetEnvironmentVariable(PerfLogDirEnvVar);
if (Directory.Exists(logDirectory))

if (!string.IsNullOrEmpty(logDirectory) && Directory.CreateDirectory(logDirectory).Exists)
{
eventListener = new PerformanceLogEventListener();
eventListener.Initialize(logDirectory);
Expand Down
4 changes: 4 additions & 0 deletions src/Shared/UnitTests/TestAssemblyInfo.cs
Expand Up @@ -40,6 +40,10 @@ public MSBuildTestAssemblyFixture()
// (VerifySubToolsetVersionSetByConstructorOverridable), as the environment variable would take precedence.
_testEnvironment.SetEnvironmentVariable("VisualStudioVersion", string.Empty);

// Prevent test assemblies from logging any performance info.
// https://github.com/dotnet/msbuild/pull/6274
_testEnvironment.SetEnvironmentVariable("DOTNET_PERFLOG_DIR", string.Empty);

SetDotnetHostPath(_testEnvironment);

// Use a project-specific temporary path
Expand Down

0 comments on commit 369631b

Please sign in to comment.