Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SIMPLE_PERF_SAMPLE_TREE_H_ |
| 18 | #define SIMPLE_PERF_SAMPLE_TREE_H_ |
| 19 | |
Yabin Cui | 0c093f3 | 2017-04-19 11:48:44 -0700 | [diff] [blame] | 20 | #include <unordered_map> |
| 21 | |
Yabin Cui | 0338145 | 2017-12-13 11:31:53 -0800 | [diff] [blame] | 22 | #include "OfflineUnwinder.h" |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 23 | #include "SampleComparator.h" |
| 24 | #include "SampleDisplayer.h" |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 25 | #include "callchain.h" |
| 26 | #include "perf_regs.h" |
| 27 | #include "record.h" |
Yabin Cui | 60a0ea9 | 2015-07-22 20:30:43 -0700 | [diff] [blame] | 28 | #include "thread_tree.h" |
Yabin Cui | 41d4ba9 | 2015-06-22 12:27:58 -0700 | [diff] [blame] | 29 | |
Yabin Cui | faa7b92 | 2021-01-11 17:35:57 -0800 | [diff] [blame] | 30 | namespace simpleperf { |
Yabin Cui | 0338145 | 2017-12-13 11:31:53 -0800 | [diff] [blame] | 31 | |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 32 | // A SampleTree is a collection of samples. A profiling report is mainly about |
| 33 | // constructing a SampleTree and display it. There are three steps involved: |
| 34 | // build the tree, sort the tree, and display it. For example, if we want to |
| 35 | // show how many cpu-cycles are spent in different functions, we should do as |
| 36 | // follows: |
| 37 | // 1. Build a SampleTree from SampleRecords with each sample containing |
| 38 | // (cpu-cycles, function name). When building the tree, we should merge |
| 39 | // samples containing the same function name. |
| 40 | // 2. Sort the SampleTree by cpu-cycles in the sample. As we want to display the |
| 41 | // samples in a decreasing order of cpu-cycles, we should sort it like this. |
| 42 | // 3. Display the SampleTree, each sample prints its (cpu-cycles, function name) |
| 43 | // pair. |
| 44 | // |
| 45 | // We represent the three steps with three template classes. |
| 46 | // 1. A SampleTree is built by SampleTreeBuilder. The comparator passed in |
| 47 | // SampleTreeBuilder's constructor decides the property of samples should be |
| 48 | // merged together. |
| 49 | // 2. After a SampleTree is built and got from SampleTreeBuilder, it should be |
| 50 | // sorted by SampleTreeSorter. The sort result decides the order to show |
| 51 | // samples. |
| 52 | // 3. At last, the sorted SampleTree is passed to SampleTreeDisplayer, which |
| 53 | // displays each sample in the SampleTree. |
Yabin Cui | ecb9a30 | 2015-07-01 10:00:52 -0700 | [diff] [blame] | 54 | |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 55 | template <typename EntryT, typename AccumulateInfoT> |
| 56 | class SampleTreeBuilder { |
Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 57 | public: |
Yabin Cui | 68b8383 | 2017-07-19 17:54:57 -0700 | [diff] [blame] | 58 | explicit SampleTreeBuilder(const SampleComparator<EntryT>& comparator) |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 59 | : sample_set_(comparator), |
Yabin Cui | 6965d42 | 2016-06-15 11:41:42 -0700 | [diff] [blame] | 60 | accumulate_callchain_(false), |
Yabin Cui | 9970a23 | 2016-06-29 12:18:11 -0700 | [diff] [blame] | 61 | sample_comparator_(comparator), |
Yabin Cui | 4e391de | 2021-11-02 13:28:24 -0700 | [diff] [blame] | 62 | filtered_sample_set_(comparator), |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 63 | use_branch_address_(false), |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 64 | build_callchain_(false), |
Yabin Cui | 0338145 | 2017-12-13 11:31:53 -0800 | [diff] [blame] | 65 | use_caller_as_callchain_root_(false) {} |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 66 | |
| 67 | virtual ~SampleTreeBuilder() {} |
| 68 | |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 69 | void SetBranchSampleOption(bool use_branch_address) { use_branch_address_ = use_branch_address; } |
Yabin Cui | b47de4a | 2015-06-08 12:27:19 -0700 | [diff] [blame] | 70 | |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 71 | void SetCallChainSampleOptions(bool accumulate_callchain, bool build_callchain, |
Yabin Cui | 6e75e1b | 2018-02-06 13:42:16 -0800 | [diff] [blame] | 72 | bool use_caller_as_callchain_root) { |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 73 | accumulate_callchain_ = accumulate_callchain; |
| 74 | build_callchain_ = build_callchain; |
| 75 | use_caller_as_callchain_root_ = use_caller_as_callchain_root; |
Yabin Cui | 0338145 | 2017-12-13 11:31:53 -0800 | [diff] [blame] | 76 | if (accumulate_callchain_) { |
Yabin Cui | 5ac7a25 | 2019-07-18 10:43:32 -0700 | [diff] [blame] | 77 | offline_unwinder_ = OfflineUnwinder::Create(false); |
Yabin Cui | 0338145 | 2017-12-13 11:31:53 -0800 | [diff] [blame] | 78 | } |
Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Yabin Cui | 91784fd | 2020-01-29 17:08:49 -0800 | [diff] [blame] | 81 | OfflineUnwinder* GetUnwinder() { return offline_unwinder_.get(); } |
| 82 | |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 83 | void ProcessSampleRecord(const SampleRecord& r) { |
| 84 | if (use_branch_address_ && (r.sample_type & PERF_SAMPLE_BRANCH_STACK)) { |
Yabin Cui | 190a848 | 2016-08-04 10:22:17 -0700 | [diff] [blame] | 85 | for (uint64_t i = 0; i < r.branch_stack_data.stack_nr; ++i) { |
| 86 | auto& item = r.branch_stack_data.stack[i]; |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 87 | if (item.from != 0 && item.to != 0) { |
| 88 | CreateBranchSample(r, item); |
| 89 | } |
| 90 | } |
| 91 | return; |
| 92 | } |
| 93 | bool in_kernel = r.InKernel(); |
| 94 | AccumulateInfoT acc_info; |
| 95 | EntryT* sample = CreateSample(r, in_kernel, &acc_info); |
| 96 | if (sample == nullptr) { |
| 97 | return; |
| 98 | } |
| 99 | if (accumulate_callchain_) { |
| 100 | std::vector<uint64_t> ips; |
| 101 | if (r.sample_type & PERF_SAMPLE_CALLCHAIN) { |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 102 | ips.insert(ips.end(), r.callchain_data.ips, r.callchain_data.ips + r.callchain_data.ip_nr); |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 103 | } |
| 104 | const ThreadEntry* thread = GetThreadOfSample(sample); |
| 105 | // Use stack_user_data.data.size() instead of stack_user_data.dyn_size, to |
| 106 | // make up for the missing kernel patch in N9. See b/22612370. |
| 107 | if (thread != nullptr && (r.sample_type & PERF_SAMPLE_REGS_USER) && |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 108 | (r.regs_user_data.reg_mask != 0) && (r.sample_type & PERF_SAMPLE_STACK_USER) && |
Yabin Cui | 190a848 | 2016-08-04 10:22:17 -0700 | [diff] [blame] | 109 | (r.GetValidStackSize() > 0)) { |
Yabin Cui | 6e75e1b | 2018-02-06 13:42:16 -0800 | [diff] [blame] | 110 | RegSet regs(r.regs_user_data.abi, r.regs_user_data.reg_mask, r.regs_user_data.regs); |
Yabin Cui | 81a9d33 | 2017-12-10 13:09:07 -0800 | [diff] [blame] | 111 | std::vector<uint64_t> user_ips; |
| 112 | std::vector<uint64_t> sps; |
Yabin Cui | 6e75e1b | 2018-02-06 13:42:16 -0800 | [diff] [blame] | 113 | if (offline_unwinder_->UnwindCallChain(*thread, regs, r.stack_user_data.data, |
| 114 | r.GetValidStackSize(), &user_ips, &sps)) { |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 115 | ips.push_back(PERF_CONTEXT_USER); |
Yabin Cui | 81a9d33 | 2017-12-10 13:09:07 -0800 | [diff] [blame] | 116 | ips.insert(ips.end(), user_ips.begin(), user_ips.end()); |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | std::vector<EntryT*> callchain; |
| 121 | callchain.push_back(sample); |
| 122 | |
| 123 | bool first_ip = true; |
| 124 | for (auto& ip : ips) { |
| 125 | if (ip >= PERF_CONTEXT_MAX) { |
| 126 | switch (ip) { |
| 127 | case PERF_CONTEXT_KERNEL: |
| 128 | in_kernel = true; |
| 129 | break; |
| 130 | case PERF_CONTEXT_USER: |
| 131 | in_kernel = false; |
| 132 | break; |
| 133 | default: |
| 134 | LOG(DEBUG) << "Unexpected perf_context in callchain: " << ip; |
| 135 | } |
| 136 | } else { |
| 137 | if (first_ip) { |
| 138 | first_ip = false; |
| 139 | // Remove duplication with sampled ip. |
| 140 | if (ip == r.ip_data.ip) { |
| 141 | continue; |
| 142 | } |
| 143 | } |
| 144 | EntryT* callchain_sample = |
Yabin Cui | 847f3fd | 2019-05-02 12:58:05 -0700 | [diff] [blame] | 145 | CreateCallChainSample(thread, sample, ip, in_kernel, callchain, acc_info); |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 146 | if (callchain_sample == nullptr) { |
| 147 | break; |
| 148 | } |
| 149 | callchain.push_back(callchain_sample); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | if (build_callchain_) { |
| 154 | std::set<EntryT*> added_set; |
| 155 | if (use_caller_as_callchain_root_) { |
| 156 | std::reverse(callchain.begin(), callchain.end()); |
| 157 | } |
Yabin Cui | 0c093f3 | 2017-04-19 11:48:44 -0700 | [diff] [blame] | 158 | EntryT* parent = nullptr; |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 159 | while (callchain.size() >= 2) { |
| 160 | EntryT* sample = callchain[0]; |
| 161 | callchain.erase(callchain.begin()); |
| 162 | // Add only once for recursive calls on callchain. |
| 163 | if (added_set.find(sample) != added_set.end()) { |
| 164 | continue; |
| 165 | } |
| 166 | added_set.insert(sample); |
| 167 | InsertCallChainForSample(sample, callchain, acc_info); |
Yabin Cui | 0c093f3 | 2017-04-19 11:48:44 -0700 | [diff] [blame] | 168 | UpdateCallChainParentInfo(sample, parent); |
| 169 | parent = sample; |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | std::vector<EntryT*> GetSamples() const { |
| 176 | std::vector<EntryT*> result; |
| 177 | for (auto& entry : sample_set_) { |
| 178 | result.push_back(entry); |
| 179 | } |
| 180 | return result; |
| 181 | } |
| 182 | |
| 183 | protected: |
| 184 | virtual EntryT* CreateSample(const SampleRecord& r, bool in_kernel, |
| 185 | AccumulateInfoT* acc_info) = 0; |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 186 | virtual EntryT* CreateBranchSample(const SampleRecord& r, const BranchStackItemType& item) = 0; |
Yabin Cui | 847f3fd | 2019-05-02 12:58:05 -0700 | [diff] [blame] | 187 | virtual EntryT* CreateCallChainSample(const ThreadEntry* thread, const EntryT* sample, |
| 188 | uint64_t ip, bool in_kernel, |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 189 | const std::vector<EntryT*>& callchain, |
| 190 | const AccumulateInfoT& acc_info) = 0; |
| 191 | virtual const ThreadEntry* GetThreadOfSample(EntryT*) = 0; |
Yabin Cui | 9970a23 | 2016-06-29 12:18:11 -0700 | [diff] [blame] | 192 | virtual uint64_t GetPeriodForCallChain(const AccumulateInfoT& acc_info) = 0; |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 193 | virtual bool FilterSample(const EntryT*) { return true; } |
| 194 | |
| 195 | virtual void UpdateSummary(const EntryT*) {} |
| 196 | |
| 197 | virtual void MergeSample(EntryT* sample1, EntryT* sample2) = 0; |
| 198 | |
| 199 | EntryT* InsertSample(std::unique_ptr<EntryT> sample) { |
Yabin Cui | 4e391de | 2021-11-02 13:28:24 -0700 | [diff] [blame] | 200 | if (sample == nullptr) { |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 201 | return nullptr; |
| 202 | } |
Yabin Cui | 4e391de | 2021-11-02 13:28:24 -0700 | [diff] [blame] | 203 | if (!FilterSample(sample.get())) { |
| 204 | // Store in filtered_sample_set_ for use in other EntryT's callchain. |
| 205 | auto it = filtered_sample_set_.find(sample.get()); |
| 206 | if (it != filtered_sample_set_.end()) { |
| 207 | return *it; |
| 208 | } |
| 209 | EntryT* result = sample.get(); |
| 210 | filtered_sample_set_.insert(sample.get()); |
| 211 | sample_storage_.push_back(std::move(sample)); |
| 212 | return result; |
| 213 | } |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 214 | UpdateSummary(sample.get()); |
| 215 | EntryT* result; |
| 216 | auto it = sample_set_.find(sample.get()); |
| 217 | if (it == sample_set_.end()) { |
| 218 | result = sample.get(); |
| 219 | sample_set_.insert(sample.get()); |
| 220 | sample_storage_.push_back(std::move(sample)); |
| 221 | } else { |
| 222 | result = *it; |
| 223 | MergeSample(*it, sample.get()); |
| 224 | } |
| 225 | return result; |
| 226 | } |
| 227 | |
| 228 | EntryT* InsertCallChainSample(std::unique_ptr<EntryT> sample, |
| 229 | const std::vector<EntryT*>& callchain) { |
| 230 | if (sample == nullptr) { |
| 231 | return nullptr; |
| 232 | } |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 233 | auto it = sample_set_.find(sample.get()); |
| 234 | if (it != sample_set_.end()) { |
| 235 | EntryT* sample = *it; |
| 236 | // Process only once for recursive function call. |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 237 | if (std::find(callchain.begin(), callchain.end(), sample) != callchain.end()) { |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 238 | return sample; |
| 239 | } |
| 240 | } |
| 241 | return InsertSample(std::move(sample)); |
| 242 | } |
| 243 | |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 244 | void InsertCallChainForSample(EntryT* sample, const std::vector<EntryT*>& callchain, |
Yabin Cui | 9970a23 | 2016-06-29 12:18:11 -0700 | [diff] [blame] | 245 | const AccumulateInfoT& acc_info) { |
| 246 | uint64_t period = GetPeriodForCallChain(acc_info); |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 247 | sample->callchain.AddCallChain(callchain, period, [&](const EntryT* s1, const EntryT* s2) { |
| 248 | return sample_comparator_.IsSameSample(s1, s2); |
| 249 | }); |
Yabin Cui | 9970a23 | 2016-06-29 12:18:11 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Yabin Cui | 0c093f3 | 2017-04-19 11:48:44 -0700 | [diff] [blame] | 252 | void AddCallChainDuplicateInfo() { |
| 253 | if (build_callchain_) { |
| 254 | for (EntryT* sample : sample_set_) { |
| 255 | auto it = callchain_parent_map_.find(sample); |
| 256 | if (it != callchain_parent_map_.end() && !it->second.has_multiple_parents) { |
| 257 | sample->callchain.duplicated = true; |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | } |
| 262 | |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 263 | std::set<EntryT*, SampleComparator<EntryT>> sample_set_; |
Yabin Cui | 6965d42 | 2016-06-15 11:41:42 -0700 | [diff] [blame] | 264 | bool accumulate_callchain_; |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 265 | |
| 266 | private: |
Yabin Cui | 0c093f3 | 2017-04-19 11:48:44 -0700 | [diff] [blame] | 267 | void UpdateCallChainParentInfo(EntryT* sample, EntryT* parent) { |
| 268 | if (parent == nullptr) { |
| 269 | return; |
| 270 | } |
| 271 | auto it = callchain_parent_map_.find(sample); |
| 272 | if (it == callchain_parent_map_.end()) { |
| 273 | CallChainParentInfo info; |
| 274 | info.parent = parent; |
| 275 | info.has_multiple_parents = false; |
| 276 | callchain_parent_map_[sample] = info; |
| 277 | } else if (it->second.parent != parent) { |
| 278 | it->second.has_multiple_parents = true; |
| 279 | } |
| 280 | } |
| 281 | |
Yabin Cui | 9970a23 | 2016-06-29 12:18:11 -0700 | [diff] [blame] | 282 | const SampleComparator<EntryT> sample_comparator_; |
Yabin Cui | 4e391de | 2021-11-02 13:28:24 -0700 | [diff] [blame] | 283 | // If a Sample/CallChainSample is filtered out, it is stored in filtered_sample_set_, |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 284 | // and only used in other EntryT's callchain. |
Yabin Cui | 4e391de | 2021-11-02 13:28:24 -0700 | [diff] [blame] | 285 | std::set<EntryT*, SampleComparator<EntryT>> filtered_sample_set_; |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 286 | std::vector<std::unique_ptr<EntryT>> sample_storage_; |
| 287 | |
Yabin Cui | 0c093f3 | 2017-04-19 11:48:44 -0700 | [diff] [blame] | 288 | struct CallChainParentInfo { |
| 289 | EntryT* parent; |
| 290 | bool has_multiple_parents; |
| 291 | }; |
| 292 | std::unordered_map<EntryT*, CallChainParentInfo> callchain_parent_map_; |
| 293 | |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 294 | bool use_branch_address_; |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 295 | bool build_callchain_; |
| 296 | bool use_caller_as_callchain_root_; |
Yabin Cui | 0338145 | 2017-12-13 11:31:53 -0800 | [diff] [blame] | 297 | std::unique_ptr<OfflineUnwinder> offline_unwinder_; |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | template <typename EntryT> |
| 301 | class SampleTreeSorter { |
| 302 | public: |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 303 | explicit SampleTreeSorter(SampleComparator<EntryT> comparator) : comparator_(comparator) {} |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 304 | |
| 305 | virtual ~SampleTreeSorter() {} |
| 306 | |
| 307 | void Sort(std::vector<EntryT*>& v, bool sort_callchain) { |
| 308 | if (sort_callchain) { |
| 309 | for (auto& sample : v) { |
| 310 | SortCallChain(sample); |
| 311 | } |
| 312 | } |
| 313 | if (!comparator_.empty()) { |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 314 | std::sort(v.begin(), v.end(), |
| 315 | [this](const EntryT* s1, const EntryT* s2) { return comparator_(s1, s2); }); |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
| 319 | protected: |
| 320 | void SortCallChain(EntryT* sample) { sample->callchain.SortByPeriod(); } |
| 321 | |
| 322 | private: |
| 323 | SampleComparator<EntryT> comparator_; |
| 324 | }; |
| 325 | |
| 326 | template <typename EntryT, typename InfoT> |
| 327 | class SampleTreeDisplayer { |
| 328 | public: |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 329 | explicit SampleTreeDisplayer(SampleDisplayer<EntryT, InfoT> displayer) : displayer_(displayer) {} |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 330 | |
| 331 | virtual ~SampleTreeDisplayer() {} |
| 332 | |
Thiébaud Weksteen | 4848ee0 | 2020-10-23 16:06:59 +0200 | [diff] [blame] | 333 | void DisplaySamples(FILE* fp, const std::vector<EntryT*>& samples, const InfoT* info) { |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 334 | displayer_.SetInfo(info); |
| 335 | for (const auto& sample : samples) { |
| 336 | displayer_.AdjustWidth(sample); |
| 337 | } |
| 338 | displayer_.PrintNames(fp); |
| 339 | for (const auto& sample : samples) { |
| 340 | displayer_.PrintSample(fp, sample); |
| 341 | } |
Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | private: |
Yabin Cui | b64a863 | 2016-05-24 18:23:33 -0700 | [diff] [blame] | 345 | SampleDisplayer<EntryT, InfoT> displayer_; |
Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 346 | }; |
| 347 | |
Yabin Cui | faa7b92 | 2021-01-11 17:35:57 -0800 | [diff] [blame] | 348 | } // namespace simpleperf |
| 349 | |
Yabin Cui | 2672dea | 2015-05-21 12:17:23 -0700 | [diff] [blame] | 350 | #endif // SIMPLE_PERF_SAMPLE_TREE_H_ |