Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 12 additions & 3 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
using ConsoleHandle = Microsoft.Win32.SafeHandles.SafeFileHandle;
using NakedWin32Handle = System.IntPtr;
using System.Management.Automation.Tracing;
#if LEGACYTELEMETRY
using Microsoft.PowerShell.Telemetry.Internal;
#endif
using Debugger = System.Management.Automation.Debugger;

namespace Microsoft.PowerShell
Expand All @@ -44,8 +46,10 @@ internal sealed partial class ConsoleHost
:
PSHost,
IDisposable,
IHostSupportsInteractiveSession,
IHostProvidesTelemetryData
#if LEGACYTELEMETRY
IHostProvidesTelemetryData,
#endif
IHostSupportsInteractiveSession
{
#region static methods

Expand Down Expand Up @@ -271,7 +275,9 @@ internal static int Start(
{
if (s_theConsoleHost != null)
{
#if LEGACYTELEMETRY
TelemetryAPI.ReportExitTelemetry(s_theConsoleHost);
#endif
s_theConsoleHost.Dispose();
}
}
Expand Down Expand Up @@ -1038,6 +1044,7 @@ public override void NotifyEndApplication()
}
}

#if LEGACYTELEMETRY
bool IHostProvidesTelemetryData.HostIsInteractive
{
get
Expand All @@ -1049,6 +1056,7 @@ bool IHostProvidesTelemetryData.HostIsInteractive
double IHostProvidesTelemetryData.ProfileLoadTimeInMS { get { return _profileLoadTimeInMS; } }
double IHostProvidesTelemetryData.ReadyForInputTimeInMS { get { return _readyForInputTimeInMS; } }
int IHostProvidesTelemetryData.InteractiveCommandCount { get { return _interactiveCommandCount; } }
#endif

private double _profileLoadTimeInMS;
private double _readyForInputTimeInMS;
Expand Down Expand Up @@ -1807,10 +1815,11 @@ private void DoRunspaceInitialization(bool importSystemModules, bool skipProfile
s_tracer.WriteLine("-noprofile option specified: skipping profiles");
}
}

#if LEGACYTELEMETRY
// Startup is reported after possibly running the profile, but before running the initial command (or file)
// if one is specified.
TelemetryAPI.ReportStartupTelemetry(this);
#endif

// If a file was specified as the argument to run, then run it...
if (s_cpp != null && s_cpp.File != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
using System.Management.Automation.Language;
using System.Management.Automation.Runspaces;
using System.Text.RegularExpressions;
#if LEGACYTELEMETRY
using Microsoft.PowerShell.Telemetry.Internal;
#endif

namespace System.Management.Automation
{
Expand Down Expand Up @@ -591,8 +593,10 @@ private static CommandCompletion CompleteInputImpl(Ast ast, Token[] tokens, IScr

var completionResults = results ?? EmptyCompletionResult;
sw.Stop();
#if LEGACYTELEMETRY
TelemetryAPI.ReportTabCompletionTelemetry(sw.ElapsedMilliseconds, completionResults.Count,
completionResults.Count > 0 ? completionResults[0].ResultType : CompletionResultType.Text);
#endif
return new CommandCompletion(
new Collection<CompletionResult>(completionResults),
-1,
Expand Down
3 changes: 3 additions & 0 deletions src/System.Management.Automation/engine/GetCommandCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ private void OutputResultsHelper(IEnumerable<CommandInfo> results)

_timer.Stop();

#if LEGACYTELEMETRY
// We want telementry on commands people look for but don't exist - this should give us an idea
// what sort of commands people expect but either don't exist, or maybe should be installed by default.
// The StartsWith is to avoid logging telemetry when suggestion mode checks the
Expand All @@ -539,6 +540,8 @@ private void OutputResultsHelper(IEnumerable<CommandInfo> results)
{
Telemetry.Internal.TelemetryAPI.ReportGetCommandFailed(Name, _timer.ElapsedMilliseconds);
}
#endif

}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
using Parser = System.Management.Automation.Language.Parser;
using ScriptBlock = System.Management.Automation.ScriptBlock;
using Token = System.Management.Automation.Language.Token;
#if LEGACYTELEMETRY
using Microsoft.PowerShell.Telemetry.Internal;
#endif

#if CORECLR
// Use stub for SecurityZone.
Expand Down Expand Up @@ -1720,7 +1722,9 @@ protected override void ProcessRecord()
{
SetModuleBaseForEngineModules(foundModule.Name, this.Context);

#if LEGACYTELEMETRY
TelemetryAPI.ReportModuleLoad(foundModule);
#endif
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using System.Threading;
using System.Management.Automation.Host;
using System.Management.Automation.Internal;
#if LEGACYTELEMETRY
using Microsoft.PowerShell.Telemetry.Internal;
#endif
using Dbg = System.Management.Automation.Diagnostics;

#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings
Expand Down Expand Up @@ -279,6 +281,7 @@ private void CoreOpen(bool syncCall)
OpenHelper(syncCall);
if (etwEnabled) RunspaceEventSource.Log.OpenRunspaceStop();

#if LEGACYTELEMETRY
// We report startup telementry when opening the runspace - because this is the first time
// we are really using PowerShell. This isn't the cleanest place though, because
// sometimes there are many runspaces created - the callee ensures telemetry is only
Expand All @@ -288,6 +291,7 @@ private void CoreOpen(bool syncCall)
{
TelemetryAPI.ReportStartupTelemetry(null);
}
#endif
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
using Dbg = System.Management.Automation.Diagnostics;
using System.Diagnostics;
using System.Linq;
#if LEGACYTELEMETRY
using Microsoft.PowerShell.Telemetry.Internal;
#endif

#pragma warning disable 1634, 1691 // Stops compiler from warning about unknown warnings

Expand Down Expand Up @@ -737,7 +739,9 @@ private void DoOpenHelper()
}
}

#if LEGACYTELEMETRY
TelemetryAPI.ReportLocalSessionCreated(InitialSessionState, TranscriptionData);
#endif
}

/// <summary>
Expand Down Expand Up @@ -936,6 +940,8 @@ private void DoCloseHelper()
RaiseRunspaceStateEvents();

// Report telemetry if we have no more open runspaces.

#if LEGACYTELEMETRY
bool allRunspacesClosed = true;
bool hostProvidesExitTelemetry = false;
foreach (var r in Runspace.RunspaceList)
Expand All @@ -956,6 +962,7 @@ private void DoCloseHelper()
{
TelemetryAPI.ReportExitTelemetry(null);
}
#endif
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion src/System.Management.Automation/engine/pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,9 @@ private void Start(bool incomingStream)
CommandState.Started,
commandProcessor.Command.MyInvocation);

//Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.TraceExecutedCommand(commandProcessor.Command.CommandInfo, commandProcessor.Command.CommandOrigin);
#if LEGACYTELEMETRY
Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.TraceExecutedCommand(commandProcessor.Command.CommandInfo, commandProcessor.Command.CommandOrigin);
#endif

// Log the execution of a command (not script chunks, as they
// are not commands in and of themselves)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
using System.Management.Automation.Host;
using System.Collections.ObjectModel;
using System.Management.Automation.Remoting.Client;
#if LEGACYTELEMETRY
using Microsoft.PowerShell.Telemetry.Internal;
#endif

namespace System.Management.Automation.Runspaces.Internal
{
Expand Down Expand Up @@ -850,7 +852,9 @@ protected override IAsyncResult CoreOpen(bool isAsync, AsyncCallback callback,
PSEtwLog.LogOperationalVerbose(PSEventId.RunspacePoolOpen, PSOpcode.Open,
PSTask.CreateRunspace, PSKeyword.UseAlwaysOperational);

#if LEGACYTELEMETRY
TelemetryAPI.ReportRemoteSessionCreated(_connectionInfo);
#endif

lock (syncObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
#if LEGACYTELEMETRY
using Microsoft.PowerShell.Telemetry.Internal;
#endif

namespace System.Management.Automation
{
Expand Down Expand Up @@ -178,11 +180,12 @@ private void ReallyCompile(bool optimize)
Compiler compiler = new Compiler();
compiler.Compile(this, optimize);

#if LEGACYTELEMETRY
if (!IsProductCode)
{
TelemetryAPI.ReportScriptTelemetry((Ast)_ast, !optimize, sw.ElapsedMilliseconds);
}

#endif
if (etwEnabled) ParserEventSource.Log.CompileStop();
}

Expand Down
7 changes: 6 additions & 1 deletion src/System.Management.Automation/help/HelpCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ public SwitchParameter ShowWindow
#endif

private readonly Stopwatch _timer = new Stopwatch();
#if LEGACYTELEMETRY
private bool _updatedHelp;
#endif

#endregion

Expand All @@ -252,7 +254,9 @@ protected override void BeginProcessing()
if (ShouldContinue(HelpDisplayStrings.UpdateHelpPromptBody, HelpDisplayStrings.UpdateHelpPromptTitle))
{
System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace).AddCommand("Update-Help").Invoke();
#if LEGACYTELEMETRY
_updatedHelp = true;
#endif
}

UpdatableHelpSystem.SetDisablePromptToUpdateHelp();
Expand Down Expand Up @@ -332,9 +336,10 @@ protected override void ProcessRecord()

_timer.Stop();

#if LEGACYTELEMETRY
if (!string.IsNullOrEmpty(Name))
Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI.ReportGetHelpTelemetry(Name, countOfHelpInfos, _timer.ElapsedMilliseconds, _updatedHelp);

#endif
// Write full help as there is only one help info object
if (1 == countOfHelpInfos)
{
Expand Down
2 changes: 2 additions & 0 deletions src/System.Management.Automation/utils/PSTelemetryMethods.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if LEGACYTELEMETRY
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
Expand Down Expand Up @@ -519,3 +520,4 @@ public interface IHostProvidesTelemetryData
int InteractiveCommandCount { get; }
}
}
#endif
2 changes: 2 additions & 0 deletions src/System.Management.Automation/utils/PSTelemetryWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if LEGACYTELEMETRY
/********************************************************************++
Copyright (c) Microsoft Corporation. All rights reserved.
--********************************************************************/
Expand Down Expand Up @@ -146,3 +147,4 @@ public static void TraceMessage<T>(string message, T arguments)
}
}
}
#endif