Efficient Timelog implementation based on TLS (thread-local storage)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.