| 1055 | } |
| 1056 | |
| 1057 | void RuntimeProfile::SortChildrenByTotalTime() { |
| 1058 | lock_guard<SpinLock> l(children_lock_); |
| 1059 | // Create a snapshot of total time values so that they don't change while we're |
| 1060 | // sorting. Sort the <total_time, index> pairs, then reshuffle children_. |
| 1061 | vector<pair<int64_t, int64_t>> total_times; |
| 1062 | total_times.reserve(children_.size()); |
| 1063 | for (int i = 0; i < children_.size(); ++i) { |
| 1064 | total_times.emplace_back(children_[i].first->total_time_counter()->value(), i); |
| 1065 | } |
| 1066 | // Order by descending total time. |
| 1067 | sort(total_times.begin(), total_times.end(), |
| 1068 | [](const pair<int64_t, int64_t>& p1, const pair<int64_t, int64_t>& p2) { |
| 1069 | return p1.first > p2.first; |
| 1070 | }); |
| 1071 | ChildVector new_children; |
| 1072 | new_children.reserve(total_times.size()); |
| 1073 | for (const auto& p : total_times) new_children.emplace_back(children_[p.second]); |
| 1074 | children_ = move(new_children); |
| 1075 | } |
| 1076 | |
| 1077 | void RuntimeProfileBase::AddInfoString(const string& key, const string& value) { |
| 1078 | return AddInfoStringInternal(key, value, false); |