Skip to content

Commit 6e4912e

Browse files
committed
add traces to dotnet new instantiation
1 parent 78fd341 commit 6e4912e

13 files changed

+43
-35
lines changed

Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<PackageVersion Include="System.Composition.Runtime" Version="$(SystemCompositionRuntimePackageVersion)" />
112112
<PackageVersion Include="System.Composition.TypedParts" Version="$(SystemCompositionTypedPartsPackageVersion)" />
113113
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerPackageVersion)" />
114+
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourcePackageVersion)" />
114115
<PackageVersion Include="System.Formats.Asn1" Version="$(SystemFormatsAsn1Version)" />
115116
<PackageVersion Include="System.IO.Hashing" Version="$(SystemIOHashingPackageVersion)" />
116117
<!-- System.Reflection.Metadata and System.Collections.Immutable cannot be pinned here because of hard dependencies within Roslyn on specific versions that have to work both here and in VS -->
@@ -160,4 +161,4 @@
160161
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildMinimumVersion)" />
161162
<PackageVersion Include="Microsoft.NET.StringTools" Version="$(MicrosoftBuildMinimumVersion)" />
162163
</ItemGroup>
163-
</Project>
164+
</Project>

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<SystemCompositionRuntimePackageVersion>10.0.0-preview.6.25316.103</SystemCompositionRuntimePackageVersion>
125125
<SystemCompositionTypedPartsPackageVersion>10.0.0-preview.6.25316.103</SystemCompositionTypedPartsPackageVersion>
126126
<SystemConfigurationConfigurationManagerPackageVersion>10.0.0-preview.6.25316.103</SystemConfigurationConfigurationManagerPackageVersion>
127+
<SystemDiagnosticsDiagnosticSourcePackageVersion>10.0.0-preview.6.25316.103</SystemDiagnosticsDiagnosticSourcePackageVersion>
127128
<SystemReflectionMetadataLoadContextVersion>10.0.0-preview.6.25316.103</SystemReflectionMetadataLoadContextVersion>
128129
<SystemResourcesExtensionsPackageVersion>10.0.0-preview.6.25316.103</SystemResourcesExtensionsPackageVersion>
129130
<SystemSecurityCryptographyPkcsPackageVersion>10.0.0-preview.6.25316.103</SystemSecurityCryptographyPkcsPackageVersion>

src/Cli/dotnet/Activities.cs renamed to src/Cli/Microsoft.DotNet.Cli.Utils/Activities.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
14
using System.Diagnostics;
2-
using Microsoft.DotNet.Cli.Utils;
35

4-
namespace Microsoft.DotNet.Cli;
6+
namespace Microsoft.DotNet.Cli.Utils;
57

68

79
public static class Activities

src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static string GetMSBuildExePath()
171171
MSBuildExeName);
172172
}
173173

174-
private static string GetMSBuildSDKsPath()
174+
public static string GetMSBuildSDKsPath()
175175
{
176176
var envMSBuildSDKsPath = Environment.GetEnvironmentVariable("MSBuildSDKsPath");
177177

src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))' == '.NETCoreApp'"
4343
GeneratePathProperty="true" />
4444
<PackageReference Include="Microsoft.Extensions.DependencyModel" />
45+
<PackageReference Include="System.Diagnostics.DiagnosticSource"/>
4546
<PackageReference Include="NuGet.Versioning" />
4647
<PackageReference Include="NuGet.Packaging" />
4748
<PackageReference Include="NuGet.Frameworks" />

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/InstantiateCommand.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ internal static async Task<IEnumerable<TemplateGroup>> GetTemplateGroupsAsync(
7474
HostSpecificDataLoader hostSpecificDataLoader,
7575
CancellationToken cancellationToken)
7676
{
77+
using var createTemplateGroupsActivity = Activities.s_source.StartActivity("create-template-groups");
7778
IReadOnlyList<ITemplateInfo> templates = await templatePackageManager.GetTemplatesAsync(cancellationToken).ConfigureAwait(false);
7879
return TemplateGroup.FromTemplateList(CliTemplateInfo.FromTemplateInfo(templates, hostSpecificDataLoader));
7980
}
@@ -84,6 +85,7 @@ internal static HashSet<TemplateCommand> GetTemplateCommand(
8485
TemplatePackageManager templatePackageManager,
8586
TemplateGroup templateGroup)
8687
{
88+
using var getTemplateActivity = Activities.s_source.StartActivity("get-template-command");
8789
//groups templates in the group by precedence
8890
foreach (IGrouping<int, CliTemplateInfo> templateGrouping in templateGroup.Templates.GroupBy(g => g.Precedence).OrderByDescending(g => g.Key))
8991
{
@@ -204,6 +206,8 @@ private static async Task<NewCommandStatus> ExecuteIntAsync(
204206

205207
return await templateListCoordinator.DisplayCommandDescriptionAsync(instantiateArgs, cancellationToken).ConfigureAwait(false);
206208
}
209+
using var createActivity = Activities.s_source.StartActivity("instantiate-command");
210+
createActivity?.DisplayName = $"Invoke '{instantiateArgs.ShortName}'";
207211

208212
IEnumerable<TemplateGroup> allTemplateGroups = await GetTemplateGroupsAsync(
209213
templatePackageManager,
@@ -273,10 +277,11 @@ private static async Task<NewCommandStatus> HandleTemplateInstantiationAsync(
273277
{
274278
TemplateCommand templateCommandToRun = candidates.Single();
275279
args.Command.Subcommands.Add(templateCommandToRun);
276-
280+
var templateParseActivity = Activities.s_source.StartActivity("reparse-for-template");
277281
ParseResult updatedParseResult = args.ParseResult.RootCommandResult.Command.Parse(
278282
args.ParseResult.Tokens.Select(t => t.Value).ToArray(),
279283
args.ParseResult.Configuration);
284+
templateParseActivity?.Stop();
280285
return await candidates.Single().InvokeAsync(updatedParseResult, cancellationToken).ConfigureAwait(false);
281286
}
282287
else if (candidates.Any())

src/Cli/Microsoft.TemplateEngine.Cli/Commands/create/TemplateCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,23 @@ internal static async Task<IReadOnlyList<TemplateConstraintResult>> ValidateCons
146146

147147
internal async Task<NewCommandStatus> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken)
148148
{
149+
using var templateInvocationActivity = Activities.s_source.StartActivity("invoke-template");
149150
TemplateCommandArgs args = new(this, _instantiateCommand, parseResult);
150151
TemplateInvoker invoker = new(_environmentSettings, () => Console.ReadLine() ?? string.Empty);
151152
TemplatePackageCoordinator packageCoordinator = new(_environmentSettings, _templatePackageManager);
152-
TemplateConstraintManager constraintManager = new(_environmentSettings);
153+
using TemplateConstraintManager constraintManager = new(_environmentSettings);
153154
TemplatePackageDisplay templatePackageDisplay = new(Reporter.Output, Reporter.Error);
154155

155156
CancellationTokenSource cancellationTokenSource = new();
156157
cancellationTokenSource.CancelAfter(ConstraintEvaluationTimeout);
157158

159+
#pragma warning disable CA2025 // Do not pass 'IDisposable' instances into unawaited tasks
158160
Task<IReadOnlyList<TemplateConstraintResult>> constraintsEvaluation = ValidateConstraintsAsync(constraintManager, args.Template, args.IsForceFlagSpecified ? cancellationTokenSource.Token : cancellationToken);
161+
#pragma warning restore CA2025 // Do not pass 'IDisposable' instances into unawaited tasks
159162

160163
if (!args.IsForceFlagSpecified)
161164
{
165+
using var constraintResultsActivity = Activities.s_source.StartActivity("validate-constraints");
162166
var constraintResults = await constraintsEvaluation.ConfigureAwait(false);
163167
if (constraintResults.Any())
164168
{

src/Cli/Microsoft.TemplateEngine.Cli/TemplateInvoker.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ internal TemplateInvoker(
3737

3838
internal async Task<NewCommandStatus> InvokeTemplateAsync(TemplateCommandArgs templateArgs, CancellationToken cancellationToken)
3939
{
40+
using var invokerActivity = Activities.s_source.StartActivity("invoker-invoking");
4041
cancellationToken.ThrowIfCancellationRequested();
4142

4243
CliTemplateInfo templateToRun = templateArgs.Template;
@@ -158,6 +159,7 @@ private async Task<NewCommandStatus> CreateTemplateAsync(TemplateCommandArgs tem
158159

159160
try
160161
{
162+
using var templateCreationActivity = Activities.s_source.StartActivity("actual-instantiate-template");
161163
instantiateResult = await _templateCreator.InstantiateAsync(
162164
templateArgs.Template,
163165
templateArgs.Name,
@@ -306,6 +308,7 @@ private async Task<NewCommandStatus> CreateTemplateAsync(TemplateCommandArgs tem
306308

307309
private NewCommandStatus HandlePostActions(ITemplateCreationResult creationResult, TemplateCommandArgs args)
308310
{
311+
using var postActionActivity = Activities.s_source.StartActivity("post-actions");
309312
PostActionExecutionStatus result = _postActionDispatcher.Process(creationResult, args.IsDryRun, args.AllowScripts ?? AllowRunScripts.Prompt);
310313

311314
return result switch

src/Cli/Microsoft.TemplateEngine.Cli/TemplateListCoordinator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal TemplateListCoordinator(
3030
_templatePackageManager = templatePackageManager ?? throw new ArgumentNullException(nameof(templatePackageManager));
3131
_hostSpecificDataLoader = hostSpecificDataLoader ?? throw new ArgumentNullException(nameof(hostSpecificDataLoader));
3232
_defaultLanguage = engineEnvironmentSettings.GetDefaultLanguage();
33+
using var constraintManagerActivity = Activities.s_source.StartActivity("create-constraints");
3334
_constraintManager = new TemplateConstraintManager(_engineEnvironmentSettings);
3435
}
3536

src/Cli/dotnet/Commands/New/BuiltInTemplatePackageProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#nullable disable
55

6+
using Microsoft.DotNet.Cli.Utils;
67
using Microsoft.TemplateEngine.Abstractions;
78
using Microsoft.TemplateEngine.Abstractions.TemplatePackage;
89
using NuGet.Versioning;
@@ -44,7 +45,7 @@ private static IEnumerable<string> GetTemplateFolders(IEngineEnvironmentSettings
4445
{
4546
var templateFoldersToInstall = new List<string>();
4647

47-
var sdksDirectory = new DirectoryInfo(environmentSettings.Environment.GetEnvironmentVariable("MSBuildSDKsPath"));
48+
var sdksDirectory = new DirectoryInfo(MSBuildForwardingAppWithoutLogging.GetMSBuildSDKsPath());
4849
var sdkDirectory = sdksDirectory.Parent!;
4950
var sdkVersion = sdkDirectory.Name;
5051
var dotnetRootPath = sdkDirectory.Parent!.Parent!;

0 commit comments

Comments
 (0)