From 31e58809ccb9769d11c3085cf620f557264748c2 Mon Sep 17 00:00:00 2001 From: David Kaplan Date: Mon, 24 May 2021 22:24:01 +0100 Subject: [PATCH] Add cooked data read tracing (#10166) Added trace to conhost to instrument buffers that are cooked prior to being passed to the console. * [x] I've discussed this with core contributors already (internal) VALIDATION - Ensured trace is correctly logged in ETL (via TraceLog) --- src/host/readDataCooked.cpp | 2 ++ src/host/tracing.cpp | 13 ++++++++++++- src/host/tracing.hpp | 2 ++ src/inc/til.h | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/host/readDataCooked.cpp b/src/host/readDataCooked.cpp index 641ca12b0..458f351b3 100644 --- a/src/host/readDataCooked.cpp +++ b/src/host/readDataCooked.cpp @@ -1030,6 +1030,8 @@ void COOKED_READ_DATA::SavePendingInput(const size_t index, const bool multiline WI_IsFlagSet(gci.Flags, CONSOLE_HISTORY_NODUP))); } + Tracing::s_TraceCookedRead(_backupLimit); + // check for alias ProcessAliases(LineCount); } diff --git a/src/host/tracing.cpp b/src/host/tracing.cpp index ec8eda589..6e20fe33e 100644 --- a/src/host/tracing.cpp +++ b/src/host/tracing.cpp @@ -20,7 +20,8 @@ enum TraceKeywords Input = 0x200, API = 0x400, UIA = 0x800, - All = 0xFFF + CookedRead = 0x1000, + All = 0x1FFF }; DEFINE_ENUM_FLAG_OPERATORS(TraceKeywords); @@ -404,6 +405,16 @@ void Tracing::s_TraceInputRecord(const INPUT_RECORD& inputRecord) } } +void Tracing::s_TraceCookedRead(_In_z_ const wchar_t* pwszCookedBuffer) +{ + TraceLoggingWrite( + g_hConhostV2EventTraceProvider, + "CookedRead", + TraceLoggingWideString(pwszCookedBuffer, "ReadBuffer"), + TraceLoggingKeyword(TIL_KEYWORD_TRACE), + TraceLoggingKeyword(TraceKeywords::CookedRead)); +} + void __stdcall Tracing::TraceFailure(const wil::FailureInfo& failure) noexcept { TraceLoggingWrite( diff --git a/src/host/tracing.hpp b/src/host/tracing.hpp index 40744ec21..36ae55423 100644 --- a/src/host/tracing.hpp +++ b/src/host/tracing.hpp @@ -62,6 +62,8 @@ public: static void s_TraceWindowMessage(const MSG& msg); static void s_TraceInputRecord(const INPUT_RECORD& inputRecord); + static void s_TraceCookedRead(_In_z_ const wchar_t* pwszCookedBuffer); + static void __stdcall TraceFailure(const wil::FailureInfo& failure) noexcept; private: diff --git a/src/inc/til.h b/src/inc/til.h index c574da12b..9e8792b4c 100644 --- a/src/inc/til.h +++ b/src/inc/til.h @@ -44,7 +44,7 @@ // See also https://osgwiki.com/wiki/TraceLogging#Semantics // // Note that Conhost had already defined some keywords -// between bits 0..11 so be sure to not overlap those. +// between bits 0..12 so be sure to not overlap those. // See `TraceKeywords`. // We will therefore try to reserve 32..42 for TIL // as common flags for the entire Terminal team projects.