Skip to content

Commit

Permalink
wip async interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gralkapk committed Jul 14, 2023
1 parent 7c5d88d commit 22f3620
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions frontend/services/power_service/Power_Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#ifdef MEGAMOL_USE_POWER

#include <codecvt>
#include <fstream>
#include <numeric>
#include <regex>
Expand Down Expand Up @@ -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<std::codecvt_utf8_utf16<wchar_t>, wchar_t>{}.to_bytes(std::wstring(name));
return no_mueller;
}

static int measure_time_in_ms = 50;
static int sample_count = 50000;

Expand Down Expand Up @@ -122,7 +129,7 @@ bool Power_Service::init(void* configPtr) {
//setup_measurement();

auto sensor_count = nvml_sensor::for_all(nullptr, 0);
std::vector<nvml_sensor> tmp_sensors(sensor_count);
std::vector<visus::power_overwhelming::nvml_sensor> tmp_sensors(sensor_count);
nvml_sensor::for_all(tmp_sensors.data(), tmp_sensors.size());

sensor_count = msr_sensor::for_all(nullptr, 0);
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 22f3620

Please sign in to comment.