| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 const std::string& TraceAnalyzer::GetThreadName( | 710 const std::string& TraceAnalyzer::GetThreadName( |
| 711 const TraceEvent::ProcessThreadID& thread) { | 711 const TraceEvent::ProcessThreadID& thread) { |
| 712 // If thread is not found, just add and return empty string. | 712 // If thread is not found, just add and return empty string. |
| 713 return thread_names_[thread]; | 713 return thread_names_[thread]; |
| 714 } | 714 } |
| 715 | 715 |
| 716 void TraceAnalyzer::ParseMetadata() { | 716 void TraceAnalyzer::ParseMetadata() { |
| 717 for (size_t i = 0; i < raw_events_.size(); ++i) { | 717 for (size_t i = 0; i < raw_events_.size(); ++i) { |
| 718 TraceEvent& this_event = raw_events_[i]; | 718 TraceEvent& this_event = raw_events_[i]; |
| 719 // Check for thread name metadata. | 719 // Check for thread name metadata. |
| 720 if (this_event.phase != base::debug::TRACE_EVENT_PHASE_METADATA || | 720 if (this_event.phase != TRACE_EVENT_PHASE_METADATA || |
| 721 this_event.name != "thread_name") | 721 this_event.name != "thread_name") |
| 722 continue; | 722 continue; |
| 723 std::map<std::string, std::string>::const_iterator string_it = | 723 std::map<std::string, std::string>::const_iterator string_it = |
| 724 this_event.arg_strings.find("name"); | 724 this_event.arg_strings.find("name"); |
| 725 if (string_it != this_event.arg_strings.end()) | 725 if (string_it != this_event.arg_strings.end()) |
| 726 thread_names_[this_event.thread] = string_it->second; | 726 thread_names_[this_event.thread] = string_it->second; |
| 727 } | 727 } |
| 728 } | 728 } |
| 729 | 729 |
| 730 } // namespace trace_analyzer | 730 } // namespace trace_analyzer |
| 731 | 731 |
| OLD | NEW |