Skip to content

Commit ec15385

Browse files
committed
improve verbose property tracing
1 parent 3da2868 commit ec15385

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

IntelPresentMon/CommonUtilities/Meta.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55
namespace pmon::util
66
{
7-
template <typename T> struct MemberPointerInfo;
8-
97
// deconstruct member pointer into the object type the pointer works with and the member type
8+
template <typename T> struct MemberPointerInfo;
109
template <typename S, typename M>
1110
struct MemberPointerInfo<M S::*> {
1211
using StructType = S;
@@ -38,4 +37,19 @@ namespace pmon::util
3837
template <template <typename...> typename Template, typename T>
3938
concept IsContainer = IsContainerLike<T> && std::is_same_v<T, Template<typename T::value_type>>;
4039

40+
// trait to deduce/extract the signature details of a function by pointer
41+
namespace impl {
42+
template <typename T>
43+
struct FunctionPtrTraitsImpl_;
44+
template <typename R, typename... Args>
45+
struct FunctionPtrTraitsImpl_<R(*)(Args...)> {
46+
using ReturnType = R;
47+
using ParameterTypes = std::tuple<Args...>;
48+
template<size_t N>
49+
using ParameterType = std::tuple_element_t<N, ParameterTypes>;
50+
static constexpr size_t ParameterCount = sizeof...(Args);
51+
};
52+
}
53+
template <typename T>
54+
struct FunctionPtrTraits : impl::FunctionPtrTraitsImpl_<std::remove_cvref_t<T>> {};
4155
}

PresentData/Debug.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "ETW/Microsoft_Windows_Win32k.h"
1717
#include "ETW/NT_Process.h"
1818

19+
#include "../IntelPresentMon/CommonUtilities/Meta.h"
20+
1921
#include <assert.h>
2022
#include <dxgi.h>
2123

@@ -224,21 +226,8 @@ void PrintEventHeaderHelper_(EVENT_RECORD* eventRecord, EventMetadata* metadata,
224226
{
225227
wprintf(L" %s=", propName);
226228

227-
const auto propFuncVoid = reinterpret_cast<const void*>(propFunc);
228-
if (propFuncVoid == reinterpret_cast<const void*>(PrintBool)) PrintBool(metadata->GetEventData<uint32_t>(eventRecord, propName) != 0);
229-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintU32)) PrintU32(metadata->GetEventData<uint32_t>(eventRecord, propName));
230-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintU64)) PrintU64(metadata->GetEventData<uint64_t>(eventRecord, propName));
231-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintU64x)) PrintU64x(metadata->GetEventData<uint64_t>(eventRecord, propName));
232-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintString)) PrintString(metadata->GetEventData<std::string>(eventRecord, propName));
233-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintWString)) PrintWString(metadata->GetEventData<std::wstring>(eventRecord, propName));
234-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintTime)) PrintTime(metadata->GetEventData<uint64_t>(eventRecord, propName));
235-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintTimeDelta)) PrintTimeDelta(metadata->GetEventData<uint64_t>(eventRecord, propName));
236-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintQueuePacketType)) PrintQueuePacketType(metadata->GetEventData<uint32_t>(eventRecord, propName));
237-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintDmaPacketType)) PrintDmaPacketType(metadata->GetEventData<uint32_t>(eventRecord, propName));
238-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintPresentFlags)) PrintPresentFlags(metadata->GetEventData<uint32_t>(eventRecord, propName));
239-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintPresentHistoryModel)) PrintPresentHistoryModel(metadata->GetEventData<uint32_t>(eventRecord, propName));
240-
else if (propFuncVoid == reinterpret_cast<const void*>(PrintInputType)) PrintInputType(metadata->GetEventData<uint8_t>(eventRecord, propName));
241-
else assert(false && "unknown prop function for verbose PrintEventHeader");
229+
using ParamType = pmon::util::FunctionPtrTraits<F>::template ParameterType<0>;
230+
propFunc(metadata->GetEventData<std::remove_cvref_t<ParamType>>(eventRecord, propName));
242231

243232
if constexpr (sizeof...(T)) {
244233
PrintEventHeaderHelper_(eventRecord, metadata, rest...);

PresentData/TraceConsumer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,8 @@ std::wstring EventDataDesc::GetData<std::wstring>() const
283283
{
284284
return GetEventString<std::wstring>(*this);
285285
}
286+
287+
template<> bool EventDataDesc::GetData<bool>() const
288+
{
289+
return (bool)GetData<uint32_t>();
290+
}

PresentData/TraceConsumer.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ struct EventDataDesc {
6363

6464
template<> std::string EventDataDesc::GetData<std::string>() const;
6565
template<> std::wstring EventDataDesc::GetData<std::wstring>() const;
66+
// specialization for bool because it is actually stored as uint32_t
67+
template<> bool EventDataDesc::GetData<bool>() const;
6668

6769
struct EventMetadata {
6870
std::unordered_map<EventMetadataKey, std::vector<uint8_t>, EventMetadataKeyHash, EventMetadataKeyEqual> metadata_;

0 commit comments

Comments
 (0)