Skip to content

Commit 3998ce0

Browse files
PowerShellTeamandyleejordan
authored andcommitted
Update files from Source Depot changeset [SD:700586]
Corresponds to 84837459913bb00660964d19ea07f5e0c7b4b442 in psl-monad.
1 parent a7ba339 commit 3998ce0

40 files changed

Lines changed: 1635 additions & 488 deletions

src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ internal bool WasInitialCommandEncoded
6363
}
6464
}
6565

66+
internal bool ShowBanner
67+
{
68+
get
69+
{
70+
Dbg.Assert(dirty, "Parse has not been called yet");
71+
return showBanner;
72+
}
73+
}
74+
6675
internal bool NoExit
6776
{
6877
get
@@ -229,7 +238,7 @@ private void ShowHelp()
229238
ui.WriteLine("");
230239
}
231240

232-
private void ShowBanner()
241+
private void DisplayBanner()
233242
{
234243
// We need to show the banner only if it has not been already shown in native layer
235244
if (!showInitialPrompt)
@@ -699,7 +708,7 @@ private void ParseHelper(string[] args)
699708

700709
if (showBanner && !showHelp)
701710
{
702-
ShowBanner();
711+
DisplayBanner();
703712
}
704713

705714
Dbg.Assert(

src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Collections;
1111
using System.Collections.Generic;
1212
using System.Collections.ObjectModel;
13+
using System.Diagnostics;
1314
using System.Globalization;
1415
using System.IO;
1516
using System.Reflection;
@@ -36,7 +37,7 @@
3637
using NakedWin32Handle = System.IntPtr;
3738
using System.Management.Automation.Tracing;
3839
using Microsoft.PowerShell.Telemetry.Internal;
39-
40+
using Debugger = System.Management.Automation.Debugger;
4041

4142
namespace Microsoft.PowerShell
4243
{
@@ -51,7 +52,8 @@ internal sealed partial class ConsoleHost
5152
:
5253
PSHost,
5354
IDisposable,
54-
IHostSupportsInteractiveSession
55+
IHostSupportsInteractiveSession,
56+
IHostProvidesTelemetryData
5557
{
5658

5759
#region static methods
@@ -202,17 +204,8 @@ internal static int Start(
202204
theConsoleHost.UI.WriteWarningLine(preStartWarning);
203205
}
204206

205-
using (theConsoleHost)
207+
try
206208
{
207-
#region Telemetry
208-
209-
// Data Point to Collect: PowerShell Version on this device
210-
// If null Version is supplied, the Telemetry infrastucture will log an empty value for null
211-
string version = theConsoleHost.ver.ToString();
212-
Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.TraceMessage("PSCONSOLEHOST_START", new { PSVersion = version });
213-
214-
#endregion
215-
216209
cpp = new CommandLineParameterParser(theConsoleHost, theConsoleHost.ver, bannerText, helpText);
217210
string[] tempArgs = new string[args.GetLength(0)];
218211
args.CopyTo(tempArgs, 0);
@@ -239,15 +232,17 @@ internal static int Start(
239232
else if (cpp.NamedPipeServerMode)
240233
{
241234
ClrFacade.StartProfileOptimization("StartupProfileData-NamedPipeServerMode");
242-
System.Management.Automation.Remoting.RemoteSessionNamedPipeServer.RunServerMode(cpp.ConfigurationName);
235+
System.Management.Automation.Remoting.RemoteSessionNamedPipeServer.RunServerMode(
236+
cpp.ConfigurationName);
243237
exitCode = 0;
244238
}
245239
else if (cpp.SocketServerMode)
246240
{
247241
ClrFacade.StartProfileOptimization("StartupProfileData-SocketServerMode");
248-
System.Management.Automation.Remoting.Server.HyperVSocketMediator.Run(cpp.InitialCommand, cpp.ConfigurationName);
242+
System.Management.Automation.Remoting.Server.HyperVSocketMediator.Run(cpp.InitialCommand,
243+
cpp.ConfigurationName);
249244
exitCode = 0;
250-
}
245+
}
251246
else
252247
{
253248
ClrFacade.StartProfileOptimization(
@@ -256,7 +251,14 @@ internal static int Start(
256251
: "StartupProfileData-NonInteractive");
257252
exitCode = theConsoleHost.Run(cpp, !string.IsNullOrEmpty(preStartWarning));
258253
}
254+
259255
}
256+
finally
257+
{
258+
TelemetryAPI.ReportExitTelemetry(theConsoleHost);
259+
theConsoleHost.Dispose();
260+
}
261+
260262
unchecked
261263
{
262264
return (int)exitCode;
@@ -970,6 +972,22 @@ public override void NotifyEndApplication()
970972
}
971973
}
972974

975+
bool IHostProvidesTelemetryData.HostIsInteractive
976+
{
977+
get
978+
{
979+
return !cpp.NonInteractive && !cpp.AbortStartup &&
980+
((cpp.InitialCommand == null && cpp.File == null) || cpp.NoExit);
981+
}
982+
}
983+
double IHostProvidesTelemetryData.ProfileLoadTimeInMS { get { return _profileLoadTimeInMS; } }
984+
double IHostProvidesTelemetryData.ReadyForInputTimeInMS { get { return _readyForInputTimeInMS; } }
985+
int IHostProvidesTelemetryData.InteractiveCommandCount { get { return _interactiveCommandCount; } }
986+
987+
private double _profileLoadTimeInMS;
988+
private double _readyForInputTimeInMS;
989+
private int _interactiveCommandCount;
990+
973991
#endregion overrides
974992

975993
#region non-overrides
@@ -1370,6 +1388,7 @@ private uint DoRunspaceLoop(string initialCommand, bool skipProfiles, Collection
13701388

13711389
RunspaceCreationEventArgs args = new RunspaceCreationEventArgs(initialCommand, skipProfiles, staMode, importSystemModules, configurationName, initialCommandArgs);
13721390
CreateRunspace(args);
1391+
13731392
if (ExitCode == ExitCodeInitFailure) { break; }
13741393

13751394
if (!noExit && !ui.ReadFromStdin)
@@ -1564,6 +1583,9 @@ private void DoCreateRunspace(string initialCommand, bool skipProfiles, bool sta
15641583
PSTask.PowershellConsoleStartup, PSKeyword.UseAlwaysOperational);
15651584
}
15661585

1586+
// Record how long it took from process start to runspace open for telemetry.
1587+
_readyForInputTimeInMS = (DateTime.Now - Process.GetCurrentProcess().StartTime).TotalMilliseconds;
1588+
15671589
DoRunspaceInitialization(importSystemModules, skipProfiles, initialCommand, configurationName, initialCommandArgs);
15681590
}
15691591

@@ -1697,17 +1719,32 @@ private void DoRunspaceInitialization(bool importSystemModules, bool skipProfile
16971719
// 3. host independent profile of the current user
16981720
// 4. host specific profile of the current user
16991721

1722+
var sw = new Stopwatch();
1723+
sw.Start();
17001724
RunProfile(allUsersProfile, exec);
17011725
RunProfile(allUsersHostSpecificProfile, exec);
17021726
RunProfile(currentUserProfile, exec);
17031727
RunProfile(currentUserHostSpecificProfile, exec);
1728+
sw.Stop();
1729+
1730+
var profileLoadTimeInMs = sw.ElapsedMilliseconds;
1731+
if (profileLoadTimeInMs > 500 && cpp.ShowBanner)
1732+
{
1733+
Console.Error.WriteLine(ConsoleHostStrings.SlowProfileLoadingMessage, profileLoadTimeInMs);
1734+
}
1735+
1736+
_profileLoadTimeInMS = profileLoadTimeInMs;
17041737
}
17051738
else
17061739
{
17071740
tracer.WriteLine("-noprofile option specified: skipping profiles");
17081741
}
17091742
}
17101743

1744+
// Startup is reported after possibly running the profile, but before running the initial command (or file)
1745+
// if one is specified.
1746+
TelemetryAPI.ReportStartupTelemetry(this);
1747+
17111748
// If a file was specified as the argument to run, then run it...
17121749
if (cpp != null && cpp.File != null)
17131750
{
@@ -2714,6 +2751,9 @@ e is RemoteException ||
27142751
parent.PopRunspace();
27152752
}
27162753
}
2754+
2755+
if (!inBlockMode)
2756+
theConsoleHost._interactiveCommandCount += 1;
27172757
}
27182758
}
27192759
// NTRAID#Windows Out Of Band Releases-915506-2005/09/09

src/Microsoft.PowerShell.ConsoleHost/resources/CommandLineParameterParserStrings.resx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@
133133
<value>PowerShell[.exe] [-PSConsoleFile &lt;file&gt; | -Version &lt;version&gt;]
134134
[-NoLogo] [-NoExit] [-NoProfile] [-NonInteractive] [-STA]
135135
[-OutputFormat {Text | XML}] [-InputFormat {Text | XML}]
136+
[-ConfigurationName &lt;string&gt;]
137+
[-File fileName [arguments...]] [-ExecutionPolicy &lt;ExecutionPolicy&gt;]
136138
[-Command { - | &lt;script-block&gt; [-args &lt;arg-array&gt;]
137139
| &lt;string&gt; [&lt;CommandParameters&gt;] } ]
138-
[-File fileName [arguments...]] [-ExecutionPolicy &lt;ExecutionPolicy&gt;]
139140

140141
PowerShell[.exe] -Help | -? | /?
141142

142-
143143
-PSConsoleFile
144144
Loads the specified Windows PowerShell console file. To create a console
145145
file, use Export-Console in Windows PowerShell.
@@ -170,6 +170,12 @@ PowerShell[.exe] -Help | -? | /?
170170
Describes the format of data sent to Windows PowerShell. Valid values are
171171
"Text" (text strings) or "XML" (serialized CLIXML format).
172172

173+
-ConfigurationName
174+
Specifies a configuration endpoint in which Windows PowerShell is run.
175+
This can be any endpoint registered on the local machine including the
176+
default Windows PowerShell remoting endpoints or a custom endpoint having
177+
specific user role capabilities.
178+
173179
-Command
174180
Executes the specified commands (and any parameters) as though they were
175181
typed at the Windows PowerShell command prompt, and then exits, unless
@@ -201,6 +207,7 @@ PowerShell[.exe] -Help | -? | /?
201207
EXAMPLES
202208
PowerShell -PSConsoleFile SqlSnapin.Psc1
203209
PowerShell -version 1.0 -NoLogo -InputFormat text -OutputFormat XML
210+
PowerShell -ConfigurationName AdminRoles
204211
PowerShell -Command {Get-EventLog -LogName security}
205212
PowerShell -Command "&amp; {Get-EventLog -LogName security}"
206213
</value>

src/Microsoft.PowerShell.ConsoleHost/resources/ConsoleHostStrings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,7 @@ The current session does not support debugging; execution will continue.
185185
<data name="ConflictingServerModeParameters" xml:space="preserve">
186186
<value>More than one server mode parameter was specified. Server mode parameters must be used exclusively.</value>
187187
</data>
188-
</root>
188+
<data name="SlowProfileLoadingMessage" xml:space="preserve">
189+
<value>Loading personal and system profiles took {0}ms.</value>
190+
</data>
191+
</root>

src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ Copyright (C) 2016 Microsoft Corporation. All rights reserved.</value>
124124
<data name="ShellHelp" xml:space="preserve">
125125
<value>PowerShell[.exe] [-PSConsoleFile &lt;file&gt; | -Version &lt;version&gt;]
126126
[-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive]
127-
[-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
128-
[-WindowStyle &lt;style&gt;] [-EncodedCommand &lt;Base64EncodedCommand&gt;]
127+
[-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
128+
[-WindowStyle &lt;style&gt;] [-EncodedCommand &lt;Base64EncodedCommand&gt;]
129+
[-ConfigurationName &lt;string&gt;]
129130
[-File &lt;filePath&gt; &lt;args&gt;] [-ExecutionPolicy &lt;ExecutionPolicy&gt;]
130131
[-Command { - | &lt;script-block&gt; [-args &lt;arg-array&gt;]
131132
| &lt;string&gt; [&lt;CommandParameters&gt;] } ]
@@ -174,6 +175,12 @@ PowerShell[.exe] -Help | -? | /?
174175
Accepts a base-64-encoded string version of a command. Use this parameter
175176
to submit commands to Windows PowerShell that require complex quotation
176177
marks or curly braces.
178+
179+
-ConfigurationName
180+
Specifies a configuration endpoint in which Windows PowerShell is run.
181+
This can be any endpoint registered on the local machine including the
182+
default Windows PowerShell remoting endpoints or a custom endpoint having
183+
specific user role capabilities.
177184

178185
-File
179186
Runs the specified script in the local scope ("dot-sourced"), so that the
@@ -220,6 +227,7 @@ PowerShell[.exe] -Help | -? | /?
220227
EXAMPLES
221228
PowerShell -PSConsoleFile SqlSnapIn.Psc1
222229
PowerShell -version 2.0 -NoLogo -InputFormat text -OutputFormat XML
230+
PowerShell -ConfigurationName AdminRoles
223231
PowerShell -Command {Get-EventLog -LogName security}
224232
PowerShell -Command "&amp; {Get-EventLog -LogName security}"
225233

src/Modules/Microsoft.PowerShell.Archive/Microsoft.PowerShell.Archive.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ GUID="eb74e8da-9ae2-482a-a648-e96550fb8733"
33
Author="Microsoft Corporation"
44
CompanyName="Microsoft Corporation"
55
Copyright="© Microsoft Corporation. All rights reserved."
6-
ModuleVersion="1.0.0.0"
6+
ModuleVersion="1.0.1.0"
77
FunctionsToExport = @('Compress-Archive', 'Expand-Archive')
8+
DotNetFrameworkVersion = 4.5
89
CmdletsToExport = @()
910
AliasesToExport = @()
1011
NestedModules="Microsoft.PowerShell.Archive.psm1"
Binary file not shown.
630 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)