Skip to content

Commit

Permalink
Add conditioning to protect the hardware statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
saikishor committed Jan 18, 2025
1 parent cdb5427 commit 4a67663
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
13 changes: 7 additions & 6 deletions controller_manager/src/controller_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3393,6 +3393,10 @@ void ControllerManager::hardware_components_diagnostic_callback(
const std::string & statistics_type_suffix, auto & diag_level, const auto & comp_info,
const auto & params)
{
if (!statistics)
{
return;
}
const bool is_async = comp_info.is_async;
const std::string periodicity_suffix = ".periodicity";
const std::string exec_time_suffix = ".execution_time";
Expand Down Expand Up @@ -3461,12 +3465,9 @@ void ControllerManager::hardware_components_diagnostic_callback(
component_name, component_info.read_statistics, read_cycle_suffix, level, component_info,
params_);
// For components : {actuator and system}
if (component_info.write_statistics)
{
update_stats(
component_name, component_info.write_statistics, write_cycle_suffix, level,
component_info, params_);
}
update_stats(
component_name, component_info.write_statistics, write_cycle_suffix, level, component_info,
params_);
}
}

Expand Down
26 changes: 16 additions & 10 deletions hardware_interface/src/resource_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1774,11 +1774,14 @@ HardwareReadWriteStatus ResourceManager::read(
ret_val = component.read(current_time, actual_period);
}
}
const auto & read_statistics_collector = component.get_read_statistics();
hardware_component_info.read_statistics->execution_time.update_statistics(
read_statistics_collector.execution_time);
hardware_component_info.read_statistics->periodicity.update_statistics(
read_statistics_collector.periodicity);
if (hardware_component_info.read_statistics)
{
const auto & read_statistics_collector = component.get_read_statistics();
hardware_component_info.read_statistics->execution_time.update_statistics(
read_statistics_collector.execution_time);
hardware_component_info.read_statistics->periodicity.update_statistics(
read_statistics_collector.periodicity);
}
const auto component_group = component.get_group_name();
ret_val =
resource_storage_->update_hardware_component_group_state(component_group, ret_val);
Expand Down Expand Up @@ -1865,11 +1868,14 @@ HardwareReadWriteStatus ResourceManager::write(
ret_val = component.write(current_time, actual_period);
}
}
const auto & write_statistics_collector = component.get_write_statistics();
hardware_component_info.write_statistics->execution_time.update_statistics(
write_statistics_collector.execution_time);
hardware_component_info.write_statistics->periodicity.update_statistics(
write_statistics_collector.periodicity);
if (hardware_component_info.write_statistics)
{
const auto & write_statistics_collector = component.get_write_statistics();
hardware_component_info.write_statistics->execution_time.update_statistics(
write_statistics_collector.execution_time);
hardware_component_info.write_statistics->periodicity.update_statistics(
write_statistics_collector.periodicity);
}
const auto component_group = component.get_group_name();
ret_val =
resource_storage_->update_hardware_component_group_state(component_group, ret_val);
Expand Down

0 comments on commit 4a67663

Please sign in to comment.