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 751dc7e
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions frontend/services/power_service/Power_Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -122,7 +130,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 +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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 751dc7e

Please sign in to comment.