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

Unified Diff: apps/benchmark/event.cc

Issue 1305193002: Trace-based benchmarking via a mojo app. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Further address Etienne's comments. Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « apps/benchmark/event.h ('k') | apps/benchmark/event_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apps/benchmark/event.cc
diff --git a/apps/benchmark/event.cc b/apps/benchmark/event.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6c528488810cada738322bd7c7c1486e4d01e2b4
--- /dev/null
+++ b/apps/benchmark/event.cc
@@ -0,0 +1,69 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/benchmark/event.h"
+
+#include "base/json/json_reader.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+
+namespace benchmark {
+
+Event::Event() {}
+
+Event::Event(std::string name,
+ std::string category,
+ base::TimeTicks timestamp,
+ base::TimeDelta duration)
+ : name(name),
+ category(category),
+ timestamp(timestamp),
+ duration(duration) {}
+
+Event::~Event() {}
+
+bool GetEvents(const std::string& trace_json, std::vector<Event>* result) {
+ result->clear();
+
+ // Parse the JSON string describing the events.
+ base::JSONReader reader;
+ scoped_ptr<base::Value> trace_data = reader.ReadToValue(trace_json);
+ if (!trace_data) {
+ return false;
+ }
+
+ base::ListValue* event_list;
+ if (!trace_data->GetAsList(&event_list))
+ return false;
+
+ for (base::Value* val : *event_list) {
+ Event event;
+ base::DictionaryValue* dict;
+ if (!val->GetAsDictionary(&dict))
+ return false;
+
+ if (!dict->GetString("name", &event.name))
+ return false;
+
+ if (!dict->GetString("cat", &event.category))
+ return false;
+
+ double timestamp;
+ if (!dict->GetDouble("ts", &timestamp))
+ return false;
+ event.timestamp = base::TimeTicks::FromInternalValue(timestamp);
+
+ // It is valid for an event to not have duration.
+ double duration;
+ if (!dict->GetDouble("dur", &duration)) {
+ event.duration = base::TimeDelta();
+ } else {
+ event.duration = base::TimeDelta::FromInternalValue(duration);
+ }
+
+ result->push_back(event);
+ }
+ return true;
+}
+} // namespace benchmark
« no previous file with comments | « apps/benchmark/event.h ('k') | apps/benchmark/event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698