OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/test/trace_event_analyzer.h" | 5 #include "base/test/trace_event_analyzer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <math.h> | 8 #include <math.h> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 return false; // Invalid trace event JSON format. | 65 return false; // Invalid trace event JSON format. |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 return true; | 69 return true; |
70 } | 70 } |
71 | 71 |
72 return false; | 72 return false; |
73 } | 73 } |
74 | 74 |
75 bool TraceEvent::GetAbsTimeToOtherEvent(double* duration) const { | 75 double TraceEvent::GetAbsTimeToOtherEvent() const { |
76 if (!other_event) | 76 return fabs(other_event->timestamp - timestamp); |
77 return false; | |
78 | |
79 *duration = fabs(other_event->timestamp - timestamp); | |
80 return true; | |
81 } | 77 } |
82 | 78 |
83 bool TraceEvent::GetArgAsString(const std::string& name, | 79 bool TraceEvent::GetArgAsString(const std::string& name, |
84 std::string* arg) const { | 80 std::string* arg) const { |
85 std::map<std::string, std::string>::const_iterator i = arg_strings.find(name); | 81 std::map<std::string, std::string>::const_iterator i = arg_strings.find(name); |
86 if (i != arg_strings.end()) { | 82 if (i != arg_strings.end()) { |
87 *arg = i->second; | 83 *arg = i->second; |
88 return true; | 84 return true; |
89 } | 85 } |
90 return false; | 86 return false; |
91 } | 87 } |
92 | 88 |
93 bool TraceEvent::GetArgAsNumber(const std::string& name, | 89 bool TraceEvent::GetArgAsNumber(const std::string& name, |
94 double* arg) const { | 90 double* arg) const { |
95 std::map<std::string, double>::const_iterator i = arg_numbers.find(name); | 91 std::map<std::string, double>::const_iterator i = arg_numbers.find(name); |
96 if (i != arg_numbers.end()) { | 92 if (i != arg_numbers.end()) { |
97 *arg = i->second; | 93 *arg = i->second; |
98 return true; | 94 return true; |
99 } | 95 } |
100 return false; | 96 return false; |
101 } | 97 } |
102 | 98 |
| 99 bool TraceEvent::HasStringArg(const std::string& name) const { |
| 100 return (arg_strings.find(name) != arg_strings.end()); |
| 101 } |
| 102 |
| 103 bool TraceEvent::HasNumberArg(const std::string& name) const { |
| 104 return (arg_numbers.find(name) != arg_numbers.end()); |
| 105 } |
| 106 |
| 107 std::string TraceEvent::GetKnownArgAsString(const std::string& name) const { |
| 108 std::string arg_string; |
| 109 if (GetArgAsString(name, &arg_string)) |
| 110 return arg_string; |
| 111 NOTREACHED(); |
| 112 return ""; |
| 113 } |
| 114 |
| 115 double TraceEvent::GetKnownArgAsDouble(const std::string& name) const { |
| 116 double arg_double; |
| 117 if (GetArgAsNumber(name, &arg_double)) |
| 118 return arg_double; |
| 119 NOTREACHED(); |
| 120 return 0; |
| 121 } |
| 122 |
| 123 int TraceEvent::GetKnownArgAsInt(const std::string& name) const { |
| 124 double arg_double; |
| 125 if (GetArgAsNumber(name, &arg_double)) |
| 126 return static_cast<int>(arg_double); |
| 127 NOTREACHED(); |
| 128 return 0; |
| 129 } |
| 130 |
| 131 bool TraceEvent::GetKnownArgAsBool(const std::string& name) const { |
| 132 double arg_double; |
| 133 if (GetArgAsNumber(name, &arg_double)) |
| 134 return (arg_double != 0.0); |
| 135 NOTREACHED(); |
| 136 return false; |
| 137 } |
| 138 |
103 // QueryNode | 139 // QueryNode |
104 | 140 |
105 QueryNode::QueryNode(const Query& query) : query_(query) { | 141 QueryNode::QueryNode(const Query& query) : query_(query) { |
106 } | 142 } |
107 | 143 |
108 QueryNode::~QueryNode() { | 144 QueryNode::~QueryNode() { |
109 } | 145 } |
110 | 146 |
111 // Query | 147 // Query |
112 | 148 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 case OTHER_PID: | 415 case OTHER_PID: |
380 return static_cast<double>(the_event->thread.process_id); | 416 return static_cast<double>(the_event->thread.process_id); |
381 case EVENT_TID: | 417 case EVENT_TID: |
382 case OTHER_TID: | 418 case OTHER_TID: |
383 return static_cast<double>(the_event->thread.thread_id); | 419 return static_cast<double>(the_event->thread.thread_id); |
384 case EVENT_TIME: | 420 case EVENT_TIME: |
385 case OTHER_TIME: | 421 case OTHER_TIME: |
386 return the_event->timestamp; | 422 return the_event->timestamp; |
387 case EVENT_DURATION: | 423 case EVENT_DURATION: |
388 { | 424 { |
389 double duration; | 425 if (the_event->has_other_event()) |
390 if (the_event->GetAbsTimeToOtherEvent(&duration)) | 426 return the_event->GetAbsTimeToOtherEvent(); |
391 return duration; | |
392 else | 427 else |
393 return base::debug::TraceValue(); | 428 return base::debug::TraceValue(); |
394 } | 429 } |
395 case EVENT_PHASE: | 430 case EVENT_PHASE: |
396 case OTHER_PHASE: | 431 case OTHER_PHASE: |
397 return static_cast<double>(the_event->phase); | 432 return static_cast<double>(the_event->phase); |
398 case EVENT_CATEGORY: | 433 case EVENT_CATEGORY: |
399 case OTHER_CATEGORY: | 434 case OTHER_CATEGORY: |
400 return the_event->category; | 435 return the_event->category; |
401 case EVENT_NAME: | 436 case EVENT_NAME: |
402 case OTHER_NAME: | 437 case OTHER_NAME: |
403 return the_event->name; | 438 return the_event->name; |
404 case EVENT_HAS_ARG: | 439 case EVENT_HAS_STRING_ARG: |
405 case OTHER_HAS_ARG: | 440 case OTHER_HAS_STRING_ARG: |
406 // Search for the argument name and return true if found. | 441 return (the_event->HasStringArg(string_) ? 1.0 : 0.0); |
407 return static_cast<double>((the_event->arg_strings.find(string_) != | 442 case EVENT_HAS_NUMBER_ARG: |
408 the_event->arg_strings.end()) || | 443 case OTHER_HAS_NUMBER_ARG: |
409 (the_event->arg_numbers.find(string_) != | 444 return (the_event->HasNumberArg(string_) ? 1.0 : 0.0); |
410 the_event->arg_numbers.end()) ? 1 : 0); | |
411 case EVENT_ARG: | 445 case EVENT_ARG: |
412 case OTHER_ARG: | 446 case OTHER_ARG: |
413 { | 447 { |
414 // Search for the argument name and return its value if found. | 448 // Search for the argument name and return its value if found. |
415 | 449 |
416 std::map<std::string, std::string>::const_iterator str_i = | 450 std::map<std::string, std::string>::const_iterator str_i = |
417 the_event->arg_strings.find(string_); | 451 the_event->arg_strings.find(string_); |
418 if (str_i != the_event->arg_strings.end()) | 452 if (str_i != the_event->arg_strings.end()) |
419 return str_i->second; | 453 return str_i->second; |
420 | 454 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 continue; | 722 continue; |
689 std::map<std::string, std::string>::const_iterator string_it = | 723 std::map<std::string, std::string>::const_iterator string_it = |
690 this_event.arg_strings.find("name"); | 724 this_event.arg_strings.find("name"); |
691 if (string_it != this_event.arg_strings.end()) | 725 if (string_it != this_event.arg_strings.end()) |
692 thread_names_[this_event.thread] = string_it->second; | 726 thread_names_[this_event.thread] = string_it->second; |
693 } | 727 } |
694 } | 728 } |
695 | 729 |
696 } // namespace trace_analyzer | 730 } // namespace trace_analyzer |
697 | 731 |
OLD | NEW |