mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Clean up the use of 'SetProfileRoot' and 'StartProfile' in ConsoleHost (#9931)
* Clean up the use of 'SetProfileRoot' and 'StartProfile' in ConsoleHost * Remove 'pwsh.pdb' from our component file list
This commit is contained in:
@@ -325,9 +325,6 @@
|
||||
<Component Id="cmp7F0E91316B501D5C0C5FDC147C91981E" Guid="{E3D382A4-8DC4-4BD1-816B-9ADB12A83412}">
|
||||
<File Id="filB2058AD00ED3F7C051D3F6A4705F37C6" KeyPath="yes" Source="$(env.ProductSourcePath)\System.IO.FileSystem.DriveInfo.dll" />
|
||||
</Component>
|
||||
<Component Id="cmp03B6932DD9DCA3B838936482F6C72DF5" Guid="{4D708BC6-412F-482A-867C-4D2EF354900E}">
|
||||
<File Id="fil3FC478E85DC9718A496BC8FA9D2AFE3E" KeyPath="yes" Source="$(env.ProductSourcePath)\pwsh.pdb" />
|
||||
</Component>
|
||||
<Component Id="cmp49EA2B6077C3CFE16C87CE6C69B211FB" Guid="{04C22CA0-2365-4E40-9B4B-6B42AA205BCD}">
|
||||
<File Id="filDB9405064AEB93B55BA7A5608BBBFA97" KeyPath="yes" Source="$(env.ProductSourcePath)\Install-PowerShellRemoting.ps1" />
|
||||
</Component>
|
||||
@@ -2456,7 +2453,6 @@
|
||||
<ComponentRef Id="cmp9568B438265B4B9537FB278425E51F9D" />
|
||||
<ComponentRef Id="cmp96F5D79C2A39A3FCE2832C9F0DA1FFB9" />
|
||||
<ComponentRef Id="cmp7F0E91316B501D5C0C5FDC147C91981E" />
|
||||
<ComponentRef Id="cmp03B6932DD9DCA3B838936482F6C72DF5" />
|
||||
<ComponentRef Id="cmp49EA2B6077C3CFE16C87CE6C69B211FB" />
|
||||
<ComponentRef Id="cmpFD2810C7EB4AE4047C456491CE5AABA5" />
|
||||
<ComponentRef Id="cmpCB73A07CE8A738AA1591F9E7C13B0DC6" />
|
||||
|
||||
@@ -2154,6 +2154,7 @@ function Start-CrossGen {
|
||||
|
||||
# Common PowerShell libraries to crossgen
|
||||
$psCoreAssemblyList = @(
|
||||
"pwsh.dll",
|
||||
"Microsoft.PowerShell.Commands.Utility.dll",
|
||||
"Microsoft.PowerShell.Commands.Management.dll",
|
||||
"Microsoft.PowerShell.Security.dll",
|
||||
|
||||
@@ -498,21 +498,6 @@ namespace Microsoft.PowerShell
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes the command line parameters to ConsoleHost which must be parsed before the Host is created.
|
||||
/// Success to indicate that the program should continue running.
|
||||
/// </summary>
|
||||
/// <param name="args">
|
||||
/// The command line parameters to be processed.
|
||||
/// </param>
|
||||
internal static void EarlyParse(string[] args)
|
||||
{
|
||||
// indicates that we've called this method on this instance, and that when it's done, the state variables
|
||||
// will reflect the parse.
|
||||
|
||||
EarlyParseHelper(args);
|
||||
}
|
||||
|
||||
private static string GetConfigurationNameFromGroupPolicy()
|
||||
{
|
||||
// Current user policy takes precedence.
|
||||
@@ -529,7 +514,7 @@ namespace Microsoft.PowerShell
|
||||
/// <param name="args">
|
||||
/// The command line parameters to be processed.
|
||||
/// </param>
|
||||
private static void EarlyParseHelper(string[] args)
|
||||
internal static void EarlyParse(string[] args)
|
||||
{
|
||||
if (args == null)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ using System.Management.Automation.Runspaces;
|
||||
using System.Management.Automation.Remoting;
|
||||
using System.Management.Automation.Security;
|
||||
using System.Threading;
|
||||
using System.Runtime;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Management.Automation.Language;
|
||||
|
||||
@@ -133,7 +134,7 @@ namespace Microsoft.PowerShell
|
||||
Directory.CreateDirectory(profileDir);
|
||||
}
|
||||
#endif
|
||||
ClrFacade.SetProfileOptimizationRoot(profileDir);
|
||||
ProfileOptimization.SetProfileRoot(profileDir);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -143,7 +144,7 @@ namespace Microsoft.PowerShell
|
||||
|
||||
uint exitCode = ExitCodeSuccess;
|
||||
|
||||
System.Threading.Thread.CurrentThread.Name = "ConsoleHost main thread";
|
||||
Thread.CurrentThread.Name = "ConsoleHost main thread";
|
||||
|
||||
try
|
||||
{
|
||||
@@ -205,26 +206,26 @@ namespace Microsoft.PowerShell
|
||||
// First check for and handle PowerShell running in a server mode.
|
||||
if (s_cpp.ServerMode)
|
||||
{
|
||||
ClrFacade.StartProfileOptimization("StartupProfileData-ServerMode");
|
||||
ProfileOptimization.StartProfile("StartupProfileData-ServerMode");
|
||||
System.Management.Automation.Remoting.Server.OutOfProcessMediator.Run(s_cpp.InitialCommand);
|
||||
exitCode = 0;
|
||||
}
|
||||
else if (s_cpp.NamedPipeServerMode)
|
||||
{
|
||||
ClrFacade.StartProfileOptimization("StartupProfileData-NamedPipeServerMode");
|
||||
ProfileOptimization.StartProfile("StartupProfileData-NamedPipeServerMode");
|
||||
System.Management.Automation.Remoting.RemoteSessionNamedPipeServer.RunServerMode(
|
||||
s_cpp.ConfigurationName);
|
||||
exitCode = 0;
|
||||
}
|
||||
else if (s_cpp.SSHServerMode)
|
||||
{
|
||||
ClrFacade.StartProfileOptimization("StartupProfileData-SSHServerMode");
|
||||
ProfileOptimization.StartProfile("StartupProfileData-SSHServerMode");
|
||||
System.Management.Automation.Remoting.Server.SSHProcessMediator.Run(s_cpp.InitialCommand);
|
||||
exitCode = 0;
|
||||
}
|
||||
else if (s_cpp.SocketServerMode)
|
||||
{
|
||||
ClrFacade.StartProfileOptimization("StartupProfileData-SocketServerMode");
|
||||
ProfileOptimization.StartProfile("StartupProfileData-SocketServerMode");
|
||||
System.Management.Automation.Remoting.Server.HyperVSocketMediator.Run(s_cpp.InitialCommand,
|
||||
s_cpp.ConfigurationName);
|
||||
exitCode = 0;
|
||||
@@ -238,16 +239,17 @@ namespace Microsoft.PowerShell
|
||||
throw hostException;
|
||||
}
|
||||
|
||||
ProfileOptimization.StartProfile(
|
||||
s_theConsoleHost.LoadPSReadline()
|
||||
? "StartupProfileData-Interactive"
|
||||
: "StartupProfileData-NonInteractive");
|
||||
|
||||
s_theConsoleHost.BindBreakHandler();
|
||||
PSHost.IsStdOutputRedirected = Console.IsOutputRedirected;
|
||||
|
||||
// Send startup telemetry for ConsoleHost startup
|
||||
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry();
|
||||
|
||||
ClrFacade.StartProfileOptimization(
|
||||
s_theConsoleHost.LoadPSReadline()
|
||||
? "StartupProfileData-Interactive"
|
||||
: "StartupProfileData-NonInteractive");
|
||||
exitCode = s_theConsoleHost.Run(s_cpp, false);
|
||||
}
|
||||
}
|
||||
@@ -2833,7 +2835,7 @@ namespace Microsoft.PowerShell
|
||||
private ConsoleControl.ConsoleModes _savedConsoleMode = ConsoleControl.ConsoleModes.Unknown;
|
||||
private ConsoleControl.ConsoleModes _initialConsoleMode = ConsoleControl.ConsoleModes.Unknown;
|
||||
#endif
|
||||
private System.Threading.Thread _breakHandlerThread;
|
||||
private Thread _breakHandlerThread;
|
||||
private bool _isDisposed;
|
||||
internal ConsoleHostUserInterface ui;
|
||||
|
||||
|
||||
@@ -27,13 +27,14 @@ namespace Microsoft.PowerShell
|
||||
/// <param name="args">
|
||||
/// Command line arguments to the managed MSH
|
||||
/// </param>
|
||||
#pragma warning disable 1573
|
||||
/// <param name="argc" />
|
||||
public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 2)]string[] args, int argc)
|
||||
#pragma warning restore 1573
|
||||
{
|
||||
// Warm up some components concurrently on background threads.
|
||||
System.Management.Automation.Runspaces.EarlyStartup.Init();
|
||||
|
||||
// We need to read the settings file before we create the console host
|
||||
Microsoft.PowerShell.CommandLineParameterParser.EarlyParse(args);
|
||||
System.Management.Automation.Runspaces.EarlyStartup.Init();
|
||||
|
||||
#if !UNIX
|
||||
// NOTE: On Unix, logging has to be deferred until after command-line parsing
|
||||
|
||||
@@ -194,22 +194,6 @@ namespace System.Management.Automation
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the profile optimization root on the appropriate load context.
|
||||
/// </summary>
|
||||
internal void SetProfileOptimizationRootImpl(string directoryPath)
|
||||
{
|
||||
AssemblyLoadContext.Default.SetProfileOptimizationRoot(directoryPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the profile optimization on the appropriate load context.
|
||||
/// </summary>
|
||||
internal void StartProfileOptimizationImpl(string profile)
|
||||
{
|
||||
AssemblyLoadContext.Default.StartProfileOptimization(profile);
|
||||
}
|
||||
|
||||
#endregion Internal_Methods
|
||||
|
||||
#region Private_Methods
|
||||
|
||||
@@ -56,13 +56,13 @@ namespace System.Management.Automation.Runspaces
|
||||
{
|
||||
// Loading the resources for System.Management.Automation can be expensive, so force that to
|
||||
// happen early on a background thread.
|
||||
var unused0 = RunspaceInit.OutputEncodingDescription;
|
||||
_ = RunspaceInit.OutputEncodingDescription;
|
||||
|
||||
// This will init some tables and could load some assemblies.
|
||||
var unused1 = TypeAccelerators.builtinTypeAccelerators;
|
||||
_ = TypeAccelerators.builtinTypeAccelerators;
|
||||
|
||||
// This will init some tables and could load some assemblies.
|
||||
var unused2 = LanguagePrimitives.GetEnumerator(null);
|
||||
LanguagePrimitives.GetEnumerator(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,24 +361,6 @@ namespace System.Management.Automation
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Facade for ProfileOptimization.SetProfileRoot.
|
||||
/// </summary>
|
||||
/// <param name="directoryPath">The full path to the folder where profile files are stored for the current application domain.</param>
|
||||
internal static void SetProfileOptimizationRoot(string directoryPath)
|
||||
{
|
||||
PSAssemblyLoadContext.SetProfileOptimizationRootImpl(directoryPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Facade for ProfileOptimization.StartProfile.
|
||||
/// </summary>
|
||||
/// <param name="profile">The file name of the profile to use.</param>
|
||||
internal static void StartProfileOptimization(string profile)
|
||||
{
|
||||
PSAssemblyLoadContext.StartProfileOptimizationImpl(profile);
|
||||
}
|
||||
|
||||
#endregion Misc
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
|
||||
<!-- See definitions in C:\Windows\Microsoft.NET\Framework\v4.0.30319\CLR-ETW.man for .NET events -->
|
||||
<!-- See MSDN docs about 'region of interest': https://docs.microsoft.com/windows-hardware/test/wpt/regions-of-interest -->
|
||||
<!--
|
||||
Unlike JIT GC is largely single threaded and the times correlate very well with PerfView where we can drill down into each GC
|
||||
Unlike JIT, GC is largely single threaded and the times correlate very well with PerfView where we can drill down into each GC
|
||||
generation in the region graph in WPA.
|
||||
We use bascially the GC Start/Stop events where the GC Start event has also the generation traced which enables us to create
|
||||
regions for each GC type.
|
||||
GC suspensions work a bit different were I use the GCSuspendEE_V1 as start and GCRestartEEEnd as end event. This allows us
|
||||
to capture in principle also the time where the suspension or resumption itself takes an abnormally long time whic would indicate
|
||||
to capture in principle also the time where the suspension or resumption itself takes. An abnormally long time would indicate
|
||||
a GC bug or a thread priority problem.
|
||||
-->
|
||||
<InstrumentationManifest>
|
||||
|
||||
@@ -8,8 +8,9 @@ param(
|
||||
$ScriptBlock,
|
||||
|
||||
$LogFileName = '.\perfview.log',
|
||||
|
||||
$PowerShellPath = $(Get-Command pwsh.exe).Source)
|
||||
$PowerShellPath = $(Get-Command -Name pwsh.exe).Source,
|
||||
$PerfViewPath = $(Get-Command -Name PerfView.exe).Source
|
||||
)
|
||||
|
||||
$EncodedScriptBlock = [System.Convert]::ToBase64String([System.Text.Encoding]::UNICODE.GetBytes($ScriptBlock.ToString()))
|
||||
$perfViewArgs = @(
|
||||
@@ -30,26 +31,7 @@ $perfViewArgs = @(
|
||||
$EncodedScriptBlock
|
||||
)
|
||||
|
||||
$process = Start-Process -FilePath (Get-Command PerfView.exe).Source -ArgumentList $perfViewArgs -PassThru
|
||||
|
||||
$rs = [runspacefactory]::CreateRunspace($host)
|
||||
$rs.Open()
|
||||
$ps = [powershell]::Create()
|
||||
$ps.Runspace = $rs
|
||||
|
||||
$null = $ps.AddCommand("Get-Content").
|
||||
AddArgument($LogFileName).
|
||||
AddParameter("Wait").
|
||||
AddParameter("Tail", 0)
|
||||
$null = $ps.AddCommand("Out-Host")
|
||||
|
||||
# If log file doesn't exist yet, wait a little bit so Get-Content doesn't fail
|
||||
while (!(Test-Path $LogFileName))
|
||||
{
|
||||
Start-Sleep -Seconds 1
|
||||
}
|
||||
|
||||
$null = $ps.BeginInvoke()
|
||||
$process = Start-Process -FilePath $PerfViewPath -ArgumentList $perfViewArgs -PassThru
|
||||
$process.WaitForExit()
|
||||
$ps.Stop()
|
||||
|
||||
Get-Content $LogFileName | Out-Host
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version='1.0' encoding='utf-8' standalone='yes'?>
|
||||
<?Copyright (c) Microsoft Corporation. All rights reserved.?>
|
||||
<!-- See MSDN docs about 'region of interest': https://docs.microsoft.com/windows-hardware/test/wpt/regions-of-interest -->
|
||||
<InstrumentationManifest>
|
||||
<Instrumentation>
|
||||
<Regions>
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- To work with ngen'd images and non-ngen'd images, entries are duplicated,
|
||||
once with .dll, and again with .ni.dll -->
|
||||
<!-- See MSDN docs about 'region of interest': https://docs.microsoft.com/windows-hardware/test/wpt/stack-tags -->
|
||||
<Tag Name="PowerShell">
|
||||
<Tag Name="Pipeline Execution">
|
||||
<Tag Name="Interpreter">
|
||||
<Entrypoint Module="System.Management.Automation.dll" Method="System.Management.Automation.Interpreter.*"/>
|
||||
<Entrypoint Module="System.Core.dll" Method="System.Dynamic.UpdateDelegates.*"/>
|
||||
<Entrypoint Module="System.Core.dll" Method="System.Runtime.CompilerServices.CallSiteBinder.*"/>
|
||||
<Entrypoint Module="System.Linq.Expressions.dll" Method="System.Dynamic.UpdateDelegates.*"/>
|
||||
<Entrypoint Module="System.Linq.Expressions.dll" Method="System.Runtime.CompilerServices.CallSiteBinder.*"/>
|
||||
<Entrypoint Module="System.Management.Automation.ni.dll" Method="System.Management.Automation.Interpreter.*"/>
|
||||
<Entrypoint Module="System.Core.ni.dll" Method="System.Dynamic.UpdateDelegates.*"/>
|
||||
<Entrypoint Module="System.Core.ni.dll" Method="System.Runtime.CompilerServices.CallSiteBinder.*"/>
|
||||
<Entrypoint Module="System.Linq.Expressions.ni.dll" Method="System.Dynamic.UpdateDelegates.*"/>
|
||||
<Entrypoint Module="System.Linq.Expressions.ni.dll" Method="System.Runtime.CompilerServices.CallSiteBinder.*"/>
|
||||
</Tag>
|
||||
<Tag Name="CommandDiscovery">
|
||||
<Entrypoint Module="System.Management.Automation.dll" Method="System.Management.Automation.CommandDiscovery.*"/>
|
||||
|
||||
Reference in New Issue
Block a user