Get stats into "r". Also, if class_count != NULL, class_count[k] will be set to the total number of objects of size class k in the central cache, transfer cache, and per-thread caches. If small_spans is non-NULL, it is filled. Same for large_spans.
| 317 | // central cache, transfer cache, and per-thread caches. If small_spans |
| 318 | // is non-NULL, it is filled. Same for large_spans. |
| 319 | static void ExtractStats(TCMallocStats* r, uint64_t* class_count, |
| 320 | PageHeap::SmallSpanStats* small_spans, |
| 321 | PageHeap::LargeSpanStats* large_spans) { |
| 322 | r->central_bytes = 0; |
| 323 | r->transfer_bytes = 0; |
| 324 | for (int cl = 0; cl < kNumClasses; ++cl) { |
| 325 | const int length = Static::central_cache()[cl].length(); |
| 326 | const int tc_length = Static::central_cache()[cl].tc_length(); |
| 327 | const size_t cache_overhead = Static::central_cache()[cl].OverheadBytes(); |
| 328 | const size_t size = static_cast<uint64_t>( |
| 329 | Static::sizemap()->ByteSizeForClass(cl)); |
| 330 | r->central_bytes += (size * length) + cache_overhead; |
| 331 | r->transfer_bytes += (size * tc_length); |
| 332 | if (class_count) { |
| 333 | // Sum the lengths of all per-class freelists, except the per-thread |
| 334 | // freelists, which get counted when we call GetThreadStats(), below. |
| 335 | class_count[cl] = length + tc_length; |
| 336 | } |
| 337 | |
| 338 | } |
| 339 | |
| 340 | // Add stats from per-thread heaps |
| 341 | r->thread_bytes = 0; |
| 342 | { // scope |
| 343 | SpinLockHolder h(Static::pageheap_lock()); |
| 344 | ThreadCache::GetThreadStats(&r->thread_bytes, class_count); |
| 345 | r->metadata_bytes = TCMALLOC_NAMESPACE::metadata_system_bytes(); |
| 346 | r->pageheap = Static::pageheap()->stats(); |
| 347 | if (small_spans != NULL) { |
| 348 | Static::pageheap()->GetSmallSpanStats(small_spans); |
| 349 | } |
| 350 | if (large_spans != NULL) { |
| 351 | Static::pageheap()->GetLargeSpanStats(large_spans); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | static double PagesToMiB(uint64_t pages) { |
| 357 | return (pages << kPageShift) / 1048576.0; |
no test coverage detected