]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
2 | * This file is open source software, licensed to you under the terms | |
3 | * of the Apache License, Version 2.0 (the "License"). See the NOTICE file | |
4 | * distributed with this work for additional information regarding copyright | |
5 | * ownership. You may not use this file except in compliance with the License. | |
6 | * | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, | |
12 | * software distributed under the License is distributed on an | |
13 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
14 | * KIND, either express or implied. See the License for the | |
15 | * specific language governing permissions and limitations | |
16 | * under the License. | |
17 | */ | |
18 | /* | |
19 | * Copyright 2020 ScyllaDB | |
20 | */ | |
21 | ||
22 | #pragma once | |
23 | ||
24 | #include <seastar/util/noncopyable_function.hh> | |
25 | ||
26 | namespace seastar { | |
27 | namespace memory { | |
28 | ||
29 | /// \brief The kind of allocation failures to dump diagnostics report for. | |
30 | /// | |
31 | /// Note that if the seastar_memory logger is set to level debug, there will | |
32 | /// be a report dumped for any allocation failure, regardless of this | |
33 | /// configuration. | |
34 | enum class alloc_failure_kind { | |
35 | /// Dump diagnostic error report for none of the allocation failures. | |
36 | none, | |
37 | /// Dump diagnostic error report for critical allocation failures, see | |
38 | /// \ref scoped_critical_alloc_section. | |
39 | critical, | |
40 | /// Dump diagnostic error report for all the allocation failures. | |
41 | all, | |
42 | }; | |
43 | ||
44 | /// \brief Configure when memory diagnostics are dumped. | |
45 | /// | |
46 | /// See \ref alloc_failure_kind on available options. | |
47 | /// Applies configuration on all shards. | |
48 | void set_dump_memory_diagnostics_on_alloc_failure_kind(alloc_failure_kind); | |
49 | ||
50 | /// \brief Configure when memory diagnostics are dumped. | |
51 | /// | |
52 | /// String version. See \ref alloc_failure_kind on available options. | |
53 | /// Applies configuration on all shards. | |
54 | void set_dump_memory_diagnostics_on_alloc_failure_kind(std::string_view); | |
55 | ||
56 | /// \brief A functor which writes its argument into the diagnostics report. | |
57 | using memory_diagnostics_writer = noncopyable_function<void(std::string_view)>; | |
58 | ||
59 | /// \brief Set a producer of additional diagnostic information. | |
60 | /// | |
61 | /// This allows the application running on top of seastar to add its own part to | |
62 | /// the diagnostics dump. The application can supply higher level diagnostics | |
63 | /// information, that might help explain how the memory was consumed. | |
64 | /// | |
65 | /// The application specific part will be added just below the main stats | |
66 | /// (free/used/total memory). | |
67 | /// | |
68 | /// \param producer - the functor to produce the additional diagnostics, specific | |
69 | /// to the application, to be added to the generated report. The producer is | |
70 | /// passed a writer functor, which it can use to add its parts to the report. | |
71 | /// | |
72 | /// \note As the report is generated at a time when allocations are failing, the | |
73 | /// producer should try as hard as possible to not allocate while producing | |
74 | /// the output. | |
75 | void set_additional_diagnostics_producer(noncopyable_function<void(memory_diagnostics_writer)> producer); | |
76 | ||
77 | /// Manually generate a diagnostics report | |
78 | /// | |
79 | /// Note that contrary to the automated report generation (triggered by | |
80 | /// allocation failure), this method does allocate memory and can fail in | |
81 | /// low-memory conditions. | |
82 | sstring generate_memory_diagnostics_report(); | |
83 | ||
84 | } // namespace memory | |
85 | } // namespace seastar |