/** * @file include/ActivMiddleware/ActivFramework/TraceBuffer.h * * @brief Header for the TraceBuffer class. */ #if (!defined ACTIV_FRAMEWORK_TRACE_BUFFER_H) #define ACTIV_FRAMEWORK_TRACE_BUFFER_H #include "ActivMiddleware/ActivFramework/External.h" #include "ActivMiddleware/ActivBase/IniFileParser.h" #include "ActivMiddleware/ActivBase/Tracing/ScopedTracePoint.h" #include "ActivMiddleware/ActivBase/Tracing/TraceBufferBase.h" #include "ActivMiddleware/CxxYZ/string_view.h" //! Activ namespace. namespace Activ { class Component; class ManagedEndPoint; //! Buffer to store recent trace history. class TraceBuffer : public TraceBufferBase { public: //! Settings class. class Settings { public: //! Default constructor. ACTIV_FRAMEWORK_API Settings(); /** * @brief Read settings from an ini file section. * * @param sectionIterator iterator to an ini file section. * * @throw Exception */ ACTIV_FRAMEWORK_API void Read(const IniFileParser::ConstSectionIterator §ionIterator); bool m_isEnabled; ///< Whether trace logging is enabled. uint32_t m_eventCount; ///< Number of events to count, must be a power of 2. String m_logFileName; ///< Name of the log file to write to, filled in automatically if empty. size_t m_numberOfBackups; ///< Number of backups of the log file. size_t m_minLogInterval; ///< Minimum number of nanoseconds between logging two trace dumps. size_t m_logCountInterval; ///< Interval in nanoseconds to track number of logs produced. size_t m_maxLogCount; ///< Maximum logs allowed within a log count interval. size_t m_logBatchSize; ///< Number of entries to log per iteration. size_t m_clearBatchSize; ///< Number of entries to clear per iteration. size_t m_logBufferSendThreshold; ///< Size of log buffer to trigger sending. size_t m_initialSuppressionPeriod; ///< Number of nanoseconds to suppress tracing after initialization. }; /** * @brief Construct the trace buffer. * * @param managedEndPoint * @param settings */ TraceBuffer(ManagedEndPoint &managedEndPoint, const Settings &settings); //! Destructor. virtual ~TraceBuffer() ACTIV_OVERRIDE; /** * @brief Add a dynamic trace point. * * This method is here rather than the base class to solve a circular dependency between ScopedTracePoint and TraceBufferBase. * * @tparam T the event type. * * @return a ScopedTracePoint object. */ template ScopedTracePoint Add(); /** * @brief Add a dynamic trace point. * * This method is here rather than the base class to solve a circular dependency between ScopedTracePoint and TraceBufferBase. * * @param staticData argument to be passed to T::Decode(). * * @tparam T the event type. * * @return a ScopedTracePoint object. */ template ScopedTracePoint Add(const StaticData &staticData); /** * @brief Should a log be generated? * * Use this method to check if a log should be generated to save building a string. The Log() method will check anyway. * * @param currentTimestamp * * @return whether Log() will actually log. */ ACTIV_FRAMEWORK_API bool ShouldLog(const uint64_t currentTimestamp); /** * @brief Log trace from specificed timestamp. * * @param currentTimestamp the current timestamp. * @param fromTimestamp timestamp to log from. * @param message the reason for generating the log. */ ACTIV_FRAMEWORK_API void Log(const uint64_t currentTimestamp, const uint64_t fromTimestamp, const CxxYZ::string_view &message); private: //! Initialize, called after ManagedEndPoint constructor. void Initialize(); //! Destroy the buffer internals before the ManagedEndPoint destructor. ACTIV_FRAMEWORK_API void Destroy(); class Impl; CxxYZ::unique_ptr m_pImpl; friend class AgentApplication; friend class ManagedEndPoint; friend class ManagedEndPointImpl; friend class ThinApplication; }; // --------------------------------------------------------------------------------------------------------------------------------- template ScopedTracePoint TraceBuffer::Add() { CxxYZ::unique_ptr pTracePoint(new TracePointT(EmptyStaticData())); return ScopedTracePoint(*this, this->TraceBufferBase::Add(pTracePoint)); } // --------------------------------------------------------------------------------------------------------------------------------- template ScopedTracePoint TraceBuffer::Add(const StaticData &staticData) { CxxYZ::unique_ptr pTracePoint(new TracePointT(staticData)); return ScopedTracePoint(*this, this->TraceBufferBase::Add(pTracePoint)); } } // namespace Activ #endif // (!defined ACTIV_FRAMEWORK_TRACE_BUFFER_H)