Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'f' suffix mean on a C++ library name and how do I load it?

I'm using gperftools v2.3rc and would like to use the improved profiling of threads feature. The release notes state in part:

new cpu profiling mode on Linux is now implemented. It sets up separate profiling timers for separate threads. ... [It] is enabled if both librt.f is loaded and CPUPROFILE_PER_THREAD_TIMERS environment variable is set. ...

My C++ application is linked with librt.so (-lrt — the POSIX.1b Realtime Extensions library), but I have not heard of a library with a .f suffix before. What does the .f mean, where can I find this library, and how do I load it in my application?

like image 266
WilliamKF Avatar asked Dec 04 '14 16:12

WilliamKF


1 Answers

I suspect temporary arthritis brought on by lack of coffee (it's a typo). What is meant is librt.so. From the middle of src/profile-handler.cc:

// We use weak alias to timer_create to avoid runtime dependency on
// -lrt and in turn -lpthread.
//
// At runtime we detect if timer_create is available and if so we
// can enable linux-sigev-thread mode of profiling

and further down in the code:

#if HAVE_LINUX_SIGEV_THREAD_ID
  if (getenv("CPUPROFILE_PER_THREAD_TIMERS")) {
    if (timer_create && pthread_once) {  // <-- note this bit here.
      timer_sharing_ = TIMERS_SEPARATE;
      CreateThreadTimerKey(&thread_timer_key);
      per_thread_timer_enabled_ = true;
    } else {
      RAW_LOG(INFO,
              "Not enabling linux-per-thread-timers mode due to lack of timer_create."
              " Preload or link to librt.so for this to work");
    }
  }
#endif

It's checking if the envvar is set and librt has been loaded. It's about librt.so.

like image 120
Wintermute Avatar answered Nov 05 '22 09:11

Wintermute