| OLD | NEW |
| 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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 number_(0) { | 627 number_(0) { |
| 628 type_ = (unary_op < OP_ADD ? | 628 type_ = (unary_op < OP_ADD ? |
| 629 QUERY_BOOLEAN_OPERATOR : QUERY_ARITHMETIC_OPERATOR); | 629 QUERY_BOOLEAN_OPERATOR : QUERY_ARITHMETIC_OPERATOR); |
| 630 } | 630 } |
| 631 | 631 |
| 632 namespace { | 632 namespace { |
| 633 | 633 |
| 634 // Search |events| for |query| and add matches to |output|. | 634 // Search |events| for |query| and add matches to |output|. |
| 635 size_t FindMatchingEvents(const std::vector<TraceEvent>& events, | 635 size_t FindMatchingEvents(const std::vector<TraceEvent>& events, |
| 636 const Query& query, | 636 const Query& query, |
| 637 TraceEventVector* output) { | 637 TraceEventVector* output, |
| 638 bool ignore_metadata_events) { |
| 638 for (size_t i = 0; i < events.size(); ++i) { | 639 for (size_t i = 0; i < events.size(); ++i) { |
| 640 if (ignore_metadata_events && events[i].phase == TRACE_EVENT_PHASE_METADATA) |
| 641 continue; |
| 639 if (query.Evaluate(events[i])) | 642 if (query.Evaluate(events[i])) |
| 640 output->push_back(&events[i]); | 643 output->push_back(&events[i]); |
| 641 } | 644 } |
| 642 return output->size(); | 645 return output->size(); |
| 643 } | 646 } |
| 644 | 647 |
| 645 bool ParseEventsFromJson(const std::string& json, | 648 bool ParseEventsFromJson(const std::string& json, |
| 646 std::vector<TraceEvent>* output) { | 649 std::vector<TraceEvent>* output) { |
| 647 scoped_ptr<base::Value> root; | 650 scoped_ptr<base::Value> root; |
| 648 root.reset(base::JSONReader::Read(json)); | 651 root.reset(base::JSONReader::Read(json)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 662 } | 665 } |
| 663 } | 666 } |
| 664 | 667 |
| 665 return true; | 668 return true; |
| 666 } | 669 } |
| 667 | 670 |
| 668 } // namespace | 671 } // namespace |
| 669 | 672 |
| 670 // TraceAnalyzer | 673 // TraceAnalyzer |
| 671 | 674 |
| 672 TraceAnalyzer::TraceAnalyzer() : allow_assocation_changes_(true) { | 675 TraceAnalyzer::TraceAnalyzer() |
| 673 } | 676 : ignore_metadata_events_(false), |
| 677 allow_assocation_changes_(true) {} |
| 674 | 678 |
| 675 TraceAnalyzer::~TraceAnalyzer() { | 679 TraceAnalyzer::~TraceAnalyzer() { |
| 676 } | 680 } |
| 677 | 681 |
| 678 // static | 682 // static |
| 679 TraceAnalyzer* TraceAnalyzer::Create(const std::string& json_events) { | 683 TraceAnalyzer* TraceAnalyzer::Create(const std::string& json_events) { |
| 680 scoped_ptr<TraceAnalyzer> analyzer(new TraceAnalyzer()); | 684 scoped_ptr<TraceAnalyzer> analyzer(new TraceAnalyzer()); |
| 681 if (analyzer->SetEvents(json_events)) | 685 if (analyzer->SetEvents(json_events)) |
| 682 return analyzer.release(); | 686 return analyzer.release(); |
| 683 return NULL; | 687 return NULL; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 other->arg_strings.begin(), | 785 other->arg_strings.begin(), |
| 782 other->arg_strings.end()); | 786 other->arg_strings.end()); |
| 783 other = other->other_event; | 787 other = other->other_event; |
| 784 } | 788 } |
| 785 } | 789 } |
| 786 } | 790 } |
| 787 | 791 |
| 788 size_t TraceAnalyzer::FindEvents(const Query& query, TraceEventVector* output) { | 792 size_t TraceAnalyzer::FindEvents(const Query& query, TraceEventVector* output) { |
| 789 allow_assocation_changes_ = false; | 793 allow_assocation_changes_ = false; |
| 790 output->clear(); | 794 output->clear(); |
| 791 return FindMatchingEvents(raw_events_, query, output); | 795 return FindMatchingEvents( |
| 796 raw_events_, query, output, ignore_metadata_events_); |
| 792 } | 797 } |
| 793 | 798 |
| 794 const TraceEvent* TraceAnalyzer::FindFirstOf(const Query& query) { | 799 const TraceEvent* TraceAnalyzer::FindFirstOf(const Query& query) { |
| 795 TraceEventVector output; | 800 TraceEventVector output; |
| 796 if (FindEvents(query, &output) > 0) | 801 if (FindEvents(query, &output) > 0) |
| 797 return output.front(); | 802 return output.front(); |
| 798 return NULL; | 803 return NULL; |
| 799 } | 804 } |
| 800 | 805 |
| 801 const TraceEvent* TraceAnalyzer::FindLastOf(const Query& query) { | 806 const TraceEvent* TraceAnalyzer::FindLastOf(const Query& query) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 end_position = (end_position < events.size()) ? end_position : events.size(); | 959 end_position = (end_position < events.size()) ? end_position : events.size(); |
| 955 size_t count = 0u; | 960 size_t count = 0u; |
| 956 for (size_t i = begin_position; i < end_position; ++i) { | 961 for (size_t i = begin_position; i < end_position; ++i) { |
| 957 if (query.Evaluate(*events.at(i))) | 962 if (query.Evaluate(*events.at(i))) |
| 958 ++count; | 963 ++count; |
| 959 } | 964 } |
| 960 return count; | 965 return count; |
| 961 } | 966 } |
| 962 | 967 |
| 963 } // namespace trace_analyzer | 968 } // namespace trace_analyzer |
| OLD | NEW |