#ifndef OSDEV_COMPONENTS_MQTT_MEASUREMENT_TIMEMEASUREMENT_H #define OSDEV_COMPONENTS_MQTT_MEASUREMENT_TIMEMEASUREMENT_H #include #include #include #include namespace osdev { namespace components { namespace mqtt { namespace measurement { using TimeMeasurementCallback = std::function; class TimeMeasurement { public: TimeMeasurement(const std::string& id, const TimeMeasurementCallback& callback, bool measureOnDestruction = true); ~TimeMeasurement(); TimeMeasurement(const TimeMeasurement&) = delete; TimeMeasurement& operator=(const TimeMeasurement&) = delete; TimeMeasurement(TimeMeasurement&&) = default; TimeMeasurement& operator=(TimeMeasurement&&) = default; void set(); void measure(); private: std::string m_id; std::chrono::steady_clock::time_point m_start; std::chrono::steady_clock::time_point m_last; TimeMeasurementCallback m_callback; bool m_measureOnDestruction; }; template std::ostream& operator<<(std::ostream& os, const std::chrono::duration& rhs) { os << rhs.count(); return os; } } // End namespace measurement } // End namespace mqtt } // End namespace components } // End namespace osdev #endif // OSDEV_COMPONENTS_MQTT_MEASUREMENT_TIMEMEASUREMENT_H