jrl-umi3218 / mc_rtc

mc_rtc is an interface for simulated and real robotic systems suitable for real-time control
BSD 2-Clause "Simplified" License
122 stars 37 forks source link

Log file update timing #214

Closed mmurooka closed 2 years ago

mmurooka commented 2 years ago

I'm using mc_rtc::Logger as follows in the project which is not related to mc_rtc controller.

std::make_shared<mc_rtc::Logger> logger;
logger = std::make_shared<mc_rtc::Logger>(mc_rtc::Logger::Policy::THREADED, "/tmp", "my-name");
MC_RTC_LOG_HELPER("my_var", my_var_);
logger->log();

Link to the codes (internal only): https://github.com/isri-aist/optmotiongen/blob/dcedbc70eb1234923c507c3366666f5feba1c1b9/optmotiongen/src/Problem/Problem.cpp#L23

I am solving a relatively large optimization problem in the project, and for each optimization iteration, I call logger->log(). One iteration may take up to 10 seconds, in which case logger->log() will be called only once every 10 seconds. I found that the bin file generated in /tmp is zero bytes for a while (for example, until the end of the first 20 iterations, that is around 200 sec for my case), and then becomes non-zero bytes when the program is terminated. While the bin file is zero bytes, mc_log_ui cannot visualize the log data. This is inconvenient, and I would like to visualize the log data at any time by updating the bin file after each iteration.

The behavior was same even when policy is mc_rtc::Logger::Policy::NON_THREADED.

gergondet commented 2 years ago

Hi @mmurooka

you can call the flush method to force a disk flush of the log. This is only implemented with the non threaded policy

mmurooka commented 2 years ago

@gergondet Thank you, I confirmed it works!