diff --git a/include/dynamic-graph/entity.h b/include/dynamic-graph/entity.h index 5c57b5f37cf7a8e8f7530ca960acdc6e687d48fa..1db47a3796efa14964594e79dab6bf968d5bc206 100644 --- a/include/dynamic-graph/entity.h +++ b/include/dynamic-graph/entity.h @@ -112,7 +112,24 @@ namespace dynamicgraph /// \brief Get the logger's verbosity level. LoggerVerbosity getLoggerVerbosityLevel() - { return logger_.getVerbosity(); }; + { return logger_.getVerbosity(); } + + /// \brief Set the time sample. + bool setTimeSample(double t) + { return logger_.setTimeSample(t); } + + /// \brief Get the time sample. + double getTimeSample() + { return logger_.getTimeSample();} + + /// \brief Set the period of the stream period + bool setStreamPrintPeriod(double t) + { return logger_.setStreamPrintPeriod(t); } + + /// \brief Get the period of the stream period + double getStreamPrintPeriod() + { return logger_.getStreamPrintPeriod();} + protected: void addCommand(const std::string& name,command::Command* command); diff --git a/include/dynamic-graph/logger.h b/include/dynamic-graph/logger.h index 46a58ca3380ba5234490c3270a092c849ee14887..a88e9501c3d85f1816d4517031194a128623cfbf 100644 --- a/include/dynamic-graph/logger.h +++ b/include/dynamic-graph/logger.h @@ -178,9 +178,16 @@ namespace dynamicgraph { * is going to be called. */ bool setTimeSample(double t); + /** Get the sampling time at which the method countdown() + * is going to be called. */ + double getTimeSample(); + /** Set the time period for printing of streaming messages. */ bool setStreamPrintPeriod(double s); + /** Get the time period for printing of streaming messages. */ + double getStreamPrintPeriod(); + /** Set the verbosity level of the logger. */ void setVerbosity(LoggerVerbosity lv); diff --git a/src/debug/logger.cpp b/src/debug/logger.cpp index 7aa01ccf7e0e9872013cb6425be0527bf7c95b0a..41b809d763f678b2bd5279585ad777273fe0d02a 100644 --- a/src/debug/logger.cpp +++ b/src/debug/logger.cpp @@ -62,7 +62,7 @@ namespace dynamicgraph return; // if print is allowed by current verbosity level - if(isStreamMsg(type)) + if( isStreamMsg(type)) { // check whether counter already exists string id = file+toString(line); @@ -101,4 +101,14 @@ namespace dynamicgraph m_streamPrintPeriod = s; return true; } + + double Logger::getTimeSample() + { + return m_timeSample; + } + + double Logger::getStreamPrintPeriod() + { + return m_streamPrintPeriod; + } } // namespace dynamicgraph diff --git a/src/debug/real-time-logger.cpp b/src/debug/real-time-logger.cpp index 340738054f903b13fb8104b6569ed8b6c406d35c..c78348b31e87d02664b07d3e7683be70fd1be823 100644 --- a/src/debug/real-time-logger.cpp +++ b/src/debug/real-time-logger.cpp @@ -87,22 +87,22 @@ namespace dynamicgraph int threadPolicy; struct sched_param threadParam; if (pthread_getschedparam (pthread_self(), &threadPolicy, &threadParam) == 0) - { - threadPolicy = SCHED_OTHER; - threadParam.sched_priority -= 5; - if (threadParam.sched_priority < sched_get_priority_min (threadPolicy)) - threadParam.sched_priority = sched_get_priority_min (threadPolicy); + { + threadPolicy = SCHED_OTHER; + threadParam.sched_priority -= 5; + if (threadParam.sched_priority < sched_get_priority_min (threadPolicy)) + threadParam.sched_priority = sched_get_priority_min (threadPolicy); - pthread_setschedparam (pthread_self(), threadPolicy, &threadParam); - } + pthread_setschedparam (pthread_self(), threadPolicy, &threadParam); + } while (!requestShutdown_ || !logger->empty()) - { - // If the logger did not write anything, it means the buffer is empty. - // Do a pause - if (!logger->spinOnce()) - boost::this_thread::sleep(boost::posix_time::milliseconds(100)); - } + { + // If the logger did not write anything, it means the buffer is empty. + // Do a pause + if (!logger->spinOnce()) + boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + } } }; diff --git a/tests/debug-logger-winit.cpp b/tests/debug-logger-winit.cpp index da951130b554dc4414123c233e9b1740a04562d2..a9907526bfdf0fe3218cb5f3ad0cfd25ed0b51de 100644 --- a/tests/debug-logger-winit.cpp +++ b/tests/debug-logger-winit.cpp @@ -16,11 +16,15 @@ #include <dynamic-graph/real-time-logger.h> #include <dynamic-graph/logger.h> + #define BOOST_TEST_MODULE debug-logger #include <boost/test/unit_test.hpp> #include <boost/test/output_test_stream.hpp> +#include <boost/thread/thread.hpp> +#include <boost/date_time/posix_time/posix_time.hpp> + using boost::test_tools::output_test_stream; @@ -78,7 +82,7 @@ BOOST_AUTO_TEST_CASE(debug_logger_wrong_initialization) dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity", "my-entity-2"))); - for(unsigned int i=0;i<10000;i++) + for(unsigned int i=0;i<1000;i++) { entity.testDebugTrace(); } diff --git a/tests/debug-logger.cpp b/tests/debug-logger.cpp index e36483f42d4002eaa6a5e863018614d57773740a..7499e0b100922d97b517b691f294cab3a16857c7 100644 --- a/tests/debug-logger.cpp +++ b/tests/debug-logger.cpp @@ -78,6 +78,11 @@ BOOST_AUTO_TEST_CASE(debug_logger) dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity", "my-entity"))); + entity.setTimeSample(0.002); + BOOST_CHECK_EQUAL(entity.getTimeSample(),0.002); + entity.setStreamPrintPeriod(0.004); + BOOST_CHECK_EQUAL(entity.getStreamPrintPeriod(),0.004); + for(unsigned int i=0;i<10000;i++) { entity.testDebugTrace();