/// <summary>
        /// Called after there are no more open runspaces. In some host applications, this could
        /// report multiple exits.
        /// </summary>
        public static void ReportExitTelemetry(IHostProvidesTelemetryData ihptd)
        {
            TelemetryWrapper.TraceMessage("PSHostStop", new
            {
                InteractiveCommandCount   = ihptd != null ? ihptd.InteractiveCommandCount : 0,
                TabCompletionTimes        = s_tabCompletionTimes,
                TabCompletionCounts       = s_tabCompletionCounts,
                TabCompletionResultCounts = s_tabCompletionResultCounts,
                SessionTime = (DateTime.Now - s_sessionStartTime).TotalMilliseconds
            });

            // In case a host opens another runspace, we will want another PSHostStart event,
            // so reset our flag here to allow that event to fire.
            s_anyPowerShellSessionOpen = 0;
        }
        /// <summary>
        /// Called either after opening a runspace (the default), or by the host application.
        /// </summary>
        public static void ReportStartupTelemetry(IHostProvidesTelemetryData ihptd)
        {
            // Avoid reporting startup more than once, except if we report "exited" and
            // another runspace gets opened.
            if (Interlocked.CompareExchange(ref s_anyPowerShellSessionOpen, 1, 0) == 1)
            {
                return;
            }

            bool is32Bit;

#if CORECLR
            is32Bit = IntPtr.Size == 4;
#else
            is32Bit = !Environment.Is64BitProcess;
#endif
            var psversion = PSVersionInfo.PSVersion.ToString();
            var hostName  = Process.GetCurrentProcess().ProcessName;
            if (ihptd != null)
            {
                TelemetryWrapper.TraceMessage("PSHostStart", new
                {
                    Interactive       = ihptd.HostIsInteractive ? HostIsInteractive.Iteractive : HostIsInteractive.NonInteractive,
                    ProfileLoadTime   = ihptd.ProfileLoadTimeInMS,
                    ReadyForInputTime = ihptd.ReadyForInputTimeInMS,
                    Is32Bit           = is32Bit,
                    PSVersion         = psversion,
                    ProcessName       = hostName,
                });
            }
            else
            {
                TelemetryWrapper.TraceMessage("PSHostStart", new
                {
                    Interactive       = HostIsInteractive.Unknown,
                    ProfileLoadTime   = 0,
                    ReadyForInputTime = 0,
                    Is32Bit           = is32Bit,
                    PSVersion         = psversion,
                    ProcessName       = hostName,
                });
            }
            s_sessionStartTime = DateTime.Now;
        }