Advertisement
Guest User

TCmalloc Thread cache size test

a guest
Apr 9th, 2015
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #ifdef HAVE_GPERFTOOLS_HEAP_PROFILER_H
  4. #include <gperftools/heap-profiler.h>
  5. #else
  6. #include <google/heap-profiler.h>
  7. #endif
  8.  
  9. #ifdef HAVE_GPERFTOOLS_MALLOC_EXTENSION_H
  10. #include <gperftools/malloc_extension.h>
  11. #else
  12. #include <google/malloc_extension.h>
  13. #endif
  14.  
  15. using namespace std;
  16.  
  17. int main ()
  18. {
  19.   size_t tc_cache_sz;
  20.   size_t env_cache_sz;
  21.   char *env_cache_sz_str;
  22.   int st;
  23.  
  24.   env_cache_sz_str = getenv("TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES");
  25.   if (env_cache_sz_str) {
  26.     env_cache_sz = strtoul(env_cache_sz_str, NULL, 0);
  27.     if (env_cache_sz == 33554432) {
  28.         cout << "TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES Value same as default:"
  29.                 " 33554432 export a different value for test" << endl;
  30.         exit(EXIT_FAILURE);
  31.     }
  32.     tc_cache_sz = 0;
  33.     MallocExtension::instance()->
  34.         GetNumericProperty("tcmalloc.max_total_thread_cache_bytes",
  35.                         &tc_cache_sz);
  36.     if (tc_cache_sz == env_cache_sz) {
  37.       cout << "Tcmalloc OK! Internal and Env cache size are same:" <<
  38.               tc_cache_sz << endl;
  39.       st = EXIT_SUCCESS;
  40.     } else {
  41.       cout << "Tcmalloc BUG! TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES: "
  42.               << env_cache_sz << " Internal Size: " << tc_cache_sz
  43.               << " different" << endl;
  44.       st = EXIT_FAILURE;
  45.     }
  46.   } else {
  47.     cout << "TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES Env Not Set" << endl;
  48.     st = EXIT_FAILURE;
  49.   }
  50.   exit(st);
  51. }
  52. /* EOF */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement