Phosphor
trace_config.h
1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  * Copyright 2016 Couchbase, Inc
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
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, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include <memory>
21 #include <mutex>
22 
23 #include "trace_buffer.h"
24 
25 namespace phosphor {
26 
27  // Forward declare
28  class PHOSPHOR_API TraceLog;
29  class PHOSPHOR_API TraceConfig;
30 
59  public:
60  virtual ~TracingStoppedCallback() {}
61 
62  virtual void operator()(TraceLog&, std::lock_guard<TraceLog>&) = 0;
63 
64  };
65 
73  enum class BufferMode : char {
74  custom = 0,
75  fixed,
76  ring,
77  };
78 
82  PHOSPHOR_API
83  std::ostream& operator<<(std::ostream& stream, const BufferMode mode);
84 
89  struct PHOSPHOR_API StringPtrDeleter {
90  void operator()(const std::string* ptr);
91  };
92 
104  using StringPtr = std::unique_ptr<const std::string, StringPtrDeleter>;
105 
112  StringPtr make_String(const std::string& str);
113 
123  class PHOSPHOR_API TraceLogConfig {
124  public:
129  }
130 
139  TraceLogConfig& setStartupTrace(const TraceConfig& _startup_trace);
140 
147  TraceLogConfig& clearStartupTrace();
148 
153  TraceConfig* getStartupTrace() const;
154 
164  TraceLogConfig& fromEnvironment();
165 
166  protected:
167  std::unique_ptr<TraceConfig> startup_trace;
168  };
169 
188  class PHOSPHOR_API TraceConfig {
189  public:
190  TraceConfig();
191 
192  ~TraceConfig();
193 
201  TraceConfig(BufferMode _buffer_mode, size_t _buffer_size);
202 
209  TraceConfig(trace_buffer_factory _buffer_factory, size_t _buffer_size);
210 
214  BufferMode getBufferMode() const;
215 
219  size_t getBufferSize() const;
220 
225  trace_buffer_factory getBufferFactory() const;
226 
238  TraceConfig& setStoppedCallback(
239  std::shared_ptr<TracingStoppedCallback> _tracing_stopped_callback);
240 
245  TracingStoppedCallback* getStoppedCallback() const;
246 
254  TraceConfig& setStopTracingOnDestruct(bool _stop_tracing);
255 
260  bool getStopTracingOnDestruct() const;
261 
269  TraceConfig& setCategories(const std::vector<std::string>& enabled,
270  const std::vector<std::string>& disabled);
271 
275  const std::vector<std::string>& getEnabledCategories() const;
276 
280  const std::vector<std::string>& getDisabledCategories() const;
281 
293  static TraceConfig fromString(const std::string& config);
294 
303  StringPtr toString() const;
304 
305  protected:
315  static trace_buffer_factory modeToFactory(BufferMode mode);
316 
317  BufferMode buffer_mode = BufferMode::fixed;
318  size_t buffer_size = 0;
319  trace_buffer_factory buffer_factory = nullptr;
320  std::shared_ptr<TracingStoppedCallback> tracing_stopped_callback;
321  bool stop_tracing = false;
322 
323  std::vector<std::string> enabled_categories;
324  std::vector<std::string> disabled_categories;
325  };
326 
327 }
Definition: trace_config.h:89
Definition: trace_log.h:54
Definition: trace_config.h:188
Definition: trace_config.h:58
Definition: trace_config.h:123
TraceLogConfig()
Definition: trace_config.h:128
Definition: category_registry.h:32
std::function< buffer_ptr(size_t generation, size_t buffer_size)> trace_buffer_factory
Definition: trace_buffer.h:360