LogSpamTest.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXCore::ArmarXObjects::LogSpamTest
17 * @date 2026
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <atomic>
25#include <random>
26#include <string>
27#include <vector>
28
31
32namespace armarx
33{
34 /**
35 * @class LogSpamTestPropertyDefinitions
36 * @brief Properties of the LogSpamTest component.
37 */
43
44 /**
45 * @defgroup Component-LogSpamTest LogSpamTest
46 * @ingroup ArmarXCore-Components
47 *
48 * Emits log messages at a configurable rate, severity mix and shape, to put the
49 * logging path (LogSender -> IceStorm "Log" topic -> LogViewer GUI) under a
50 * reproducible load.
51 *
52 * Every message is unique: the text is assembled from random words plus a per-thread
53 * counter and a random id. That matters because the viewer deduplicates nothing and
54 * because identical lines would not exercise its per-entry work realistically.
55 *
56 * The knobs are chosen to reach the parts of the path that actually cost something:
57 *
58 * - @c WarningPercent / @c ErrorPercent -- messages at WARN and above carry a full
59 * backtrace (see LogSender::log), which dominates both payload size and sender cost.
60 * - @c MultilinePercent -- multi-line messages are what give the viewer's table rows
61 * individual heights.
62 * - @c TagCount -- spreads messages over several tags.
63 * - @c ThreadCount -- concurrent senders, so the global console mutex in LogSender is
64 * contended as it is in a real component.
65 * - @c BurstEveryMs / @c BurstSize -- periodic bursts on top of the steady rate, to
66 * exercise the viewer's staging queue rather than only its steady-state throughput.
67 *
68 * The component name shown in the viewer is the *application* name, so a scenario runs
69 * several instances of this app to produce several distinct log sources.
70 *
71 * @class LogSpamTest
72 * @ingroup Component-LogSpamTest
73 * @brief Generates configurable log load for testing the logging path.
74 */
75 class LogSpamTest : virtual public armarx::Component
76 {
77 public:
78 /// @see armarx::ManagedIceObject::getDefaultName()
79 std::string getDefaultName() const override;
80
81 protected:
82 /// @see armarx::ManagedIceObject::onInitComponent()
83 void onInitComponent() override;
84
85 /// @see armarx::ManagedIceObject::onConnectComponent()
86 void onConnectComponent() override;
87
88 /// @see armarx::ManagedIceObject::onDisconnectComponent()
89 void onDisconnectComponent() override;
90
91 /// @see armarx::ManagedIceObject::onExitComponent()
92 void onExitComponent() override;
93
94 /// @see PropertyUser::createPropertyDefinitions()
96
97 private:
98 //! Body of each spam thread: paces itself to its share of the target rate.
99 void spamTaskRun();
100
101 //! Emit one random message. \p rng is the calling thread's generator.
102 void emitOne(std::mt19937& rng, long& counter);
103
104 //! Build a random, unique message body.
105 std::string buildMessage(std::mt19937& rng, long counter) const;
106
107 int messagesPerSecond = 0;
108 int threadCount = 1;
109 int seed = 0;
110 int warningPercent = 0;
111 int errorPercent = 0;
112 int verbosePercent = 0;
113 int multilinePercent = 0;
114 int multilineMaxLines = 1;
115 int minWords = 1;
116 int maxWords = 1;
117 int tagCount = 1;
118 int burstEveryMs = 0;
119 int burstSize = 0;
120
121 //! Hands each spam thread its index, so they can seed their generators distinctly.
122 std::atomic<int> nextThreadIndex{0};
123
124 //! Cleared before the tasks are stopped, so the loops leave promptly.
125 std::atomic<bool> running{false};
126
127 std::vector<RunningTask<LogSpamTest>::pointer_type> tasks;
128 };
129} // namespace armarx
Default component property definition container.
Definition Component.h:70
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
LogSpamTestPropertyDefinitions(std::string prefix)
Generates configurable log load for testing the logging path.
Definition LogSpamTest.h:76
void onInitComponent() override
void onDisconnectComponent() override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onConnectComponent() override
void onExitComponent() override
std::string getDefaultName() const override
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.