Update pool_stats for all queries tracked through query memory trackers:
| 419 | |
| 420 | // Update pool_stats for all queries tracked through query memory trackers: |
| 421 | void MemTracker::UpdatePoolStatsForQueries(int limit, TPoolStats& pool_stats) { |
| 422 | if (limit == 0) return; |
| 423 | // Init all memory consumption related fields |
| 424 | pool_stats.heavy_memory_queries.clear(); |
| 425 | pool_stats.min_memory_consumed = std::numeric_limits<int64_t>::max(); |
| 426 | pool_stats.max_memory_consumed = 0; |
| 427 | pool_stats.total_memory_consumed = 0; |
| 428 | pool_stats.num_running = 0; |
| 429 | // Collect the top 'limit' queries into 'min_pq'. |
| 430 | MinPriorityQueue min_pq; |
| 431 | GetTopNQueriesAndUpdatePoolStats(min_pq, limit, pool_stats); |
| 432 | // Grab all remaining entries from the priority queue and assign them in the descending |
| 433 | // order of memory consumption to the pool_stats.heavy_memory_queries field in |
| 434 | // pool_stats. |
| 435 | auto& queries = pool_stats.heavy_memory_queries; |
| 436 | queries.clear(); |
| 437 | while (!min_pq.empty()) { |
| 438 | queries.push_back(min_pq.top()); |
| 439 | min_pq.pop(); |
| 440 | } |
| 441 | std::reverse(queries.begin(), queries.end()); |
| 442 | // If not a single query is found, set the min_memory_consumed to 0. |
| 443 | if (pool_stats.num_running == 0) { |
| 444 | pool_stats.min_memory_consumed = 0; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | void MemTracker::GetTopNQueriesAndUpdatePoolStats( |
| 449 | MinPriorityQueue& min_pq, int limit, TPoolStats& pool_stats) { |