Skip to content

Commit 4634862

Browse files
committed
Merge #120: Add computation timing
2 parents 8588deb + fa9b177 commit 4634862

File tree

13 files changed

+46
-18
lines changed

13 files changed

+46
-18
lines changed

core/include/moveit/task_constructor/stage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class Stage
210210
inline void setProperty(const std::string& name, const char* value) { setProperty(name, std::string(value)); }
211211
/// analyze source of error and report accordingly
212212
void reportPropertyError(const Property::error& e);
213+
double getTotalComputeTime() const;
213214

214215
protected:
215216
/// Stage can only be instantiated through derived classes

core/include/moveit/task_constructor/stage_p.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <moveit/task_constructor/storage.h>
4343
#include <moveit/task_constructor/cost_queue.h>
4444
#include <ostream>
45+
#include <chrono>
4546

4647
// define pimpl() functions accessing correctly casted pimpl_ pointer
4748
#define PIMPL_FUNCTIONS(Class) \
@@ -131,6 +132,12 @@ class StagePrivate
131132
bool storeSolution(const SolutionBasePtr& solution);
132133
void newSolution(const SolutionBasePtr& solution);
133134
bool storeFailures() const { return introspection_ != nullptr; }
135+
void runCompute() {
136+
auto compute_start_time = std::chrono::steady_clock::now();
137+
compute();
138+
auto compute_stop_time = std::chrono::steady_clock::now();
139+
total_compute_time_ += compute_stop_time - compute_start_time;
140+
}
134141

135142
protected:
136143
Stage* me_; // associated/owning Stage instance
@@ -140,6 +147,9 @@ class StagePrivate
140147
InterfacePtr starts_;
141148
InterfacePtr ends_;
142149

150+
// The total compute time
151+
std::chrono::duration<double> total_compute_time_;
152+
143153
// functions called for each new solution
144154
std::list<Stage::SolutionCallback> solution_cbs_;
145155

@@ -281,5 +291,5 @@ class ConnectingPrivate : public ComputeBasePrivate
281291
ordered<StatePair, StatePairLess> pending;
282292
};
283293
PIMPL_FUNCTIONS(Connecting)
284-
}
285-
}
294+
} // namespace task_constructor
295+
} // namespace moveit

core/src/container.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ void SerialContainer::compute() {
667667
continue;
668668

669669
ROS_DEBUG("Computing stage '%s'", stage->name().c_str());
670-
stage->pimpl()->compute();
670+
stage->pimpl()->runCompute();
671671
} catch (const Property::error& e) {
672672
stage->reportPropertyError(e);
673673
}
@@ -861,7 +861,7 @@ bool WrapperBase::canCompute() const {
861861

862862
void WrapperBase::compute() {
863863
try {
864-
wrapped()->pimpl()->compute();
864+
wrapped()->pimpl()->runCompute();
865865
} catch (const Property::error& e) {
866866
wrapped()->reportPropertyError(e);
867867
}
@@ -877,7 +877,7 @@ bool Alternatives::canCompute() const {
877877
void Alternatives::compute() {
878878
for (const auto& stage : pimpl()->children()) {
879879
try {
880-
stage->pimpl()->compute();
880+
stage->pimpl()->runCompute();
881881
} catch (const Property::error& e) {
882882
stage->reportPropertyError(e);
883883
}
@@ -917,7 +917,7 @@ void Fallbacks::compute() {
917917
return;
918918

919919
try {
920-
active_child_->pimpl()->compute();
920+
active_child_->pimpl()->runCompute();
921921
} catch (const Property::error& e) {
922922
active_child_->reportPropertyError(e);
923923
}
@@ -982,7 +982,7 @@ bool Merger::canCompute() const {
982982
void Merger::compute() {
983983
for (const auto& stage : pimpl()->children()) {
984984
try {
985-
stage->pimpl()->compute();
985+
stage->pimpl()->runCompute();
986986
} catch (const Property::error& e) {
987987
stage->reportPropertyError(e);
988988
}

core/src/introspection.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ void Introspection::fillStageStatistics(const Stage& stage, moveit_task_construc
198198
for (const auto& solution : stage.failures())
199199
s.failed.push_back(solutionId(*solution));
200200

201+
s.total_compute_time = stage.getTotalComputeTime();
201202
s.num_failed = stage.numFailures();
202203
}
203204

core/src/stage.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ std::ostream& operator<<(std::ostream& os, const InitStageException& e) {
6969
}
7070

7171
StagePrivate::StagePrivate(Stage* me, const std::string& name)
72-
: me_(me), name_(name), parent_(nullptr), introspection_(nullptr) {}
72+
: me_(me), name_(name), parent_(nullptr), total_compute_time_{}, introspection_(nullptr) {}
7373

7474
InterfaceFlags StagePrivate::interfaceFlags() const {
7575
InterfaceFlags f;
@@ -298,6 +298,10 @@ void Stage::setProperty(const std::string& name, const boost::any& value) {
298298
pimpl()->properties_.set(name, value);
299299
}
300300

301+
double Stage::getTotalComputeTime() const {
302+
return pimpl()->total_compute_time_.count();
303+
}
304+
301305
void StagePrivate::composePropertyErrorMsg(const std::string& property_name, std::ostream& os) {
302306
if (property_name.empty())
303307
return;

core/src/task.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ bool Task::canCompute() const {
278278
}
279279

280280
void Task::compute() {
281-
stages()->compute();
281+
stages()->pimpl()->runCompute();
282282
}
283283

284284
bool Task::plan(size_t max_solutions) {

msgs/msg/StageStatistics.msg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ uint32[] solved
1010
uint32[] failed
1111
# number of failed solutions (if failed is empty)
1212
uint32 num_failed
13+
# total computation time in seconds
14+
float64 total_compute_time

visualization/motion_planning_tasks/src/remote_task_model.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ QVariant RemoteTaskModel::data(const QModelIndex& index, int role) const {
254254
return n->solutions_->numSuccessful();
255255
case 2:
256256
return n->solutions_->numFailed();
257+
case 3:
258+
return n->solutions_->totalComputeTime();
257259
}
258260
break;
259261
case Qt::ForegroundRole:
@@ -353,7 +355,7 @@ void RemoteTaskModel::processStageStatistics(const moveit_task_constructor_msgs:
353355
continue;
354356
}
355357
Node* n = it->second;
356-
n->solutions_->processSolutionIDs(s.solved, s.failed, s.num_failed);
358+
n->solutions_->processSolutionIDs(s.solved, s.failed, s.num_failed, s.total_compute_time);
357359

358360
// emit notify about model changes when node was already visited
359361
if (n->node_flags_ & WAS_VISITED) {
@@ -622,7 +624,8 @@ void RemoteSolutionModel::sortInternal() {
622624

623625
// process solution ids received in stage statistics
624626
void RemoteSolutionModel::processSolutionIDs(const std::vector<uint32_t>& successful,
625-
const std::vector<uint32_t>& failed, size_t num_failed) {
627+
const std::vector<uint32_t>& failed, size_t num_failed,
628+
double total_compute_time) {
626629
// append new items to the end of data_
627630
processSolutionIDs(successful, true);
628631
processSolutionIDs(failed, false);
@@ -636,6 +639,7 @@ void RemoteSolutionModel::processSolutionIDs(const std::vector<uint32_t>& succes
636639
// but it may report the overall number of failures
637640
num_failed_data_ = failed.size(); // needed to compute number of successes
638641
num_failed_ = std::max(num_failed, num_failed_data_);
642+
total_compute_time_ = total_compute_time;
639643

640644
sortInternal();
641645
}

visualization/motion_planning_tasks/src/remote_task_model.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class RemoteSolutionModel : public QAbstractTableModel
118118
DataList data_;
119119
size_t num_failed_data_ = 0; // number of failed solutions in data_
120120
size_t num_failed_ = 0; // number of reported failures
121+
double total_compute_time_ = 0.0;
121122

122123
// solutions ordered (by default according to cost)
123124
int sort_column_ = -1;
@@ -134,6 +135,7 @@ class RemoteSolutionModel : public QAbstractTableModel
134135

135136
uint numSuccessful() const { return data_.size() - num_failed_data_; }
136137
uint numFailed() const { return num_failed_; }
138+
double totalComputeTime() const { return total_compute_time_; }
137139

138140
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
139141
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
@@ -143,6 +145,6 @@ class RemoteSolutionModel : public QAbstractTableModel
143145

144146
void setSolutionData(uint32_t id, float cost, const QString& comment);
145147
void processSolutionIDs(const std::vector<uint32_t>& successful, const std::vector<uint32_t>& failed,
146-
size_t num_failed);
148+
size_t num_failed, double total_compute_time);
147149
};
148150
}

visualization/motion_planning_tasks/src/task_list_model.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ QVariant TaskListModel::horizontalHeader(int column, int role) {
6565
return tr(u8"");
6666
case 2:
6767
return tr(u8"");
68+
case 3:
69+
return tr("time");
6870
}
6971
break;
7072

@@ -87,6 +89,8 @@ QVariant TaskListModel::horizontalHeader(int column, int role) {
8789
case 2:
8890
return tr("failed solution attempts");
8991
case 3:
92+
return tr("total computation time [s]");
93+
case 4:
9094
return tr("pending");
9195
}
9296
break;

0 commit comments

Comments
 (0)