Skip to content

Commit

Permalink
Add CPU and memory measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
marioney committed Apr 21, 2021
1 parent 586d2e6 commit 3845a92
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions launch/stop_simulation.launch
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
<param name="n_obstacles" value="$(arg obstacles)" type="int"/>
</node>

<node pkg="cob_monitoring" type="cpu_monitor.py" name="cpu_monitoring" output="screen">
</node>



</launch>
4 changes: 4 additions & 0 deletions metacontrol_experiments.rosinstall
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@
local-name: ros_model_parser
uri: https://github.com/ipa320/ros_model_parser.git
version: master
- git:
local-name: cob_command_tools
uri: https://github.com/marioney/cob_command_tools.git
version: metacontrol_models

40 changes: 38 additions & 2 deletions src/stop_simulation_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class LogData
double safety_threshold_;
double average_safety_;
int safety_over_zero_count_;
std::string av_cpu_load_;
std::string memory_used_;

std::string errors_from_reasoner_;

Expand Down Expand Up @@ -275,7 +277,34 @@ void LogData::diagnostics_callback(const diagnostic_msgs::DiagnosticArray::Const
{
diagnostic_msgs::DiagnosticStatus tmp_diagnostic = msg_diagnostics->status[i];

if (tmp_diagnostic.message.compare(0, 2, "QA") == 0 )
if (tmp_diagnostic.name.compare("CPU Usage") == 0 )
{
// ROS_INFO("[LogData :: diagnostics_callback] - Message: %s", tmp_diagnostic.message.c_str());
if (tmp_diagnostic.values.size() > 1)
{
// if (tmp_diagnostic.values[1].key.compare("1 min Load Average") == 0)
// {
av_cpu_load_ = tmp_diagnostic.values[1].value;
// }
}
}
else if (tmp_diagnostic.name.compare("Memory Usage") == 0 )
{
// ROS_INFO("[LogData :: diagnostics_callback] - Message: %s", tmp_diagnostic.message.c_str());
if (tmp_diagnostic.values.size() > 1)
{
if (tmp_diagnostic.values[1].key.compare("Mem Used") == 0)
{
memory_used_ = tmp_diagnostic.values[1].value;
}
}
}
else if (tmp_diagnostic.name.compare(0, 2, "QA") == 0 )
{
// ROS_INFO("[LogData :: diagnostics_callback] - Message: %s", tmp_diagnostic.message.c_str());
updateQA(tmp_diagnostic);
}
else if (tmp_diagnostic.message.compare(0, 2, "QA") == 0 )
{
// ROS_INFO("[LogData :: diagnostics_callback] - Message: %s", tmp_diagnostic.message.c_str());
updateQA(tmp_diagnostic);
Expand All @@ -301,6 +330,7 @@ void LogData::updateQA(const diagnostic_msgs::DiagnosticStatus diagnostic_status
}
}


void LogData::goal_result_callback(const move_base_msgs::MoveBaseActionResult::ConstPtr& msg_goal_result)
{
if(msg_goal_result->status.status == 3)
Expand Down Expand Up @@ -454,6 +484,8 @@ bool LogData::write_log_header()
log_data_file_ << "goal_reached, ";
log_data_file_ << "QA_satisfied, ";
log_data_file_ << "Av_safety_satisfied, ";
log_data_file_ << "Average CPU Usage, ";
log_data_file_ << "Memory Compsumption, ";
log_data_file_ << "reasoner_error_log";
log_data_file_ << "\n";
log_data_file_.close();
Expand Down Expand Up @@ -570,8 +602,12 @@ void LogData::store_info()
// tmp_string = buffer;
// log_data_file_ << tmp_string.c_str();

log_data_file_ << std::string((average_safety_ < 0.5) ? "true," : "false,").c_str();
log_data_file_ << std::string((average_safety_ < 0.6) ? "true," : "false,").c_str();

// Cpu ussage and memory compsumption
tmp_string.clear();
tmp_string = av_cpu_load_ + std::string(", ") + memory_used_ + std::string(", ");
log_data_file_ << tmp_string.c_str();

// Add error logs from reasoner
log_data_file_ << errors_from_reasoner_.c_str();
Expand Down

0 comments on commit 3845a92

Please sign in to comment.