From 15f924457717aea6f804ff2ceb13d790437c4276 Mon Sep 17 00:00:00 2001 From: Damon Kohler Date: Wed, 26 Oct 2016 15:23:37 +0200 Subject: [PATCH] Removes sensor packet period histogram. (#104) --- cartographer/common/histogram.cc | 32 ------- cartographer/common/histogram.h | 9 -- cartographer/sensor/CMakeLists.txt | 12 --- cartographer/sensor/collator.h | 5 -- .../sensor_packet_period_histogram_builder.cc | 84 ------------------- .../sensor_packet_period_histogram_builder.h | 45 ---------- 6 files changed, 187 deletions(-) delete mode 100644 cartographer/sensor/sensor_packet_period_histogram_builder.cc delete mode 100644 cartographer/sensor/sensor_packet_period_histogram_builder.h diff --git a/cartographer/common/histogram.cc b/cartographer/common/histogram.cc index 2dbb286319..56c42873f1 100644 --- a/cartographer/common/histogram.cc +++ b/cartographer/common/histogram.cc @@ -26,38 +26,6 @@ namespace cartographer { namespace common { -namespace { - -string PaddedTo(string input, int new_length) { - CHECK_GE(new_length, input.size()); - input.insert(input.begin(), new_length - input.size(), ' '); - return input; -} - -} // namespace - -void BucketHistogram::Hit(const string& bucket) { ++buckets_[bucket]; } - -string BucketHistogram::ToString() const { - int64 sum = 0; - size_t max_bucket_name_length = 0; - for (const auto& pair : buckets_) { - sum += pair.second; - max_bucket_name_length = - std::max(pair.first.size(), max_bucket_name_length); - } - - string result; - for (const auto& pair : buckets_) { - const float percent = 100.f * pair.second / std::max(1, sum); - result += PaddedTo(pair.first, max_bucket_name_length) + ": " + - PaddedTo(std::to_string(pair.second), 7) + " (" + - std::to_string(percent) + " %)\n"; - } - result += "Total: " + std::to_string(sum); - return result; -} - void Histogram::Add(const float value) { values_.push_back(value); } string Histogram::ToString(const int buckets) const { diff --git a/cartographer/common/histogram.h b/cartographer/common/histogram.h index ec49a4ebc8..4b49141116 100644 --- a/cartographer/common/histogram.h +++ b/cartographer/common/histogram.h @@ -26,15 +26,6 @@ namespace cartographer { namespace common { -class BucketHistogram { - public: - void Hit(const string& bucket); - string ToString() const; - - private: - std::map buckets_; -}; - class Histogram { public: void Add(float value); diff --git a/cartographer/sensor/CMakeLists.txt b/cartographer/sensor/CMakeLists.txt index 6a863d4806..9320efacdb 100644 --- a/cartographer/sensor/CMakeLists.txt +++ b/cartographer/sensor/CMakeLists.txt @@ -24,7 +24,6 @@ google_library(sensor_collator common_time sensor_data sensor_ordered_multi_queue - sensor_sensor_packet_period_histogram_builder ) google_library(sensor_compressed_point_cloud @@ -103,17 +102,6 @@ google_library(sensor_point_cloud transform_transform ) -google_library(sensor_sensor_packet_period_histogram_builder - USES_GLOG - SRCS - sensor_packet_period_histogram_builder.cc - HDRS - sensor_packet_period_histogram_builder.h - DEPENDS - common_histogram - common_port -) - google_library(sensor_voxel_filter SRCS voxel_filter.cc diff --git a/cartographer/sensor/collator.h b/cartographer/sensor/collator.h index 96ac2d6eae..54ffdead73 100644 --- a/cartographer/sensor/collator.h +++ b/cartographer/sensor/collator.h @@ -29,7 +29,6 @@ #include "cartographer/common/time.h" #include "cartographer/sensor/data.h" #include "cartographer/sensor/ordered_multi_queue.h" -#include "cartographer/sensor/sensor_packet_period_histogram_builder.h" #include "glog/logging.h" namespace cartographer { @@ -71,8 +70,6 @@ class Collator { // order. void AddSensorData(const int trajectory_id, const string& sensor_id, std::unique_ptr data) { - sensor_packet_period_histogram_builder_.Add( - trajectory_id, common::ToUniversal(data->time), sensor_id); queue_.Add(QueueKey{trajectory_id, sensor_id}, std::move(data)); } @@ -80,7 +77,6 @@ class Collator { // AddSensorData may not be called after Flush. void Flush() { queue_.Flush(); - sensor_packet_period_histogram_builder_.LogHistogramsAndClear(); } // Returns the number of packets associated with 'trajectory_id' that are @@ -99,7 +95,6 @@ class Collator { // Map of trajectory ID to all associated QueueKeys. std::unordered_map> queue_keys_; - SensorPacketPeriodHistogramBuilder sensor_packet_period_histogram_builder_; }; } // namespace sensor diff --git a/cartographer/sensor/sensor_packet_period_histogram_builder.cc b/cartographer/sensor/sensor_packet_period_histogram_builder.cc deleted file mode 100644 index 38f9979293..0000000000 --- a/cartographer/sensor/sensor_packet_period_histogram_builder.cc +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2016 The Cartographer Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "cartographer/sensor/sensor_packet_period_histogram_builder.h" - -#include "glog/logging.h" - -namespace cartographer { -namespace sensor { -namespace { - -string ToBucket(int ticks) { - if (ticks < 1 * 10000) { - return "< 1ms"; - } else if (ticks < 3 * 10000) { - return "< 3ms"; - } else if (ticks < 5 * 10000) { - return "< 5ms"; - } else if (ticks < 7 * 10000) { - return "< 7ms"; - } else if (ticks < 10 * 10000) { - return "< 10ms"; - } else if (ticks < 30 * 10000) { - return "< 30ms"; - } else if (ticks < 100 * 10000) { - return "< 100ms"; - } else if (ticks < 500 * 10000) { - return "< 500ms"; - } - return "> 500ms"; -} - -} // namespace - -void SensorPacketPeriodHistogramBuilder::Add(const int trajectory_id, - const int64 timestamp, - const string& frame_id) { - if (histograms_.count(trajectory_id) == 0) { - histograms_.emplace(trajectory_id, - std::unordered_map()); - } - if (histograms_.at(trajectory_id).count(frame_id) == 0) { - histograms_.at(trajectory_id).emplace(frame_id, common::BucketHistogram()); - } - const Key key = std::make_pair(trajectory_id, frame_id); - if (last_timestamps_.count(key) != 0) { - const int64 previous_timestamp = last_timestamps_.at(key); - histograms_.at(trajectory_id) - .at(frame_id) - .Hit(ToBucket(timestamp - previous_timestamp)); - } - last_timestamps_[key] = timestamp; -} - -void SensorPacketPeriodHistogramBuilder::LogHistogramsAndClear() { - for (const auto& trajectory_map_entry : histograms_) { - LOG(INFO) << "Printing histograms for trajectory with id " - << trajectory_map_entry.first; - for (const auto& frame_id_to_histogram_map : trajectory_map_entry.second) { - LOG(INFO) << "Sensor packet period histogram for '" - << frame_id_to_histogram_map.first << "' from trajectory '" - << trajectory_map_entry.first << "':\n" - << frame_id_to_histogram_map.second.ToString(); - } - } - histograms_.clear(); - last_timestamps_.clear(); -} - -} // namespace sensor -} // namespace cartographer diff --git a/cartographer/sensor/sensor_packet_period_histogram_builder.h b/cartographer/sensor/sensor_packet_period_histogram_builder.h deleted file mode 100644 index b51ff1abf5..0000000000 --- a/cartographer/sensor/sensor_packet_period_histogram_builder.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2016 The Cartographer Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CARTOGRAPHER_SENSOR_SENSOR_PACKET_PERIOD_HISTOGRAM_BUILDER_H_ -#define CARTOGRAPHER_SENSOR_SENSOR_PACKET_PERIOD_HISTOGRAM_BUILDER_H_ - -#include -#include - -#include "cartographer/common/histogram.h" -#include "cartographer/common/port.h" - -namespace cartographer { -namespace sensor { - -class SensorPacketPeriodHistogramBuilder { - public: - void Add(int trajectory_id, int64 timestamp, const string& frame_id); - void LogHistogramsAndClear(); - - private: - using Key = std::pair; - - std::map last_timestamps_; - std::unordered_map> - histograms_; -}; - -} // namespace sensor -} // namespace cartographer - -#endif // CARTOGRAPHER_SENSOR_SENSOR_PACKET_PERIOD_HISTOGRAM_BUILDER_H_