userver: userver/testsuite/dump_control.hpp Source File
Loading...
Searching...
No Matches
dump_control.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/testsuite/dump_control.hpp
4/// @brief @copybrief testsuite::DumpControl
5
6#include <string>
7#include <unordered_map>
8#include <vector>
9
10#include <userver/components/component_fwd.hpp>
11#include <userver/concurrent/variable.hpp>
12#include <userver/utils/not_null.hpp>
13#include <userver/utils/resource_scopes_fwd.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace testsuite {
18
19/// @brief Testsuite-facing API of a dump manager.
20class Dumper {
21public:
22 virtual ~Dumper();
23
24 virtual const std::string& Name() const = 0;
25
26 virtual void WriteDumpSyncDebug() = 0;
27
28 virtual void ReadDumpDebug() = 0;
29};
30
31/// @brief Dumper control interface for testsuite
32/// @details All methods are coro-safe.
33class DumpControl final {
34public:
35 enum class PeriodicsMode { kDisabled, kEnabled };
36
37 explicit DumpControl(PeriodicsMode periodics_mode);
38
39 PeriodicsMode GetPeriodicsMode() const;
40
41 void WriteCacheDumps(const std::vector<std::string>& dumper_names);
42
43 void ReadCacheDumps(const std::vector<std::string>& dumper_names);
44
45 /// @brief Registers a dumper bound to @a scopes.
46 ///
47 /// The dumper is registered after construction of the object that owns
48 /// @a scopes and is unregistered just before that object is destroyed.
49 ///
50 /// @param scopes storage that owns the dumper registration lifetime.
51 /// See @ref resource_scopes_parameter "where to obtain scopes".
52 void RegisterScope(utils::ResourceScopeStorage& scopes, Dumper& dumper);
53
54private:
55 void RegisterDumper(Dumper& dumper);
56
57 void UnregisterDumper(Dumper& dumper) noexcept;
58
59 Dumper& FindDumper(const std::string& name) const;
60
61 PeriodicsMode periodics_mode_;
62 concurrent::Variable<std::unordered_map<std::string, utils::NotNull<Dumper*>>> dumpers_;
63};
64
65} // namespace testsuite
66
67USERVER_NAMESPACE_END