OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/trace.h" | 5 #include "tools/gn/trace.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <sstream> | 9 #include <sstream> |
10 #include <vector> | 10 #include <vector> |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 | 58 |
59 bool CoalescedDurationGreater(const Coalesced& a, const Coalesced& b) { | 59 bool CoalescedDurationGreater(const Coalesced& a, const Coalesced& b) { |
60 return a.total_duration > b.total_duration; | 60 return a.total_duration > b.total_duration; |
61 } | 61 } |
62 | 62 |
63 void SummarizeParses(std::vector<const TraceItem*>& loads, | 63 void SummarizeParses(std::vector<const TraceItem*>& loads, |
64 std::ostream& out) { | 64 std::ostream& out) { |
65 out << "File parse times: (time in ms, name)\n"; | 65 out << "File parse times: (time in ms, name)\n"; |
66 | 66 |
67 std::sort(loads.begin(), loads.end(), &DurationGreater); | 67 std::sort(loads.begin(), loads.end(), &DurationGreater); |
68 | 68 for (const auto* load : loads) { |
scottmg
2014/09/30 19:31:47
*?
| |
69 for (size_t i = 0; i < loads.size(); i++) { | 69 out << base::StringPrintf(" %8.2f ", load->delta().InMillisecondsF()); |
70 out << base::StringPrintf(" %8.2f ", | 70 out << load->name() << std::endl; |
71 loads[i]->delta().InMillisecondsF()); | |
72 out << loads[i]->name() << std::endl; | |
73 } | 71 } |
74 } | 72 } |
75 | 73 |
76 void SummarizeCoalesced(std::vector<const TraceItem*>& items, | 74 void SummarizeCoalesced(std::vector<const TraceItem*>& items, |
77 std::ostream& out) { | 75 std::ostream& out) { |
78 // Group by file name. | 76 // Group by file name. |
79 std::map<std::string, Coalesced> coalesced; | 77 std::map<std::string, Coalesced> coalesced; |
80 for (size_t i = 0; i < items.size(); i++) { | 78 for (const auto& item : items) { |
81 Coalesced& c = coalesced[items[i]->name()]; | 79 Coalesced& c = coalesced[item->name()]; |
82 c.name_ptr = &items[i]->name(); | 80 c.name_ptr = &item->name(); |
83 c.total_duration += items[i]->delta().InMillisecondsF(); | 81 c.total_duration += item->delta().InMillisecondsF(); |
84 c.count++; | 82 c.count++; |
85 } | 83 } |
86 | 84 |
87 // Sort by duration. | 85 // Sort by duration. |
88 std::vector<Coalesced> sorted; | 86 std::vector<Coalesced> sorted; |
89 for (std::map<std::string, Coalesced>::iterator iter = coalesced.begin(); | 87 for (const auto& pair : coalesced) |
90 iter != coalesced.end(); ++iter) | 88 sorted.push_back(pair.second); |
91 sorted.push_back(iter->second); | |
92 std::sort(sorted.begin(), sorted.end(), &CoalescedDurationGreater); | 89 std::sort(sorted.begin(), sorted.end(), &CoalescedDurationGreater); |
93 | 90 |
94 for (size_t i = 0; i < sorted.size(); i++) { | 91 for (const auto& cur : sorted) { |
95 out << base::StringPrintf(" %8.2f %d ", | 92 out << base::StringPrintf(" %8.2f %d ", cur.total_duration, cur.count); |
96 sorted[i].total_duration, sorted[i].count); | 93 out << *cur.name_ptr << std::endl; |
97 out << *sorted[i].name_ptr << std::endl; | |
98 } | 94 } |
99 } | 95 } |
100 | 96 |
101 void SummarizeFileExecs(std::vector<const TraceItem*>& execs, | 97 void SummarizeFileExecs(std::vector<const TraceItem*>& execs, |
102 std::ostream& out) { | 98 std::ostream& out) { |
103 out << "File execute times: (total time in ms, # executions, name)\n"; | 99 out << "File execute times: (total time in ms, # executions, name)\n"; |
104 SummarizeCoalesced(execs, out); | 100 SummarizeCoalesced(execs, out); |
105 } | 101 } |
106 | 102 |
107 void SummarizeScriptExecs(std::vector<const TraceItem*>& execs, | 103 void SummarizeScriptExecs(std::vector<const TraceItem*>& execs, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 return std::string(); | 176 return std::string(); |
181 | 177 |
182 std::vector<TraceItem*> events = trace_log->events(); | 178 std::vector<TraceItem*> events = trace_log->events(); |
183 | 179 |
184 // Classify all events. | 180 // Classify all events. |
185 std::vector<const TraceItem*> parses; | 181 std::vector<const TraceItem*> parses; |
186 std::vector<const TraceItem*> file_execs; | 182 std::vector<const TraceItem*> file_execs; |
187 std::vector<const TraceItem*> script_execs; | 183 std::vector<const TraceItem*> script_execs; |
188 std::vector<const TraceItem*> check_headers; | 184 std::vector<const TraceItem*> check_headers; |
189 int headers_checked = 0; | 185 int headers_checked = 0; |
190 for (size_t i = 0; i < events.size(); i++) { | 186 for (const auto& event : events) { |
191 switch (events[i]->type()) { | 187 switch (event->type()) { |
192 case TraceItem::TRACE_FILE_PARSE: | 188 case TraceItem::TRACE_FILE_PARSE: |
193 parses.push_back(events[i]); | 189 parses.push_back(event); |
194 break; | 190 break; |
195 case TraceItem::TRACE_FILE_EXECUTE: | 191 case TraceItem::TRACE_FILE_EXECUTE: |
196 file_execs.push_back(events[i]); | 192 file_execs.push_back(event); |
197 break; | 193 break; |
198 case TraceItem::TRACE_SCRIPT_EXECUTE: | 194 case TraceItem::TRACE_SCRIPT_EXECUTE: |
199 script_execs.push_back(events[i]); | 195 script_execs.push_back(event); |
200 break; | 196 break; |
201 case TraceItem::TRACE_CHECK_HEADERS: | 197 case TraceItem::TRACE_CHECK_HEADERS: |
202 check_headers.push_back(events[i]); | 198 check_headers.push_back(event); |
203 break; | 199 break; |
204 case TraceItem::TRACE_CHECK_HEADER: | 200 case TraceItem::TRACE_CHECK_HEADER: |
205 headers_checked++; | 201 headers_checked++; |
206 break; | 202 break; |
207 case TraceItem::TRACE_SETUP: | 203 case TraceItem::TRACE_SETUP: |
208 case TraceItem::TRACE_FILE_LOAD: | 204 case TraceItem::TRACE_FILE_LOAD: |
209 case TraceItem::TRACE_FILE_WRITE: | 205 case TraceItem::TRACE_FILE_WRITE: |
210 case TraceItem::TRACE_DEFINE_TARGET: | 206 case TraceItem::TRACE_DEFINE_TARGET: |
211 break; // Ignore these for the summary. | 207 break; // Ignore these for the summary. |
212 } | 208 } |
213 } | 209 } |
214 | 210 |
215 std::ostringstream out; | 211 std::ostringstream out; |
216 SummarizeParses(parses, out); | 212 SummarizeParses(parses, out); |
217 out << std::endl; | 213 out << std::endl; |
218 SummarizeFileExecs(file_execs, out); | 214 SummarizeFileExecs(file_execs, out); |
219 out << std::endl; | 215 out << std::endl; |
220 SummarizeScriptExecs(script_execs, out); | 216 SummarizeScriptExecs(script_execs, out); |
221 out << std::endl; | 217 out << std::endl; |
222 | 218 |
223 // Generally there will only be one header check, but it's theoretically | 219 // Generally there will only be one header check, but it's theoretically |
224 // possible for more than one to run if more than one build is going in | 220 // possible for more than one to run if more than one build is going in |
225 // parallel. Just report the total of all of them. | 221 // parallel. Just report the total of all of them. |
226 if (!check_headers.empty()) { | 222 if (!check_headers.empty()) { |
227 float check_headers_time = 0; | 223 float check_headers_time = 0; |
228 for (size_t i = 0; i < check_headers.size(); i++) | 224 for (const auto& cur : check_headers) |
229 check_headers_time += check_headers[i]->delta().InMillisecondsF(); | 225 check_headers_time += cur->delta().InMillisecondsF(); |
230 | 226 |
231 out << "Header check time: (total time in ms, files checked)\n"; | 227 out << "Header check time: (total time in ms, files checked)\n"; |
232 out << base::StringPrintf(" %8.2f %d\n", | 228 out << base::StringPrintf(" %8.2f %d\n", |
233 check_headers_time, headers_checked); | 229 check_headers_time, headers_checked); |
234 } | 230 } |
235 | 231 |
236 return out.str(); | 232 return out.str(); |
237 } | 233 } |
238 | 234 |
239 void SaveTraces(const base::FilePath& file_name) { | 235 void SaveTraces(const base::FilePath& file_name) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 } | 312 } |
317 out << "}"; | 313 out << "}"; |
318 } | 314 } |
319 | 315 |
320 out << "]}"; | 316 out << "]}"; |
321 | 317 |
322 std::string out_str = out.str(); | 318 std::string out_str = out.str(); |
323 base::WriteFile(file_name, out_str.data(), | 319 base::WriteFile(file_name, out_str.data(), |
324 static_cast<int>(out_str.size())); | 320 static_cast<int>(out_str.size())); |
325 } | 321 } |
OLD | NEW |