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 <functional>
7#include <unordered_map>
8#include <vector>
9
10#include <userver/components/component_fwd.hpp>
11#include <userver/concurrent/variable.hpp>
12#include <userver/dump/dumper.hpp>
13#include <userver/utils/not_null.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace testsuite {
18
19/// @brief Dumper control interface for testsuite
20/// @details All methods are coro-safe.
21class DumpControl final {
22public:
23 enum class PeriodicsMode { kDisabled, kEnabled };
24
25 explicit DumpControl(PeriodicsMode periodics_mode);
26
27 PeriodicsMode GetPeriodicsMode() const;
28
29 void WriteCacheDumps(const std::vector<std::string>& dumper_names);
30
31 void ReadCacheDumps(const std::vector<std::string>& dumper_names);
32
33private:
34 friend class DumperRegistrationHolder;
35
36 void RegisterDumper(dump::Dumper& dumper);
37
38 void UnregisterDumper(dump::Dumper& dumper);
39
40 dump::Dumper& FindDumper(const std::string& name) const;
41
42 PeriodicsMode periodics_mode_;
43 concurrent::Variable<std::unordered_map<std::string, utils::NotNull<dump::Dumper*>>> dumpers_;
44};
45
46/// RAII helper for testsuite registration
47class DumperRegistrationHolder final {
48public:
49 DumperRegistrationHolder(DumpControl&, dump::Dumper&);
50
51 DumperRegistrationHolder(DumperRegistrationHolder&&) = delete;
52 DumperRegistrationHolder& operator=(DumperRegistrationHolder&&) = delete;
53 ~DumperRegistrationHolder();
54
55private:
56 DumpControl& control_;
57 dump::Dumper& dumper_;
58};
59
60} // namespace testsuite
61
62USERVER_NAMESPACE_END