Skip to content

Commit 68256a8

Browse files
Merge pull request #411 from GameTechDev/feature/ipcv2
API backwards compatibility with dynamic loading + loader helper DLL
2 parents 3371b2c + 8c2fe9d commit 68256a8

File tree

78 files changed

+1584
-2697
lines changed

Some content is hidden

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

78 files changed

+1584
-2697
lines changed

IntelPresentMon/AppCef/CefNano.args.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
"Id": "8634f48b-7ed1-45af-8b73-5973c7b4b3c7",
3737
"Command": "--p2c-log-svc-pipe-enable"
3838
},
39+
{
40+
"Id": "b0fec119-97eb-46b4-bdd7-e1eb8b857c45",
41+
"Command": "--p2c-middleware-dll-path .\\PresentMonAPI2.dll"
42+
},
43+
{
44+
"Id": "0fb8cd38-1cf3-417f-a81c-894f60801ce8",
45+
"Command": "--p2c-log-middleware-copy"
46+
},
3947
{
4048
"Id": "bc2faf34-6d97-458c-8ff1-67f3102617da",
4149
"Command": "--p2c-enable-ui-dev-options"

IntelPresentMon/AppCef/source/winmain.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <Versioning/BuildId.h>
1212
#include <CommonUtilities/win/Utilities.h>
1313
#include <PresentMonAPIWrapper/DiagnosticHandler.h>
14+
#include <PresentMonAPI2Loader/Loader.h>
1415
#include <dwmapi.h>
1516

1617
#pragma warning(push)
@@ -187,8 +188,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
187188
#else
188189
constexpr bool is_debug = true;
189190
#endif
190-
// create logging system and ensure cleanup before main ext
191-
LogChannelManager zLogMan_;
192191
// parse the command line arguments and make them globally available
193192
if (auto err = Options::Init(__argc, __argv, true)) {
194193
if (*err == 0) {
@@ -202,6 +201,12 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
202201
return *err;
203202
}
204203
const auto& opt = Options::Get();
204+
// optionally override the middleware dll path (typically when running from IDE in dev cycle)
205+
if (auto path = opt.middlewareDllPath.AsOptional()) {
206+
pmLoaderSetPathToMiddlewareDll_(path->c_str());
207+
}
208+
// create logging system and ensure cleanup before main ext
209+
LogChannelManager zLogMan_;
205210
// wait for debugger connection
206211
if ((opt.cefType && *opt.cefType == "renderer" && opt.debugWaitRender) ||
207212
(!opt.cefType && opt.debugWaitClient)) {
@@ -272,7 +277,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
272277

273278
// code from here on is only executed by the root process (browser window process)
274279

275-
pmlog_info(std::format("== client section starting build#{} clean:{} ==", BuildIdShortHash(), BuildIdDirtyFlag()));
280+
pmlog_info(std::format("== client section starting build#{} clean:{} ==", BuildIdShortHash(), !BuildIdDirtyFlag()));
276281

277282
{
278283
auto& folderResolver = infra::util::FolderResolver::Get();

IntelPresentMon/CommonUtilities/Exception.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,19 @@ namespace pmon::util
6868
return PM_STATUS_FAILURE;
6969
}
7070

71+
bool Exception::HasPmStatus() const noexcept
72+
{
73+
return false;
74+
}
75+
7176
void DoCapture_(Exception& e)
7277
{
7378
if (log::GlobalPolicy::Get().GetExceptionTrace()) {
7479
e.CaptureStackTrace();
7580
}
7681
}
7782

78-
std::string ReportException(std::string note, std::exception_ptr pEx) noexcept
83+
std::pair<std::string, std::optional<PM_STATUS>> ReportException(std::string note, std::exception_ptr pEx) noexcept
7984
{
8085
if (!pEx) {
8186
pEx = std::current_exception();
@@ -92,15 +97,26 @@ namespace pmon::util
9297
try {
9398
std::rethrow_exception(pEx);
9499
}
100+
catch (const pmon::util::Exception& e) {
101+
try {
102+
if (e.HasPmStatus()) {
103+
return { concat(std::format("[{}] {}", typeid(e).name(), e.what())), e.GeneratePmStatus() };
104+
}
105+
else {
106+
return { concat(std::format("[{}] {}", typeid(e).name(), e.what())), std::nullopt };
107+
}
108+
}
109+
catch (...) { return {}; }
110+
}
95111
catch (const std::exception& e) {
96-
try { return concat(std::format("[{}] {}", typeid(e).name(), e.what())); }
112+
try { return { concat(std::format("[{}] {}", typeid(e).name(), e.what())), std::nullopt }; }
97113
catch (...) { return {}; }
98114
}
99115
catch (...) {
100-
return concat("Unrecognized exception");
116+
return { concat("Unrecognized exception"), std::nullopt };
101117
}
102118
}
103-
return concat("No exception in flight");
119+
return { concat("No exception in flight"), std::nullopt };
104120
}
105121

106122
PM_STATUS GeneratePmStatus(std::exception_ptr pEx) noexcept

IntelPresentMon/CommonUtilities/Exception.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "str/String.h"
33
#include <exception>
44
#include <memory>
5+
#include <optional>
56
#include "../PresentMonAPI2/PresentMonAPI.h"
67

78
namespace pmon::util
@@ -22,6 +23,7 @@ namespace pmon::util
2223
std::string GetTraceString() const;
2324
bool HasTrace() const noexcept;
2425
virtual PM_STATUS GeneratePmStatus() const noexcept;
26+
virtual bool HasPmStatus() const noexcept;
2527
protected:
2628
virtual std::string ComposeWhatString_() const noexcept;
2729
private:
@@ -40,7 +42,7 @@ namespace pmon::util
4042
return exception;
4143
}
4244

43-
std::string ReportException(std::string note = {}, std::exception_ptr pEx = {}) noexcept;
45+
std::pair<std::string, std::optional<PM_STATUS>> ReportException(std::string note = {}, std::exception_ptr pEx = {}) noexcept;
4446

4547
PM_STATUS GeneratePmStatus(std::exception_ptr pEx = {}) noexcept;
4648

IntelPresentMon/CommonUtilities/cli/CliFramework.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace pmon::util::cli
5656
for (auto pWideStr : std::span{ wargv, size_t(argc) }) {
5757
const auto narrow = str::ToNarrow(pWideStr);
5858
auto pNarrowStr = new char[narrow.size() + 1];
59-
strcpy_s(pNarrowStr, narrow.size() + 1, narrow.c_str());
59+
strncpy_s(pNarrowStr, narrow.size() + 1, narrow.c_str(), _TRUNCATE);
6060
stringPointerArray.push_back(pNarrowStr);
6161
}
6262
}

IntelPresentMon/CommonUtilities/log/DiagnosticDriver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ namespace pmon::util::log
2626
void DiagnosticDriver::Submit(const Entry& e)
2727
{
2828
// ignore non-diagnostic entries and low-priority levels
29-
if (!e.diagnosticLayer_ || int(e.level_) > int(config_.filterLevel)) {
29+
if ((!e.diagnosticLayer_ && !config_.disableDiagnosticFilter)
30+
|| int(e.level_) > int(config_.filterLevel)) {
3031
return;
3132
}
3233
// filtering by subsystem

IntelPresentMon/CommonUtilities/log/EntryBuilder.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,22 @@ namespace pmon::util::log
7474
EntryBuilder& diag() noexcept;
7575
EntryBuilder& subsys(Subsystem sys) noexcept;
7676
EntryStream stream() noexcept;
77-
template<typename T>
78-
EntryBuilder& code(const T& code) noexcept
77+
template<typename C>
78+
EntryBuilder& code(const C& code) noexcept
7979
{
8080
errorCode_ = { code };
8181
return *this;
82-
}
82+
}
83+
template<typename C>
84+
EntryBuilder& note(std::pair<std::string, std::optional<C>> noteWithCode) noexcept
85+
{
86+
auto&& [msg_, code_] = noteWithCode;
87+
note(std::move(msg_));
88+
if (code_) {
89+
code(*code_);
90+
}
91+
return *this;
92+
}
8393
private:
8494
// functions
8595
void commit_() noexcept;

IntelPresentMon/CommonUtilities/log/Log.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ namespace pmon::util::log
3434
#endif
3535
#endif
3636

37-
#define pmlog_(lvl) ((PMLOG_BUILD_LEVEL_ < lvl) || (::pmon::util::log::GlobalPolicy::Get().GetLogLevel() < lvl)) \
38-
? (void)0 : ::pmon::util::log::Voidifier_{} & ::pmon::util::log::EntryBuilder{ lvl, __FILE__, __FUNCTION__, __LINE__ } \
37+
#define pmlog_from_(lvl, file, function, line) ((PMLOG_BUILD_LEVEL_ < lvl) || (::pmon::util::log::GlobalPolicy::Get().GetLogLevel() < lvl)) \
38+
? (void)0 : ::pmon::util::log::Voidifier_{} & ::pmon::util::log::EntryBuilder{ lvl, file, function, line } \
3939
.subsys(::pmon::util::log::GlobalPolicy::Get().GetSubsystem()) \
4040
.to(::pmon::util::log::GetDefaultChannel())
41+
#define pmlog_(lvl) pmlog_from_(lvl, __FILE__, __FUNCTION__, __LINE__)
4142
#define pmlog_fatal pmlog_(::pmon::util::log::Level::Fatal).note
4243
#define pmlog_error pmlog_(::pmon::util::log::Level::Error).note
4344
#define pmlog_warn pmlog_(::pmon::util::log::Level::Warning).note

IntelPresentMon/CommonUtilities/log/PanicLogger.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <string>
3+
#include <optional>
34

45
#ifndef NDEBUG
56
#define pmlog_panic_ PMLogPanic_
@@ -10,5 +11,10 @@
1011
namespace pmon::util::log
1112
{
1213
void PMLogPanic_(const std::string& msg) noexcept;
14+
template<class C>
15+
void PMLogPanic_(const std::pair<std::string, std::optional<C>>& msg) noexcept
16+
{
17+
PMLogPanic_(msg.first);
18+
}
1319
}
1420

IntelPresentMon/CommonUtilities/reg/Registry.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,20 @@ namespace pmon::util::reg
153153
return key_.IsValid();
154154
}
155155
protected:
156-
Registry(HKEY hive, std::wstring keyPath) noexcept
156+
Registry(HKEY hive, std::wstring keyPath, bool readOnly) noexcept
157157
:
158158
hive_{ hive },
159159
keyPath_{ keyPath }
160160
{
161161
// opening existing key
162162
try {
163-
key_.Open(hive_, keyPath_);
163+
key_.Open(hive_, keyPath_, readOnly ? (KEY_READ) : (KEY_READ | KEY_WRITE));
164164
return;
165165
}
166166
catch (const winreg::RegException& e) {
167167
if (e.code().value() == 2) {
168168
pmlog_warn(std::format("Registry key [{}] does not exist, creating...", str::ToNarrow(keyPath)));
169+
// note the lack of return here, allowing us to continue on to the creation routine below
169170
}
170171
else {
171172
pmlog_error(ReportException(std::format("Failed to open registry key [{}]", str::ToNarrow(keyPath))));
@@ -190,7 +191,7 @@ namespace pmon::util::reg
190191
winreg::RegKey key_;
191192
};
192193

193-
template<class T>
194+
template<class T, HKEY Hive>
194195
class RegistryBase : public Registry
195196
{
196197
public:
@@ -199,13 +200,13 @@ namespace pmon::util::reg
199200
static T reg;
200201
return reg;
201202
}
202-
static void SetPrivileged(bool privileged) noexcept
203+
static void SetReadonly(bool readonly = true) noexcept
203204
{
204-
privileged_ = privileged;
205+
readonly_ = readonly;
205206
}
206207
protected:
207-
RegistryBase() : Registry{ privileged_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, T::keyPath_ } {}
208+
RegistryBase() : Registry{ Hive, T::keyPath_, readonly_ } {}
208209
private:
209-
inline static bool privileged_ = true;
210+
inline static bool readonly_ = false;
210211
};
211212
}

IntelPresentMon/Core/Core.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@
169169
<ProjectReference Include="..\CommonUtilities\CommonUtilities.vcxproj">
170170
<Project>{08a704d8-ca1c-45e9-8ede-542a1a43b53e}</Project>
171171
</ProjectReference>
172-
<ProjectReference Include="..\PresentMonAPI2\PresentMonAPI2.vcxproj">
173-
<Project>{5ddba061-53a0-4835-8aaf-943f403f924f}</Project>
172+
<ProjectReference Include="..\PresentMonAPI2Loader\PresentMonAPI2Loader.vcxproj">
173+
<Project>{8f86d067-2437-46fc-8f82-4d7155ceced7}</Project>
174174
</ProjectReference>
175175
<ProjectReference Include="..\PresentMonAPIWrapperCommon\PresentMonAPIWrapperCommon.vcxproj">
176176
<Project>{2b343210-86ab-4153-9a6c-945e4af54c7c}</Project>

IntelPresentMon/Core/source/cli/CliOptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ namespace p2c::cli
4141
Option<std::string> logFolder{ this, "--p2c-log-folder", "", "Path to directory in which to store log files", CLI::ExistingDirectory };
4242
Option<std::string> logSvcPipe{ this, "--p2c-log-svc-pipe", ::pmon::gid::defaultLogPipeBaseName, "Base name of pipe to use when connecting to service IPC log" };
4343
Flag logSvcPipeEnable{ this, "--p2c-log-svc-pipe-enable", "Enable pipe connection to service IPC log stream" };
44+
Flag logMiddlewareCopy{ this, "--p2c-log-middleware-copy", "Copy log entries from middleware channel to this client" };
4445

4546
private: Group gi_{ this, "Internal", "Internal options, do not supply manually"}; public:
4647
Option<std::string> cefType{ this, "--type", "", "Type of the current chromium process" };
4748
Option<std::string> logPipeName{ this, "--p2c-log-pipe-name", "", "The postfix used to create the named pipe for logging source server" };
49+
Option<std::string> middlewareDllPath{ this, "--p2c-middleware-dll-path", "", "Override middleware DLL path discovery with custom path" };
4850

4951
static constexpr const char* description = "PresentMon performance overlay and trace capture application";
5052
static constexpr const char* name = "PresentMon.exe";

0 commit comments

Comments
 (0)