| 601 | } |
| 602 | |
| 603 | void AggregatedRuntimeProfile::UpdateCountersFromInstances( |
| 604 | const TRuntimeProfileNode& node, int start_idx, ObjectPool* pool) { |
| 605 | unique_lock<SpinLock> l(counter_map_lock_); |
| 606 | DCHECK(node.__isset.aggregated); |
| 607 | const TAggregatedRuntimeProfileNode& agg_node = node.aggregated; |
| 608 | for (const TAggCounter& tcounter : agg_node.counters) { |
| 609 | auto dst_iter = counter_map_.find(tcounter.name); |
| 610 | // Get the counter with the same name in dst_iter (this->counter_map_) |
| 611 | // Create one if it doesn't exist. |
| 612 | AveragedCounter* avg_counter; |
| 613 | if (dst_iter == counter_map_.end()) { |
| 614 | avg_counter = pool->Add(new AveragedCounter(tcounter.unit, num_input_profiles_)); |
| 615 | counter_map_[tcounter.name] = avg_counter; |
| 616 | } else { |
| 617 | DCHECK(dst_iter->second->unit() == tcounter.unit); |
| 618 | avg_counter = static_cast<AveragedCounter*>(dst_iter->second); |
| 619 | } |
| 620 | avg_counter->Update(start_idx, tcounter.has_value, tcounter.values); |
| 621 | } |
| 622 | |
| 623 | for (const TAggTimeSeriesCounter& tcounter : agg_node.time_series_counters) { |
| 624 | TAggTimeSeriesCounter& dst = time_series_counter_map_[tcounter.name]; |
| 625 | if (dst.values.empty()) { |
| 626 | dst.name = tcounter.name; |
| 627 | dst.unit = tcounter.unit; |
| 628 | dst.period_ms.resize(num_input_profiles_); |
| 629 | dst.values.resize(num_input_profiles_); |
| 630 | dst.start_index.resize(num_input_profiles_); |
| 631 | } else { |
| 632 | DCHECK_EQ(dst.unit, tcounter.unit); |
| 633 | } |
| 634 | DCHECK_LE(start_idx + tcounter.values.size(), num_input_profiles_); |
| 635 | DCHECK_EQ(tcounter.values.size(), tcounter.period_ms.size()); |
| 636 | DCHECK_EQ(tcounter.values.size(), tcounter.start_index.size()) << tcounter.name; |
| 637 | for (int i = 0; i < tcounter.values.size(); ++i) { |
| 638 | int idx = start_idx + i; |
| 639 | if (UNLIKELY(tcounter.values[i].empty() && !dst.values[idx].empty())) continue; |
| 640 | dst.period_ms[idx] = tcounter.period_ms[i]; |
| 641 | dst.values[idx] = tcounter.values[i]; |
| 642 | dst.start_index[idx] = tcounter.start_index[i]; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | UpdateChildCountersLocked(l, node.child_counters_map); |
| 647 | } |
| 648 | |
| 649 | void AggregatedRuntimeProfile::UpdateInfoStringsFromInstances( |
| 650 | const TRuntimeProfileNode& node, int start_idx, ObjectPool* pool) { |