Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Create libstatistics_collector package #117

Merged
merged 17 commits into from Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
96 changes: 96 additions & 0 deletions statistics_collector_lib/CMakeLists.txt
@@ -0,0 +1,96 @@
cmake_minimum_required(VERSION 3.5)
project(statistics_collector_lib)
mm318 marked this conversation as resolved.
Show resolved Hide resolved

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

# Enable strict compiler flags if possible.
include(CheckCXXCompilerFlag)
set(FLAGS -pedantic -Wno-long-long -Wall -Wextra -Wcast-qual -Wformat -Wwrite-strings -Wcast-align
-Wno-error=cast-align -Wmissing-declarations)
foreach(FLAG ${FLAGS})
check_cxx_compiler_flag(${FLAG} R${FLAG})
if(${R${FLAG}})
set(WARNING_CXX_FLAGS "${WARNING_CXX_FLAGS} ${FLAG}")
endif()
endforeach()

if(WIN32)
add_definitions(-DNOMINMAX)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rcl REQUIRED)
find_package(rcpputils REQUIRED)

include_directories(include)

add_library(${PROJECT_NAME} SHARED
src/moving_average_statistics/moving_average.cpp
src/moving_average_statistics/types.cpp
src/collector/collector.cpp
)

ament_target_dependencies(${PROJECT_NAME}
rcl
rcpputils)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
find_package(ament_cmake_gtest REQUIRED)

ament_lint_auto_find_test_dependencies()

ament_add_gtest(test_collector
test/collector/test_collector.cpp)
target_link_libraries(test_collector ${PROJECT_NAME})
ament_target_dependencies(test_collector rcpputils)

ament_add_gtest(test_moving_average_statistics
test/moving_average_statistics/test_moving_average_statistics.cpp)
target_link_libraries(test_moving_average_statistics ${PROJECT_NAME})

dabonnie marked this conversation as resolved.
Show resolved Hide resolved

ament_add_gtest(test_received_message_period
test/topic_statistics_collector/test_received_message_period.cpp)
target_link_libraries(test_received_message_period ${PROJECT_NAME})
ament_target_dependencies(test_received_message_period rcl rcpputils)

ament_add_gtest(test_received_message_age
test/topic_statistics_collector/test_received_message_age.cpp)
target_link_libraries(test_received_message_age ${PROJECT_NAME})
ament_target_dependencies(test_received_message_age rcl rcpputils std_msgs sensor_msgs)
endif()

install(
TARGETS "${PROJECT_NAME}"
EXPORT "${PROJECT_NAME}-targets"
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
Copy link
Member

Choose a reason for hiding this comment

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

isn'it the default?

Copy link
Member

Choose a reason for hiding this comment

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

What about this tested on OS X and Windows? If ROS2 is depending on it, I guess we'll need to make sure it works too there?

Copy link
Member

Choose a reason for hiding this comment

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

Removed ARCHIVE and INCLUDES. Are you saying we should remove the whole thing?

)

install(
DIRECTORY include/
DESTINATION include
)

ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(rcl)
ament_export_dependencies(rcpputils)
mm318 marked this conversation as resolved.
Show resolved Hide resolved

ament_package()

export(TARGETS ${PROJECT_NAME}
FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-targets.cmake")
export(PACKAGE ${PROJECT_NAME})
mm318 marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
mm318 marked this conversation as resolved.
Show resolved Hide resolved
// limitations under the License.

#ifndef SYSTEM_METRICS_COLLECTOR__COLLECTOR_HPP_
#define SYSTEM_METRICS_COLLECTOR__COLLECTOR_HPP_
#ifndef COLLECTOR__COLLECTOR_HPP_
mm318 marked this conversation as resolved.
Show resolved Hide resolved
#define COLLECTOR__COLLECTOR_HPP_

#include <mutex>
#include <string>
Expand All @@ -24,7 +24,7 @@

#include "rcpputils/thread_safety_annotations.hpp"

namespace system_metrics_collector
namespace collector
mm318 marked this conversation as resolved.
Show resolved Hide resolved
{

/**
Expand Down Expand Up @@ -114,6 +114,6 @@ class Collector : public MetricDetailsInterface
bool started_{false} RCPPUTILS_TSA_GUARDED_BY(mutex_);
};

} // namespace system_metrics_collector
} // namespace collector

#endif // SYSTEM_METRICS_COLLECTOR__COLLECTOR_HPP_
#endif // COLLECTOR__COLLECTOR_HPP_
@@ -0,0 +1,49 @@
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// 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 COLLECTOR__METRIC_DETAILS_INTERFACE_HPP_
#define COLLECTOR__METRIC_DETAILS_INTERFACE_HPP_

#include <string>

namespace collector
{
/**
* Interface to represent a single metric's name and unit,
* which are used for metric message generation and publication.
*/

class MetricDetailsInterface
{
public:
virtual ~MetricDetailsInterface() = default;

/**
* Return a single metric's name.
*
* @return a string representing the metric name
*/
virtual std::string GetMetricName() const = 0;

/**
* Return a single metric's measurement unit.
*
* @return a string representing the metric unit
*/
virtual std::string GetMetricUnit() const = 0;
};

} // namespace collector

#endif // COLLECTOR__METRIC_DETAILS_INTERFACE_HPP_
Expand Up @@ -111,7 +111,7 @@ class ReceivedMessageAgeCollector : public TopicStatisticsCollector<T>
const std::chrono::nanoseconds age_nanos{now_nanoseconds - timestamp_from_header.second};
const auto age_millis = std::chrono::duration_cast<std::chrono::milliseconds>(age_nanos);

system_metrics_collector::Collector::AcceptData(static_cast<double>(age_millis.count()));
collector::Collector::AcceptData(static_cast<double>(age_millis.count()));
} // else no valid time to compute age
}
}
Expand Down
Expand Up @@ -21,7 +21,6 @@

#include "constants.hpp"
#include "topic_statistics_collector.hpp"
#include "system_metrics_collector/collector.hpp"

#include "rcl/time.h"

Expand Down Expand Up @@ -69,7 +68,7 @@ class ReceivedMessagePeriodCollector : public TopicStatisticsCollector<T>
const std::chrono::nanoseconds nanos{now_nanoseconds - time_last_message_received_};
const auto period = std::chrono::duration_cast<std::chrono::milliseconds>(nanos);
time_last_message_received_ = now_nanoseconds;
system_metrics_collector::Collector::AcceptData(static_cast<double>(period.count()));
collector::Collector::AcceptData(static_cast<double>(period.count()));
}
}

Expand Down
Expand Up @@ -21,7 +21,7 @@

#include "rcl/time.h"

#include "system_metrics_collector/collector.hpp"
#include "collector/collector.hpp"

namespace topic_statistics_collector
{
Expand All @@ -31,7 +31,7 @@ namespace topic_statistics_collector
* @tparam T the ROS2 message type to collect
*/
template<typename T>
class TopicStatisticsCollector : public system_metrics_collector::Collector
class TopicStatisticsCollector : public collector::Collector
{
public:
TopicStatisticsCollector() = default;
Expand Down
24 changes: 24 additions & 0 deletions statistics_collector_lib/package.xml
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>statistics_collector_lib</name>
<version>0.0.0</version>
<description>Lightweight aggregation utilities to collect statistics and measure message metrics.</description>
<maintainer email="ros-tooling@googlegroups.com">ROS Tooling Working Group</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>rcl</depend>
<depend>rcpputils</depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>sensor_msgs</test_depend>
<test_depend>std_msgs</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "collector.hpp"
#include "collector/collector.hpp"

#include <mutex>
#include <sstream>
Expand All @@ -21,7 +21,7 @@
#include "moving_average_statistics/moving_average.hpp"
#include "moving_average_statistics/types.hpp"

namespace system_metrics_collector
namespace collector
{

bool Collector::Start()
Expand Down Expand Up @@ -79,4 +79,4 @@ std::string Collector::GetStatusString() const
return ss.str();
}

} // namespace system_metrics_collector
} // namespace collector
Expand Up @@ -21,8 +21,8 @@
#include <numeric>
#include <type_traits>

#include "moving_average.hpp"
#include "types.hpp"
#include "moving_average_statistics/moving_average.hpp"
#include "moving_average_statistics/types.hpp"

namespace moving_average_statistics
{
Expand Down
Expand Up @@ -15,7 +15,7 @@
#include <sstream>
#include <string>

#include "types.hpp"
#include "moving_average_statistics/types.hpp"

namespace moving_average_statistics
{
Expand Down
Expand Up @@ -20,7 +20,7 @@

#include "moving_average_statistics/types.hpp"

#include "system_metrics_collector/collector.hpp"
#include "collector/collector.hpp"

namespace
{
Expand All @@ -31,7 +31,7 @@ constexpr const char kTestMetricUnit[] = "test_metric_unit";
/**
* Simple extension to test basic functionality
*/
class TestCollector : public system_metrics_collector::Collector
class TestCollector : public collector::Collector
{
public:
TestCollector() = default;
Expand Down
47 changes: 2 additions & 45 deletions system_metrics_collector/CMakeLists.txt
Expand Up @@ -28,6 +28,7 @@ endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(statistics_collector_lib REQUIRED)
find_package(message_filters REQUIRED)
find_package(metrics_statistics_msgs REQUIRED)
find_package(rcl REQUIRED)
Expand All @@ -42,11 +43,7 @@ find_package(std_msgs REQUIRED)
include_directories(src)

add_library(system_metrics_collector SHARED
src/moving_average_statistics/moving_average.cpp
src/moving_average_statistics/types.cpp
src/moving_average_statistics/types.hpp
src/system_metrics_collector/metrics_message_publisher.cpp
src/system_metrics_collector/collector.cpp
src/system_metrics_collector/linux_cpu_measurement_node.cpp
src/system_metrics_collector/linux_memory_measurement_node.cpp
src/system_metrics_collector/linux_process_cpu_measurement_node.cpp
Expand All @@ -57,6 +54,7 @@ add_library(system_metrics_collector SHARED
src/system_metrics_collector/utilities.cpp
)
ament_target_dependencies(system_metrics_collector
statistics_collector_lib
message_filters
metrics_statistics_msgs
rcl
Expand Down Expand Up @@ -91,11 +89,6 @@ if(BUILD_TESTING)

ament_lint_auto_find_test_dependencies()

ament_add_gtest(test_collector
test/system_metrics_collector/test_collector.cpp)
target_link_libraries(test_collector system_metrics_collector)
ament_target_dependencies(test_collector rclcpp)

ament_add_gtest(test_metrics_message_publisher
test/system_metrics_collector/test_metrics_message_publisher.cpp)
target_link_libraries(test_metrics_message_publisher system_metrics_collector)
Expand All @@ -121,11 +114,6 @@ if(BUILD_TESTING)
target_link_libraries(test_linux_process_memory_measurement_node system_metrics_collector)
ament_target_dependencies(test_linux_process_memory_measurement_node lifecycle_msgs metrics_statistics_msgs rclcpp)

ament_add_gtest(test_moving_average_statistics
test/moving_average_statistics/test_moving_average_statistics.cpp)
target_link_libraries(test_moving_average_statistics system_metrics_collector)
ament_target_dependencies(test_moving_average_statistics rclcpp)

ament_add_gtest(test_periodic_measurement_node
test/system_metrics_collector/test_periodic_measurement_node.cpp)
target_link_libraries(test_periodic_measurement_node system_metrics_collector)
Expand All @@ -139,37 +127,6 @@ if(BUILD_TESTING)
test/system_metrics_collector/test_utilities.cpp)
target_link_libraries(test_utilities system_metrics_collector)
ament_target_dependencies(test_utilities rclcpp)

ament_add_gtest(test_received_message_period
test/topic_statistics_collector/test_received_message_period.cpp)
target_link_libraries(test_received_message_period system_metrics_collector)
ament_target_dependencies(test_received_message_period rcl rclcpp)

ament_add_gtest(test_received_message_age
test/topic_statistics_collector/test_received_message_age.cpp)
target_link_libraries(test_received_message_age system_metrics_collector)
ament_target_dependencies(test_received_message_age rcl rclcpp message_filters std_msgs sensor_msgs)

install(TARGETS
test_moving_average_statistics
DESTINATION
lib/${PROJECT_NAME})
install(TARGETS
test_collector
DESTINATION
lib/${PROJECT_NAME})
install(TARGETS
test_periodic_measurement_node
DESTINATION
lib/${PROJECT_NAME})
install(TARGETS
test_received_message_period
DESTINATION
lib/${PROJECT_NAME})
install(TARGETS
test_received_message_age
DESTINATION
lib/${PROJECT_NAME})
endif()

# Install launch files
Expand Down