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

Remove string allocation in the count of subscribers and publishers #167

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Changes from all commits
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
56 changes: 12 additions & 44 deletions rmw_fastrtps_cpp/src/rmw_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,21 @@ rmw_count_publishers(

CustomParticipantInfo * impl = static_cast<CustomParticipantInfo *>(node->data);

std::map<std::string, std::vector<std::string>> unfiltered_topics;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to set *count to 0 here (like you do in rmw_count_subscribers), no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll fix this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Updated

WriterInfo * slave_target = impl->secondaryPubListener;
slave_target->mapmutex.lock();
*count = 0;
for (auto it : slave_target->topicNtypes) {
for (auto & itt : it.second) {
// truncate the ROS specific prefix
auto topic_fqdn = _demangle_if_ros_topic(it.first);
unfiltered_topics[topic_fqdn].push_back(itt);
auto topic_fqdn = _demangle_if_ros_topic(it.first);
if (topic_fqdn == topic_name) {
*count += it.second.size();
}
}
slave_target->mapmutex.unlock();

// get count
auto it = unfiltered_topics.find(topic_name);
if (it == unfiltered_topics.end()) {
*count = 0;
} else {
*count = it->second.size();
}

RCUTILS_LOG_DEBUG_NAMED(
"rmw_fastrtps_cpp",
"looking for subscriber topic: %s", topic_name)
for (auto it : unfiltered_topics) {
RCUTILS_LOG_DEBUG_NAMED(
"rmw_fastrtps_cpp",
"available topic: %s", it.first.c_str())
}
RCUTILS_LOG_DEBUG_NAMED(
"rmw_fastrtps_cpp",
"number of matches: %zu", *count)
"looking for subscriber topic: %s, number of matches: %zu",
topic_name, *count)

return RMW_RET_OK;
}
Expand All @@ -103,37 +87,21 @@ rmw_count_subscribers(

CustomParticipantInfo * impl = static_cast<CustomParticipantInfo *>(node->data);

std::map<std::string, std::vector<std::string>> unfiltered_topics;
ReaderInfo * slave_target = impl->secondarySubListener;
*count = 0;
slave_target->mapmutex.lock();
for (auto it : slave_target->topicNtypes) {
for (auto & itt : it.second) {
// truncate the ROS specific prefix
auto topic_fqdn = _demangle_if_ros_topic(it.first);
unfiltered_topics[topic_fqdn].push_back(itt);
auto topic_fqdn = _demangle_if_ros_topic(it.first);
if (topic_fqdn == topic_name) {
*count += it.second.size();
}
}
slave_target->mapmutex.unlock();

// get_count
auto it = unfiltered_topics.find(topic_name);
if (it == unfiltered_topics.end()) {
*count = 0;
} else {
*count = it->second.size();
}

RCUTILS_LOG_DEBUG_NAMED(
"rmw_fastrtps_cpp",
"looking for subscriber topic: %s", topic_name)
for (auto it : unfiltered_topics) {
RCUTILS_LOG_DEBUG_NAMED(
"rmw_fastrtps_cpp",
"available topic: %s", it.first.c_str())
}
RCUTILS_LOG_DEBUG_NAMED(
"rmw_fastrtps_cpp",
"number of matches: %zu", *count)
"looking for subscriber topic: %s, number of matches: %zu",
topic_name, *count)

return RMW_RET_OK;
}
Expand Down