Make `benchmark.mojo` resilient to incorrect trace events. This patch majes `benchmark.mojo` print a warning and ignore incorrect events instead of failing hard. The warnings are surfaced in `mojo_benchmark`. Fixes #425. R=qsr@chromium.org Review URL: https://codereview.chromium.org/1343413002 .
diff --git a/apps/benchmark/event.cc b/apps/benchmark/event.cc index e782b57..74dc83b 100644 --- a/apps/benchmark/event.cc +++ b/apps/benchmark/event.cc
@@ -100,15 +100,17 @@ for (base::Value* val : *event_list) { base::DictionaryValue* event_dict; - if (!val->GetAsDictionary(&event_dict)) - return false; + if (!val->GetAsDictionary(&event_dict)) { + LOG(WARNING) << "Ignoring incorrect trace event (not a dictionary)"; + continue; + } Event event; std::string phase; if (!event_dict->GetString("ph", &phase)) { - LOG(ERROR) << "Incorrect trace event (missing phase)"; - return false; + LOG(WARNING) << "Ignoring incorrect trace event (missing phase)"; + continue; } if (phase == "X") { event.type = EventType::COMPLETE; @@ -125,22 +127,22 @@ } if (!event_dict->GetString("cat", &event.categories)) { - LOG(ERROR) << "Incorrect trace event (no categories)"; - return false; + LOG(WARNING) << "Ignoring incorrect trace event (no categories)"; + continue; } double timestamp; if (!event_dict->GetDouble("ts", ×tamp)) { - LOG(ERROR) << "Incorrect trace event (no timestamp)"; - return false; + LOG(WARNING) << "Ingoring incorrect trace event (no timestamp)"; + continue; } event.timestamp = base::TimeTicks::FromInternalValue(timestamp); if (event.type == EventType::COMPLETE) { double duration; if (!event_dict->GetDouble("dur", &duration)) { - LOG(ERROR) << "Incorrect complete or duration event (no duration)"; - return false; + LOG(WARNING) << "Ignoring incorrect complete event (no duration)"; + continue; } event.duration = base::TimeDelta::FromInternalValue(duration);
diff --git a/mojo/devtools/common/mojo_benchmark b/mojo/devtools/common/mojo_benchmark index a8191f5..5373d35 100755 --- a/mojo/devtools/common/mojo_benchmark +++ b/mojo/devtools/common/mojo_benchmark
@@ -97,7 +97,7 @@ # Echo measurement results. for line in output_lines: - if line.strip().startswith('measurement:'): + if line.strip().startswith('measurement:') or 'WARNING' in line: print line return True