Skip to content

Commit

Permalink
Find out how often are people actually using marks, Themes (#14356)
Browse files Browse the repository at this point in the history
Let's find out!

* [x] This is all the current bullets in #14324. I'm going to leave that open till we signoff on the release.
  • Loading branch information
zadjii-msft authored Dec 1, 2022
1 parent 0eff8c0 commit 52cc523
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 18 deletions.
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"

// 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,
"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 @@ -196,6 +206,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 @@ -311,6 +334,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 :
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

0 comments on commit 52cc523

Please sign in to comment.