|
9 | 9 | #include "../../CommonUtilities/str/String.h" |
10 | 10 | #include "../../CommonUtilities/win/Privileges.h" |
11 | 11 |
|
12 | | -#include "inc/uci/uci-versions.h" |
13 | | - |
14 | 12 | #include <algorithm> |
15 | 13 | #include <exception> |
16 | 14 | #include <format> |
|
22 | 20 | using namespace pmon; |
23 | 21 | using namespace std::literals; |
24 | 22 |
|
| 23 | +#if PMON_HAS_UCI_SDK |
| 24 | + |
| 25 | +#include <uci/uci-versions.h> |
| 26 | + |
25 | 27 | namespace pmon::tel::uci |
26 | 28 | { |
27 | 29 | namespace |
28 | 30 | { |
29 | 31 | using v = util::log::V; |
30 | 32 |
|
| 33 | + struct UciApi_ |
| 34 | + { |
| 35 | + HMODULE module = nullptr; |
| 36 | + decltype(&::uciGetCollectorFromIdentifier) uciGetCollectorFromIdentifier = nullptr; |
| 37 | + decltype(&::uciInitialize) uciInitialize = nullptr; |
| 38 | + decltype(&::uciDestroy) uciDestroy = nullptr; |
| 39 | + decltype(&::uciEnumerateMetrics) uciEnumerateMetrics = nullptr; |
| 40 | + decltype(&::uciGetMetricContainerMetrics) uciGetMetricContainerMetrics = nullptr; |
| 41 | + decltype(&::uciGetMetricId) uciGetMetricId = nullptr; |
| 42 | + decltype(&::uciGetMetricName) uciGetMetricName = nullptr; |
| 43 | + decltype(&::uciGetMetricDescription) uciGetMetricDescription = nullptr; |
| 44 | + decltype(&::uciGetMetricEvents) uciGetMetricEvents = nullptr; |
| 45 | + decltype(&::uciGetEventId) uciGetEventId = nullptr; |
| 46 | + decltype(&::uciGetMetricEventName) uciGetMetricEventName = nullptr; |
| 47 | + decltype(&::uciGetMetricEventDescription) uciGetMetricEventDescription = nullptr; |
| 48 | + decltype(&::uciGetMetricContainerGroups) uciGetMetricContainerGroups = nullptr; |
| 49 | + decltype(&::uciGetMetricGroupId) uciGetMetricGroupId = nullptr; |
| 50 | + decltype(&::uciGetMetricGroupName) uciGetMetricGroupName = nullptr; |
| 51 | + decltype(&::uciGetMetricGroupDescription) uciGetMetricGroupDescription = nullptr; |
| 52 | + decltype(&::uciGetMetricsInGroup) uciGetMetricsInGroup = nullptr; |
| 53 | + decltype(&::uciGetMetricContainerEvents) uciGetMetricContainerEvents = nullptr; |
| 54 | + decltype(&::uciFreeMetricContainer) uciFreeMetricContainer = nullptr; |
| 55 | + decltype(&::uciMetricRecordGetMetricName) uciMetricRecordGetMetricName = nullptr; |
| 56 | + decltype(&::uciMetricRecordGetEntity) uciMetricRecordGetEntity = nullptr; |
| 57 | + decltype(&::uciMetricRecordGetDescriptor) uciMetricRecordGetDescriptor = nullptr; |
| 58 | + decltype(&::uciMetricRecordGetUnit) uciMetricRecordGetUnit = nullptr; |
| 59 | + decltype(&::uciMetricRecordGetSample) uciMetricRecordGetSample = nullptr; |
| 60 | + decltype(&::uciMetricRecordGetRecordTimestamp) uciMetricRecordGetRecordTimestamp = nullptr; |
| 61 | + decltype(&::uciMetricRecordGetRecordDuration) uciMetricRecordGetRecordDuration = nullptr; |
| 62 | + decltype(&::uciConfigureCollection) uciConfigureCollection = nullptr; |
| 63 | + decltype(&::uciSetDataCallback) uciSetDataCallback = nullptr; |
| 64 | + decltype(&::uciStartCollection) uciStartCollection = nullptr; |
| 65 | + decltype(&::uciStopCollection) uciStopCollection = nullptr; |
| 66 | + |
| 67 | + UciApi_() |
| 68 | + { |
| 69 | + module = LoadLibraryW(L"unified-collector-interface.dll"); |
| 70 | + if (module == nullptr) { |
| 71 | + throw Except<TelemetrySubsystemAbsent>(std::format( |
| 72 | + "UCI telemetry provider unavailable because unified-collector-interface.dll is not present; error={}", |
| 73 | + GetLastError())); |
| 74 | + } |
| 75 | + |
| 76 | + LoadProc_(uciGetCollectorFromIdentifier, "uciGetCollectorFromIdentifier"); |
| 77 | + LoadProc_(uciInitialize, "uciInitialize"); |
| 78 | + LoadProc_(uciDestroy, "uciDestroy"); |
| 79 | + LoadProc_(uciEnumerateMetrics, "uciEnumerateMetrics"); |
| 80 | + LoadProc_(uciGetMetricContainerMetrics, "uciGetMetricContainerMetrics"); |
| 81 | + LoadProc_(uciGetMetricId, "uciGetMetricId"); |
| 82 | + LoadProc_(uciGetMetricName, "uciGetMetricName"); |
| 83 | + LoadProc_(uciGetMetricDescription, "uciGetMetricDescription"); |
| 84 | + LoadProc_(uciGetMetricEvents, "uciGetMetricEvents"); |
| 85 | + LoadProc_(uciGetEventId, "uciGetEventId"); |
| 86 | + LoadProc_(uciGetMetricEventName, "uciGetMetricEventName"); |
| 87 | + LoadProc_(uciGetMetricEventDescription, "uciGetMetricEventDescription"); |
| 88 | + LoadProc_(uciGetMetricContainerGroups, "uciGetMetricContainerGroups"); |
| 89 | + LoadProc_(uciGetMetricGroupId, "uciGetMetricGroupId"); |
| 90 | + LoadProc_(uciGetMetricGroupName, "uciGetMetricGroupName"); |
| 91 | + LoadProc_(uciGetMetricGroupDescription, "uciGetMetricGroupDescription"); |
| 92 | + LoadProc_(uciGetMetricsInGroup, "uciGetMetricsInGroup"); |
| 93 | + LoadProc_(uciGetMetricContainerEvents, "uciGetMetricContainerEvents"); |
| 94 | + LoadProc_(uciFreeMetricContainer, "uciFreeMetricContainer"); |
| 95 | + LoadProc_(uciMetricRecordGetMetricName, "uciMetricRecordGetMetricName"); |
| 96 | + LoadProc_(uciMetricRecordGetEntity, "uciMetricRecordGetEntity"); |
| 97 | + LoadProc_(uciMetricRecordGetDescriptor, "uciMetricRecordGetDescriptor"); |
| 98 | + LoadProc_(uciMetricRecordGetUnit, "uciMetricRecordGetUnit"); |
| 99 | + LoadProc_(uciMetricRecordGetSample, "uciMetricRecordGetSample"); |
| 100 | + LoadProc_(uciMetricRecordGetRecordTimestamp, "uciMetricRecordGetRecordTimestamp"); |
| 101 | + LoadProc_(uciMetricRecordGetRecordDuration, "uciMetricRecordGetRecordDuration"); |
| 102 | + LoadProc_(uciConfigureCollection, "uciConfigureCollection"); |
| 103 | + LoadProc_(uciSetDataCallback, "uciSetDataCallback"); |
| 104 | + LoadProc_(uciStartCollection, "uciStartCollection"); |
| 105 | + LoadProc_(uciStopCollection, "uciStopCollection"); |
| 106 | + } |
| 107 | + |
| 108 | + template<class T> |
| 109 | + void LoadProc_(T& proc, const char* name) |
| 110 | + { |
| 111 | + proc = reinterpret_cast<T>(GetProcAddress(module, name)); |
| 112 | + if (proc == nullptr) { |
| 113 | + throw Except<TelemetrySubsystemAbsent>(std::format( |
| 114 | + "UCI telemetry provider unavailable because {} is missing from unified-collector-interface.dll", |
| 115 | + name)); |
| 116 | + } |
| 117 | + } |
| 118 | + }; |
| 119 | + |
| 120 | + UciApi_& Api_() |
| 121 | + { |
| 122 | + static UciApi_ api; |
| 123 | + return api; |
| 124 | + } |
| 125 | + |
| 126 | +#define uciConfigureCollection Api_().uciConfigureCollection |
| 127 | +#define uciDestroy Api_().uciDestroy |
| 128 | +#define uciEnumerateMetrics Api_().uciEnumerateMetrics |
| 129 | +#define uciFreeMetricContainer Api_().uciFreeMetricContainer |
| 130 | +#define uciGetCollectorFromIdentifier Api_().uciGetCollectorFromIdentifier |
| 131 | +#define uciGetEventId Api_().uciGetEventId |
| 132 | +#define uciGetMetricContainerEvents Api_().uciGetMetricContainerEvents |
| 133 | +#define uciGetMetricContainerGroups Api_().uciGetMetricContainerGroups |
| 134 | +#define uciGetMetricContainerMetrics Api_().uciGetMetricContainerMetrics |
| 135 | +#define uciGetMetricDescription Api_().uciGetMetricDescription |
| 136 | +#define uciGetMetricEventDescription Api_().uciGetMetricEventDescription |
| 137 | +#define uciGetMetricEventName Api_().uciGetMetricEventName |
| 138 | +#define uciGetMetricEvents Api_().uciGetMetricEvents |
| 139 | +#define uciGetMetricGroupDescription Api_().uciGetMetricGroupDescription |
| 140 | +#define uciGetMetricGroupId Api_().uciGetMetricGroupId |
| 141 | +#define uciGetMetricGroupName Api_().uciGetMetricGroupName |
| 142 | +#define uciGetMetricId Api_().uciGetMetricId |
| 143 | +#define uciGetMetricName Api_().uciGetMetricName |
| 144 | +#define uciGetMetricsInGroup Api_().uciGetMetricsInGroup |
| 145 | +#define uciInitialize Api_().uciInitialize |
| 146 | +#define uciMetricRecordGetDescriptor Api_().uciMetricRecordGetDescriptor |
| 147 | +#define uciMetricRecordGetEntity Api_().uciMetricRecordGetEntity |
| 148 | +#define uciMetricRecordGetMetricName Api_().uciMetricRecordGetMetricName |
| 149 | +#define uciMetricRecordGetRecordDuration Api_().uciMetricRecordGetRecordDuration |
| 150 | +#define uciMetricRecordGetRecordTimestamp Api_().uciMetricRecordGetRecordTimestamp |
| 151 | +#define uciMetricRecordGetSample Api_().uciMetricRecordGetSample |
| 152 | +#define uciMetricRecordGetUnit Api_().uciMetricRecordGetUnit |
| 153 | +#define uciSetDataCallback Api_().uciSetDataCallback |
| 154 | +#define uciStartCollection Api_().uciStartCollection |
| 155 | +#define uciStopCollection Api_().uciStopCollection |
| 156 | + |
31 | 157 | constexpr std::string_view kCpuPowerMetricName_ = "pkg-pwr"; |
32 | 158 | constexpr std::string_view kCpuTemperatureMetricName_ = "core-temp"; |
33 | 159 | constexpr std::string_view kCpuPowerRecordMetricName_ = "PKG-PWR"; |
@@ -183,12 +309,6 @@ namespace pmon::tel::uci |
183 | 309 | throw Except<TelemetrySubsystemAbsent>("UCI telemetry provider disabled because service is not elevated"); |
184 | 310 | } |
185 | 311 |
|
186 | | - if (LoadLibraryW(L"unified-collector-interface.dll") == nullptr) { |
187 | | - throw Except<TelemetrySubsystemAbsent>(std::format( |
188 | | - "UCI telemetry provider unavailable because unified-collector-interface.dll is not present; error={}", |
189 | | - GetLastError())); |
190 | | - } |
191 | | - |
192 | 312 | CheckUciCall_( |
193 | 313 | uciGetCollectorFromIdentifier(SoCWatchIdentifier, &collector_), |
194 | 314 | "uciGetCollectorFromIdentifier", |
@@ -737,3 +857,52 @@ namespace pmon::tel::uci |
737 | 857 | collectionStarted_ = false; |
738 | 858 | } |
739 | 859 | } |
| 860 | + |
| 861 | +#else |
| 862 | + |
| 863 | +namespace pmon::tel::uci |
| 864 | +{ |
| 865 | + UciTelemetryProvider::UciTelemetryProvider() |
| 866 | + { |
| 867 | + throw Except<TelemetrySubsystemAbsent>("UCI telemetry provider unavailable because service was built without UCI dependency present."); |
| 868 | + } |
| 869 | + |
| 870 | + UciTelemetryProvider::~UciTelemetryProvider() = default; |
| 871 | + |
| 872 | + ProviderCapabilityMap UciTelemetryProvider::GetCaps() |
| 873 | + { |
| 874 | + return {}; |
| 875 | + } |
| 876 | + |
| 877 | + const TelemetryDeviceFingerprint& UciTelemetryProvider::GetFingerPrint( |
| 878 | + ProviderDeviceId providerDeviceId) const |
| 879 | + { |
| 880 | + (void)providerDeviceId; |
| 881 | + throw Except<UciException>("UCI provider device not found"); |
| 882 | + } |
| 883 | + |
| 884 | + TelemetryMetricValue UciTelemetryProvider::PollMetric( |
| 885 | + ProviderDeviceId providerDeviceId, |
| 886 | + PM_METRIC metricId, |
| 887 | + uint32_t arrayIndex, |
| 888 | + int64_t requestQpc) |
| 889 | + { |
| 890 | + (void)providerDeviceId; |
| 891 | + (void)metricId; |
| 892 | + (void)arrayIndex; |
| 893 | + (void)requestQpc; |
| 894 | + throw Except<UciException>("UCI provider unavailable"); |
| 895 | + } |
| 896 | + |
| 897 | + void UciTelemetryProvider::SetPollRate(uint32_t pollRateMs) |
| 898 | + { |
| 899 | + (void)pollRateMs; |
| 900 | + } |
| 901 | + |
| 902 | + void UciTelemetryProvider::SetMetricUse(const svc::DeviceMetricUse& metricUse) |
| 903 | + { |
| 904 | + (void)metricUse; |
| 905 | + } |
| 906 | +} |
| 907 | + |
| 908 | +#endif |
0 commit comments