abumq / easyloggingpp

C++ logging library. It is extremely powerful, extendable, light-weight, fast performing, thread and type safe and consists of many built-in features. It provides ability to write logs in your own customized format. It also provide support for logging your classes, third-party libraries, STL and third-party containers etc.
MIT License
3.75k stars 918 forks source link

Compilation error when using TIMED_FUNC inside method called by multiple threads #853

Open davidelahoz opened 4 months ago

davidelahoz commented 4 months ago

I'm trying to use easyloggingpp for tracking the performance of a computation intensive method called from multiple theads. In order to achieve that, this method starts by calling TIMED_FUNC(timerObj); as shown bellow:

void class::intensiveMethod(){
   TIMED_FUNC(timerObj);
   // Some calculations...
}

Easyloggingpp is initialized with the following macros defined:

#define ELPP_FEATURE_ALL
#define ELPP_THREAD_SAFE
#define ELPP_FORCE_USE_STD_THREAD
INITIALIZE_EASYLOGGINGPP

As a result, compiler fails and shows this error: ``

/tmp/build-via-sdist-dtgmx5ps/example/src/example.cpp:57:5: error: invalid use of incomplete type ‘class el::base::PerformanceTracker’
   57 |     TIMED_FUNC(timerObj);
      |     ^~~~~~~~~~
In file included from /tmp/build-via-sdist-dtgmx5ps/example/src/example.cpp:1:
/config/.conan2/p/b/easyl65a687b0e9e22/p/include/easylogging++.h:484:7: note: forward declaration of ‘class el::base::PerformanceTracker’
  484 | class PerformanceTracker;
      |       ^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/locale_conv.h:41,
                 from /usr/include/c++/11/locale:43,
                 from /usr/include/c++/11/bits/fs_path.h:37,
                 from /usr/include/c++/11/filesystem:45,
                 ...
                 from /tmp/build-via-sdist-dtgmx5ps/example/src/example.cpp:1:
/usr/include/c++/11/bits/unique_ptr.h: In instantiation of ‘void std::default_delete<_Tp>::operator()(_Tp*) const [with _Tp = el::base::PerformanceTracker]’:
/usr/include/c++/11/bits/unique_ptr.h:361:17:   required from ‘std::unique_ptr<_Tp, _Dp>::~unique_ptr() [with _Tp = el::base::PerformanceTracker; _Dp = std::default_delete<el::base::PerformanceTracker>]’
/tmp/build-via-sdist-dtgmx5ps/example/src/example.cpp:57:5:   required from here
/usr/include/c++/11/bits/unique_ptr.h:83:23: error: invalid application of ‘sizeof’ to incomplete type ‘el::base::PerformanceTracker’
   83 |         static_assert(sizeof(_Tp)>0,
      |                       ^~~~~~~~~~~

If I comment TIMED_FUNC(timerObj);, the program compiles fine.

Does performance tracking require defining additional macros or creating timerObj as a global variable?