Phosphor
phosphor::TraceConfig Class Reference

#include <trace_config.h>

Public Member Functions

 TraceConfig (BufferMode _buffer_mode, size_t _buffer_size)
 
 TraceConfig (trace_buffer_factory _buffer_factory, size_t _buffer_size)
 
BufferMode getBufferMode () const
 
size_t getBufferSize () const
 
trace_buffer_factory getBufferFactory () const
 
TraceConfigsetStoppedCallback (std::shared_ptr< TracingStoppedCallback > _tracing_stopped_callback)
 
TracingStoppedCallbackgetStoppedCallback () const
 
TraceConfigsetStopTracingOnDestruct (bool _stop_tracing)
 
bool getStopTracingOnDestruct () const
 
TraceConfigsetCategories (const std::vector< std::string > &enabled, const std::vector< std::string > &disabled)
 
const std::vector< std::string > & getEnabledCategories () const
 
const std::vector< std::string > & getDisabledCategories () const
 
StringPtr toString () const
 

Static Public Member Functions

static TraceConfig fromString (const std::string &config)
 

Static Protected Member Functions

static trace_buffer_factory modeToFactory (BufferMode mode)
 

Protected Attributes

BufferMode buffer_mode = BufferMode::fixed
 
size_t buffer_size = 0
 
trace_buffer_factory buffer_factory = nullptr
 
std::shared_ptr< TracingStoppedCallbacktracing_stopped_callback
 
bool stop_tracing = false
 
std::vector< std::string > enabled_categories
 
std::vector< std::string > disabled_categories
 

Detailed Description

The TraceConfig is used to configure a TraceLog for starting Trace when it is enabled.

The TraceConfig has two constructors with two different aims in mind

  • Using a built-in TraceBuffer type, either ring or fixed
  • Using a user supplied TraceBuffer by supplying a TraceBufferFactory

The first of these is specified by using the mode enumeration, the second is specified by passing in the TraceBufferFactory.

The second parameter to both of these is the size in bytes of the TraceBuffer.

All other arguments are optional and may be specified using chainable methods.

Constructor & Destructor Documentation

phosphor::TraceConfig::TraceConfig ( BufferMode  _buffer_mode,
size_t  _buffer_size 
)

Constructor used when using a builtin TraceBuffer type

Parameters
_buffer_modeWhich buffer mode to use. Cannot be BufferMode::Custom.
_buffer_sizeMaximum size in bytes of the trace buffer.
phosphor::TraceConfig::TraceConfig ( trace_buffer_factory  _buffer_factory,
size_t  _buffer_size 
)

Constructor used when supplying a custom TraceBuffer implementation

Parameters
_buffer_factoryThe trace buffer factory to be used.
_buffer_sizeMaximum size in bytes of the trace buffer.

Member Function Documentation

TraceConfig phosphor::TraceConfig::fromString ( const std::string &  config)
static

Generate a TraceConfig from a config string (Usually set from an environment variable).

Example:

TraceConfig::fromString("buffer-mode:fixed,buffer-size:1024");
Parameters
configConfig string to be used to generate the TraceConfig
Returns
Generated TraceConfig
trace_buffer_factory phosphor::TraceConfig::getBufferFactory ( ) const
Returns
The trace buffer factory that will be used to create a TraceBuffer when tracing is enabled.
BufferMode phosphor::TraceConfig::getBufferMode ( ) const
Returns
The buffer mode that is selected
size_t phosphor::TraceConfig::getBufferSize ( ) const
Returns
The size of the buffer in megabytes that will be used
const std::vector< std::string > & phosphor::TraceConfig::getDisabledCategories ( ) const
Returns
The disabled categories for this trace config
const std::vector< std::string > & phosphor::TraceConfig::getEnabledCategories ( ) const
Returns
The enabled categories for this trace config
TracingStoppedCallback * phosphor::TraceConfig::getStoppedCallback ( ) const
Returns
The tracing_stopped_callback to be invoked when tracing stops.
bool phosphor::TraceConfig::getStopTracingOnDestruct ( ) const
Returns
Whether or not the tracing shutdown (and therefore callbacks) should be run when the TraceLog is destroyed.
trace_buffer_factory phosphor::TraceConfig::modeToFactory ( BufferMode  mode)
staticprotected

Get the trace buffer factory for the given mode.

Cannot be used for the custom mode

Parameters
modeThe trace buffer mode to convert
Returns
The trace buffer factory for
Exceptions
std::invalidargument if given mode is invalid
TraceConfig & phosphor::TraceConfig::setCategories ( const std::vector< std::string > &  enabled,
const std::vector< std::string > &  disabled 
)

Set the categories to enable/disable in this trace config

Parameters
enabledThe categories to explicitly enable
disabledThe categories to explicitly disable
Returns
reference to the TraceConfig being configured
TraceConfig & phosphor::TraceConfig::setStoppedCallback ( std::shared_ptr< TracingStoppedCallback _tracing_stopped_callback)

Set the tracing_stopped_callback to be invoked when tracing stops.

Parameters
_tracing_stopped_callbackCallback to be used. Note this is passed as a shared_ptr due to it not being safe to copy Callbacks in the general case, as it may have been allocated with a different CRT than phosphor itself is linked against.
Returns
reference to the TraceConfig be configured
TraceConfig & phosphor::TraceConfig::setStopTracingOnDestruct ( bool  _stop_tracing)

Sets whether or not the tracing shutdown (and therefore callbacks) should be run when the TraceLog is destroyed. Defaults to false.

Parameters
_stop_tracingStop tracing on shutdown
Returns
reference to the TraceConfig being configured
StringPtr phosphor::TraceConfig::toString ( ) const

Converts a TraceConfig to a config string.

This can be used to convert the TraceConfig that a TraceLog is using to a human readable form.

Returns
The config string

The documentation for this class was generated from the following files: