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

Side by Side Diff: apps/benchmark/event.cc

Issue 1343413002: Make `benchmark.mojo` resilient to incorrect trace events. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « no previous file | mojo/devtools/common/mojo_benchmark » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "apps/benchmark/event.h" 5 #include "apps/benchmark/event.h"
6 6
7 #include <map> 7 #include <map>
8 #include <stack> 8 #include <stack>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 } 94 }
95 return true; 95 return true;
96 } 96 }
97 97
98 bool ParseEvents(base::ListValue* event_list, std::vector<Event>* result) { 98 bool ParseEvents(base::ListValue* event_list, std::vector<Event>* result) {
99 result->clear(); 99 result->clear();
100 100
101 for (base::Value* val : *event_list) { 101 for (base::Value* val : *event_list) {
102 base::DictionaryValue* event_dict; 102 base::DictionaryValue* event_dict;
103 if (!val->GetAsDictionary(&event_dict)) 103 if (!val->GetAsDictionary(&event_dict)) {
104 return false; 104 LOG(WARNING) << "Ignoring incorrect trace event (not a dictionary)";
105 continue;
106 }
105 107
106 Event event; 108 Event event;
107 109
108 std::string phase; 110 std::string phase;
109 if (!event_dict->GetString("ph", &phase)) { 111 if (!event_dict->GetString("ph", &phase)) {
110 LOG(ERROR) << "Incorrect trace event (missing phase)"; 112 LOG(WARNING) << "Ignoring incorrect trace event (missing phase)";
111 return false; 113 continue;
112 } 114 }
113 if (phase == "X") { 115 if (phase == "X") {
114 event.type = EventType::COMPLETE; 116 event.type = EventType::COMPLETE;
115 } else if (phase == "I") { 117 } else if (phase == "I") {
116 event.type = EventType::INSTANT; 118 event.type = EventType::INSTANT;
117 } else { 119 } else {
118 // Skip all event types we do not handle. 120 // Skip all event types we do not handle.
119 continue; 121 continue;
120 } 122 }
121 123
122 if (!event_dict->GetString("name", &event.name)) { 124 if (!event_dict->GetString("name", &event.name)) {
123 LOG(ERROR) << "Incorrect trace event (no name)"; 125 LOG(ERROR) << "Incorrect trace event (no name)";
124 return false; 126 return false;
125 } 127 }
126 128
127 if (!event_dict->GetString("cat", &event.categories)) { 129 if (!event_dict->GetString("cat", &event.categories)) {
128 LOG(ERROR) << "Incorrect trace event (no categories)"; 130 LOG(WARNING) << "Ignoring incorrect trace event (no categories)";
129 return false; 131 continue;
130 } 132 }
131 133
132 double timestamp; 134 double timestamp;
133 if (!event_dict->GetDouble("ts", &timestamp)) { 135 if (!event_dict->GetDouble("ts", &timestamp)) {
134 LOG(ERROR) << "Incorrect trace event (no timestamp)"; 136 LOG(WARNING) << "Ingoring incorrect trace event (no timestamp)";
135 return false; 137 continue;
136 } 138 }
137 event.timestamp = base::TimeTicks::FromInternalValue(timestamp); 139 event.timestamp = base::TimeTicks::FromInternalValue(timestamp);
138 140
139 if (event.type == EventType::COMPLETE) { 141 if (event.type == EventType::COMPLETE) {
140 double duration; 142 double duration;
141 if (!event_dict->GetDouble("dur", &duration)) { 143 if (!event_dict->GetDouble("dur", &duration)) {
142 LOG(ERROR) << "Incorrect complete or duration event (no duration)"; 144 LOG(WARNING) << "Ignoring incorrect complete event (no duration)";
143 return false; 145 continue;
144 } 146 }
145 147
146 event.duration = base::TimeDelta::FromInternalValue(duration); 148 event.duration = base::TimeDelta::FromInternalValue(duration);
147 } else { 149 } else {
148 event.duration = base::TimeDelta(); 150 event.duration = base::TimeDelta();
149 } 151 }
150 152
151 result->push_back(event); 153 result->push_back(event);
152 } 154 }
153 return true; 155 return true;
(...skipping 18 matching lines...) Expand all
172 } 174 }
173 175
174 if (!JoinDurationEvents(event_list)) 176 if (!JoinDurationEvents(event_list))
175 return false; 177 return false;
176 178
177 if (!ParseEvents(event_list, result)) 179 if (!ParseEvents(event_list, result))
178 return false; 180 return false;
179 return true; 181 return true;
180 } 182 }
181 } // namespace benchmark 183 } // namespace benchmark
OLDNEW
« no previous file with comments | « no previous file | mojo/devtools/common/mojo_benchmark » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698