Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: base/test/trace_event_analyzer.cc

Issue 10911268: Add some TraceAnalyzer utility methods to simplify test code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/test/trace_event_analyzer.h ('k') | base/test/trace_event_analyzer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <set> 9 #include <set>
10 10
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 if (!ParseEventsFromJson(json_events, &raw_events_)) 687 if (!ParseEventsFromJson(json_events, &raw_events_))
688 return false; 688 return false;
689 std::stable_sort(raw_events_.begin(), raw_events_.end()); 689 std::stable_sort(raw_events_.begin(), raw_events_.end());
690 ParseMetadata(); 690 ParseMetadata();
691 return true; 691 return true;
692 } 692 }
693 693
694 void TraceAnalyzer::AssociateBeginEndEvents() { 694 void TraceAnalyzer::AssociateBeginEndEvents() {
695 using trace_analyzer::Query; 695 using trace_analyzer::Query;
696 696
697 Query begin(Query::EventPhase() == Query::Phase(TRACE_EVENT_PHASE_BEGIN)); 697 Query begin(Query::EventPhaseIs(TRACE_EVENT_PHASE_BEGIN));
698 Query end(Query::EventPhase() == Query::Phase(TRACE_EVENT_PHASE_END)); 698 Query end(Query::EventPhaseIs(TRACE_EVENT_PHASE_END));
699 Query match(Query::EventName() == Query::OtherName() && 699 Query match(Query::EventName() == Query::OtherName() &&
700 Query::EventCategory() == Query::OtherCategory() && 700 Query::EventCategory() == Query::OtherCategory() &&
701 Query::EventTid() == Query::OtherTid() && 701 Query::EventTid() == Query::OtherTid() &&
702 Query::EventPid() == Query::OtherPid()); 702 Query::EventPid() == Query::OtherPid());
703 703
704 AssociateEvents(begin, end, match); 704 AssociateEvents(begin, end, match);
705 } 705 }
706 706
707 void TraceAnalyzer::AssociateAsyncBeginEndEvents() { 707 void TraceAnalyzer::AssociateAsyncBeginEndEvents() {
708 using trace_analyzer::Query; 708 using trace_analyzer::Query;
709 709
710 Query begin( 710 Query begin(
711 Query::EventPhase() == Query::Phase(TRACE_EVENT_PHASE_ASYNC_BEGIN) || 711 Query::EventPhaseIs(TRACE_EVENT_PHASE_ASYNC_BEGIN) ||
712 Query::EventPhase() == Query::Phase(TRACE_EVENT_PHASE_ASYNC_STEP)); 712 Query::EventPhaseIs(TRACE_EVENT_PHASE_ASYNC_STEP));
713 Query end(Query::EventPhase() == Query::Phase(TRACE_EVENT_PHASE_ASYNC_END) || 713 Query end(Query::EventPhaseIs(TRACE_EVENT_PHASE_ASYNC_END) ||
714 Query::EventPhase() == Query::Phase(TRACE_EVENT_PHASE_ASYNC_STEP)); 714 Query::EventPhaseIs(TRACE_EVENT_PHASE_ASYNC_STEP));
715 Query match(Query::EventName() == Query::OtherName() && 715 Query match(Query::EventName() == Query::OtherName() &&
716 Query::EventCategory() == Query::OtherCategory() && 716 Query::EventCategory() == Query::OtherCategory() &&
717 Query::EventId() == Query::OtherId()); 717 Query::EventId() == Query::OtherId());
718 718
719 AssociateEvents(begin, end, match); 719 AssociateEvents(begin, end, match);
720 } 720 }
721 721
722 void TraceAnalyzer::AssociateEvents(const Query& first, 722 void TraceAnalyzer::AssociateEvents(const Query& first,
723 const Query& second, 723 const Query& second,
724 const Query& match) { 724 const Query& match) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 } 781 }
782 } 782 }
783 } 783 }
784 784
785 size_t TraceAnalyzer::FindEvents(const Query& query, TraceEventVector* output) { 785 size_t TraceAnalyzer::FindEvents(const Query& query, TraceEventVector* output) {
786 allow_assocation_changes_ = false; 786 allow_assocation_changes_ = false;
787 output->clear(); 787 output->clear();
788 return FindMatchingEvents(raw_events_, query, output); 788 return FindMatchingEvents(raw_events_, query, output);
789 } 789 }
790 790
791 const TraceEvent* TraceAnalyzer::FindOneEvent(const Query& query) { 791 const TraceEvent* TraceAnalyzer::FindFirstOf(const Query& query) {
792 TraceEventVector output; 792 TraceEventVector output;
793 if (FindEvents(query, &output) > 0) 793 if (FindEvents(query, &output) > 0)
794 return output.front(); 794 return output.front();
795 return NULL; 795 return NULL;
796 } 796 }
797 797
798 const TraceEvent* TraceAnalyzer::FindLastOf(const Query& query) {
799 TraceEventVector output;
800 if (FindEvents(query, &output) > 0)
801 return output.back();
802 return NULL;
803 }
804
798 const std::string& TraceAnalyzer::GetThreadName( 805 const std::string& TraceAnalyzer::GetThreadName(
799 const TraceEvent::ProcessThreadID& thread) { 806 const TraceEvent::ProcessThreadID& thread) {
800 // If thread is not found, just add and return empty string. 807 // If thread is not found, just add and return empty string.
801 return thread_names_[thread]; 808 return thread_names_[thread];
802 } 809 }
803 810
804 void TraceAnalyzer::ParseMetadata() { 811 void TraceAnalyzer::ParseMetadata() {
805 for (size_t i = 0; i < raw_events_.size(); ++i) { 812 for (size_t i = 0; i < raw_events_.size(); ++i) {
806 TraceEvent& this_event = raw_events_[i]; 813 TraceEvent& this_event = raw_events_[i];
807 // Check for thread name metadata. 814 // Check for thread name metadata.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 end_position = (end_position < events.size()) ? end_position : events.size(); 957 end_position = (end_position < events.size()) ? end_position : events.size();
951 size_t count = 0u; 958 size_t count = 0u;
952 for (size_t i = begin_position; i < end_position; ++i) { 959 for (size_t i = begin_position; i < end_position; ++i) {
953 if (query.Evaluate(*events.at(i))) 960 if (query.Evaluate(*events.at(i)))
954 ++count; 961 ++count;
955 } 962 }
956 return count; 963 return count;
957 } 964 }
958 965
959 } // namespace trace_analyzer 966 } // namespace trace_analyzer
OLDNEW
« no previous file with comments | « base/test/trace_event_analyzer.h ('k') | base/test/trace_event_analyzer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698