Add gauge metric for current number of submap scan matchers. (#1738)

Useful for analyzing memory-related issues.
See: #1737

Signed-off-by: Michael Grupp <grupp@magazino.eu>
master
Michael Grupp 2020-08-25 11:04:59 +02:00 committed by GitHub
parent 98d957ae43
commit 01cb6b1d6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -48,6 +48,7 @@ static auto* kGlobalConstraintsFoundMetric = metrics::Counter::Null();
static auto* kQueueLengthMetric = metrics::Gauge::Null(); static auto* kQueueLengthMetric = metrics::Gauge::Null();
static auto* kConstraintScoresMetric = metrics::Histogram::Null(); static auto* kConstraintScoresMetric = metrics::Histogram::Null();
static auto* kGlobalConstraintScoresMetric = metrics::Histogram::Null(); static auto* kGlobalConstraintScoresMetric = metrics::Histogram::Null();
static auto* kNumSubmapScanMatchersMetric = metrics::Gauge::Null();
transform::Rigid2d ComputeSubmapPose(const Submap2D& submap) { transform::Rigid2d ComputeSubmapPose(const Submap2D& submap) {
return transform::Project2D(submap.local_pose()); return transform::Project2D(submap.local_pose());
@ -163,6 +164,7 @@ ConstraintBuilder2D::DispatchScanMatcherConstruction(const SubmapId& submap_id,
return &submap_scan_matchers_.at(submap_id); return &submap_scan_matchers_.at(submap_id);
} }
auto& submap_scan_matcher = submap_scan_matchers_[submap_id]; auto& submap_scan_matcher = submap_scan_matchers_[submap_id];
kNumSubmapScanMatchersMetric->Set(submap_scan_matchers_.size());
submap_scan_matcher.grid = grid; submap_scan_matcher.grid = grid;
auto& scan_matcher_options = options_.fast_correlative_scan_matcher_options(); auto& scan_matcher_options = options_.fast_correlative_scan_matcher_options();
auto scan_matcher_task = absl::make_unique<common::Task>(); auto scan_matcher_task = absl::make_unique<common::Task>();
@ -303,6 +305,7 @@ void ConstraintBuilder2D::DeleteScanMatcher(const SubmapId& submap_id) {
<< "DeleteScanMatcher was called while WhenDone was scheduled."; << "DeleteScanMatcher was called while WhenDone was scheduled.";
} }
submap_scan_matchers_.erase(submap_id); submap_scan_matchers_.erase(submap_id);
kNumSubmapScanMatchersMetric->Set(submap_scan_matchers_.size());
} }
void ConstraintBuilder2D::RegisterMetrics(metrics::FamilyFactory* factory) { void ConstraintBuilder2D::RegisterMetrics(metrics::FamilyFactory* factory) {
@ -326,6 +329,10 @@ void ConstraintBuilder2D::RegisterMetrics(metrics::FamilyFactory* factory) {
"Constraint scores built", boundaries); "Constraint scores built", boundaries);
kConstraintScoresMetric = scores->Add({{"search_region", "local"}}); kConstraintScoresMetric = scores->Add({{"search_region", "local"}});
kGlobalConstraintScoresMetric = scores->Add({{"search_region", "global"}}); kGlobalConstraintScoresMetric = scores->Add({{"search_region", "global"}});
auto* num_matchers = factory->NewGaugeFamily(
"mapping_constraints_constraint_builder_2d_num_submap_scan_matchers",
"Current number of constructed submap scan matchers");
kNumSubmapScanMatchersMetric = num_matchers->Add({});
} }
} // namespace constraints } // namespace constraints

View File

@ -54,6 +54,7 @@ static auto* kGlobalConstraintRotationalScoresMetric =
metrics::Histogram::Null(); metrics::Histogram::Null();
static auto* kGlobalConstraintLowResolutionScoresMetric = static auto* kGlobalConstraintLowResolutionScoresMetric =
metrics::Histogram::Null(); metrics::Histogram::Null();
static auto* kNumSubmapScanMatchersMetric = metrics::Gauge::Null();
ConstraintBuilder3D::ConstraintBuilder3D( ConstraintBuilder3D::ConstraintBuilder3D(
const proto::ConstraintBuilderOptions& options, const proto::ConstraintBuilderOptions& options,
@ -167,6 +168,7 @@ ConstraintBuilder3D::DispatchScanMatcherConstruction(const SubmapId& submap_id,
return &submap_scan_matchers_.at(submap_id); return &submap_scan_matchers_.at(submap_id);
} }
auto& submap_scan_matcher = submap_scan_matchers_[submap_id]; auto& submap_scan_matcher = submap_scan_matchers_[submap_id];
kNumSubmapScanMatchersMetric->Set(submap_scan_matchers_.size());
submap_scan_matcher.high_resolution_hybrid_grid = submap_scan_matcher.high_resolution_hybrid_grid =
&submap->high_resolution_hybrid_grid(); &submap->high_resolution_hybrid_grid();
submap_scan_matcher.low_resolution_hybrid_grid = submap_scan_matcher.low_resolution_hybrid_grid =
@ -334,6 +336,7 @@ void ConstraintBuilder3D::DeleteScanMatcher(const SubmapId& submap_id) {
<< "DeleteScanMatcher was called while WhenDone was scheduled."; << "DeleteScanMatcher was called while WhenDone was scheduled.";
} }
submap_scan_matchers_.erase(submap_id); submap_scan_matchers_.erase(submap_id);
kNumSubmapScanMatchersMetric->Set(submap_scan_matchers_.size());
} }
void ConstraintBuilder3D::RegisterMetrics(metrics::FamilyFactory* factory) { void ConstraintBuilder3D::RegisterMetrics(metrics::FamilyFactory* factory) {
@ -367,6 +370,10 @@ void ConstraintBuilder3D::RegisterMetrics(metrics::FamilyFactory* factory) {
scores->Add({{"search_region", "global"}, {"kind", "rotational_score"}}); scores->Add({{"search_region", "global"}, {"kind", "rotational_score"}});
kGlobalConstraintLowResolutionScoresMetric = scores->Add( kGlobalConstraintLowResolutionScoresMetric = scores->Add(
{{"search_region", "global"}, {"kind", "low_resolution_score"}}); {{"search_region", "global"}, {"kind", "low_resolution_score"}});
auto* num_matchers = factory->NewGaugeFamily(
"mapping_constraints_constraint_builder_3d_num_submap_scan_matchers",
"Current number of constructed submap scan matchers");
kNumSubmapScanMatchersMetric = num_matchers->Add({});
} }
} // namespace constraints } // namespace constraints