Skip to content

RuntimeCompatibilityOptions Insights #5599

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
27 changes: 25 additions & 2 deletions dev/RuntimeCompatibilityOptions/RuntimeCompatibilityOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Microsoft.Windows.ApplicationModel.WindowsAppRuntime.RuntimeCompatibilityOptions.g.cpp"
#include "AssemblyInfo.h"
#include <FrameworkUdk/Containment.h>
#include "RuntimeCompatibilityOptions_TraceLogger.h"

namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implementation
{
Expand All @@ -16,6 +17,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem

void RuntimeCompatibilityOptions::Apply()
{
std::wstring patchLevel1Str = std::to_wstring(m_patchLevel1.Major) + L"." +
std::to_wstring(m_patchLevel1.Minor) + L"." +
std::to_wstring(m_patchLevel1.Patch);
std::wstring patchLevel2Str = std::to_wstring(m_patchLevel2.Major) + L"." +
std::to_wstring(m_patchLevel2.Minor) + L"." +
std::to_wstring(m_patchLevel2.Patch);
RuntimeCompatibilityOptions_TraceLogger::ApplyCalled(patchLevel1Str.c_str(), patchLevel2Str.c_str());

WinAppSdk::Containment::WinAppSDKRuntimeConfiguration config;

// If both patch levels are set to the same major.minor version, error out if the patch versions are different.
Expand All @@ -24,6 +33,10 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
{
if (m_patchLevel1.Patch != m_patchLevel2.Patch)
{
RuntimeCompatibilityOptions_TraceLogger::ApplyFailed(
E_INVALIDARG,
L"Patch levels should target different Major.Minor versions or match Patch version."
);
throw hresult_invalid_argument(L"Patch levels should target different Major.Minor versions or match Patch version.");
}
}
Expand All @@ -44,9 +57,10 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
std::vector<UINT32> disabledChanges;
for (auto changeId : m_disabledChanges)
{
// TODO: Telemetry! Log the changeId that was disabled.
// UINT32 is used internally for the changeId, so cast from the enum's Int32 to that.
disabledChanges.push_back(static_cast<UINT32>(changeId));
auto id = static_cast<UINT32>(changeId);
RuntimeCompatibilityOptions_TraceLogger::ChangeDisabled(id);
disabledChanges.push_back(id);
}
config.disabledChanges = disabledChanges.data();
config.disabledChangesCount = static_cast<UINT32>(disabledChanges.size());
Expand All @@ -56,8 +70,17 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
{
if (hr == E_ILLEGAL_STATE_CHANGE)
{
RuntimeCompatibilityOptions_TraceLogger::ApplyFailed(
hr,
L"Configuration already set or locked."
);
throw winrt::hresult_illegal_state_change(L"Configuration already set or locked.");
}

RuntimeCompatibilityOptions_TraceLogger::ApplyFailed(
hr,
L"SetConfiguration failed."
);
winrt::throw_hresult(hr);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.

#pragma once

#include "pch.h"
#include <../WindowsAppRuntime_Insights/WindowsAppRuntimeInsights.h>

class RuntimeCompatibilityOptions_TraceLogger final : public wil::TraceLoggingProvider
{
IMPLEMENT_TRACELOGGING_CLASS(
RuntimeCompatibilityOptions_TraceLogger,
"Microsoft.WindowsAppRuntime.RuntimeCompatibilityOptions",
// {1741c54b-ba96-4540-867b-29830307d0cc}
(0x1741c54b, 0xba96, 0x4540, 0x86, 0x7b, 0x29, 0x83, 0x03, 0x07, 0xd0, 0xcc));

public:

DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM1(
ChangeDisabled,
PDT_ProductAndServicePerformance,
UINT32, changeId
);

DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM2(
ApplyCalled,
PDT_ProductAndServicePerformance,
PCWSTR, patchLevel1,
PCWSTR, patchLevel2
);

DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM2(
ApplyFailed,
PDT_ProductAndServicePerformance,
HRESULT, hresult,
PCWSTR, message
);
};