prof_accum.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "prof_accum.h"
  2. #ifdef JEMALLOC_PROF
  3. const char *malloc_conf =
  4. "prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0";
  5. #endif
  6. static int
  7. prof_dump_open_intercept(bool propagate_err, const char *filename)
  8. {
  9. int fd;
  10. fd = open("/dev/null", O_WRONLY);
  11. assert_d_ne(fd, -1, "Unexpected open() failure");
  12. return (fd);
  13. }
  14. static void *
  15. alloc_from_permuted_backtrace(unsigned thd_ind, unsigned iteration)
  16. {
  17. return (alloc_0(thd_ind*NALLOCS_PER_THREAD + iteration));
  18. }
  19. static void *
  20. thd_start(void *varg)
  21. {
  22. unsigned thd_ind = *(unsigned *)varg;
  23. size_t bt_count_prev, bt_count;
  24. unsigned i_prev, i;
  25. i_prev = 0;
  26. bt_count_prev = 0;
  27. for (i = 0; i < NALLOCS_PER_THREAD; i++) {
  28. void *p = alloc_from_permuted_backtrace(thd_ind, i);
  29. dallocx(p, 0);
  30. if (i % DUMP_INTERVAL == 0) {
  31. assert_d_eq(mallctl("prof.dump", NULL, NULL, NULL, 0),
  32. 0, "Unexpected error while dumping heap profile");
  33. }
  34. if (i % BT_COUNT_CHECK_INTERVAL == 0 ||
  35. i+1 == NALLOCS_PER_THREAD) {
  36. bt_count = prof_bt_count();
  37. assert_zu_le(bt_count_prev+(i-i_prev), bt_count,
  38. "Expected larger backtrace count increase");
  39. i_prev = i;
  40. bt_count_prev = bt_count;
  41. }
  42. }
  43. return (NULL);
  44. }
  45. TEST_BEGIN(test_idump)
  46. {
  47. bool active;
  48. thd_t thds[NTHREADS];
  49. unsigned thd_args[NTHREADS];
  50. unsigned i;
  51. test_skip_if(!config_prof);
  52. active = true;
  53. assert_d_eq(mallctl("prof.active", NULL, NULL, &active, sizeof(active)),
  54. 0, "Unexpected mallctl failure while activating profiling");
  55. prof_dump_open = prof_dump_open_intercept;
  56. for (i = 0; i < NTHREADS; i++) {
  57. thd_args[i] = i;
  58. thd_create(&thds[i], thd_start, (void *)&thd_args[i]);
  59. }
  60. for (i = 0; i < NTHREADS; i++)
  61. thd_join(thds[i], NULL);
  62. }
  63. TEST_END
  64. int
  65. main(void)
  66. {
  67. return (test(
  68. test_idump));
  69. }