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

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

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« 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 <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory>
10 #include <set> 11 #include <set>
11 12
12 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/pattern.h" 14 #include "base/strings/pattern.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 16
17 namespace trace_analyzer { 17 namespace trace_analyzer {
18 18
19 // TraceEvent 19 // TraceEvent
20 20
21 TraceEvent::TraceEvent() 21 TraceEvent::TraceEvent()
22 : thread(0, 0), 22 : thread(0, 0),
23 timestamp(0), 23 timestamp(0),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 double* arg) const { 137 double* arg) const {
138 const auto it = arg_numbers.find(name); 138 const auto it = arg_numbers.find(name);
139 if (it != arg_numbers.end()) { 139 if (it != arg_numbers.end()) {
140 *arg = it->second; 140 *arg = it->second;
141 return true; 141 return true;
142 } 142 }
143 return false; 143 return false;
144 } 144 }
145 145
146 bool TraceEvent::GetArgAsValue(const std::string& name, 146 bool TraceEvent::GetArgAsValue(const std::string& name,
147 scoped_ptr<base::Value>* arg) const { 147 std::unique_ptr<base::Value>* arg) const {
148 const auto it = arg_values.find(name); 148 const auto it = arg_values.find(name);
149 if (it != arg_values.end()) { 149 if (it != arg_values.end()) {
150 *arg = it->second->CreateDeepCopy(); 150 *arg = it->second->CreateDeepCopy();
151 return true; 151 return true;
152 } 152 }
153 return false; 153 return false;
154 } 154 }
155 155
156 bool TraceEvent::HasStringArg(const std::string& name) const { 156 bool TraceEvent::HasStringArg(const std::string& name) const {
157 return (arg_strings.find(name) != arg_strings.end()); 157 return (arg_strings.find(name) != arg_strings.end());
(...skipping 28 matching lines...) Expand all
186 return static_cast<int>(arg_double); 186 return static_cast<int>(arg_double);
187 } 187 }
188 188
189 bool TraceEvent::GetKnownArgAsBool(const std::string& name) const { 189 bool TraceEvent::GetKnownArgAsBool(const std::string& name) const {
190 double arg_double = 0; 190 double arg_double = 0;
191 bool result = GetArgAsNumber(name, &arg_double); 191 bool result = GetArgAsNumber(name, &arg_double);
192 DCHECK(result); 192 DCHECK(result);
193 return (arg_double != 0.0); 193 return (arg_double != 0.0);
194 } 194 }
195 195
196 scoped_ptr<base::Value> TraceEvent::GetKnownArgAsValue( 196 std::unique_ptr<base::Value> TraceEvent::GetKnownArgAsValue(
197 const std::string& name) const { 197 const std::string& name) const {
198 scoped_ptr<base::Value> arg_value; 198 std::unique_ptr<base::Value> arg_value;
199 bool result = GetArgAsValue(name, &arg_value); 199 bool result = GetArgAsValue(name, &arg_value);
200 DCHECK(result); 200 DCHECK(result);
201 return arg_value; 201 return arg_value;
202 } 202 }
203 203
204 // QueryNode 204 // QueryNode
205 205
206 QueryNode::QueryNode(const Query& query) : query_(query) { 206 QueryNode::QueryNode(const Query& query) : query_(query) {
207 } 207 }
208 208
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 if (ignore_metadata_events && events[i].phase == TRACE_EVENT_PHASE_METADATA) 672 if (ignore_metadata_events && events[i].phase == TRACE_EVENT_PHASE_METADATA)
673 continue; 673 continue;
674 if (query.Evaluate(events[i])) 674 if (query.Evaluate(events[i]))
675 output->push_back(&events[i]); 675 output->push_back(&events[i]);
676 } 676 }
677 return output->size(); 677 return output->size();
678 } 678 }
679 679
680 bool ParseEventsFromJson(const std::string& json, 680 bool ParseEventsFromJson(const std::string& json,
681 std::vector<TraceEvent>* output) { 681 std::vector<TraceEvent>* output) {
682 scoped_ptr<base::Value> root = base::JSONReader::Read(json); 682 std::unique_ptr<base::Value> root = base::JSONReader::Read(json);
683 683
684 base::ListValue* root_list = NULL; 684 base::ListValue* root_list = NULL;
685 if (!root.get() || !root->GetAsList(&root_list)) 685 if (!root.get() || !root->GetAsList(&root_list))
686 return false; 686 return false;
687 687
688 for (size_t i = 0; i < root_list->GetSize(); ++i) { 688 for (size_t i = 0; i < root_list->GetSize(); ++i) {
689 base::Value* item = NULL; 689 base::Value* item = NULL;
690 if (root_list->Get(i, &item)) { 690 if (root_list->Get(i, &item)) {
691 TraceEvent event; 691 TraceEvent event;
692 if (event.SetFromJSON(item)) 692 if (event.SetFromJSON(item))
(...skipping 12 matching lines...) Expand all
705 705
706 TraceAnalyzer::TraceAnalyzer() 706 TraceAnalyzer::TraceAnalyzer()
707 : ignore_metadata_events_(false), 707 : ignore_metadata_events_(false),
708 allow_assocation_changes_(true) {} 708 allow_assocation_changes_(true) {}
709 709
710 TraceAnalyzer::~TraceAnalyzer() { 710 TraceAnalyzer::~TraceAnalyzer() {
711 } 711 }
712 712
713 // static 713 // static
714 TraceAnalyzer* TraceAnalyzer::Create(const std::string& json_events) { 714 TraceAnalyzer* TraceAnalyzer::Create(const std::string& json_events) {
715 scoped_ptr<TraceAnalyzer> analyzer(new TraceAnalyzer()); 715 std::unique_ptr<TraceAnalyzer> analyzer(new TraceAnalyzer());
716 if (analyzer->SetEvents(json_events)) 716 if (analyzer->SetEvents(json_events))
717 return analyzer.release(); 717 return analyzer.release();
718 return NULL; 718 return NULL;
719 } 719 }
720 720
721 bool TraceAnalyzer::SetEvents(const std::string& json_events) { 721 bool TraceAnalyzer::SetEvents(const std::string& json_events) {
722 raw_events_.clear(); 722 raw_events_.clear();
723 if (!ParseEventsFromJson(json_events, &raw_events_)) 723 if (!ParseEventsFromJson(json_events, &raw_events_))
724 return false; 724 return false;
725 std::stable_sort(raw_events_.begin(), raw_events_.end()); 725 std::stable_sort(raw_events_.begin(), raw_events_.end());
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 end_position = (end_position < events.size()) ? end_position : events.size(); 990 end_position = (end_position < events.size()) ? end_position : events.size();
991 size_t count = 0u; 991 size_t count = 0u;
992 for (size_t i = begin_position; i < end_position; ++i) { 992 for (size_t i = begin_position; i < end_position; ++i) {
993 if (query.Evaluate(*events.at(i))) 993 if (query.Evaluate(*events.at(i)))
994 ++count; 994 ++count;
995 } 995 }
996 return count; 996 return count;
997 } 997 }
998 998
999 } // namespace trace_analyzer 999 } // 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