Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for topic statistics on breadcrumb deployments #532

Merged
merged 6 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions src/systems/breadcrumbs/Breadcrumbs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,32 @@ void Breadcrumbs::Configure(const Entity &_entity,
}

// Subscribe to commands
std::string topic{"/model/" + this->model.Name(_ecm) + "/breadcrumbs/" +
this->modelRoot.ModelByIndex(0)->Name() + "/deploy"};
this->topic = "/model/" + this->model.Name(_ecm) + "/breadcrumbs/" +
this->modelRoot.ModelByIndex(0)->Name() + "/deploy";

if (_sdf->HasElement("topic"))
topic = _sdf->Get<std::string>("topic");
this->topic = _sdf->Get<std::string>("topic");

this->node.Subscribe(topic, &Breadcrumbs::OnDeploy, this);
this->remainingPub = this->node.Advertise<msgs::Int32>(topic + "/remaining");
this->topicStatistics = _sdf->Get<bool>("topic_statistics",
this->topicStatistics).first;

ignmsg << "Breadcrumbs subscribing to deploy messages on [" << topic << "]"
<< std::endl;
// Enable topic statistics when requested.
if (this->topicStatistics)
{
if (!node.EnableStats(this->topic, true))
{
ignerr << "Unable to enable topic statistics on topic["
<< this->topic << "]." << std::endl;
this->topicStatistics = false;
}
}

this->node.Subscribe(this->topic, &Breadcrumbs::OnDeploy, this);
this->remainingPub = this->node.Advertise<msgs::Int32>(
this->topic + "/remaining");

ignmsg << "Breadcrumbs subscribing to deploy messages on ["
<< this->topic << "]" << std::endl;

this->creator = std::make_unique<SdfEntityCreator>(_ecm, _eventMgr);

Expand Down Expand Up @@ -385,6 +400,30 @@ void Breadcrumbs::OnDeploy(const msgs::Empty &)
IGN_PROFILE("Breadcrumbs::PreUpdate");
{
std::lock_guard<std::mutex> lock(this->pendingCmdsMutex);

// Check topic statistics for dropped messages
if (this->topicStatistics)
{
ignmsg << "Received breadcrumb deployment for " <<
this->modelRoot.ModelByIndex(0)->Name() << std::endl;
std::optional<transport::TopicStatistics> stats =
this->node.TopicStats(this->topic);
if (stats)
{
if (stats->DroppedMsgCount() > 0)
{
ignwarn << "Dropped message count of " << stats->DroppedMsgCount()
<< " for breadcrumbs on model "
<< this->modelRoot.ModelByIndex(0)->Name() << std::endl;
}
}
else
{
ignerr << "Unable to get topic statistics for topic["
<< this->topic << "]." << std::endl;
}
}

this->pendingCmds.push_back(true);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/systems/breadcrumbs/Breadcrumbs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ namespace systems
/// Defaults to false.
/// `<breadcrumb>`: This is the model used as a template for deploying
/// breadcrumbs.
/// `<topic_statistics>`: If true, then topic statistics are enabled on
/// `<topic>` and error messages will be generated when messages are
/// dropped. Default to false.
class IGNITION_GAZEBO_VISIBLE Breadcrumbs
: public System,
public ISystemConfigure,
Expand Down Expand Up @@ -163,6 +166,12 @@ namespace systems

/// \brief Publishes remaining deployments.
public: transport::Node::Publisher remainingPub;

/// \brief True when topic statistics are enabled.
public: bool topicStatistics{false};

/// \brief Name of the deploy topic.
public: std::string topic;
};
}
}
Expand Down