Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a403beb
Add project evaluation metrics
OvesN Jul 20, 2026
2d6b44b
Fix evaluation duration listener accounting
OvesN Jul 24, 2026
270c1d6
Add evaluation pass duration metrics
OvesN Jul 24, 2026
ce3d324
wip
OvesN Jul 24, 2026
e3e0430
Rename evaluation origin outside build submission
OvesN Jul 24, 2026
e9550a7
Remove evaluation histogram bucket advice
OvesN Jul 24, 2026
1fd03cb
Simplify evaluation metric helpers
OvesN Jul 24, 2026
bb714e4
Correlate evaluation metrics with build submissions
OvesN Jul 28, 2026
62fc99d
Ship DiagnosticSource with VS MSBuild
OvesN Aug 26, 2026
d322a7d
Merge branch 'main' into dev/veronikao/evaluation-metrics
OvesN Aug 27, 2026
2a91d77
Potential fix for pull request finding
OvesN Aug 31, 2026
2c8b4dc
NGEN DiagnosticSource for both MSBuild architectures
OvesN Aug 31, 2026
309d603
Remove invalid xUnit abstractions import
OvesN Sep 1, 2026
e616e42
Explain process-wide submission correlation
OvesN Sep 2, 2026
1bbf3a5
Use event names in evaluation metrics test
OvesN Sep 2, 2026
f23cb79
Test submission correlation through environment
OvesN Sep 2, 2026
068cadb
remove unnecessary tests
OvesN Sep 2, 2026
d04eff7
Preserve per-manager submission IDs
OvesN Sep 2, 2026
fdf7fb0
Remove evaluation submission ID tag
OvesN Sep 2, 2026
1d7bde2
Order EventSource before evaluation metrics
OvesN Sep 2, 2026
86f6e18
Document evaluation metric constants
OvesN Sep 2, 2026
f52052d
Clarify evaluation origin tags
OvesN Sep 2, 2026
3cd5d22
Split lazy item evaluation metrics
OvesN Sep 2, 2026
13d8efd
Guard evaluation metrics dependency loading
OvesN Sep 3, 2026
1f20d07
Package DiagnosticSource for amd64 MSBuild
OvesN Sep 3, 2026
468174b
Unify project evaluation instrumentation
AlesProkop Sep 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/Deploy-MSBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ if ($runtime -eq "Desktop") {

FileToCopy "$bootstrapBinDirectory\System.Buffers.dll"
FileToCopy "$bootstrapBinDirectory\System.Collections.Immutable.dll"
FileToCopy "$bootstrapBinDirectory\System.Diagnostics.DiagnosticSource.dll"
FileToCopy "$bootstrapBinDirectory\System.Memory.dll"
FileToCopy "$bootstrapBinDirectory\System.Numerics.Vectors.dll"
FileToCopy "$bootstrapBinDirectory\System.Reflection.MetadataLoadContext.dll"
Expand Down
537 changes: 537 additions & 0 deletions src/Build.UnitTests/Telemetry/EvaluationMetrics_Tests.cs

Large diffs are not rendered by default.

153 changes: 93 additions & 60 deletions src/Build/Evaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.Build.Collections;
using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation.Context;
using Microsoft.Build.Eventing;
using Microsoft.Build.Execution;
using Microsoft.Build.ProjectCache;
using Microsoft.Build.FileSystem;
Expand All @@ -25,6 +24,7 @@
using Microsoft.Build.Internal;
using Microsoft.Build.Shared;
using Microsoft.Build.Shared.FileSystem;
using Microsoft.Build.TelemetryInfra;
using static Microsoft.Build.Execution.ProjectPropertyInstance;
using Constants = Microsoft.Build.Framework.Constants;
using EngineFileUtilities = Microsoft.Build.Internal.EngineFileUtilities;
Expand Down Expand Up @@ -348,61 +348,72 @@ internal static void Evaluate(
bool interactive = false,
ProjectEvaluationStage evaluationStage = ProjectEvaluationStage.Full)
{
MSBuildEventSource.Log.EvaluateStart(root.ProjectFileLocation.File);
var profileEvaluation = (loadSettings & ProjectLoadSettings.ProfileEvaluation) != 0 || loggingService.IncludeEvaluationProfile;
var evaluator = new Evaluator<P, I, M, D>(
data,
project,
root,
loadSettings,
maxNodeCount,
environmentProperties,
propertiesFromCommandLine,
itemFactory,
toolsetProvider,
directoryCacheFactory,
projectRootElementCache,
sdkResolverService,
submissionId,
evaluationContext,
profileEvaluation,
interactive,
loggingService,
buildEventContext,
evaluationStage);
using EvaluationInstrumentation.EvaluationScope evaluationInstrumentation =
EvaluationInstrumentation.StartEvaluation(root.ProjectFileLocation.File, evaluationStage, submissionId);
Evaluator<P, I, M, D> evaluator = null;
bool evaluationSucceeded = false;

try
{
evaluator.Evaluate();
}
catch (PathTooLongException ex)
{
evaluator._evaluationLoggingContext.LogErrorFromText(null, null, null, new BuildEventFileInfo(root.ProjectFileLocation.File),
ex.Message);
var profileEvaluation = (loadSettings & ProjectLoadSettings.ProfileEvaluation) != 0 || loggingService.IncludeEvaluationProfile;
evaluator = new Evaluator<P, I, M, D>(
data,
project,
root,
loadSettings,
maxNodeCount,
environmentProperties,
propertiesFromCommandLine,
itemFactory,
toolsetProvider,
directoryCacheFactory,
projectRootElementCache,
sdkResolverService,
submissionId,
evaluationContext,
profileEvaluation,
interactive,
loggingService,
buildEventContext,
evaluationStage);

try
{
evaluator.Evaluate();
evaluationSucceeded = true;
}
catch (PathTooLongException ex)
{
evaluator._evaluationLoggingContext.LogErrorFromText(null, null, null, new BuildEventFileInfo(root.ProjectFileLocation.File),
ex.Message);
}
}
finally
{
IEnumerable globalProperties = null;
IEnumerable properties = null;
IEnumerable items = null;
evaluationInstrumentation.CompleteEvaluation(evaluationSucceeded);

if (evaluator._evaluationLoggingContext.LoggingService.IncludeEvaluationPropertiesAndItemsInEvaluationFinishedEvent)
if (evaluator is not null)
{
globalProperties = evaluator._data.GlobalPropertiesDictionary;
properties = Traits.LogAllEnvironmentVariables ? evaluator._data.Properties : evaluator.FilterOutEnvironmentDerivedProperties(evaluator._data.Properties);
items = evaluator._data.Items;
}
IEnumerable globalProperties = null;
IEnumerable properties = null;
IEnumerable items = null;

string skippedMessage = evaluator._projectRootElementCache.ParserIgnoreConfiguration?.GetSkippedSummaryMessage();
if (skippedMessage is not null)
{
evaluator._evaluationLoggingContext.LogCommentFromText(MessageImportance.Low, skippedMessage);
}
if (evaluator._evaluationLoggingContext.LoggingService.IncludeEvaluationPropertiesAndItemsInEvaluationFinishedEvent)
{
globalProperties = evaluator._data.GlobalPropertiesDictionary;
properties = Traits.LogAllEnvironmentVariables ? evaluator._data.Properties : evaluator.FilterOutEnvironmentDerivedProperties(evaluator._data.Properties);
items = evaluator._data.Items;
}

evaluator._evaluationLoggingContext.LogProjectEvaluationFinished(globalProperties, properties, items, evaluator._evaluationProfiler.ProfiledResult);
}
string skippedMessage = evaluator._projectRootElementCache.ParserIgnoreConfiguration?.GetSkippedSummaryMessage();
if (skippedMessage is not null)
{
evaluator._evaluationLoggingContext.LogCommentFromText(MessageImportance.Low, skippedMessage);
}

MSBuildEventSource.Log.EvaluateStop(root.ProjectFileLocation.File);
evaluator._evaluationLoggingContext.LogProjectEvaluationFinished(globalProperties, properties, items, evaluator._evaluationProfiler.ProfiledResult);
}
}
}

/// <summary>
Expand Down Expand Up @@ -662,7 +673,6 @@ private static ProjectTargetInstance ReadNewTargetElement(ProjectTargetElement t
/// </summary>
private void Evaluate()
{
string projectFile = string.IsNullOrEmpty(_projectRootElement.ProjectFileLocation.File) ? "(null)" : _projectRootElement.ProjectFileLocation.File;
using (_evaluationProfiler.TrackPass(EvaluationPass.TotalEvaluation))
{
Assumed.Equal(_data.EvaluationId, BuildEventContext.InvalidEvaluationId, "There is no prior evaluation ID. The evaluator data needs to be reset at this point");
Expand All @@ -683,11 +693,16 @@ private void Evaluate()

int globalPropertiesCount;

EvaluationInstrumentation.EvaluationPassScope passInstrumentation;
using (_evaluationProfiler.TrackPass(EvaluationPass.InitialProperties))
{
// Pass0: load initial properties
// Follow the order of precedence so that Global properties overwrite Environment properties
MSBuildEventSource.Log.EvaluatePass0Start(_projectRootElement.ProjectFileLocation.File);
passInstrumentation = EvaluationInstrumentation.StartPass(
_projectRootElement.ProjectFileLocation.File,
EvaluationPass.InitialProperties,
_evaluationStage,
_submissionId);
AddBuiltInProperties();
AddEnvironmentProperties();
AddToolsetProperties();
Expand All @@ -701,10 +716,14 @@ private void Evaluate()

Assumed.NotEqual(_data.EvaluationId, BuildEventContext.InvalidEvaluationId, "Evaluation should produce an evaluation ID");

MSBuildEventSource.Log.EvaluatePass0Stop(projectFile);
passInstrumentation.Complete();

// Pass1: evaluate properties, load imports, and gather everything else
MSBuildEventSource.Log.EvaluatePass1Start(projectFile);
passInstrumentation = EvaluationInstrumentation.StartPass(
_projectRootElement.ProjectFileLocation.File,
EvaluationPass.Properties,
_evaluationStage,
_submissionId);
using (_evaluationProfiler.TrackPass(EvaluationPass.Properties))
{
PerformDepthFirstPass(_projectRootElement);
Expand All @@ -719,7 +738,7 @@ private void Evaluate()
}

_data.InitialTargets = initialTargets;
MSBuildEventSource.Log.EvaluatePass1Stop(projectFile);
passInstrumentation.Complete();

if (_evaluationStage <= ProjectEvaluationStage.Properties)
{
Expand All @@ -729,7 +748,11 @@ private void Evaluate()

// Pass2: evaluate item definitions
// Don't box via IEnumerator and foreach; cache count so not to evaluate via interface each iteration
MSBuildEventSource.Log.EvaluatePass2Start(projectFile);
passInstrumentation = EvaluationInstrumentation.StartPass(
_projectRootElement.ProjectFileLocation.File,
EvaluationPass.ItemDefinitionGroups,
_evaluationStage,
_submissionId);
using (_evaluationProfiler.TrackPass(EvaluationPass.ItemDefinitionGroups))
{
foreach (var itemDefinitionGroupElement in _itemDefinitionGroupElements)
Expand All @@ -740,7 +763,7 @@ private void Evaluate()
}
}
}
MSBuildEventSource.Log.EvaluatePass2Stop(projectFile);
passInstrumentation.Complete();

if (_evaluationStage <= ProjectEvaluationStage.ItemDefinitions)
{
Expand All @@ -755,8 +778,11 @@ private void Evaluate()
lazyEvaluator = new LazyItemEvaluator<P, I, M, D>(_data, _itemFactory, _evaluationLoggingContext, _evaluationProfiler, _evaluationContext);

// Pass3: evaluate project items
MSBuildEventSource.Log.EvaluatePass3Start(projectFile);

passInstrumentation = EvaluationInstrumentation.StartPass(
_projectRootElement.ProjectFileLocation.File,
EvaluationPass.Items,
_evaluationStage,
_submissionId);
SynthesizeImportedProjectItems();

DetectItemGlobRequest();
Expand Down Expand Up @@ -796,8 +822,7 @@ private void Evaluate()
}

SynthesizeItemGlobItems();

MSBuildEventSource.Log.EvaluatePass3Stop(projectFile);
passInstrumentation.Complete();

if (_evaluationStage <= ProjectEvaluationStage.Items)
{
Expand All @@ -806,7 +831,11 @@ private void Evaluate()
}

// Pass4: evaluate using-tasks
MSBuildEventSource.Log.EvaluatePass4Start(projectFile);
passInstrumentation = EvaluationInstrumentation.StartPass(
_projectRootElement.ProjectFileLocation.File,
EvaluationPass.UsingTasks,
_evaluationStage,
_submissionId);
using (_evaluationProfiler.TrackPass(EvaluationPass.UsingTasks))
{
// Evaluate the usingtask and add the result into the data passed in
Expand All @@ -819,7 +848,7 @@ private void Evaluate()
_evaluationContext.FileSystem);
}

MSBuildEventSource.Log.EvaluatePass4Stop(projectFile);
passInstrumentation.Complete();

if (_evaluationStage <= ProjectEvaluationStage.UsingTasks)
{
Expand Down Expand Up @@ -849,7 +878,11 @@ private void Evaluate()
using (_evaluationProfiler.TrackPass(EvaluationPass.Targets))
{
// Pass5: read targets (but don't evaluate them: that happens during build)
MSBuildEventSource.Log.EvaluatePass5Start(projectFile);
passInstrumentation = EvaluationInstrumentation.StartPass(
_projectRootElement.ProjectFileLocation.File,
EvaluationPass.Targets,
_evaluationStage,
_submissionId);
for (var i = 0; i < targetElementsCount; i++)
{
var element = _targetElements[i];
Expand Down Expand Up @@ -903,7 +936,7 @@ private void Evaluate()
}

_data.FinishEvaluation();
MSBuildEventSource.Log.EvaluatePass5Stop(projectFile);
passInstrumentation.Complete();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Build/Microsoft.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<Reference Include="System.IO.Compression" />
<PackageReference Include="System.Memory" />
<PackageReference Include="System.Security.Principal.Windows" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="System.Threading.Tasks.Dataflow" />
Expand Down Expand Up @@ -219,6 +220,7 @@
<Compile Include="Logging\BuildEventArgsExtensions.cs" />
<Compile Include="Logging\TerminalLogger\**\*.cs" />
<Compile Include="Logging\ReusableLogger.cs" />
<Compile Include="TelemetryInfra\EvaluationInstrumentation.cs" />
<Compile Include="TelemetryInfra\InternalTelemetryConsumingLogger.cs" />
<Compile Include="TelemetryInfra\ITelemetryCollector.cs" />
<Compile Include="TelemetryInfra\TasksDetailsTelemetry.cs" />
Expand Down
Loading
Loading