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 3 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
112 changes: 112 additions & 0 deletions libcollector/CMakeLists.txt
@@ -0,0 +1,112 @@
cmake_minimum_required(VERSION 3.5)
project(libcollector)

# 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(libcollector SHARED
src/moving_average_statistics/moving_average.cpp
src/moving_average_statistics/types.cpp
src/collector/collector.cpp
)

ament_target_dependencies(libcollector
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 libcollector)
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 libcollector)


ament_add_gtest(test_received_message_period
test/topic_statistics_collector/test_received_message_period.cpp)
target_link_libraries(test_received_message_period libcollector)
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 libcollector)
ament_target_dependencies(test_received_message_age rcl rcpputils 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_received_message_period
DESTINATION
lib/${PROJECT_NAME})
install(TARGETS
test_received_message_age
DESTINATION
lib/${PROJECT_NAME})
endif()

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

install(
DIRECTORY include/
DESTINATION include
)

ament_export_include_directories(include)
ament_export_libraries(${PROJECT_NAME})
ament_export_dependencies(rcpputils)

ament_package()

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

#ifndef SYSTEM_METRICS_COLLECTOR__COLLECTOR_HPP_
#define SYSTEM_METRICS_COLLECTOR__COLLECTOR_HPP_
#ifndef COLLECTOR__COLLECTOR_HPP_
#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
{

/**
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_
49 changes: 49 additions & 0 deletions libcollector/include/collector/metric_details_interface.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 libcollector/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>libcollector</name>
<version>0.0.0</version>
<description>Aggregation utilities to measure and publish metrics.</description>
dabonnie marked this conversation as resolved.
Show resolved Hide resolved
<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