From 751dc7e9a696a0c8c18fc56a2ad2a59116e91cd1 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 | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/frontend/services/power_service/Power_Service.cpp b/frontend/services/power_service/Power_Service.cpp index 3dacc74e2d..121a4c2190 100644 --- a/frontend/services/power_service/Power_Service.cpp +++ b/frontend/services/power_service/Power_Service.cpp @@ -57,6 +57,14 @@ 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) { + char* sensor_name = new char[wcslen(name) + 1]; + wcstombs(sensor_name, name, wcslen(name) + 1); + std::string no_mueller(sensor_name); + delete[] sensor_name; + return no_mueller; +} + static int measure_time_in_ms = 50; static int sample_count = 50000; @@ -122,7 +130,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 +144,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 +158,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 +283,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() {