profiler_msg_adapter.cpp
Go to the documentation of this file.
3 
4 namespace swri_profiler_tools
5 {
7 {
8 }
9 
11 {
12 }
13 
14 void ProfilerMsgAdapter::processIndex(const swri_profiler_msgs::ProfileIndexArray &msg)
15 {
16  const QString ros_node_name =
17  normalizeNodePath(QString::fromStdString(msg.header.frame_id));
18 
19  // An index message contains the entire index table for the message,
20  // so we wipe out any existing index to make sure we are completely
21  // in sync.
22  index_[ros_node_name].clear();
23 
24  for (auto const &item : msg.data) {
25  QString label = normalizeNodePath(QString::fromStdString(item.label));
26 
27  // This is a special case to handle nodelets nicely, and it works
28  // when users design their labels intelligently by wrapping each
29  // ROS callback with a SWRI_PROFILE(getName()). If the
30  // nodelet is run as part of a nodelet manager, the node name and
31  // nodelet name will differ and we want to append the node name to
32  // allow us to guage the relative runtimes of all the instrumented
33  // nodelets in that manager. If the nodelet is run standalone,
34  // then the nodelet name and node name will be the same and we
35  // don't need to duplicate it.
36  if (!label.startsWith(ros_node_name)) {
37  label = ros_node_name + label;
38  }
39 
40 
41  index_[ros_node_name][item.key] = label;
42  }
43 }
44 
46  NewProfileDataVector &out_data,
47  const swri_profiler_msgs::ProfileDataArray &msg)
48 {
49  const QString node_name(QString::fromStdString(msg.header.frame_id));
50 
51  if (index_.count(node_name) == 0) {
52  qWarning("No index for node '%s'. Dropping data update.", qPrintable(node_name));
53  return false;
54  }
55 
56  int timestamp_sec = std::round(msg.header.stamp.toSec());
57 
59  out.reserve(msg.data.size());
60  for (auto const &item : msg.data) {
61  if (index_[node_name].count(item.key) == 0) {
62  qWarning("No index for block %d of %s. Dropping all data "
63  "because index is probably invalid.",
64  item.key, qPrintable(node_name));
65  return false;
66  }
67 
68  out.emplace_back();
69  out.back().label = index_[node_name][item.key];
70  out.back().wall_stamp_sec = timestamp_sec;
71  out.back().ros_stamp_ns = msg.rostime_stamp.toNSec();
72  out.back().cumulative_call_count = item.abs_call_count;
73  out.back().cumulative_inclusive_duration_ns = item.abs_total_duration.toNSec();
74  out.back().incremental_inclusive_duration_ns = item.rel_total_duration.toNSec();
75  out.back().incremental_max_duration_ns = item.rel_max_duration.toNSec();
76  }
77 
78  out_data.insert(out_data.end(), out.begin(), out.end());
79  return true;
80 }
81 
83 {
84  index_.clear();
85 }
86 }; // namespace swri_profiler_tools
std::map< QString, std::map< int, QString > > index_
void processIndex(const swri_profiler_msgs::ProfileIndexArray &msg)
QString normalizeNodePath(const QString &path)
Definition: util.cpp:35
std::vector< NewProfileData > NewProfileDataVector
bool processData(NewProfileDataVector &out_data, const swri_profiler_msgs::ProfileDataArray &msg)


swri_profiler_tools
Author(s):
autogenerated on Fri Nov 27 2020 03:44:18