Skip to content

Commit b25a696

Browse files
Merge pull request #425 from GameTechDev/fix/sample-client
allow specifying middleware path in sample client & better wrapper errs
2 parents 16e08be + 9d8394c commit b25a696

File tree

5 files changed

+44
-112
lines changed

5 files changed

+44
-112
lines changed

IntelPresentMon/CommonUtilities/cli/CliFramework.h

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ namespace pmon::util::cli
170170
{
171171
return !bool(*this);
172172
}
173+
const T* operator->() const
174+
{
175+
return &data_;
176+
}
173177
std::optional<T> AsOptional() const
174178
{
175179
if (*this) {

IntelPresentMon/PresentMonAPIWrapperCommon/Exception.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Exception.h"
22
#include "EnumMap.h"
3+
#include "../Interprocess/source/metadata/EnumStatus.h"
34
#include <format>
45

56
namespace pmapi
@@ -19,7 +20,24 @@ namespace pmapi
1920
str.narrowSymbol, int(err), str.narrowName, str.narrowDescription);
2021
}
2122
catch (...) {
22-
return std::format("{} | Unknown error code [{}]", message, int(err));
23+
// we usually end up here trying to translate a PM_STATUS code before we have introspection access
24+
// fallback to a static lookup generated based on the known set of codes at wrapper compile time
25+
bool descriptionAvailable = false;
26+
const char* frag = nullptr;
27+
const char* name = nullptr;
28+
const char* desc = nullptr;
29+
switch (err) {
30+
#define X_STATUS_(enum_name_fragment, key_frag_, name_, short_name, desc_) \
31+
case PM_STATUS_##key_frag_: frag = #key_frag_; name = name_; desc = desc_; descriptionAvailable = true; break;
32+
ENUM_KEY_LIST_STATUS(X_STATUS_)
33+
#undef X_STATUS_
34+
}
35+
if (descriptionAvailable) {
36+
return std::format("{} | Error: {} ({}) {}: {}", message, frag, int(err), name, desc);
37+
}
38+
else {
39+
return std::format("{} | Unknown error code [{}]", message, int(err));
40+
}
2341
}
2442
}
2543
}

IntelPresentMon/SampleClient/CliOptions.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ namespace clio
99
using namespace pmon::util::cli;
1010
struct Options : public OptionsBase<Options>
1111
{
12-
Option<std::string> controlPipe{ this, "--control-pipe", "", "Name of the named pipe to use for the client-service control channel" };
13-
Option<std::string> introNsm{ this, "--intro-nsm", "", "Name of the NSM used for introspection data" };
12+
private: Group gm_{ this, "Mode", "Choose sample mode" }; public:
1413
Flag introspectionSample{ this, "--introspection-sample", "Example of how to view availability of all system metrics via introspection" };
1514
Flag dynamicQuerySample{ this, "--dynamic-query-sample", "Example of how to use a dynamic query to poll metric data" };
1615
Flag frameQuerySample{ this, "--frame-query-sample", "Example of how to use a frame query to consume raw frame data" };
@@ -19,14 +18,19 @@ namespace clio
1918
Flag wrapperStaticQuerySample{ this, "--wrapper-static-query-sample", "Example of using the wrapper to poll static metric data" };
2019
Flag genCsv{ this, "--gen-csv", "Example of creating a csv file from consumed raw frame data" };
2120
Flag addGPUMetric{ this, "--add-gpu-metric", "Example of how to search for an available GPU metric and add it to a dynamic query" };
21+
Option<int> logDemo{ this, "--log-demo", 0, "Demos of log utility features" };
22+
Option<int> diagDemo{ this, "--diag-demo", 0, "Demos of debug diagnostic layer interface" };
23+
private: Group gc_{ this, "Connection", "Control client connection" }; public:
24+
Option<std::string> controlPipe{ this, "--control-pipe", "", "Name of the named pipe to use for the client-service control channel" };
25+
Option<std::string> introNsm{ this, "--intro-nsm", "", "Name of the NSM used for introspection data" };
26+
Option<std::string> middlewareDllPath{ this, "--middleware-dll-path", "", "Override middleware DLL path discovery with custom path" };
27+
private: Group gs_{ this, "Sampling", "Control sampling / targeting behavior" }; public:
2228
Option<double> metricOffset{ this, "--metric-offset", 1000., "Offset from top for frame data. Used in --dynamic-query-sample" };
2329
Option<double> windowSize{ this, "--window-size", 2000., "Window size used for metrics calculation. Used in --dynamic-query-sample" };
2430
Option<unsigned int> processId{ this, "--process-id", 0, "Process Id to use for polling or frame data capture" };
2531
Option<std::string> processName{ this, "--process-name", "", "Name of process to use for polling or frame data capture" };
2632
Option<std::string> metric{ this, "--metric", "", "PM_METRIC, ex. PM_METRIC_PRESENTED_FPS" };
27-
Option<int> logDemo{ this, "--log-demo", 0, "Demos of log utility features" };
28-
Option<int> diagDemo{ this, "--diag-demo", 0, "Demos of debug diagnostic layer interface" };
29-
33+
private: Group gl_{ this, "Logging", "Control logging behavior" }; public:
3034
Option<log::Level> logLevel{ this, "--log-level", log::Level::Error, "Severity to log at", CLI::CheckedTransformer{ log::GetLevelMapNarrow(), CLI::ignore_case } };
3135
Option<log::Level> logTraceLevel{ this, "--log-trace-level", log::Level::Error, "Severity to print stacktrace at", CLI::CheckedTransformer{ log::GetLevelMapNarrow(), CLI::ignore_case } };
3236
Flag logTraceExceptions{ this, "--log-trace-exceptions", "Add stack trace to all thrown exceptions (including SEH exceptions)" };

IntelPresentMon/SampleClient/SampleClient.args.json

+5-105
Original file line numberDiff line numberDiff line change
@@ -3,116 +3,16 @@
33
"Id": "79fe382a-c29c-4c32-a028-b8d1abdf51b0",
44
"Items": [
55
{
6-
"Id": "04b29279-a10b-4fba-b127-1816b6a05c21",
7-
"Command": "--log-demo 0"
8-
},
9-
{
10-
"Id": "178328e1-cee6-4ec9-898d-470073f9bc88",
11-
"Command": "--log-demo 1"
12-
},
13-
{
14-
"Id": "3c5a7c74-4cc0-4251-8cef-a3c5dc135a1d",
15-
"Command": "--log-demo 17"
16-
},
17-
{
18-
"Id": "bb813e93-75af-46b5-9d4f-d4051007e9e8",
19-
"Command": "--log-demo 18"
20-
},
21-
{
22-
"Id": "c1c14433-3ec1-4fc3-9b3b-70b6580bc080",
23-
"Command": "--log-allow-list \"black.txt\""
24-
},
25-
{
26-
"Id": "6248d4d3-1a61-499d-84e8-83be773d62af",
27-
"Command": "--log-trace-level info"
28-
},
29-
{
30-
"Id": "edbe1209-2ed7-4381-8cd4-5eb6fe9e966a",
31-
"Command": "--log-level info"
32-
},
33-
{
34-
"Id": "afc8e7e1-be12-46f8-aed2-d8c09c4a5cfa",
35-
"Command": "--log-allow-list bbb"
36-
},
37-
{
38-
"Id": "b8b13731-0ee5-48c0-bee5-216f8ef884d5",
39-
"Command": "--log-deny-list aaa"
40-
},
41-
{
42-
"Id": "78f46a64-b667-4d83-91f5-48b1332ca0c0",
43-
"Command": "--diag-demo 32612"
44-
},
45-
{
46-
"Id": "edf9d064-e8f2-4c3c-8ab3-a70ae989a245",
47-
"Command": "--log-demo 29916"
48-
},
49-
{
50-
"Id": "78f46a64-b667-4d83-91f5-48b1332ca0c0",
51-
"Command": "--diag-demo 32612"
52-
},
53-
{
54-
"Id": "edf9d064-e8f2-4c3c-8ab3-a70ae989a245",
55-
"Command": "--log-demo 29916"
56-
},
57-
{
58-
"Id": "de172ca4-f013-4f7c-99e2-5b93c03c4ec5",
59-
"Command": "--log-demo 19"
60-
},
61-
{
62-
"Id": "55055cc7-7bbb-4db3-8f8f-27f1b5994bd2",
63-
"Command": "--wrapper-static-query-sample"
64-
},
65-
{
66-
"Id": "aec2f3f0-8119-42e8-a154-f0362d3a79bc",
67-
"Command": "--gen-csv"
68-
},
69-
{
70-
"Id": "fdccba8e-f10c-42b0-a1d0-b71cfa1fe849",
71-
"Command": "--add-gpu-metric"
72-
},
73-
{
74-
"Id": "68093de8-734b-45c0-b00c-718b665cbb85",
75-
"Command": "--check-metric-sample"
76-
},
77-
{
78-
"Id": "905a2f3c-5d4d-4d8e-becd-182e5078fba4",
79-
"Command": "--metric PM_METRIC_GPU_MEM_MAX_BANDWIDTH"
80-
},
81-
{
82-
"Id": "c3af5374-64e9-40e0-ae04-a5e3142e0bc7",
83-
"Command": "--frame-query-sample"
84-
},
85-
{
86-
"Id": "6c0c832e-fb7b-4738-afa4-a71bc23235e9",
87-
"Command": "--introspection-sample"
88-
},
89-
{
90-
"Id": "e4c5c9a2-dee7-4185-afe1-51c4e6c3281b",
91-
"Command": "--dynamic-query-sample"
92-
},
93-
{
94-
"Id": "ef857247-b1e3-491c-931a-c1be6924dd90",
6+
"Id": "91c5d42b-2da5-4d40-96bf-4ba9e1cce907",
957
"Command": "--help"
968
},
979
{
98-
"Id": "4d012d46-c606-4e44-91a4-8bfa0865cfbc",
99-
"Command": "--process-name Valley.exe"
100-
},
101-
{
102-
"Id": "90f7b819-b9e5-4f19-a315-186c1affaa5d",
103-
"Command": "--control-pipe \\\\.\\pipe\\igs"
104-
},
105-
{
106-
"Id": "b37ef2ea-3c9c-4929-8f5b-29ba539674e2",
107-
"Command": "--intro-nsm Global\\pm2_bip_shm_igs"
108-
},
109-
{
110-
"Id": "7f6ffa38-2a9a-480c-a811-a10c76820b74",
111-
"Command": "--view-available-metrics"
10+
"Id": "e8bc0b0d-87c9-4465-b3df-ece2942c05a3",
11+
"Command": "--introspection-sample"
11212
},
11313
{
114-
"Id": "df9b72a0-fe65-4819-9bef-82142ab661e1",
115-
"Command": "--metric-offset 1080"
14+
"Id": "2cf4c62a-0c43-4a7f-a686-8dc38ffc3868",
15+
"Command": "--middleware-dll-path .\\PresentMonAPI2.dll"
11616
}
11717
]
11818
}

IntelPresentMon/SampleClient/SampleClient.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "../PresentMonAPIWrapper/PresentMonAPIWrapper.h"
2323
#include "../PresentMonAPIWrapper/FixedQuery.h"
24+
#include "../PresentMonAPI2Loader/Loader.h"
2425
#include "Utils.h"
2526
#include "DynamicQuerySample.h"
2627
#include "FrameQuerySample.h"
@@ -55,6 +56,10 @@ int main(int argc, char* argv[])
5556
return -1;
5657
}
5758

59+
if (opt.middlewareDllPath) {
60+
pmLoaderSetPathToMiddlewareDll_(opt.middlewareDllPath->c_str());
61+
}
62+
5863
// determine requested activity
5964
if (opt.introspectionSample ^ opt.dynamicQuerySample ^ opt.frameQuerySample ^ opt.checkMetricSample ^ opt.wrapperStaticQuerySample ^ opt.metricListSample) {
6065
std::unique_ptr<pmapi::Session> pSession;
@@ -85,12 +90,13 @@ int main(int argc, char* argv[])
8590
}
8691
}
8792
else {
88-
std::cout << "SampleClient supports one action at a time. Select one of:\n";
93+
std::cout << "SampleClient supports one action at a time. For example:\n";
8994
std::cout << "--introspection-sample\n";
9095
std::cout << "--wrapper-static-query-sample\n";
9196
std::cout << "--dynamic-query-sample [--process-id id | --process-name name.exe] [--add-gpu-metric]\n";
9297
std::cout << "--frame-query-sample [--process-id id | --process-name name.exe] [--gen-csv]\n";
9398
std::cout << "--check-metric-sample --metric PM_METRIC_*\n";
99+
std::cout << "Use --help to see the full list of commands and configuration options available\n";
94100
return -1;
95101
}
96102
}

0 commit comments

Comments
 (0)