Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find out how often are people actually using marks, Themes #14356

Merged
10 commits merged into from
Dec 1, 2022
4 changes: 4 additions & 0 deletions src/cascadia/TerminalControl/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <LibraryResources.h>
#include <WilErrorReporting.h>

// For g_hCTerminalCoreProvider
#include "../../cascadia/TerminalCore/tracing.hpp"
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved

// Note: Generate GUID using TlgGuid.exe tool
TRACELOGGING_DEFINE_PROVIDER(
g_hTerminalControlProvider,
Expand All @@ -20,6 +23,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD reason, LPVOID /*reserved*/)
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hInstDll);
TraceLoggingRegister(g_hTerminalControlProvider);
TraceLoggingRegister(g_hCTerminalCoreProvider);
Microsoft::Console::ErrorReporting::EnableFallbackFailureReporting(g_hTerminalControlProvider);
break;
case DLL_PROCESS_DETACH:
Expand Down
36 changes: 36 additions & 0 deletions src/cascadia/TerminalCore/TerminalApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@

#include "pch.h"
#include "Terminal.hpp"
#include "tracing.hpp"

#include "../src/inc/unicode.hpp"

using namespace Microsoft::Terminal::Core;
using namespace Microsoft::Console::Render;
using namespace Microsoft::Console::Types;
using namespace Microsoft::Console::VirtualTerminal;

// Note: Generate GUID using TlgGuid.exe tool
#pragma warning(suppress : 26477) // One of the macros uses 0/NULL. We don't have control to make it nullptr.
TRACELOGGING_DEFINE_PROVIDER(g_hCTerminalCoreProvider,
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
"Microsoft.Terminal.Core",
// {103ac8cf-97d2-51aa-b3ba-5ffd5528fa5f}
(0x103ac8cf, 0x97d2, 0x51aa, 0xb3, 0xba, 0x5f, 0xfd, 0x55, 0x28, 0xfa, 0x5f),
TraceLoggingOptionMicrosoftTelemetry());

// Print puts the text in the buffer and moves the cursor
void Terminal::PrintString(const std::wstring_view string)
{
Expand Down Expand Up @@ -185,6 +195,19 @@ void Terminal::SetTaskbarProgress(const ::Microsoft::Console::VirtualTerminal::D

void Terminal::SetWorkingDirectory(std::wstring_view uri)
{
static bool logged = false;
if (!logged)
{
TraceLoggingWrite(
g_hCTerminalCoreProvider,
"ShellIntegrationWorkingDirSet",
TraceLoggingDescription("The CWD was set by the client application"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));

logged = true;
}

_workingDirectory = uri;
}

Expand Down Expand Up @@ -300,6 +323,19 @@ void Terminal::UseMainScreenBuffer()

void Terminal::AddMark(const Microsoft::Console::VirtualTerminal::DispatchTypes::ScrollMark& mark)
{
static bool logged = false;
if (!logged)
{
TraceLoggingWrite(
g_hCTerminalCoreProvider,
"ShellIntegrationMarkAdded",
TraceLoggingDescription("A mark was added via VT at least once"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));

logged = true;
}

const til::point cursorPos{ _activeBuffer().GetCursor().GetPosition() };
AddMark(mark, cursorPos, cursorPos);
}
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
#include "winrt/Windows.Foundation.h"

#include "winrt/Microsoft.Terminal.Core.h"

#include <til.h>
1 change: 1 addition & 0 deletions src/cascadia/TerminalCore/terminalcore-common.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ClInclude Include="..\ControlKeyStates.hpp" />
<ClInclude Include="..\pch.h" />
<ClInclude Include="..\Terminal.hpp" />
<ClInclude Include="..\tracing.hpp" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions src/cascadia/TerminalCore/tracing.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.

Module Name:
- tracing.hpp

Abstract:
- This module is used for recording tracing/debugging information to the telemetry ETW channel
--*/

#pragma once
#include <string>
#include <windows.h>
#include <winmeta.h>
#include <TraceLoggingProvider.h>
#include <telemetry/ProjectTelemetry.h>

TRACELOGGING_DECLARE_PROVIDER(g_hCTerminalCoreProvider);
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/CascadiaSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
bool _hasInvalidColorScheme(const Model::Command& command) const;
void _validateThemeExists();

void _researchOnLoad();

// user settings
winrt::hstring _hash;
winrt::com_ptr<implementation::GlobalAppSettings> _globals = winrt::make_self<implementation::GlobalAppSettings>();
Expand Down
109 changes: 91 additions & 18 deletions src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -893,24 +893,7 @@ try
settings->_hash = _calculateHash(settingsString, lastWriteTime);
}

// GH#13936: We're interested in how many users opt out of useAtlasEngine,
// indicating major issues that would require us to disable it by default again.
{
size_t enabled[2]{};
for (const auto& profile : settings->_activeProfiles)
{
enabled[profile.UseAtlasEngine()]++;
}

TraceLoggingWrite(
g_hSettingsModelProvider,
"AtlasEngine_Usage",
TraceLoggingDescription("Event emitted upon settings load, containing the number of profiles opted-in/out of useAtlasEngine"),
TraceLoggingUIntPtr(enabled[0], "UseAtlasEngineDisabled", "Number of profiles for which AtlasEngine is disabled"),
TraceLoggingUIntPtr(enabled[1], "UseAtlasEngineEnabled", "Number of profiles for which AtlasEngine is enabled"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
}
settings->_researchOnLoad();

return *settings;
}
Expand All @@ -927,6 +910,96 @@ catch (const SettingsTypedDeserializationException& e)
return *settings;
}

void CascadiaSettings::_researchOnLoad()
{
// Only do this if we're actually being sampled
if (TraceLoggingProviderEnabled(g_hSettingsModelProvider, 0, MICROSOFT_KEYWORD_MEASURES))
{
// GH#13936: We're interested in how many users opt out of useAtlasEngine,
// indicating major issues that would require us to disable it by default again.
{
size_t enabled[2]{};
for (const auto& profile : _activeProfiles)
{
enabled[profile.UseAtlasEngine()]++;
}

TraceLoggingWrite(
g_hSettingsModelProvider,
"AtlasEngine_Usage",
TraceLoggingDescription("Event emitted upon settings load, containing the number of profiles opted-in/out of useAtlasEngine"),
TraceLoggingUIntPtr(enabled[0], "UseAtlasEngineDisabled", "Number of profiles for which AtlasEngine is disabled"),
TraceLoggingUIntPtr(enabled[1], "UseAtlasEngineEnabled", "Number of profiles for which AtlasEngine is enabled"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
}

// ----------------------------- RE: Themes ----------------------------
const auto numThemes = GlobalSettings().Themes().Size();
const auto themeInUse = GlobalSettings().CurrentTheme().Name();
const auto changedTheme = GlobalSettings().HasTheme();

// system: 0
// light: 1
// dark: 2
// a custom theme: 3
const auto themeChoice = themeInUse == L"system" ? 0 :
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
themeInUse == L"light" ? 1 :
themeInUse == L"dark" ? 2 :
3;

TraceLoggingWrite(
g_hSettingsModelProvider,
"ThemesInUse",
TraceLoggingDescription("Data about the themes in use"),
TraceLoggingBool(themeChoice, "Identifier for the theme chosen. 0 is system, 1 is light, 2 is dark, and 3 indicates any custom theme."),
TraceLoggingBool(changedTheme, "True if the user actually changed the theme from the default theme"),
TraceLoggingInt32(numThemes, "Number of themes in the user's settings"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));

// --------------------------- RE: sendInput ---------------------------
auto collectSendInput = [&]() {
auto totalSendInput = 0;
const auto& allActions = GlobalSettings().ActionMap().AvailableActions();
for (const auto&& [name, actionAndArgs] : allActions)
{
if (actionAndArgs.Action() == ShortcutAction::SendInput)
{
totalSendInput++;
}
}
return totalSendInput;
};

TraceLoggingWrite(
g_hSettingsModelProvider,
"SendInputUsage",
TraceLoggingDescription("Event emitted upon settings load, containing the number of sendInput actions a user has"),
TraceLoggingInt32(collectSendInput(), "Number of sendInput actions in the user's settings"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));

// ------------------------ RE: autoMarkPrompts ------------------------
auto totalAutoMark = 0;
auto totalShowMarks = 0;
for (const auto&& p : AllProfiles())
{
totalAutoMark += p.AutoMarkPrompts() ? 1 : 0;
totalShowMarks += p.ShowMarks() ? 1 : 0;
}

TraceLoggingWrite(
g_hSettingsModelProvider,
"MarksProfilesUsage",
TraceLoggingDescription("Event emitted upon settings load, containing the number of profiles opted-in to scrollbar marks"),
TraceLoggingInt32(totalAutoMark, "Number of profiles for which AutoMarkPrompts is enabled"),
TraceLoggingInt32(totalShowMarks, "Number of profiles for which ShowMarks is enabled"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
}
}

// Function Description:
// - Loads a batch of settings curated for the Universal variant of the terminal app
// Arguments:
Expand Down