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

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

Issue 1381933002: Fix the benchmark app to handle real-world events (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 | apps/benchmark/event_unittest.cc » ('j') | apps/benchmark/event_unittest.cc » ('J')
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string_number_conversions.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 15
15 namespace benchmark { 16 namespace benchmark {
16 17
17 Event::Event() {} 18 Event::Event() {}
18 19
19 Event::Event(EventType type, 20 Event::Event(EventType type,
20 std::string name, 21 std::string name,
21 std::string categories, 22 std::string categories,
22 base::TimeTicks timestamp, 23 base::TimeTicks timestamp,
23 base::TimeDelta duration) 24 base::TimeDelta duration)
24 : type(type), 25 : type(type),
25 name(name), 26 name(name),
26 categories(categories), 27 categories(categories),
27 timestamp(timestamp), 28 timestamp(timestamp),
28 duration(duration) {} 29 duration(duration) {}
29 30
30 Event::~Event() {} 31 Event::~Event() {}
31 32
32 namespace { 33 namespace {
33 // ID uniquely identifying an asynchronous event stack. 34 // ID uniquely identifying an asynchronous event stack.
34 struct AsyncEventStackId { 35 struct AsyncEventStackId {
35 int id; 36 std::string id;
36 std::string cat; 37 std::string cat;
37 }; 38 };
38 39
39 bool operator<(const AsyncEventStackId& t, const AsyncEventStackId& o) { 40 bool operator<(const AsyncEventStackId& t, const AsyncEventStackId& o) {
40 return t.id < o.id || (t.id == o.id && t.cat < o.cat); 41 return t.id < o.id || (t.id == o.id && t.cat < o.cat);
41 } 42 }
42 43
43 // ID uniquely identifying a duration event stack. 44 // ID uniquely identifying a duration event stack.
44 typedef int DurationEventStackId; 45 typedef int DurationEventStackId;
45 46
46 // Makes a unique id for a duration event stack. 47 // Makes a unique id for a duration event stack.
47 bool GetDurationEventStackId(base::DictionaryValue* event_dict, 48 bool GetDurationEventStackId(base::DictionaryValue* event_dict,
48 DurationEventStackId* durationId) { 49 DurationEventStackId* durationId) {
49 if (!event_dict->GetInteger("tid", durationId)) { 50 if (!event_dict->GetInteger("tid", durationId)) {
50 LOG(ERROR) << "Incorrect trace event (missing tid)."; 51 LOG(ERROR) << "Incorrect trace event (missing tid): " << *event_dict;
51 return false; 52 return false;
52 } 53 }
53 return true; 54 return true;
54 } 55 }
55 56
56 // Makes a unique key for an async event stack. 57 // Makes a unique key for an async event stack.
57 bool GetAsyncEventStackId(base::DictionaryValue* event_dict, 58 bool GetAsyncEventStackId(base::DictionaryValue* event_dict,
58 AsyncEventStackId* asyncId) { 59 AsyncEventStackId* asyncId) {
59 if (!event_dict->GetInteger("id", &asyncId->id)) { 60 const base::Value* value;
60 LOG(ERROR) << "Incorrect async trace event (missing id)."; 61 if (!event_dict->Get("id", &value)) {
62 LOG(ERROR) << "Incorrect async trace event (missing id): " << *event_dict;
61 return false; 63 return false;
62 } 64 }
63 65
64 // We can have an empty category, but it is still relevant for event merging, 66 if (value->IsType(base::Value::TYPE_INTEGER)) {
67 int id_int;
68 // We already verified the type, so it should be an integer.
69 DCHECK(value->GetAsInteger(&id_int));
70 asyncId->id = base::IntToString(id_int);
71 } else if (value->IsType(base::Value::TYPE_STRING)) {
72 DCHECK(value->GetAsString(&asyncId->id));
73 } else {
74 LOG(ERROR) << "Incorrect async trace event (id of wrong type): "
ppi 2015/10/01 13:09:44 (id of wrong type) -> (id is neither string nor in
etiennej 2015/10/01 13:25:17 Done.
75 << *event_dict;
76 }
77
78 // We can have an empty category, but it is still relevant for event
79 // merging,
ppi 2015/10/01 13:09:44 the comment block needs re-align
etiennej 2015/10/01 13:25:17 Done.
65 // per the documentation. 80 // per the documentation.
66 std::string cat; 81 std::string cat;
67 event_dict->GetString("cat", &asyncId->cat); 82 event_dict->GetString("cat", &asyncId->cat);
68 83
69 return true; 84 return true;
70 } 85 }
71 86
72 // Given a beginning event, registers its beginning for future merging. 87 // Given a beginning event, registers its beginning for future merging.
73 template <typename T> 88 template <typename T>
74 void RegisterEventBegin( 89 void RegisterEventBegin(
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } 258 }
244 259
245 if (!JoinEvents(event_list)) 260 if (!JoinEvents(event_list))
246 return false; 261 return false;
247 262
248 if (!ParseEvents(event_list, result)) 263 if (!ParseEvents(event_list, result))
249 return false; 264 return false;
250 return true; 265 return true;
251 } 266 }
252 } // namespace benchmark 267 } // namespace benchmark
OLDNEW
« no previous file with comments | « no previous file | apps/benchmark/event_unittest.cc » ('j') | apps/benchmark/event_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698