| 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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 | 13 |
| 14 namespace trace_analyzer { | 14 namespace trace_analyzer { |
| 15 | 15 |
| 16 // TraceEvent | 16 // TraceEvent |
| 17 | 17 |
| 18 TraceEvent::TraceEvent() | 18 TraceEvent::TraceEvent() |
| 19 : thread(0, 0), | 19 : thread(0, 0), |
| 20 timestamp(0), | 20 timestamp(0), |
| 21 phase(base::debug::TRACE_EVENT_PHASE_BEGIN), | 21 phase(TRACE_EVENT_PHASE_BEGIN), |
| 22 other_event(NULL) { | 22 other_event(NULL) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 TraceEvent::~TraceEvent() { | 25 TraceEvent::~TraceEvent() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool TraceEvent::SetFromJSON(const base::Value* event_value) { | 28 bool TraceEvent::SetFromJSON(const base::Value* event_value) { |
| 29 if (event_value->GetType() != base::Value::TYPE_DICTIONARY) | 29 if (event_value->GetType() != base::Value::TYPE_DICTIONARY) |
| 30 return false; | 30 return false; |
| 31 const base::DictionaryValue* dictionary = | 31 const base::DictionaryValue* dictionary = |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 return false; | 635 return false; |
| 636 std::stable_sort(raw_events_.begin(), raw_events_.end()); | 636 std::stable_sort(raw_events_.begin(), raw_events_.end()); |
| 637 ParseMetadata(); | 637 ParseMetadata(); |
| 638 return true; | 638 return true; |
| 639 } | 639 } |
| 640 | 640 |
| 641 void TraceAnalyzer::AssociateBeginEndEvents() { | 641 void TraceAnalyzer::AssociateBeginEndEvents() { |
| 642 using namespace trace_analyzer; | 642 using namespace trace_analyzer; |
| 643 | 643 |
| 644 Query begin(Query(EVENT_PHASE) == | 644 Query begin(Query(EVENT_PHASE) == |
| 645 Query::Phase(base::debug::TRACE_EVENT_PHASE_BEGIN)); | 645 Query::Phase(TRACE_EVENT_PHASE_BEGIN)); |
| 646 Query end(Query(EVENT_PHASE) == | 646 Query end(Query(EVENT_PHASE) == |
| 647 Query::Phase(base::debug::TRACE_EVENT_PHASE_END)); | 647 Query::Phase(TRACE_EVENT_PHASE_END)); |
| 648 Query match(Query(EVENT_NAME) == Query(OTHER_NAME) && | 648 Query match(Query(EVENT_NAME) == Query(OTHER_NAME) && |
| 649 Query(EVENT_CATEGORY) == Query(OTHER_CATEGORY) && | 649 Query(EVENT_CATEGORY) == Query(OTHER_CATEGORY) && |
| 650 Query(EVENT_TID) == Query(OTHER_TID) && | 650 Query(EVENT_TID) == Query(OTHER_TID) && |
| 651 Query(EVENT_PID) == Query(OTHER_PID)); | 651 Query(EVENT_PID) == Query(OTHER_PID)); |
| 652 | 652 |
| 653 AssociateEvents(begin, end, match); | 653 AssociateEvents(begin, end, match); |
| 654 } | 654 } |
| 655 | 655 |
| 656 void TraceAnalyzer::AssociateEvents(const Query& first, | 656 void TraceAnalyzer::AssociateEvents(const Query& first, |
| 657 const Query& second, | 657 const Query& second, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 stats->standard_deviation_us = | 745 stats->standard_deviation_us = |
| 746 sum_mean_offsets_squared / static_cast<double>(num_deltas - 1); | 746 sum_mean_offsets_squared / static_cast<double>(num_deltas - 1); |
| 747 | 747 |
| 748 return true; | 748 return true; |
| 749 } | 749 } |
| 750 | 750 |
| 751 void TraceAnalyzer::ParseMetadata() { | 751 void TraceAnalyzer::ParseMetadata() { |
| 752 for (size_t i = 0; i < raw_events_.size(); ++i) { | 752 for (size_t i = 0; i < raw_events_.size(); ++i) { |
| 753 TraceEvent& this_event = raw_events_[i]; | 753 TraceEvent& this_event = raw_events_[i]; |
| 754 // Check for thread name metadata. | 754 // Check for thread name metadata. |
| 755 if (this_event.phase != base::debug::TRACE_EVENT_PHASE_METADATA || | 755 if (this_event.phase != TRACE_EVENT_PHASE_METADATA || |
| 756 this_event.name != "thread_name") | 756 this_event.name != "thread_name") |
| 757 continue; | 757 continue; |
| 758 std::map<std::string, std::string>::const_iterator string_it = | 758 std::map<std::string, std::string>::const_iterator string_it = |
| 759 this_event.arg_strings.find("name"); | 759 this_event.arg_strings.find("name"); |
| 760 if (string_it != this_event.arg_strings.end()) | 760 if (string_it != this_event.arg_strings.end()) |
| 761 thread_names_[this_event.thread] = string_it->second; | 761 thread_names_[this_event.thread] = string_it->second; |
| 762 } | 762 } |
| 763 } | 763 } |
| 764 | 764 |
| 765 } // namespace trace_analyzer | 765 } // namespace trace_analyzer |
| 766 | 766 |
| OLD | NEW |