Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions IntelPresentMon/AppCef/Web/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,20 @@ export default Vue.extend({
widget.metrics = widget.metrics.filter(widgetMetric => {
const metric = Introspection.metrics.find(m => m.id === widgetMetric.metric.metricId);
if (metric === undefined || metric.availableDeviceIds.length === 0) {
// If the metric is undefined, this widgetMetric will be removed, so return false
// If the metric is undefined, this widgetMetric will be dropped
return false;
}
// If the metric is found, set up the deviceId and desiredUnitId as needed
widgetMetric.metric.deviceId = 0; // establish universal device id
// Check whether metric is a gpu metric, then we need non-universal device id
if (!metric.availableDeviceIds.includes(0)) {
// Set device to selected adapter, falling back to first available device if necessary
if (this.pref.adapterId !== null && metric.availableDeviceIds.includes(this.pref.adapterId)) {
widgetMetric.metric.deviceId = this.pref.adapterId;
} else {
widgetMetric.metric.deviceId = metric.availableDeviceIds[0];
// if no specific adapter id set, assume adapter id = 1 is active
const adapterId = this.pref.adapterId !== null ? this.pref.adapterId : 1;
// Set adapter id for this query element to the active one if available
if (metric.availableDeviceIds.includes(adapterId)) {
widgetMetric.metric.deviceId = adapterId;
} else { // if active adapter id is not available drop this widgetMetric
return false;
}
}
// Fill out the unit
Expand Down
2 changes: 1 addition & 1 deletion IntelPresentMon/AppCef/source/NanoCefBrowserClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace p2c::client::cef
return pContextMenuHandler;
}

#define xjs_pmlog_(lvl) ((PMLOG_BUILD_LEVEL < lvl) || (::pmon::util::log::GlobalPolicy::Get().GetLogLevel() < lvl)) \
#define xjs_pmlog_(lvl) ((PMLOG_BUILD_LEVEL_ < lvl) || (::pmon::util::log::GlobalPolicy::Get().GetLogLevel() < lvl)) \
? (void)0 : (void)::pmon::util::log::EntryBuilder{ lvl, source.ToString(), {}, line } \
.to(::pmon::util::log::GetDefaultChannel()).no_trace().note(message.ToString())

Expand Down
17 changes: 17 additions & 0 deletions IntelPresentMon/AppCef/source/util/AsyncEndpointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ namespace p2c::client::util
);
lck.unlock();

if constexpr (v::v8async) {
pmlog_verb(v::v8async)(std::format("Async call {{{}}} from V8 to endpoint [{}] with payload:\n{}",
uid, key, Traverse(V8ToCefValue(*pObj)).Dump()));
}
else {
pmlog_dbg(std::format("Async call {{{}}} from V8 to endpoint [{}]", uid, key));
}

switch (pEndpoint->GetEnvironment())
{
case AsyncEndpoint::Environment::BrowserProcess:
Expand Down Expand Up @@ -86,6 +94,15 @@ namespace p2c::client::util
if (auto i = invocations.find(uid); i != std::end(invocations))
{
auto invocation = std::move(i->second);

if constexpr (v::v8async) {
pmlog_verb(v::v8async)(std::format("Async call {{{}}} resolved with payload:\n{}",
uid, Traverse(pArgs).Dump()));
}
else {
pmlog_verb(v::v8async)(std::format("Async call {{{}}} resolved", uid));
}

invocations.erase(i);
lck.unlock();

Expand Down
99 changes: 93 additions & 6 deletions IntelPresentMon/AppCef/source/util/CefValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace p2c::client::util
{
using namespace std::literals;

CefRefPtr<CefValue> V8ToCefValue(CefV8Value& v8)
{
auto v = CefValue::Create();
Expand Down Expand Up @@ -130,7 +132,7 @@ namespace p2c::client::util
return { std::move(pVal) };
}

std::wstring CefValueTraverser::AsWString()
std::wstring CefValueTraverser::AsWString() const
{
using str::ToWide;
if (pCefValue->GetType() == CefValueType::VTYPE_STRING)
Expand All @@ -141,7 +143,7 @@ namespace p2c::client::util
throw Except<BadCefValueTraversal>();
}

std::string CefValueTraverser::AsString()
std::string CefValueTraverser::AsString() const
{
using str::ToWide;
if (pCefValue->GetType() == CefValueType::VTYPE_STRING)
Expand Down Expand Up @@ -203,17 +205,102 @@ namespace p2c::client::util
return std::move(pCefValue);
}

size_t CefValueTraverser::GetArrayLength()
bool CefValueTraverser::IsAggregate() const
{
const auto type = pCefValue->GetType();
return type == CefValueType::VTYPE_LIST || type == CefValueType::VTYPE_DICTIONARY;
}

std::string CefValueTraverser::Dump(int initial, int increment) const
{
if (pCefValue->GetType() == CefValueType::VTYPE_LIST)
return Dump_(initial, increment, false);
}

std::string CefValueTraverser::Dump_(int depth, int increment, bool labeled) const
{
std::ostringstream oss;
if (!labeled) {
oss << std::string(depth * increment, ' ');
}
switch (pCefValue->GetType()) {
case CefValueType::VTYPE_BOOL:
oss << (bool(*this) ? "true"s : "false"s) + " <bool>";
break;
case CefValueType::VTYPE_INT:
oss << std::to_string(int(*this)) + " <int>";
break;
case CefValueType::VTYPE_DOUBLE:
oss << std::to_string(double(*this)) + " <double>";
break;
case CefValueType::VTYPE_STRING:
oss << AsString() + " <string>";
break;
case CefValueType::VTYPE_BINARY:
oss << "# "s + std::to_string(pCefValue->GetBinary()->GetSize()) + " bytes # <binary>";
break;
case CefValueType::VTYPE_DICTIONARY:
{
depth++;
const std::string istr(increment * depth, ' ');
const auto pDict = pCefValue->GetDictionary();
CefDictionaryValue::KeyList keys;
pDict->GetKeys(keys);
if (keys.size() == 0) {
oss << "{}";
}
else {
oss << "{\n";
for (auto& key : keys) {
oss << istr << "\"" << key << "\": " << Traverse(pDict->GetValue(key))
.Dump_(depth, increment, true) << "\n";
}
oss << std::string(increment * (depth - 1), ' ') << "}";
}
break;
}
case CefValueType::VTYPE_LIST:
{
depth++;
const std::string istr(increment * depth, ' ');
const auto pList = pCefValue->GetList();
const auto size = pList->GetSize();
if (size == 0) {
oss << "[]";
}
else {
oss << "[\n";
for (int i = 0; i < pList->GetSize(); i++) {
oss << istr << i << ": " << Traverse(pList->GetValue(i))
.Dump_(depth, increment, true) << "\n";
}
oss << std::string(increment * (depth - 1), ' ') << "]";
}
break;
}
case CefValueType::VTYPE_NULL:
oss << "<NULL>"s;
break;
default:
oss << "<@UNKNOWN@>";
break;
}
return oss.str();
}


size_t CefValueTraverser::GetLength() const
{
if (pCefValue->GetType() == CefValueType::VTYPE_LIST) {
return pCefValue->GetList()->GetSize();
}
pmlog_error(std::format("Failed getting array length of CefValue type {}", CefValueTypeToString(pCefValue->GetType())));
else if (pCefValue->GetType() == CefValueType::VTYPE_DICTIONARY) {
return pCefValue->GetDictionary()->GetSize();
}
pmlog_error(std::format("Failed getting length of non-Array non-Dict CefValue type {}", CefValueTypeToString(pCefValue->GetType())));
throw Except<BadCefValueTraversal>();
}

bool CefValueTraverser::IsNull()
bool CefValueTraverser::IsNull() const
{
return pCefValue->GetType() == CefValueType::VTYPE_NULL;
}
Expand Down
21 changes: 13 additions & 8 deletions IntelPresentMon/AppCef/source/util/CefValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ namespace p2c::client::util
{
public:
CefValueTraverser(CefRefPtr<CefValue> pCefValue) : pCefValue{ std::move(pCefValue) } {}
std::wstring AsWString();
std::string AsString();
std::wstring AsWString() const;
std::string AsString() const;
template<typename T>
operator T()
operator T() const
{
using str::ToWide;
if constexpr (std::is_same_v<T, bool>)
Expand Down Expand Up @@ -215,7 +215,7 @@ namespace p2c::client::util
template<typename T>
std::vector<T> ToVector()
{
const auto size = GetArrayLength();
const auto size = GetLength();
std::vector<T> container;
container.reserve(size);
for (size_t i = 0; i < size; i++) {
Expand All @@ -232,9 +232,9 @@ namespace p2c::client::util
return container;
}
template<typename T>
std::vector<T> PluckAs(const char* key)
std::vector<T> PluckAs(const char* key) const
{
const auto size = GetArrayLength();
const auto size = GetLength();
std::vector<T> container;
container.reserve(size);
for (size_t i = 0; i < size; i++) {
Expand All @@ -246,9 +246,14 @@ namespace p2c::client::util
CefValueTraverser operator[](size_t index);
CefRefPtr<CefValue> AsCefValue() const &;
CefRefPtr<CefValue> AsCefValue() &&;
size_t GetArrayLength();
bool IsNull();
size_t GetLength() const;
bool IsNull() const;
bool IsAggregate() const;
std::string Dump(int initial = 1, int increment = 3) const;
private:
// functions
std::string Dump_(int depth, int increment, bool labeled) const;
// data
CefRefPtr<CefValue> pCefValue;
};

Expand Down
8 changes: 4 additions & 4 deletions IntelPresentMon/AppCef/source/util/MakeOverlaySpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ namespace p2c::client::util
// populate widgets into spec file
{
auto widgets = traversedSpec["widgets"].AsCefValue();
const auto widgetCount = Traverse(widgets).GetArrayLength();
const auto widgetCount = Traverse(widgets).GetLength();
for (size_t i = 0; i < widgetCount; i++)
{
auto widget = Traverse(widgets)[i].AsCefValue();
Expand All @@ -266,7 +266,7 @@ namespace p2c::client::util
auto type = lay::EnumRegistry<GraphType>::ToEnum(Traverse(vGraph)["graphType"]["name"].AsWString());
// create the metric specs for each line etc. in widget
std::vector<kern::GraphMetricSpec> graphMetricSpecs;
for (size_t i = 0; i < widgetMetrics.GetArrayLength(); i++) {
for (size_t i = 0; i < widgetMetrics.GetLength(); i++) {
auto widgetMetric = Traverse(widgetMetrics)[i];
const gfx::lay::AxisAffinity axis = widgetMetric["axisAffinity"];
auto qualifiedMetric = widgetMetric["metric"];
Expand Down Expand Up @@ -352,7 +352,7 @@ namespace p2c::client::util
// why is this hardcoded using index 0?
sheets.back()->InsertRaw<at::textColor>(at::make::Color(ColorFromV8(widgetMetrics[0ull]["lineColor"])));

const auto widgetMetricCount = widgetMetrics.GetArrayLength();
const auto widgetMetricCount = widgetMetrics.GetLength();
bool hasRightAxis = false;
for (size_t iWidgetMetric = 0; iWidgetMetric < widgetMetricCount; iWidgetMetric++) {
auto widgetMetric = widgetMetrics[iWidgetMetric];
Expand Down Expand Up @@ -405,7 +405,7 @@ namespace p2c::client::util
auto& vReadout = widget;
auto& sheets = pSpec->sheets;
const auto tag = std::format("r{}", i);
if (Traverse(vReadout)["metrics"].GetArrayLength() > 1) {
if (Traverse(vReadout)["metrics"].GetLength() > 1) {
pmlog_warn("Too many metricIds for readout widget");
}
auto qualifiedMetric = Traverse(vReadout)["metrics"][0ull]["metric"];
Expand Down
2 changes: 1 addition & 1 deletion IntelPresentMon/CommonUtilities/log/HrLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace pmon::util::log
void HrLogger::operator<<(uint32_t hr) const
{
if (FAILED(hr)) {
if ((PMLOG_BUILD_LEVEL >= Level::Error) || (GlobalPolicy::Get().GetLogLevel() >= Level::Error)) {
if ((PMLOG_BUILD_LEVEL_ >= Level::Error) || (GlobalPolicy::Get().GetLogLevel() >= Level::Error)) {
EntryBuilder{ Level::Error, sourceFile_, sourceFunctionName_, sourceLine_ }.hr(hr);
}
throw Except<Exception>("failed hr check");
Expand Down
12 changes: 8 additions & 4 deletions IntelPresentMon/CommonUtilities/log/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ namespace pmon::util::log
struct Voidifier_ { template<class T> void operator&(T&&) const {} };
}

#ifndef PMLOG_BUILD_LEVEL
#ifdef PMLOG_BUILD_LEVEL
#define PMLOG_BUILD_LEVEL_ ::pmon::util::log::Level::##PMLOG_BUILD_LEVEL
#endif

#ifndef PMLOG_BUILD_LEVEL_
#ifndef NDEBUG
#define PMLOG_BUILD_LEVEL ::pmon::util::log::Level::Debug
#define PMLOG_BUILD_LEVEL_ ::pmon::util::log::Level::Debug
#else
#define PMLOG_BUILD_LEVEL ::pmon::util::log::Level::Info
#define PMLOG_BUILD_LEVEL_ ::pmon::util::log::Level::Info
#endif
#endif

#define pmlog_(lvl) ((PMLOG_BUILD_LEVEL < lvl) || (::pmon::util::log::GlobalPolicy::Get().GetLogLevel() < lvl)) \
#define pmlog_(lvl) ((PMLOG_BUILD_LEVEL_ < lvl) || (::pmon::util::log::GlobalPolicy::Get().GetLogLevel() < lvl)) \
? (void)0 : ::pmon::util::log::Voidifier_{} & ::pmon::util::log::EntryBuilder{ lvl, __FILE__, __FUNCTION__, __LINE__ } \
.subsys(::pmon::util::log::GlobalPolicy::Get().GetSubsystem()) \
.to(::pmon::util::log::GetDefaultChannel())
Expand Down
2 changes: 1 addition & 1 deletion IntelPresentMon/CommonUtilities/log/TimePoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace pmon::util::log
{
TimePoint::TimePoint() noexcept
{
if constexpr (PMLOG_BUILD_LEVEL >= Level::Performance) {
if constexpr (PMLOG_BUILD_LEVEL_ >= Level::Performance) {
value = std::chrono::high_resolution_clock::now();
}
else {
Expand Down
14 changes: 14 additions & 0 deletions IntelPresentMon/Core/source/infra/Logging.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

// #define PMLOG_BUILD_LEVEL Verbose
// #define VVV_METRIC
#include <CommonUtilities/log/Log.h>


namespace p2c::v
{
#ifndef VVV_WINDOW // system that tracks overlay target process ancestry and windows spawning therein
Expand All @@ -23,4 +27,14 @@ namespace p2c::v
#else
inline constexpr bool overlay = true;
#endif
#ifndef VVV_METRIC // system for parsing QualifiedMetric lists and building queries, fetchers, and data packs
inline constexpr bool metric = false;
#else
inline constexpr bool metric = true;
#endif
#ifndef VVV_V8ASYNC // system for async calls and signals between V8 and C++
inline constexpr bool v8async = false;
#else
inline constexpr bool v8async = true;
#endif
}
7 changes: 7 additions & 0 deletions IntelPresentMon/Core/source/kernel/MetricPackMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "DataFetchPack.h"
#include "../pmon/MetricFetcherFactory.h"
#include "../pmon/DynamicQuery.h"
#include "../infra/Logging.h"
#include "OverlaySpec.h"
#include <CommonUtilities\Hash.h>
#include <unordered_map>
Expand Down Expand Up @@ -61,6 +62,9 @@ namespace p2c::kern
usageMap_.clear();
// build vector of qmet
const auto qualifiedMetrics = metricPackMap_ | vi::keys | rn::to<std::vector>();
pmlog_verb(v::metric)("Metrics for query build:\n" + [&] { return qualifiedMetrics |
vi::transform([](auto& q) {return " " + q.Dump(); }) |
vi::join_with('\n') | rn::to<std::basic_string>(); }());
// build fetchers / query
auto buildResult = factory.Build(pid, winSizeMs, metricOffsetMs, qualifiedMetrics);
// fill fetchers into map
Expand All @@ -78,9 +82,11 @@ namespace p2c::kern
auto& pPack = metricPackMap_[qmet];
if (!pPack.graphData) {
pPack.graphData = std::make_shared<gfx::lay::GraphData>(timeWindow);
pmlog_verb(v::metric)(std::format("AddGraph[new]> {}", qmet.Dump()));
}
else if (pPack.graphData->GetWindowSize() != timeWindow) {
pPack.graphData->Resize(timeWindow);
pmlog_verb(v::metric)(std::format("AddGraph[resize]> {}", qmet.Dump()));
}
usageMap_[qmet].graph = true;
}
Expand All @@ -89,6 +95,7 @@ namespace p2c::kern
auto& pPack = metricPackMap_[qmet];
if (!pPack.textData) {
pPack.textData = std::make_shared<std::wstring>();
pmlog_verb(v::metric)(std::format("AddReadout[new]> {}", qmet.Dump()));
}
usageMap_[qmet].text = true;
}
Expand Down
Loading