Skip to content

Commit

Permalink
Add tracelogging and config
Browse files Browse the repository at this point in the history
refs #31
  • Loading branch information
fredemmott committed Feb 8, 2023
1 parent 860e20e commit 831ca5a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
25 changes: 25 additions & 0 deletions scripts/HTCC.wprp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<WindowsPerformanceRecorder Version="1.0" Author="Microsoft Corporation" Copyright="Microsoft Corporation" Company="Microsoft Corporation">
<Profiles>
<EventCollector Id="EventCollector" Name="Event Collector">
<BufferSize Value="64" />
<Buffers Value="4" />
</EventCollector>

<EventProvider Id="EventProvider_FredEmmott.OpenXRTracing" Name="0f924f5f-21f0-513d-a2ab-2ede802e0b8f" />
<EventProvider Id="EventProvider_FredEmmott.OpenXRTracing.Alternate" Name="002f5359-fd69-56b8-a91f-26443c30187d" />
<EventProvider Id="EventProvider_FredEmmott.HandTrackedCockpitClicking" Name="d9675adc-8f15-5a67-f177-7b6ee279ae95" />

<Profile Id="FredEmmott.HandTrackedCockpitClicking.Verbose.File" Name="FredEmmott.HandTrackedCockpitClicking" Description="FredEmmott.HandTrackedCockpitClicking" LoggingMode="File" DetailLevel="Verbose" Default="true">
<Collectors>
<EventCollectorId Value="EventCollector">
<EventProviders>
<EventProviderId Value="EventProvider_FredEmmott.OpenXRTracing" />
<EventProviderId Value="EventProvider_FredEmmott.OpenXRTracing.Alternate" />
<EventProviderId Value="EventProvider_FredEmmott.HandTrackedCockpitClicking" />
</EventProviders>
</EventCollectorId>
</Collectors>
</Profile>
</Profiles>
</WindowsPerformanceRecorder>
12 changes: 12 additions & 0 deletions src/APILayer/APILayer_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,15 @@ XrResult __declspec(dllexport) XRAPI_CALL
return XR_SUCCESS;
}
}

BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpReserved) {
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
TraceLoggingRegister(HandTrackedCockpitClicking::gTraceProvider);
break;
case DLL_PROCESS_DETACH:
TraceLoggingUnregister(HandTrackedCockpitClicking::gTraceProvider);
break;
}
return TRUE;
}
24 changes: 22 additions & 2 deletions src/APILayer/VirtualControllerSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,16 +786,34 @@ XrResult VirtualControllerSink::xrLocateSpace(

if (!hand.present) {
*location = {XR_TYPE_SPACE_LOCATION};
TraceLoggingWrite(gTraceProvider, "xrLocateSpace_handNotPresent");
return XR_SUCCESS;
}

mOpenXR->xrLocateSpace(mLocalSpace, baseSpace, time, location);
const auto nextRet
= mOpenXR->xrLocateSpace(mLocalSpace, baseSpace, time, location);
if (!XR_SUCCEEDED(nextRet)) {
TraceLoggingWrite(
gTraceProvider,
"xrLocateSpace_failedNext",
TraceLoggingValue(static_cast<const int64_t>(nextRet), "XrResult"));
return nextRet;
}

constexpr auto poseValid = XR_SPACE_LOCATION_ORIENTATION_VALID_BIT
| XR_SPACE_LOCATION_POSITION_VALID_BIT;
constexpr auto poseTracked = XR_SPACE_LOCATION_ORIENTATION_TRACKED_BIT
| XR_SPACE_LOCATION_POSITION_TRACKED_BIT;

const auto spacePose = location->pose;
const auto spacePose = ((location->locationFlags & poseValid) == poseValid)
? location->pose
: XR_POSEF_IDENTITY;
const auto aimPose = hand.aimPose;

if (space == hand.aimSpace) {
location->pose = aimPose * spacePose;
location->locationFlags |= poseValid | poseTracked;
TraceLoggingWrite(gTraceProvider, "xrLocateSpace_handAimSpace");
return XR_SUCCESS;
}

Expand All @@ -815,6 +833,8 @@ XrResult VirtualControllerSink::xrLocateSpace(
const auto handPose = aimToGrip * aimPose;

location->pose = handPose * spacePose;
location->locationFlags |= poseValid | poseTracked;
TraceLoggingWrite(gTraceProvider, "xrLocateSpace_handGripSpace");

return XR_SUCCESS;
}
Expand Down
21 changes: 21 additions & 0 deletions src/lib/DebugPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,32 @@

#include "DebugPrint.h"

#include <TraceLoggingActivity.h>
#include <debugapi.h>
#include <evntrace.h>
#include <winmeta.h>

namespace HandTrackedCockpitClicking {

/* PS >
* [System.Diagnostics.Tracing.EventSource]::new("FredEmmott.HandTrackedCockpitClicking").guid
* d9675adc-8f15-5a67-f177-7b6ee279ae95
*/
TRACELOGGING_DEFINE_PROVIDER(
gTraceProvider,
"FredEmmott.HandTrackedCockpitClicking",
(0xd9675adc, 0x8f15, 0x5a67, 0xf1, 0x77, 0x7b, 0x6e, 0xe2, 0x79, 0xae, 0x95));

}// namespace HandTrackedCockpitClicking

namespace HandTrackedCockpitClicking::detail {

void DebugPrintString(std::wstring_view message) {
TraceLoggingWrite(
gTraceProvider,
"DebugPrint",
TraceLoggingLevel(WINEVENT_LEVEL_INFO),
TraceLoggingCountedWideString(message.data(), message.size(), "msg"));
const auto formatted
= std::format(L"[HandTrackedCockpitClicking] {}\n", message);

Expand Down
5 changes: 5 additions & 0 deletions src/lib/DebugPrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
*/
#pragma once

#include <TraceLoggingActivity.h>
#include <TraceLoggingProvider.h>

#include <format>

namespace HandTrackedCockpitClicking {

TRACELOGGING_DECLARE_PROVIDER(gTraceProvider);

namespace detail {
void DebugPrintString(std::wstring_view);
}
Expand Down

0 comments on commit 831ca5a

Please sign in to comment.