Skip to content

Commit

Permalink
[mc_control] Correctly log plugin performances
Browse files Browse the repository at this point in the history
- Setup the plugin performance log after all plugins have been loaded
- Avoid dangling references across resets by forcing the log entry to be
  re-added
  • Loading branch information
gergondet committed Aug 2, 2023
1 parent b13fe4c commit b826581
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
1 change: 1 addition & 0 deletions include/mc_control/mc_global_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,7 @@ struct MC_CONTROL_DLLAPI MCGlobalController

void start_log();
void setup_log();
void setup_plugin_log();
std::map<std::string, bool> setup_logger_ = {};

/** Timers and performance measure */
Expand Down
49 changes: 27 additions & 22 deletions src/mc_control/mc_global_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ bool MCGlobalController::run()
next_controller_->reset({controller_->robot().mbc().q});
next_controller_->resetObserverPipelines();
controller_ = next_controller_;
/** Reset plugins */
/** Reset global plugins */
for(auto & plugin : plugins_) { plugin.plugin->reset(*this); }
resetControllerPlugins();
}
Expand Down Expand Up @@ -1034,27 +1034,6 @@ void MCGlobalController::setup_log()
controller->logger().addLogEntry("perf_Log", [this]() { return log_dt.count(); });
controller->logger().addLogEntry("perf_Gui", [this]() { return gui_dt.count(); });
controller->logger().addLogEntry("perf_FrameworkCost", [this]() { return framework_cost; });
auto getPluginName = [this](GlobalPlugin * plugin) -> const std::string &
{
for(auto & p : plugins_)
{
if(p.plugin.get() == plugin) { return p.name; }
}
mc_rtc::log::error_and_throw(
"Impossible error, searched for a plugin name from a pointer to a plugin that was not loaded");
};
for(const auto & plugin : plugins_before_)
{
const auto & name = getPluginName(plugin.plugin);
controller->logger().addLogEntry(fmt::format("perf_Plugins_{}_before", name),
[&plugin]() { return plugin.plugin_before_dt.count(); });
}
for(const auto & plugin : plugins_after_)
{
const auto & name = getPluginName(plugin.plugin);
controller->logger().addLogEntry(fmt::format("perf_Plugins_{}_after", name),
[&plugin]() { return plugin.plugin_after_dt.count(); });
}
// Log system wall time as nanoseconds since epoch (can be used to manage synchronization with ros)
controller->logger().addLogEntry("timeWall",
[]() -> int64_t
Expand Down Expand Up @@ -1145,6 +1124,32 @@ void MCGlobalController::resetControllerPlugins()
auto plugin = loadPlugin(name, next_ctrl.c_str());
if(plugin) { plugin->init(*this, config.global_plugin_configs[name]); }
}
setup_plugin_log();
}

void MCGlobalController::setup_plugin_log()
{
auto getPluginName = [this](GlobalPlugin * plugin) -> const std::string &
{
for(auto & p : plugins_)
{
if(p.plugin.get() == plugin) { return p.name; }
}
mc_rtc::log::error_and_throw(
"Impossible error, searched for a plugin name from a pointer to a plugin that was not loaded");
};
for(const auto & plugin : plugins_before_)
{
const auto & name = getPluginName(plugin.plugin);
controller_->logger().addLogEntry(
fmt::format("perf_Plugins_{}_before", name), [&plugin]() { return plugin.plugin_before_dt.count(); }, true);
}
for(const auto & plugin : plugins_after_)
{
const auto & name = getPluginName(plugin.plugin);
controller_->logger().addLogEntry(
fmt::format("perf_Plugins_{}_after", name), [&plugin]() { return plugin.plugin_after_dt.count(); }, true);
}
}

} // namespace mc_control

0 comments on commit b826581

Please sign in to comment.