Skip to content

Commit 4c8a8db

Browse files
committed
Benchmark example updated
Signed-off-by: Javier Gil Aviles <[email protected]>
1 parent 07638e5 commit 4c8a8db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+5863
-0
lines changed

examples/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
set(fastdds_FOUND TRUE)
1616

17+
add_subdirectory(cpp/benchmark)
1718
add_subdirectory(cpp/configuration)
1819
add_subdirectory(cpp/content_filter)
1920
add_subdirectory(cpp/custom_payload_pool)
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file Application.cpp
17+
*
18+
*/
19+
20+
#include "Application.hpp"
21+
22+
#include "SubscriberApp.hpp"
23+
#include "PublisherApp.hpp"
24+
25+
using namespace eprosima::fastdds::dds;
26+
27+
namespace eprosima {
28+
namespace fastdds {
29+
namespace examples {
30+
namespace benchmark {
31+
32+
//! Factory method to create a publisher or subscriber
33+
std::shared_ptr<Application> Application::make_app(
34+
const CLIParser::benchmark_config& config)
35+
{
36+
std::shared_ptr<Application> entity;
37+
switch (config.entity)
38+
{
39+
case CLIParser::EntityKind::PUBLISHER:
40+
entity = std::make_shared<PublisherApp>(config.pub_config);
41+
break;
42+
case CLIParser::EntityKind::SUBSCRIBER:
43+
entity = std::make_shared<SubscriberApp>(config.sub_config);
44+
break;
45+
case CLIParser::EntityKind::UNDEFINED:
46+
default:
47+
throw std::runtime_error("Entity initialization failed");
48+
break;
49+
}
50+
return entity;
51+
}
52+
53+
} // namespace benchmark
54+
} // namespace examples
55+
} // namespace fastdds
56+
} // namespace eprosima
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2024 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file Application.hpp
17+
*
18+
*/
19+
20+
#ifndef FASTDDS_EXAMPLES_CPP_BENCHMARK__APPLICATION_HPP
21+
#define FASTDDS_EXAMPLES_CPP_BENCHMARK__APPLICATION_HPP
22+
23+
#include <atomic>
24+
25+
#include "CLIParser.hpp"
26+
27+
namespace eprosima {
28+
namespace fastdds {
29+
namespace examples {
30+
namespace benchmark {
31+
32+
class Application
33+
{
34+
public:
35+
36+
//! Virtual destructor
37+
virtual ~Application() = default;
38+
39+
//! Run application
40+
virtual void run() = 0;
41+
42+
//! Trigger the end of execution
43+
virtual void stop() = 0;
44+
45+
//! Factory method to create applications based on configuration
46+
static std::shared_ptr<Application> make_app(
47+
const CLIParser::benchmark_config& config);
48+
};
49+
50+
} // namespace benchmark
51+
} // namespace examples
52+
} // namespace fastdds
53+
} // namespace eprosima
54+
55+
#endif // FASTDDS_EXAMPLES_CPP_BENCHMARK__APPLICATION_HPP

examples/cpp/benchmark/Benchmark.hpp

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/*!
16+
* @file Benchmark.hpp
17+
* This header file contains the declaration of the described types in the IDL file.
18+
*
19+
* This file was generated by the tool fastddsgen.
20+
*/
21+
22+
#ifndef FAST_DDS_GENERATED__BENCHMARK_HPP
23+
#define FAST_DDS_GENERATED__BENCHMARK_HPP
24+
25+
#include <cstdint>
26+
#include <utility>
27+
28+
#if defined(_WIN32)
29+
#if defined(EPROSIMA_USER_DLL_EXPORT)
30+
#define eProsima_user_DllExport __declspec( dllexport )
31+
#else
32+
#define eProsima_user_DllExport
33+
#endif // EPROSIMA_USER_DLL_EXPORT
34+
#else
35+
#define eProsima_user_DllExport
36+
#endif // _WIN32
37+
38+
#if defined(_WIN32)
39+
#if defined(EPROSIMA_USER_DLL_EXPORT)
40+
#if defined(BENCHMARK_SOURCE)
41+
#define BENCHMARK_DllAPI __declspec( dllexport )
42+
#else
43+
#define BENCHMARK_DllAPI __declspec( dllimport )
44+
#endif // BENCHMARK_SOURCE
45+
#else
46+
#define BENCHMARK_DllAPI
47+
#endif // EPROSIMA_USER_DLL_EXPORT
48+
#else
49+
#define BENCHMARK_DllAPI
50+
#endif // _WIN32
51+
52+
/*!
53+
* @brief This class represents the structure BenchMark defined by the user in the IDL file.
54+
* @ingroup Benchmark
55+
*/
56+
class BenchMark
57+
{
58+
public:
59+
60+
/*!
61+
* @brief Default constructor.
62+
*/
63+
eProsima_user_DllExport BenchMark()
64+
{
65+
}
66+
67+
/*!
68+
* @brief Default destructor.
69+
*/
70+
eProsima_user_DllExport ~BenchMark()
71+
{
72+
}
73+
74+
/*!
75+
* @brief Copy constructor.
76+
* @param x Reference to the object BenchMark that will be copied.
77+
*/
78+
eProsima_user_DllExport BenchMark(
79+
const BenchMark& x)
80+
{
81+
m_index = x.m_index;
82+
83+
}
84+
85+
/*!
86+
* @brief Move constructor.
87+
* @param x Reference to the object BenchMark that will be copied.
88+
*/
89+
eProsima_user_DllExport BenchMark(
90+
BenchMark&& x) noexcept
91+
{
92+
m_index = x.m_index;
93+
}
94+
95+
/*!
96+
* @brief Copy assignment.
97+
* @param x Reference to the object BenchMark that will be copied.
98+
*/
99+
eProsima_user_DllExport BenchMark& operator =(
100+
const BenchMark& x)
101+
{
102+
103+
m_index = x.m_index;
104+
105+
return *this;
106+
}
107+
108+
/*!
109+
* @brief Move assignment.
110+
* @param x Reference to the object BenchMark that will be copied.
111+
*/
112+
eProsima_user_DllExport BenchMark& operator =(
113+
BenchMark&& x) noexcept
114+
{
115+
116+
m_index = x.m_index;
117+
return *this;
118+
}
119+
120+
/*!
121+
* @brief Comparison operator.
122+
* @param x BenchMark object to compare.
123+
*/
124+
eProsima_user_DllExport bool operator ==(
125+
const BenchMark& x) const
126+
{
127+
return (m_index == x.m_index);
128+
}
129+
130+
/*!
131+
* @brief Comparison operator.
132+
* @param x BenchMark object to compare.
133+
*/
134+
eProsima_user_DllExport bool operator !=(
135+
const BenchMark& x) const
136+
{
137+
return !(*this == x);
138+
}
139+
140+
/*!
141+
* @brief This function sets a value in member index
142+
* @param _index New value for member index
143+
*/
144+
eProsima_user_DllExport void index(
145+
uint32_t _index)
146+
{
147+
m_index = _index;
148+
}
149+
150+
/*!
151+
* @brief This function returns the value of member index
152+
* @return Value of member index
153+
*/
154+
eProsima_user_DllExport uint32_t index() const
155+
{
156+
return m_index;
157+
}
158+
159+
/*!
160+
* @brief This function returns a reference to member index
161+
* @return Reference to member index
162+
*/
163+
eProsima_user_DllExport uint32_t& index()
164+
{
165+
return m_index;
166+
}
167+
168+
169+
170+
private:
171+
172+
uint32_t m_index{0};
173+
174+
};
175+
176+
#endif // _FAST_DDS_GENERATED_BENCHMARK_HPP_
177+
178+

examples/cpp/benchmark/Benchmark.idl

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@extensibility(APPENDABLE)
2+
struct BenchMark
3+
{
4+
unsigned long index;
5+
};
6+
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/*!
16+
* @file BenchmarkCdrAux.hpp
17+
* This source file contains some definitions of CDR related functions.
18+
*
19+
* This file was generated by the tool fastddsgen.
20+
*/
21+
22+
#ifndef FAST_DDS_GENERATED__BENCHMARKCDRAUX_HPP
23+
#define FAST_DDS_GENERATED__BENCHMARKCDRAUX_HPP
24+
25+
#include "Benchmark.hpp"
26+
27+
constexpr uint32_t BenchMark_max_cdr_typesize {8UL};
28+
constexpr uint32_t BenchMark_max_key_cdr_typesize {0UL};
29+
30+
31+
namespace eprosima {
32+
namespace fastcdr {
33+
34+
class Cdr;
35+
class CdrSizeCalculator;
36+
37+
eProsima_user_DllExport void serialize_key(
38+
eprosima::fastcdr::Cdr& scdr,
39+
const BenchMark& data);
40+
41+
42+
} // namespace fastcdr
43+
} // namespace eprosima
44+
45+
#endif // FAST_DDS_GENERATED__BENCHMARKCDRAUX_HPP
46+

0 commit comments

Comments
 (0)