| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 bool CoalescedDurationGreater(const Coalesced& a, const Coalesced& b) { | 64 bool CoalescedDurationGreater(const Coalesced& a, const Coalesced& b) { |
| 65 return a.total_duration > b.total_duration; | 65 return a.total_duration > b.total_duration; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void SummarizeParses(std::vector<const TraceItem*>& loads, | 68 void SummarizeParses(std::vector<const TraceItem*>& loads, |
| 69 std::ostream& out) { | 69 std::ostream& out) { |
| 70 out << "File parse times: (time in ms, name)\n"; | 70 out << "File parse times: (time in ms, name)\n"; |
| 71 | 71 |
| 72 std::sort(loads.begin(), loads.end(), &DurationGreater); | 72 std::sort(loads.begin(), loads.end(), &DurationGreater); |
| 73 for (const auto& load : loads) { | 73 for (auto* load : loads) { |
| 74 out << base::StringPrintf(" %8.2f ", load->delta().InMillisecondsF()); | 74 out << base::StringPrintf(" %8.2f ", load->delta().InMillisecondsF()); |
| 75 out << load->name() << std::endl; | 75 out << load->name() << std::endl; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 void SummarizeCoalesced(std::vector<const TraceItem*>& items, | 79 void SummarizeCoalesced(std::vector<const TraceItem*>& items, |
| 80 std::ostream& out) { | 80 std::ostream& out) { |
| 81 // Group by file name. | 81 // Group by file name. |
| 82 std::map<std::string, Coalesced> coalesced; | 82 std::map<std::string, Coalesced> coalesced; |
| 83 for (const auto& item : items) { | 83 for (auto* item : items) { |
| 84 Coalesced& c = coalesced[item->name()]; | 84 Coalesced& c = coalesced[item->name()]; |
| 85 c.name_ptr = &item->name(); | 85 c.name_ptr = &item->name(); |
| 86 c.total_duration += item->delta().InMillisecondsF(); | 86 c.total_duration += item->delta().InMillisecondsF(); |
| 87 c.count++; | 87 c.count++; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Sort by duration. | 90 // Sort by duration. |
| 91 std::vector<Coalesced> sorted; | 91 std::vector<Coalesced> sorted; |
| 92 for (const auto& pair : coalesced) | 92 for (const auto& pair : coalesced) |
| 93 sorted.push_back(pair.second); | 93 sorted.push_back(pair.second); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 return std::string(); | 179 return std::string(); |
| 180 | 180 |
| 181 std::vector<TraceItem*> events = trace_log->events(); | 181 std::vector<TraceItem*> events = trace_log->events(); |
| 182 | 182 |
| 183 // Classify all events. | 183 // Classify all events. |
| 184 std::vector<const TraceItem*> parses; | 184 std::vector<const TraceItem*> parses; |
| 185 std::vector<const TraceItem*> file_execs; | 185 std::vector<const TraceItem*> file_execs; |
| 186 std::vector<const TraceItem*> script_execs; | 186 std::vector<const TraceItem*> script_execs; |
| 187 std::vector<const TraceItem*> check_headers; | 187 std::vector<const TraceItem*> check_headers; |
| 188 int headers_checked = 0; | 188 int headers_checked = 0; |
| 189 for (const auto& event : events) { | 189 for (auto* event : events) { |
| 190 switch (event->type()) { | 190 switch (event->type()) { |
| 191 case TraceItem::TRACE_FILE_PARSE: | 191 case TraceItem::TRACE_FILE_PARSE: |
| 192 parses.push_back(event); | 192 parses.push_back(event); |
| 193 break; | 193 break; |
| 194 case TraceItem::TRACE_FILE_EXECUTE: | 194 case TraceItem::TRACE_FILE_EXECUTE: |
| 195 file_execs.push_back(event); | 195 file_execs.push_back(event); |
| 196 break; | 196 break; |
| 197 case TraceItem::TRACE_SCRIPT_EXECUTE: | 197 case TraceItem::TRACE_SCRIPT_EXECUTE: |
| 198 script_execs.push_back(event); | 198 script_execs.push_back(event); |
| 199 break; | 199 break; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 218 SummarizeFileExecs(file_execs, out); | 218 SummarizeFileExecs(file_execs, out); |
| 219 out << std::endl; | 219 out << std::endl; |
| 220 SummarizeScriptExecs(script_execs, out); | 220 SummarizeScriptExecs(script_execs, out); |
| 221 out << std::endl; | 221 out << std::endl; |
| 222 | 222 |
| 223 // Generally there will only be one header check, but it's theoretically | 223 // 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 | 224 // 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. | 225 // parallel. Just report the total of all of them. |
| 226 if (!check_headers.empty()) { | 226 if (!check_headers.empty()) { |
| 227 double check_headers_time = 0; | 227 double check_headers_time = 0; |
| 228 for (const auto& cur : check_headers) | 228 for (auto* cur : check_headers) |
| 229 check_headers_time += cur->delta().InMillisecondsF(); | 229 check_headers_time += cur->delta().InMillisecondsF(); |
| 230 | 230 |
| 231 out << "Header check time: (total time in ms, files checked)\n"; | 231 out << "Header check time: (total time in ms, files checked)\n"; |
| 232 out << base::StringPrintf(" %8.2f %d\n", | 232 out << base::StringPrintf(" %8.2f %d\n", |
| 233 check_headers_time, headers_checked); | 233 check_headers_time, headers_checked); |
| 234 } | 234 } |
| 235 | 235 |
| 236 return out.str(); | 236 return out.str(); |
| 237 } | 237 } |
| 238 | 238 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 } | 319 } |
| 320 out << "}"; | 320 out << "}"; |
| 321 } | 321 } |
| 322 | 322 |
| 323 out << "]}"; | 323 out << "]}"; |
| 324 | 324 |
| 325 std::string out_str = out.str(); | 325 std::string out_str = out.str(); |
| 326 base::WriteFile(file_name, out_str.data(), | 326 base::WriteFile(file_name, out_str.data(), |
| 327 static_cast<int>(out_str.size())); | 327 static_cast<int>(out_str.size())); |
| 328 } | 328 } |
| OLD | NEW |