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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ dotnet-uninstall-debian-packages.sh
# ignore the version file as it is generated at build time
powershell.version

# ignore the telemetry semaphore file
DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY

# default location for produced nuget packages
/nuget-artifacts

Expand Down
3 changes: 3 additions & 0 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ function Start-PSBuild {
# save Git description to file for PowerShell to include in PSVersionTable
git --git-dir="$PSScriptRoot/.git" describe --dirty --abbrev=60 > "$psscriptroot/powershell.version"

# create the telemetry flag file
$null = new-item -force -type file "$psscriptroot/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY"
Copy link
Contributor

@PaulHigin PaulHigin Apr 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$psscriptroot [](start = 40, length = 13)

This will create the file in the directory where Start-PSBuild is being run. But don't we want this location to be the output publish path? #Closed

Copy link
Collaborator Author

@JamesWTruher JamesWTruher Apr 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The placement of the file in the actual publish directory is managed by putting it in the *.csproj files (same as powershell.version is done), but the file has to exist. #Closed


# simplify ParameterSetNames
if ($PSCmdlet.ParameterSetName -eq 'FullCLR') {
$FullCLR = $true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.2.0" />
</ItemGroup>

<PropertyGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ internal static int Start(
s_theConsoleHost.UI.WriteWarningLine(preStartWarning);
}

// Send startup telemetry for ConsoleHost startup
ApplicationInsightsTelemetry.SendPSCoreStartupTelemetry();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you measure the impact on startup?
I see that ApplicationInsights claims calls are non-blocking and telemetry is batched and sent on another thread, so there may be little or no impact.
I have a feeling we'll want to cross-gen the ApplicationInsights assembly though - JIT time is often noticeable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did some checking earlier (it was about 30ms), but will validate again since the code has changed to using a semaphore file. I will include that in the comments of the next push


In reply to: 112802910 [](ancestors = 112802910)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30ms is still quite a bit - it would be ~10% of total startup if we were matching performance of Windows PowerShell.

It would be good to know how much of that time is in JIT, see #3638 for some relative comparisons for time spent in JIT on other assemblies.

If the time is mostly in JIT (say > 95% of the time), then these changes are fine, and we can address cross-gen in the issue I've opened. If the time is not JIT time, then I think it should move to the background - for an example of where we do something similar in the console, see https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs#L52

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lzybkr initially I was also calculating a checksum of the SMA assembly which was removed, and now there's less than 2ms increase when sending telemetry. (see comments below).


ClrFacade.StartProfileOptimization(
s_theConsoleHost.LoadPSReadline()
? "StartupProfileData-Interactive"
Expand Down
79 changes: 79 additions & 0 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/Telemetry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
using System.Management.Automation;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.IO;

namespace Microsoft.PowerShell
{
/// <summary>
/// send up telemetry for startup
/// </summary>
internal static class ApplicationInsightsTelemetry
{
// The semaphore file which indicates whether telemetry should be sent
// This is temporary code waiting on the acceptance and implementation of the configuration spec
// The name of the file by when present in $PSHOME will enable telemetry.
// If this file is not present, no telemetry will be sent.
private const string TelemetrySemaphoreFilename = "DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY";

// The path to the semaphore file which enables telemetry
private static string TelemetrySemaphoreFilePath = Path.Combine(
Utils.GetApplicationBase(Utils.DefaultPowerShellShellID),
TelemetrySemaphoreFilename);

// Telemetry client to be reused when we start sending more telemetry
private static TelemetryClient _telemetryClient = null;

// Set this to true to reduce the latency of sending the telemetry
private static bool _developerMode = false;

// PSCoreInsight2 telemetry key
private const string _psCoreTelemetryKey = "ee4b2115-d347-47b0-adb6-b19c2c763808";

static ApplicationInsightsTelemetry()
{
TelemetryConfiguration.Active.InstrumentationKey = _psCoreTelemetryKey;
TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = _developerMode;
}

/// <summary>
/// Send the telemetry
/// </summary>
private static void SendTelemetry(string eventName, Dictionary<string,string>payload)
{
try
{
// if the semaphore file exists, try to send telemetry
if (Utils.NativeFileExists(TelemetrySemaphoreFilePath))
{
if ( _telemetryClient == null )
{
_telemetryClient = new TelemetryClient();
}
_telemetryClient.TrackEvent(eventName, payload, null);
}
}
catch (Exception)
{
; // Do nothing, telemetry can't be sent
}
}

/// <summary>
/// Create the startup payload and send it up
/// </summary>
internal static void SendPSCoreStartupTelemetry()
{
var properties = new Dictionary<string, string>();
properties.Add("GitCommitID", PSVersionInfo.GitCommitId);
properties.Add("OSDescription", RuntimeInformation.OSDescription);
SendTelemetry("ConsoleHostStartup", properties);
}
}
}
2 changes: 1 addition & 1 deletion src/powershell-unix/powershell-unix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="*.so;*.dylib;..\..\license_thirdparty_proprietary.txt;..\..\powershell.version">
<Content Include="*.so;*.dylib;..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
Expand Down
2 changes: 1 addition & 1 deletion src/powershell-win-core/powershell-win-core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version">
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
Expand Down