Fix #16929 do not show profile load time msg with new pwsh parameter (#17535)

* Fix #16929 do not show profile load time msg by default

This PR adds a new pwsh command line parameter to enable display of the
profile load time message.

* Switch to an opt-out paramater called -NoProfileLoadTime
This commit is contained in:
Keith Hill
2022-07-18 17:33:16 -07:00
committed by GitHub
parent b7c875b0f2
commit b6a619099b
3 changed files with 27 additions and 3 deletions
@@ -186,6 +186,7 @@ namespace Microsoft.PowerShell
"nologo",
"noninteractive",
"noprofile",
"noprofileloadtime",
"outputformat",
"removeworkingdirectorytrailingcharacter",
"settingsfile",
@@ -228,6 +229,7 @@ namespace Microsoft.PowerShell
WindowStyle = 0x01000000, // -WindowStyle | -w
WorkingDirectory = 0x02000000, // -WorkingDirectory | -wd
ConfigurationFile = 0x04000000, // -ConfigurationFile
NoProfileLoadTime = 0x08000000, // -NoProfileLoadTime
// Enum values for specified ExecutionPolicy
EPUnrestricted = 0x0000000100000000, // ExecutionPolicy unrestricted
EPRemoteSigned = 0x0000000200000000, // ExecutionPolicy remote signed
@@ -463,6 +465,15 @@ namespace Microsoft.PowerShell
}
}
internal bool NoProfileLoadTime
{
get
{
AssertArgumentsParsed();
return _noProfileLoadTime;
}
}
internal bool ShowVersion
{
get
@@ -920,6 +931,11 @@ namespace Microsoft.PowerShell
_sshServerMode = true;
ParametersUsed |= ParameterBitmap.SSHServerMode;
}
else if (MatchSwitch(switchKey, "noprofileloadtime", "noprofileloadtime"))
{
_noProfileLoadTime = true;
ParametersUsed |= ParameterBitmap.NoProfileLoadTime;
}
else if (MatchSwitch(switchKey, "interactive", "i"))
{
_noInteractive = false;
@@ -1496,6 +1512,7 @@ namespace Microsoft.PowerShell
private bool _serverMode;
private bool _namedPipeServerMode;
private bool _sshServerMode;
private bool _noProfileLoadTime;
private bool _showVersion;
private string? _configurationFile;
private string? _configurationName;
@@ -1885,7 +1885,7 @@ namespace Microsoft.PowerShell
sw.Stop();
var profileLoadTimeInMs = sw.ElapsedMilliseconds;
if (profileLoadTimeInMs > 500 && s_cpp.ShowBanner)
if (s_cpp.ShowBanner && !s_cpp.NoProfileLoadTime && profileLoadTimeInMs > 500)
{
Console.Error.WriteLine(ConsoleHostStrings.SlowProfileLoadingMessage, profileLoadTimeInMs);
}
@@ -149,8 +149,10 @@
[-EncodedCommand <Base64EncodedCommand>]
[-ExecutionPolicy <ExecutionPolicy>] [-InputFormat {Text | XML}]
[-Interactive] [-MTA] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
[-OutputFormat {Text | XML}] [-SettingsFile <filePath>] [-SSHServerMode] [-STA]
[-Version] [-WindowStyle <style>] [-WorkingDirectory <directoryPath>]
[-NoProfileLoadTime] [-OutputFormat {Text | XML}]
[-SettingsFile <filePath>] [-SSHServerMode] [-STA]
[-Version] [-WindowStyle <style>]
[-WorkingDirectory <directoryPath>]
pwsh[.exe] -h | -Help | -? | /?
@@ -399,6 +401,11 @@ All parameters are case-insensitive.</value>
Does not load the PowerShell profiles.
-NoProfileLoadTime
Hides the PowerShell profile load time text shown at startup when the load
time exceeds 500 milliseconds.
-OutputFormat | -o | -of
Determines how output from PowerShell is formatted. Valid values are "Text"