userver: userver/server/handlers/jemalloc.hpp Source File
Loading...
Searching...
No Matches
jemalloc.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/handlers/jemalloc.hpp
4/// @brief @copybrief server::handlers::Jemalloc
5
6#include <userver/server/handlers/http_handler_base.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace server::handlers {
11
12/// @ingroup userver_components userver_http_handlers
13///
14/// @brief Handler that controls the jemalloc allocator.
15///
16/// The component has no service configuration except the
17/// @ref userver_http_handlers "common handler options".
18///
19/// ## Static configuration example:
20///
21/// @snippet components/common_server_component_list_test.cpp Sample handler jemalloc component config
22///
23/// ## Schema
24/// Set an URL path argument `command` to one of the following values:
25/// * `stat` - to get jemalloc stats
26/// * `enable` - to start memory profiling
27/// * `disable` - to stop memory profiling
28/// * `dump` - to get jemalloc profiling dump
29/// * `bg_threads_set_max` - to set maximum number of background threads
30/// * `bg_threads_enable` - to start background threads
31/// * `bg_threads_disable` - to *synchronously* stop background threads
32class Jemalloc final : public HttpHandlerBase {
33public:
34 enum class Command {
35 kStat,
36 kEnable,
37 kDisable,
38 kDump,
39 kBgThreadsSetMax,
40 kBgThreadsEnable,
41 kBgThreadsDisable,
42 };
43 static std::optional<Command> GetCommandFromString(std::string_view str);
44 static std::string ListCommands();
45
46 Jemalloc(const components::ComponentConfig&, const components::ComponentContext&);
47
48 /// @ingroup userver_component_names
49 /// @brief The default name of server::handlers::Jemalloc
50 static constexpr std::string_view kName = "handler-jemalloc";
51
52 std::string HandleRequestThrow(const http::HttpRequest&, request::RequestContext&) const override;
53
54 static yaml_config::Schema GetStaticConfigSchema();
55};
56
57} // namespace server::handlers
58
59template <>
60inline constexpr bool components::kHasValidate<server::handlers::Jemalloc> = true;
61
62USERVER_NAMESPACE_END