dlr-gtlab / gt-logging

Basic C++14 logging library based on QsLog
1 stars 1 forks source link

Add macro for profiling a function block #48

Closed rainman110 closed 1 month ago

rainman110 commented 1 year ago

In GitLab by @mariusalexander on May 10, 2023, 07:36

It would be nice to have a simple macro that can be used to profile a piece of code (i.e. measure the time elapsed). It could log on Trace level by default.

It's usage could look something like this:

void myFancyFunction()
{
    GT_LOG_PROFILE();

    gtDebug() << "some message!";

    // do expensive stuff here

    return 0;
}

/* OUT: 
 > [DEBUG] [...] some message!
 > [TRACE] [...] [Profile] myFancyFunction@line_no: took xy ms
 */
mariusalexander commented 1 month ago

Closed as not planned/actively needed. I think it is best to implement this in the project where it is needed and if it is needed.

But feel free to reopen to further discuss this feature and its implementation.