Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8239d83
Reduce allocations in PSTraceSource.WriteLine(). Part 2
iSazonov Oct 10, 2022
e6085b5
Create one Write() method
iSazonov Dec 17, 2022
2414ee2
Rename handler
iSazonov Dec 25, 2022
9a0ef67
Remove classPrefix, use PSTraceSourceOptions instead
iSazonov Dec 25, 2022
509a0ca
Replace one arg WriteLine() with new Write()
iSazonov Dec 25, 2022
b4aed9f
Update handler description
iSazonov Dec 25, 2022
d454a5d
Remove unused WriteLine()
iSazonov Dec 25, 2022
67060dd
Replace 3 args WriteLine() with new Write()
iSazonov Dec 25, 2022
25240b0
Replace 0 args WriteLine() with new Write()
iSazonov Dec 25, 2022
e03c5ab
Replace 2 args WriteLine() with new Write()
iSazonov Dec 26, 2022
e37156a
Replace 1 args WriteLine() with new Write()
iSazonov Dec 26, 2022
4cb8ca1
Unify GetTrace() (always add "trace headers")
iSazonov Dec 27, 2022
cad3f9f
Replace TraceErrro() and TraceWarning() with new Write()
iSazonov Dec 27, 2022
8e98a58
Remove unused constants
iSazonov Dec 27, 2022
4a8132e
Style changes
iSazonov Dec 27, 2022
e6386f5
Style changes 2
iSazonov Dec 27, 2022
8768ad7
Replace OutputLine() with new Write()
iSazonov Dec 27, 2022
e39ad3a
Remove TraceLockHelper()
iSazonov Dec 27, 2022
88bc226
Add ref TraceScope
iSazonov Dec 27, 2022
17fa215
Rename ref TraceScope to PSTraceScope
iSazonov Dec 27, 2022
4a5ecde
Replace one arg TraceScope with new PSTraceScope
iSazonov Dec 28, 2022
75c2ccd
Replace one arg TraceScope with new PSTraceScope 2
iSazonov Dec 28, 2022
c752aa8
Replace two arg TraceScope with new PSTraceScope
iSazonov Dec 28, 2022
fb8f4c4
Replace TraceMethod with new PSTraceScope
iSazonov Dec 28, 2022
1dcc4d9
Replace TraceEventHandlers with new PSTraceScope
iSazonov Dec 28, 2022
0bd49eb
Fix test
iSazonov Dec 28, 2022
8a39f0c
Remove unused trace methods
iSazonov Dec 28, 2022
afd42c2
Enable nullable
iSazonov Dec 28, 2022
1e15a45
Revert "Fix test"
iSazonov Dec 28, 2022
2466b1e
Remove unused code and update comments
iSazonov Dec 28, 2022
520e1de
Fix test 2
iSazonov Dec 28, 2022
f363204
Reorder memebers
iSazonov Dec 28, 2022
3f47620
Refactor properties
iSazonov Dec 28, 2022
a667978
Remove ScopeTracer
iSazonov Dec 28, 2022
9da6dec
Minor cleanups
iSazonov Dec 28, 2022
44029db
Enable nullable 2
iSazonov Dec 28, 2022
dc6133e
Minor cleanups 2
iSazonov Dec 28, 2022
83abee0
Rename Write() to PSTraceWrite()
iSazonov Dec 28, 2022
10aa08c
Fix style issues
iSazonov Dec 28, 2022
059969f
Make PSTraceScope readonly
iSazonov Dec 28, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ internal void WriteContentObject(object content, long readCount, PathInfo pathIn
string psPath = pathInfo.Path;
note = new PSNoteProperty("PSPath", psPath);
result.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSPath", psPath);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSPath = {psPath}");
_currentContentItem.PSPath = psPath;

try
Expand All @@ -190,15 +190,15 @@ internal void WriteContentObject(object content, long readCount, PathInfo pathIn

note = new PSNoteProperty("PSParentPath", parentPath);
result.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSParentPath", parentPath);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSParentPath = {parentPath}");
_currentContentItem.ParentPath = parentPath;

// Get the child name

string childName = SessionState.Path.ParseChildName(pathInfo.Path, context);
note = new PSNoteProperty("PSChildName", childName);
result.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSChildName", childName);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSChildName = {childName}");
_currentContentItem.ChildName = childName;
}
catch (NotSupportedException)
Expand All @@ -213,7 +213,7 @@ internal void WriteContentObject(object content, long readCount, PathInfo pathIn
PSDriveInfo drive = pathInfo.Drive;
note = new PSNoteProperty("PSDrive", drive);
result.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSDrive", drive);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSDrive = {drive}");
_currentContentItem.Drive = drive;
}

Expand All @@ -222,7 +222,7 @@ internal void WriteContentObject(object content, long readCount, PathInfo pathIn
ProviderInfo provider = pathInfo.Provider;
note = new PSNoteProperty("PSProvider", provider);
result.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSProvider", provider);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSProvider = {provider}");
_currentContentItem.Provider = provider;
}

Expand Down Expand Up @@ -302,34 +302,34 @@ public PSObject AttachNotes(PSObject content)

PSNoteProperty note = new("PSPath", PSPath);
content.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSPath", PSPath);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSPath = {PSPath}");

// Now attach the parent path and child name

note = new PSNoteProperty("PSParentPath", ParentPath);
content.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSParentPath", ParentPath);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSParentPath = {ParentPath}");

// Attach the child name

note = new PSNoteProperty("PSChildName", ChildName);
content.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSChildName", ChildName);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSChildName = {ChildName}");

// PSDriveInfo

if (PathInfo.Drive != null)
{
note = new PSNoteProperty("PSDrive", Drive);
content.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSDrive", Drive);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSDrive = {Drive}");
}

// ProviderInfo

note = new PSNoteProperty("PSProvider", Provider);
content.Properties.Add(note, true);
tracer.WriteLine("Attaching {0} = {1}", "PSProvider", Provider);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Attaching PSProvider = {Provider}");

return content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ internal List<PSDriveInfo> GetMatchingDrives(

foreach (string providerName in providerNames)
{
tracer.WriteLine("ProviderName: {0}", providerName);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"ProviderName: {providerName}");

bool providerNameEmpty = string.IsNullOrEmpty(providerName);
bool providerNameContainsWildcardCharacters =
Expand Down Expand Up @@ -3112,7 +3112,7 @@ private void MoveItem(string path, bool literalPath = false)

currentContext.PassThru = PassThru;

tracer.WriteLine("Moving {0} to {1}", path, Destination);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Moving {path} to {Destination}");

try
{
Expand Down Expand Up @@ -3451,7 +3451,7 @@ private void RenameItem(string path, bool literalPath = false)
// the pipeline.
currentContext.PassThru = PassThru;

tracer.WriteLine("Rename {0} to {1}", path, NewName);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Rename {path} to {NewName}");

try
{
Expand Down Expand Up @@ -3707,7 +3707,7 @@ protected override void ProcessRecord()

foreach (string path in _paths)
{
tracer.WriteLine("Copy {0} to {1}", path, Destination);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Copy {path} to {Destination}");

try
{
Expand Down Expand Up @@ -3898,7 +3898,7 @@ protected override void ProcessRecord()

foreach (string path in _paths)
{
tracer.WriteLine("Clearing {0}", path);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Clearing {path}");

try
{
Expand Down Expand Up @@ -4062,7 +4062,7 @@ protected override void ProcessRecord()
{
foreach (string path in _paths)
{
tracer.WriteLine("Invoking {0}", path);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Invoking {path}");

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private static void DoGrouping(
if (!isCurrentItemGrouped)
{
// create a new group
s_tracer.WriteLine("Create a new group: {0}", currentObjectOrderValues);
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Create a new group: {currentObjectOrderValues}");
GroupInfo newObjGrp = noElement ? new GroupInfoNoElement(currentObjectEntry) : new GroupInfo(currentObjectEntry);
groups.Add(newObjGrp);

Expand Down Expand Up @@ -360,7 +360,7 @@ private static void DoOrderedGrouping(
if (!isCurrentItemGrouped)
{
// create a new group
s_tracer.WriteLine("Create a new group: {0}", currentObjectOrderValues);
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Create a new group: {currentObjectOrderValues}");
GroupInfo newObjGrp = noElement
? new GroupInfoNoElement(currentObjectEntry)
: new GroupInfo(currentObjectEntry);
Expand Down Expand Up @@ -509,7 +509,7 @@ protected override void EndProcessing()
}
}

s_tracer.WriteLine(_groups.Count);
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"{_groups.Count}");
if (_groups.Count > 0)
{
if (AsHashTable.IsPresent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ private static void WriteConsoleOutputPlain(ConsoleHandle consoleHandle, Coordin

if ((rows <= 0) || cols <= 0)
{
tracer.WriteLine("contents passed in has 0 rows and columns");
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"contents passed in has 0 rows and columns");
return;
}

Expand Down Expand Up @@ -1885,7 +1885,7 @@ internal static void ReadConsoleOutputCJK

if ((rows <= 0) || cols <= 0)
{
tracer.WriteLine("invalid contents region");
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"invalid contents region");
return;
}

Expand Down Expand Up @@ -2058,7 +2058,7 @@ private static void ReadConsoleOutputPlain

if ((rows <= 0) || cols <= 0)
{
tracer.WriteLine("invalid contents region");
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"invalid contents region");
return;
}

Expand Down Expand Up @@ -2506,7 +2506,7 @@ internal static void SetConsoleWindowTitle(string consoleTitle)
// ERROR_GEN_FAILURE is returned if this api can't be used with the terminal
if (err == 0x1f)
{
tracer.WriteLine("Call to SetConsoleTitle failed: {0}", err);
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Call to SetConsoleTitle failed: {err}");
s_dontsetConsoleWindowTitle = true;

// We ignore this specific error as the console can still continue to operate
Expand Down
34 changes: 17 additions & 17 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ internal static int Start(
// Servermode parameter validation check.
if ((s_cpp.ServerMode && s_cpp.NamedPipeServerMode) || (s_cpp.ServerMode && s_cpp.SocketServerMode) || (s_cpp.NamedPipeServerMode && s_cpp.SocketServerMode))
{
s_tracer.TraceError("Conflicting server mode parameters, parameters must be used exclusively.");
s_tracer.PSTraceWrite(PSTraceSourceOptions.Error, $"Conflicting server mode parameters, parameters must be used exclusively.");
s_theConsoleHost?.ui.WriteErrorLine(ConsoleHostStrings.ConflictingServerModeParameters);

return ExitCodeBadCommandLineParameter;
Expand Down Expand Up @@ -1439,12 +1439,12 @@ private uint Run(CommandLineParameterParser cpp, bool isPrestartWarned)

do
{
s_runspaceInitTracer.WriteLine("starting parse of command line parameters");
s_runspaceInitTracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"starting parse of command line parameters");

exitCode = ExitCodeSuccess;
if (!string.IsNullOrEmpty(cpp.InitialCommand) && isPrestartWarned)
{
s_tracer.TraceError("Start up warnings made command \"{0}\" not executed", cpp.InitialCommand);
s_tracer.PSTraceWrite(PSTraceSourceOptions.Error, $"Start up warnings made command \"{cpp.InitialCommand}\" not executed");
string msg = StringUtil.Format(ConsoleHostStrings.InitialCommandNotExecuted, cpp.InitialCommand);
ui.WriteErrorLine(msg);
exitCode = ExitCodeInitFailure;
Expand All @@ -1453,7 +1453,7 @@ private uint Run(CommandLineParameterParser cpp, bool isPrestartWarned)

if (cpp.AbortStartup)
{
s_tracer.WriteLine("processing of cmdline args failed, exiting");
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"processing of cmdline args failed, exiting");
exitCode = cpp.ExitCode;
break;
}
Expand Down Expand Up @@ -1566,7 +1566,7 @@ private Exception InitializeRunspaceHelper(string command, Executor exec, Execut
Dbg.Assert(!string.IsNullOrEmpty(command), "command should have a value");
Dbg.Assert(exec != null, "non-null Executor instance needed");

s_runspaceInitTracer.WriteLine("running command {0}", command);
s_runspaceInitTracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"running command {command}");

Exception e = null;

Expand Down Expand Up @@ -1652,7 +1652,7 @@ private void DoCreateRunspace(RunspaceCreationEventArgs args)
{
Dbg.Assert(_runspaceRef == null, "_runspaceRef field should be null");
Dbg.Assert(DefaultInitialSessionState != null, "DefaultInitialSessionState should not be null");
s_runspaceInitTracer.WriteLine("Calling RunspaceFactory.CreateRunspace");
s_runspaceInitTracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Calling RunspaceFactory.CreateRunspace");

// Use session configuration file if provided.
bool customConfigurationProvided = false;
Expand Down Expand Up @@ -1769,7 +1769,7 @@ private static void OpenConsoleRunspace(Runspace runspace, bool staMode)
runspace.ThreadOptions = PSThreadOptions.ReuseThread;
runspace.EngineActivityId = EtwActivity.GetActivityId();

s_runspaceInitTracer.WriteLine("Calling Runspace.Open");
s_runspaceInitTracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Calling Runspace.Open");
runspace.Open();
}

Expand Down Expand Up @@ -1876,7 +1876,7 @@ private void DoRunspaceInitialization(RunspaceCreationEventArgs args)
}
else
{
s_tracer.WriteLine("-noprofile option specified: skipping profiles");
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"-noprofile option specified: skipping profiles");
}
}
#if LEGACYTELEMETRY
Expand All @@ -1890,7 +1890,7 @@ private void DoRunspaceInitialization(RunspaceCreationEventArgs args)
{
string filePath = s_cpp.File;

s_tracer.WriteLine("running -file '{0}'", filePath);
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"running -file '{filePath}'");

Pipeline tempPipeline = exec.CreatePipeline();
Command c;
Expand Down Expand Up @@ -1974,7 +1974,7 @@ private void DoRunspaceInitialization(RunspaceCreationEventArgs args)
{
// Run the command passed on the command line

s_tracer.WriteLine("running initial command");
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"running initial command");

Pipeline tempPipeline = exec.CreatePipeline(args.InitialCommand, true);

Expand Down Expand Up @@ -2027,7 +2027,7 @@ private void RunProfile(string profileFileName, Executor exec)
{
if (!string.IsNullOrEmpty(profileFileName))
{
s_runspaceInitTracer.WriteLine("checking profile" + profileFileName);
s_runspaceInitTracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"checking profile {profileFileName}");

try
{
Expand All @@ -2040,14 +2040,14 @@ private void RunProfile(string profileFileName, Executor exec)
}
else
{
s_runspaceInitTracer.WriteLine("profile file not found");
s_runspaceInitTracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"profile file not found");
}
}
catch (Exception e) // Catch-all OK, 3rd party callout
{
ReportException(e, exec);

s_runspaceInitTracer.WriteLine("Could not load profile.");
s_runspaceInitTracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Could not load profile.");
}
}
}
Expand Down Expand Up @@ -2540,7 +2540,7 @@ internal void Run(bool inputLoopIsNested)
{
previousResponseWasEmpty = true;

s_tracer.WriteLine("line is null");
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"line is null");
if (!ui.ReadFromStdin)
{
// If we're not reading from stdin, the we probably got here
Expand All @@ -2567,7 +2567,7 @@ internal void Run(bool inputLoopIsNested)
{
// end block mode and execute the block accumulated block

s_tracer.WriteLine("exiting block mode");
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"exiting block mode");
line = inputBlock.ToString();
inBlockMode = false;
}
Expand All @@ -2581,7 +2581,7 @@ internal void Run(bool inputLoopIsNested)
{
if (inBlockMode)
{
s_tracer.WriteLine("adding line to block");
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"adding line to block");
inputBlock.Append('\n');
inputBlock.Append(line);
continue;
Expand Down Expand Up @@ -3092,7 +3092,7 @@ private sealed class ConsoleHostStartupException : Exception

[TraceSource("ConsoleHostRunspaceInit", "Initialization code for ConsoleHost's Runspace")]
private static readonly PSTraceSource s_runspaceInitTracer =
PSTraceSource.GetTracer("ConsoleHostRunspaceInit", "Initialization code for ConsoleHost's Runspace", false);
PSTraceSource.GetTracer("ConsoleHostRunspaceInit", "Initialization code for ConsoleHost's Runspace");
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ public override
if (region.Left >= bufferWidth || region.Top >= bufferHeight || region.Right < 0 || region.Bottom < 0)
{
// region is entirely outside the buffer boundaries
tracer.WriteLine("region outside boundaries");
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"region outside boundaries");
return;
}

Expand Down Expand Up @@ -1088,7 +1088,7 @@ public override
if (region.Left >= bufferWidth || region.Top >= bufferHeight || region.Right < 0 || region.Bottom < 0)
{
// region is entirely outside the buffer boundaries
tracer.WriteLine("region outside boundaries");
tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"region outside boundaries");
return new BufferCell[0, 0];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public override

if (cancelInput)
{
s_tracer.WriteLine("Prompt canceled");
s_tracer.PSTraceWrite(PSTraceSourceOptions.WriteLine, $"Prompt canceled");
WriteLineToConsole();
results.Clear();
break;
Expand Down Expand Up @@ -513,7 +513,7 @@ private string PromptCommandMode(string input, FieldDescription desc, out bool i
{
string noHelpErrMsg =
StringUtil.Format(ConsoleHostUserInterfaceStrings.PromptNoHelpAvailableErrorTemplate, desc.Name);
s_tracer.TraceWarning(noHelpErrMsg);
s_tracer.PSTraceWrite(PSTraceSourceOptions.Warning, $"{noHelpErrMsg}");
WriteLineToConsole(WrapToCurrentWindowWidth(noHelpErrMsg));
}
else
Expand Down
Loading