What is Timelog?
When we analyze the performance of the program, we add some logging information to record the time information of each part.
The function of the Timelog module is to provide a unified interface to allow adding and saving logging
The timelog we're using has several drawbacks.
1. Fixed size, once full, can not join the new logging
2. Each entry will have a global lock lock, which greatly affects the performance
This two-day boost-based thread_specific_ptr and circular_buffer achieve an efficient timelog, with the main features
1. Almost no lock required, so the performance is theoretically very high (although I have not really tested it)
2. The use of a fixed-size ring queue, full after the oldest information erased, so there is no full can not join the logging problem
Code
Implementation is simple
A bit of a flaw, too lazy to change
Https://github.com/cutepig123/TestCpp/blob/master/cpp11test/1/mytimelog.cpp
Known Issues
1) All timelog_create Timelog now actually point to the same implementation, so no matter how many of the Create is actually the same thing
2) The contents of the thread-local storage will not be released automatically, so there will be memory leaks (unless each of your threads uses boost thread, refer to the boost documentation)
If the thread of the program is fixed, then there is no effect
But there's a serious problem when the program constantly creates a new thread to delete.
Efficient Timelog implementation based on TLS (thread-local storage)