MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / background_thread_stats_read

Function background_thread_stats_read

deps/jemalloc/src/background_thread.c:788–822  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

786}
787
788bool
789background_thread_stats_read(tsdn_t *tsdn, background_thread_stats_t *stats) {
790 assert(config_stats);
791 malloc_mutex_lock(tsdn, &background_thread_lock);
792 if (!background_thread_enabled()) {
793 malloc_mutex_unlock(tsdn, &background_thread_lock);
794 return true;
795 }
796
797 stats->num_threads = n_background_threads;
798 uint64_t num_runs = 0;
799 nstime_init(&stats->run_interval, 0);
800 for (unsigned i = 0; i < max_background_threads; i++) {
801 background_thread_info_t *info = &background_thread_info[i];
802 if (malloc_mutex_trylock(tsdn, &info->mtx)) {
803 /*
804 * Each background thread run may take a long time;
805 * avoid waiting on the stats if the thread is active.
806 */
807 continue;
808 }
809 if (info->state != background_thread_stopped) {
810 num_runs += info->tot_n_runs;
811 nstime_add(&stats->run_interval, &info->tot_sleep_time);
812 }
813 malloc_mutex_unlock(tsdn, &info->mtx);
814 }
815 stats->num_runs = num_runs;
816 if (num_runs > 0) {
817 nstime_idivide(&stats->run_interval, num_runs);
818 }
819 malloc_mutex_unlock(tsdn, &background_thread_lock);
820
821 return false;
822}
823
824#undef BACKGROUND_THREAD_NPAGES_THRESHOLD
825#undef BILLION

Callers 2

Calls 7

nstime_initFunction · 0.70
nstime_addFunction · 0.70
nstime_idivideFunction · 0.70
malloc_mutex_lockFunction · 0.50
malloc_mutex_unlockFunction · 0.50
malloc_mutex_trylockFunction · 0.50

Tested by

no test coverage detected