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

Side by Side 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, 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 | « apps/benchmark/event.h ('k') | apps/benchmark/event_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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "apps/benchmark/event.h"
6
7 #include "base/json/json_reader.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10
11 namespace benchmark {
12
13 Event::Event() {}
14
15 Event::Event(std::string name,
16 std::string category,
17 base::TimeTicks timestamp,
18 base::TimeDelta duration)
19 : name(name),
20 category(category),
21 timestamp(timestamp),
22 duration(duration) {}
23
24 Event::~Event() {}
25
26 bool GetEvents(const std::string& trace_json, std::vector<Event>* result) {
27 result->clear();
28
29 // Parse the JSON string describing the events.
30 base::JSONReader reader;
31 scoped_ptr<base::Value> trace_data = reader.ReadToValue(trace_json);
32 if (!trace_data) {
33 return false;
34 }
35
36 base::ListValue* event_list;
37 if (!trace_data->GetAsList(&event_list))
38 return false;
39
40 for (base::Value* val : *event_list) {
41 Event event;
42 base::DictionaryValue* dict;
43 if (!val->GetAsDictionary(&dict))
44 return false;
45
46 if (!dict->GetString("name", &event.name))
47 return false;
48
49 if (!dict->GetString("cat", &event.category))
50 return false;
51
52 double timestamp;
53 if (!dict->GetDouble("ts", &timestamp))
54 return false;
55 event.timestamp = base::TimeTicks::FromInternalValue(timestamp);
56
57 // It is valid for an event to not have duration.
58 double duration;
59 if (!dict->GetDouble("dur", &duration)) {
60 event.duration = base::TimeDelta();
61 } else {
62 event.duration = base::TimeDelta::FromInternalValue(duration);
63 }
64
65 result->push_back(event);
66 }
67 return true;
68 }
69 } // namespace benchmark
OLDNEW
« 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