From 22f36202d342a3c994bbddf63b3ddf31730996ce Mon Sep 17 00:00:00 2001 From: gralkapk Date: Fri, 14 Jul 2023 10:53:23 +0200 Subject: [PATCH] wip async interface --- .../services/power_service/Power_Service.cpp | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/frontend/services/power_service/Power_Service.cpp b/frontend/services/power_service/Power_Service.cpp index 3dacc74e2d..cd217c896a 100644 --- a/frontend/services/power_service/Power_Service.cpp +++ b/frontend/services/power_service/Power_Service.cpp @@ -11,6 +11,7 @@ #ifdef MEGAMOL_USE_POWER +#include #include #include #include @@ -57,6 +58,12 @@ Power_Service::~Power_Service() { // clean up raw pointers you allocated with new, which is bad practice and nobody does } +std::string unmueller_string(wchar_t const* name) { + std::string no_mueller = + std::wstring_convert, wchar_t>{}.to_bytes(std::wstring(name)); + return no_mueller; +} + static int measure_time_in_ms = 50; static int sample_count = 50000; @@ -122,7 +129,7 @@ bool Power_Service::init(void* configPtr) { //setup_measurement(); auto sensor_count = nvml_sensor::for_all(nullptr, 0); - std::vector tmp_sensors(sensor_count); + std::vector tmp_sensors(sensor_count); nvml_sensor::for_all(tmp_sensors.data(), tmp_sensors.size()); sensor_count = msr_sensor::for_all(nullptr, 0); @@ -136,6 +143,12 @@ bool Power_Service::init(void* configPtr) { wcstombs(sensor_name, sensor_name_w, wcslen(sensor_name_w) + 1); nvml_sensors_[std::string(sensor_name)] = std::move(sensor); TracyPlotConfig(sensor_name, tracy::PlotFormatType::Number, false, true, 0); + + sensor.sample([](const visus::power_overwhelming::measurement& m, void*) { + auto name = unmueller_string(m.sensor()); + TracyPlot(name.c_str(), m.power()); + }); + delete[] sensor_name; } for (auto& sensor : tmp_msr_sensors) { @@ -144,6 +157,12 @@ bool Power_Service::init(void* configPtr) { wcstombs(sensor_name, sensor_name_w, wcslen(sensor_name_w) + 1); msr_sensors_[std::string(sensor_name)] = std::move(sensor); TracyPlotConfig(sensor_name, tracy::PlotFormatType::Number, false, true, 0); + + sensor.sample([](const visus::power_overwhelming::measurement& m, void*) { + auto name = unmueller_string(m.sensor()); + TracyPlot(name.c_str(), m.power()); + }); + delete[] sensor_name; } TracyPlotConfig("V", tracy::PlotFormatType::Number, false, true, 0); @@ -263,16 +282,16 @@ void Power_Service::postGraphRender() { // swap buffers, glClear /*if (trigger_) trigger_->WriteLow();*/ -#ifdef MEGAMOL_USE_TRACY - for (auto& [name, sensor] : nvml_sensors_) { - auto val = sensor.sample_data(); - TracyPlot(name.data(), val.power()); - } - for (auto& [name, sensor] : msr_sensors_) { - auto val = sensor.sample_data(); - TracyPlot(name.data(), val.power()); - } -#endif + //#ifdef MEGAMOL_USE_TRACY + // for (auto& [name, sensor] : nvml_sensors_) { + // auto val = sensor.sample_data(); + // TracyPlot(name.data(), val.power()); + // } + // for (auto& [name, sensor] : msr_sensors_) { + // auto val = sensor.sample_data(); + // TracyPlot(name.data(), val.power()); + // } + //#endif } void Power_Service::setup_measurement() {