Skip to content

Commit 2cbc481

Browse files
Merge pull request #512 from GameTechDev/feature/multi-client-enhance
Feature/multi client enhance
2 parents f32521c + 4525af3 commit 2cbc481

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1363
-76
lines changed

IntelPresentMon/CommonUtilities/CommonUtilities.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
<ClInclude Include="ref\StaticReflection.h" />
8585
<ClInclude Include="ref\WrapReflect.h" />
8686
<ClInclude Include="reg\Registry.h" />
87+
<ClInclude Include="rng\MemberSlice.h" />
88+
<ClInclude Include="rng\OptionalMinMax.h" />
8789
<ClInclude Include="rng\PairToRange.h" />
8890
<ClInclude Include="str\String.h" />
8991
<ClInclude Include="third\reflect.hpp" />

IntelPresentMon/CommonUtilities/CommonUtilities.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@
273273
<ClInclude Include="win\com\WbemSink.h">
274274
<Filter>Header Files</Filter>
275275
</ClInclude>
276+
<ClInclude Include="rng\MemberSlice.h">
277+
<Filter>Header Files</Filter>
278+
</ClInclude>
279+
<ClInclude Include="rng\OptionalMinMax.h">
280+
<Filter>Header Files</Filter>
281+
</ClInclude>
276282
</ItemGroup>
277283
<ItemGroup>
278284
<ClCompile Include="cli\CliFramework.cpp">

IntelPresentMon/CommonUtilities/Meta.h

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

55
namespace pmon::util
66
{
7-
// Helper: dependent_false for static_assert in templates.
7+
// Helper: DependentFalse for static_assert in templates.
88
template<typename T>
9-
struct dependent_false : std::false_type {};
9+
struct DependentFalseT : std::false_type {};
10+
template<typename T>
11+
inline constexpr bool DependentFalse = DependentFalseT<T>::value;
1012

1113
// deconstruct member pointer into the object type the pointer works with and the member type
1214
template <typename T> struct MemberPointerInfo;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
#include <concepts>
3+
#include <ranges>
4+
#include <type_traits>
5+
#include <utility>
6+
#include "../Meta.h"
7+
8+
namespace pmon::util::rng
9+
{
10+
// Takes a range R and a pointer-to-data-member `mp`.
11+
// If range elements have that member, returns a view of it.
12+
// If range elements are pair-like with `.second` having that member,
13+
// it returns a view of `.second.*mp`.
14+
template<std::ranges::input_range R, class MP>
15+
requires std::is_member_object_pointer_v<std::remove_cvref_t<MP>>
16+
auto MemberSlice(R&& r, MP mp)
17+
{
18+
// Transform projection that preserves reference categories and cv
19+
auto proj = [mp]<class E>(E&& e) -> decltype(auto) {
20+
// Direct member on the element
21+
if constexpr (requires { (std::forward<E>(e)).*mp; }) {
22+
return (std::forward<E>(e)).*mp;
23+
}
24+
// Member on mapped value of a pair-like element
25+
else if constexpr (requires { (std::forward<E>(e)).second.*mp; }) {
26+
return (std::forward<E>(e)).second.*mp;
27+
}
28+
else {
29+
static_assert(DependentFalse<E>, "MemberSlice: element type does not match the member pointer");
30+
}
31+
};
32+
return std::forward<R>(r) | std::views::transform(proj);
33+
}
34+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
#include <ranges>
3+
#include <optional>
4+
#include <utility>
5+
#include <type_traits>
6+
7+
namespace pmon::util::rng
8+
{
9+
namespace {
10+
template<class R>
11+
using OptionalRangeValueType_ =
12+
typename std::remove_cvref_t<std::ranges::range_reference_t<R>>::value_type;
13+
}
14+
15+
// OptionalMin: min over present values; nullopt if none present
16+
template<class R, class Comp = std::ranges::less>
17+
auto OptionalMin(R&& r, Comp comp = {}) -> std::optional<OptionalRangeValueType_<R>>
18+
{
19+
using T = OptionalRangeValueType_<R>;
20+
std::optional<T> acc;
21+
for (auto&& o : r) {
22+
if (!o) continue;
23+
if (!acc || std::invoke(comp, *o, *acc)) {
24+
acc = *o;
25+
}
26+
}
27+
return acc;
28+
}
29+
30+
// OptionalMax: max over present values; nullopt if none present
31+
template<class R, class Comp = std::ranges::less>
32+
auto OptionalMax(R&& r, Comp comp = {}) -> std::optional<OptionalRangeValueType_<R>>
33+
{
34+
using T = OptionalRangeValueType_<R>;
35+
std::optional<T> acc;
36+
for (auto&& o : r) {
37+
if (!o) continue;
38+
if (!acc || std::invoke(comp, *acc, *o)) {
39+
acc = *o;
40+
}
41+
}
42+
return acc;
43+
}
44+
}

IntelPresentMon/Interprocess/source/act/SymmetricActionServer.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace pmon::ipc::act
2424
class SymmetricActionServer
2525
{
2626
using SessionContextType = typename ExecCtx::SessionContextType;
27+
using SessionsMap = std::unordered_map<uint32_t, SessionContextType>;
28+
2729
public:
2830
SymmetricActionServer(ExecCtx context, std::string basePipeName,
2931
uint32_t reservedPipeInstanceCount, std::string securityString)
@@ -34,6 +36,10 @@ namespace pmon::ipc::act
3436
ctx_{ std::move(context) },
3537
worker_{ std::format("symact-{}-srv", MakeWorkerName_(basePipeName_)), &SymmetricActionServer::Run_, this}
3638
{
39+
// Only set pSessionMap if ExecCtx can be assigned a const SessionsMap*
40+
if constexpr (requires(ExecCtx& e, const SessionsMap* pSessions) { e.pSessionMap = pSessions; }) {
41+
ctx_.pSessionMap = &sessions_;
42+
}
3743
assert(reservedPipeInstanceCount_ > 0);
3844
}
3945
SymmetricActionServer(const SymmetricActionServer&) = delete;
@@ -155,7 +161,7 @@ namespace pmon::ipc::act
155161
std::string security_;
156162
as::io_context ioctx_;
157163
// maps session uid => session (uid is same as session recv (in) pipe id)
158-
std::unordered_map<uint32_t, SessionContextType> sessions_;
164+
SessionsMap sessions_;
159165
ExecCtx ctx_;
160166
mt::Thread worker_;
161167
};

IntelPresentMon/PresentMonAPI2/PresentMonAPI.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ PRESENTMON_API2_EXPORT PM_STATUS pmFreeIntrospectionRoot(const PM_INTROSPECTION_
226226
PRESENTMON_API2_EXPORT PM_STATUS pmSetTelemetryPollingPeriod(PM_SESSION_HANDLE handle, uint32_t deviceId, uint32_t timeMs)
227227
{
228228
try {
229-
LookupMiddleware_(handle).SetTelemetryPollingPeriod(deviceId, timeMs);
230-
return PM_STATUS_SUCCESS;
229+
return LookupMiddleware_(handle).SetTelemetryPollingPeriod(deviceId, timeMs);
231230
}
232231
catch (...) {
233232
const auto code = util::GeneratePmStatus();
@@ -239,8 +238,7 @@ PRESENTMON_API2_EXPORT PM_STATUS pmSetTelemetryPollingPeriod(PM_SESSION_HANDLE h
239238
PRESENTMON_API2_EXPORT PM_STATUS pmSetEtwFlushPeriod(PM_SESSION_HANDLE handle, uint32_t periodMs)
240239
{
241240
try {
242-
LookupMiddleware_(handle).SetEtwFlushPeriod(periodMs ? std::optional{ periodMs } : std::nullopt);
243-
return PM_STATUS_SUCCESS;
241+
return LookupMiddleware_(handle).SetEtwFlushPeriod(periodMs ? std::optional{ periodMs } : std::nullopt);
244242
}
245243
catch (...) {
246244
const auto code = util::GeneratePmStatus();

IntelPresentMon/PresentMonAPI2/PresentMonAPI.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <cstdint>
1111

1212
#define PM_API_VERSION_MAJOR 3
13-
#define PM_API_VERSION_MINOR 1
13+
#define PM_API_VERSION_MINOR 2
1414

1515
#ifdef __cplusplus
1616
extern "C" {
@@ -399,10 +399,14 @@ extern "C" {
399399
PRESENTMON_API2_EXPORT PM_STATUS pmGetIntrospectionRoot(PM_SESSION_HANDLE handle, const PM_INTROSPECTION_ROOT** ppRoot);
400400
// free the introspection tree structure
401401
PRESENTMON_API2_EXPORT PM_STATUS pmFreeIntrospectionRoot(const PM_INTROSPECTION_ROOT* pRoot);
402-
// sets the rate at which hardware telemetry (including CPU) is polled on a per-device basis
403-
PRESENTMON_API2_EXPORT PM_STATUS pmSetTelemetryPollingPeriod(PM_SESSION_HANDLE handle, uint32_t deviceId, uint32_t timeMs);
402+
// sets the rate at which hardware telemetry (including CPU) is polled
403+
PRESENTMON_API2_EXPORT PM_STATUS pmSetTelemetryPollingPeriod(PM_SESSION_HANDLE handle, uint32_t reserved, uint32_t timeMs);
404+
#define PM_TELEMETRY_PERIOD_MIN 4
405+
#define PM_TELEMETRY_PERIOD_MAX 5000
404406
// sets the rate at which ETW event buffers are flushed, affecting the delay of frame data reported by PresentMon
407+
// a value of zero indicates to use current service setting (default or value requested by other client)
405408
PRESENTMON_API2_EXPORT PM_STATUS pmSetEtwFlushPeriod(PM_SESSION_HANDLE handle, uint32_t periodMs);
409+
#define PM_ETW_FLUSH_PERIOD_MAX 1000
406410
// register a dynamic query used for polling metric data with (optional) statistic processing such as average or percentile
407411
PRESENTMON_API2_EXPORT PM_STATUS pmRegisterDynamicQuery(PM_SESSION_HANDLE sessionHandle, PM_DYNAMIC_QUERY_HANDLE* pHandle, PM_QUERY_ELEMENT* pElements, uint64_t numElements, double windowSizeMs, double metricOffsetMs);
408412
// free the resources associated with a registered dynamic query

0 commit comments

Comments
 (0)