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

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

Issue 1641513004: Update //base to chromium 9659b08ea5a34f889dc4166217f438095ddc10d2 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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/benchmark_app.cc ('k') | base/BUILD.gn » ('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 <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 event_specs[1] = 87 event_specs[1] =
88 "{\"tid\":1,\"ts\":2,\"ph\":\"B\",\"cat\":\"cc\",\"name\":\"Inner " 88 "{\"tid\":1,\"ts\":2,\"ph\":\"B\",\"cat\":\"cc\",\"name\":\"Inner "
89 "event\"}"; 89 "event\"}";
90 event_specs[2] = "{\"tid\":1,\"ts\":3,\"ph\":\"E\"}"; 90 event_specs[2] = "{\"tid\":1,\"ts\":3,\"ph\":\"E\"}";
91 event_specs[3] = "{\"tid\":1,\"ts\":4,\"ph\":\"E\"}"; 91 event_specs[3] = "{\"tid\":1,\"ts\":4,\"ph\":\"E\"}";
92 event_specs[4] = 92 event_specs[4] =
93 "{\"tid\":1,\"ts\":5,\"ph\":\"B\",\"cat\":\"cc\",\"name\":\"Next " 93 "{\"tid\":1,\"ts\":5,\"ph\":\"B\",\"cat\":\"cc\",\"name\":\"Next "
94 "event\"}"; 94 "event\"}";
95 event_specs[5] = "{\"tid\":1,\"ts\":6,\"ph\":\"E\"}"; 95 event_specs[5] = "{\"tid\":1,\"ts\":6,\"ph\":\"E\"}";
96 96
97 std::string trace_json = "[" + JoinString(event_specs, ',') + "]"; 97 std::string trace_json = "[" + base::JoinString(event_specs, ",") + "]";
98 std::vector<Event> events; 98 std::vector<Event> events;
99 ASSERT_TRUE(GetEvents(trace_json, &events)); 99 ASSERT_TRUE(GetEvents(trace_json, &events));
100 ASSERT_EQ(3u, events.size()); 100 ASSERT_EQ(3u, events.size());
101 101
102 EXPECT_EQ(EventType::COMPLETE, events[0].type); 102 EXPECT_EQ(EventType::COMPLETE, events[0].type);
103 EXPECT_EQ("Outer event", events[0].name); 103 EXPECT_EQ("Outer event", events[0].name);
104 EXPECT_EQ("cc", events[0].categories); 104 EXPECT_EQ("cc", events[0].categories);
105 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp); 105 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp);
106 EXPECT_EQ(base::TimeDelta::FromInternalValue(3), events[0].duration); 106 EXPECT_EQ(base::TimeDelta::FromInternalValue(3), events[0].duration);
107 107
(...skipping 12 matching lines...) Expand all
120 120
121 TEST(GetEventsTest, DurationEventsTwoThreads) { 121 TEST(GetEventsTest, DurationEventsTwoThreads) {
122 std::vector<std::string> event_specs(4); 122 std::vector<std::string> event_specs(4);
123 event_specs[0] = 123 event_specs[0] =
124 "{\"tid\":1,\"ts\":1,\"ph\":\"B\",\"cat\":\"cc\",\"name\":\"t1 event\"}"; 124 "{\"tid\":1,\"ts\":1,\"ph\":\"B\",\"cat\":\"cc\",\"name\":\"t1 event\"}";
125 event_specs[1] = 125 event_specs[1] =
126 "{\"tid\":2,\"ts\":2,\"ph\":\"B\",\"cat\":\"cc\",\"name\":\"t2 event\"}"; 126 "{\"tid\":2,\"ts\":2,\"ph\":\"B\",\"cat\":\"cc\",\"name\":\"t2 event\"}";
127 event_specs[2] = "{\"tid\":1,\"ts\":3,\"ph\":\"E\"}"; 127 event_specs[2] = "{\"tid\":1,\"ts\":3,\"ph\":\"E\"}";
128 event_specs[3] = "{\"tid\":2,\"ts\":4,\"ph\":\"E\"}"; 128 event_specs[3] = "{\"tid\":2,\"ts\":4,\"ph\":\"E\"}";
129 129
130 std::string trace_json = "[" + JoinString(event_specs, ',') + "]"; 130 std::string trace_json = "[" + base::JoinString(event_specs, ",") + "]";
131 std::vector<Event> events; 131 std::vector<Event> events;
132 ASSERT_TRUE(GetEvents(trace_json, &events)); 132 ASSERT_TRUE(GetEvents(trace_json, &events));
133 ASSERT_EQ(2u, events.size()); 133 ASSERT_EQ(2u, events.size());
134 134
135 EXPECT_EQ(EventType::COMPLETE, events[0].type); 135 EXPECT_EQ(EventType::COMPLETE, events[0].type);
136 EXPECT_EQ("t1 event", events[0].name); 136 EXPECT_EQ("t1 event", events[0].name);
137 EXPECT_EQ("cc", events[0].categories); 137 EXPECT_EQ("cc", events[0].categories);
138 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp); 138 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp);
139 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[0].duration); 139 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[0].duration);
140 140
141 EXPECT_EQ(EventType::COMPLETE, events[1].type); 141 EXPECT_EQ(EventType::COMPLETE, events[1].type);
142 EXPECT_EQ("t2 event", events[1].name); 142 EXPECT_EQ("t2 event", events[1].name);
143 EXPECT_EQ("cc", events[1].categories); 143 EXPECT_EQ("cc", events[1].categories);
144 EXPECT_EQ(base::TimeTicks::FromInternalValue(2), events[1].timestamp); 144 EXPECT_EQ(base::TimeTicks::FromInternalValue(2), events[1].timestamp);
145 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[1].duration); 145 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[1].duration);
146 } 146 }
147 147
148 TEST(GetEventsTest, DurationEventsTidIsString) { 148 TEST(GetEventsTest, DurationEventsTidIsString) {
149 std::vector<std::string> event_specs(2); 149 std::vector<std::string> event_specs(2);
150 event_specs[0] = 150 event_specs[0] =
151 "{\"tid\":\"1\",\"ts\":1,\"ph\":\"B\",\"cat\":\"cc\"," 151 "{\"tid\":\"1\",\"ts\":1,\"ph\":\"B\",\"cat\":\"cc\","
152 "\"name\":\"t1 event\"}"; 152 "\"name\":\"t1 event\"}";
153 event_specs[1] = "{\"tid\":\"1\",\"ts\":3,\"ph\":\"E\"}"; 153 event_specs[1] = "{\"tid\":\"1\",\"ts\":3,\"ph\":\"E\"}";
154 154
155 std::string trace_json = "[" + JoinString(event_specs, ',') + "]"; 155 std::string trace_json = "[" + base::JoinString(event_specs, ",") + "]";
156 std::vector<Event> events; 156 std::vector<Event> events;
157 ASSERT_TRUE(GetEvents(trace_json, &events)); 157 ASSERT_TRUE(GetEvents(trace_json, &events));
158 ASSERT_EQ(1u, events.size()); 158 ASSERT_EQ(1u, events.size());
159 159
160 EXPECT_EQ(EventType::COMPLETE, events[0].type); 160 EXPECT_EQ(EventType::COMPLETE, events[0].type);
161 EXPECT_EQ("t1 event", events[0].name); 161 EXPECT_EQ("t1 event", events[0].name);
162 EXPECT_EQ("cc", events[0].categories); 162 EXPECT_EQ("cc", events[0].categories);
163 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp); 163 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp);
164 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[0].duration); 164 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[0].duration);
165 } 165 }
166 166
167 TEST(GetEventsTest, AsyncEvents) { 167 TEST(GetEventsTest, AsyncEvents) {
168 std::vector<std::string> event_specs(4); 168 std::vector<std::string> event_specs(4);
169 event_specs[0] = 169 event_specs[0] =
170 "{\"tid\":1001,\"id\":1,\"ts\":1,\"ph\":\"S\",\"cat\":\"cc\",\"name\":" 170 "{\"tid\":1001,\"id\":1,\"ts\":1,\"ph\":\"S\",\"cat\":\"cc\",\"name\":"
171 "\"t1 event\"}"; 171 "\"t1 event\"}";
172 event_specs[1] = 172 event_specs[1] =
173 "{\"tid\":1002,\"id\":2,\"ts\":2,\"ph\":\"S\",\"cat\":\"cc\",\"name\":" 173 "{\"tid\":1002,\"id\":2,\"ts\":2,\"ph\":\"S\",\"cat\":\"cc\",\"name\":"
174 "\"t2 event\"}"; 174 "\"t2 event\"}";
175 event_specs[2] = 175 event_specs[2] =
176 "{\"tid\":1003,\"id\":1,\"ts\":3,\"ph\":\"F\",\"cat\":\"cc\",\"name\":" 176 "{\"tid\":1003,\"id\":1,\"ts\":3,\"ph\":\"F\",\"cat\":\"cc\",\"name\":"
177 "\"t1 event\"}"; 177 "\"t1 event\"}";
178 event_specs[3] = 178 event_specs[3] =
179 "{\"tid\":1004,\"id\":2,\"ts\":4,\"ph\":\"F\",\"cat\":\"cc\",\"name\":" 179 "{\"tid\":1004,\"id\":2,\"ts\":4,\"ph\":\"F\",\"cat\":\"cc\",\"name\":"
180 "\"t2 event\"}"; 180 "\"t2 event\"}";
181 181
182 std::string trace_json = "[" + JoinString(event_specs, ',') + "]"; 182 std::string trace_json = "[" + base::JoinString(event_specs, ",") + "]";
183 std::vector<Event> events; 183 std::vector<Event> events;
184 ASSERT_TRUE(GetEvents(trace_json, &events)); 184 ASSERT_TRUE(GetEvents(trace_json, &events));
185 ASSERT_EQ(2u, events.size()); 185 ASSERT_EQ(2u, events.size());
186 186
187 EXPECT_EQ(EventType::COMPLETE, events[0].type); 187 EXPECT_EQ(EventType::COMPLETE, events[0].type);
188 EXPECT_EQ("t1 event", events[0].name); 188 EXPECT_EQ("t1 event", events[0].name);
189 EXPECT_EQ("cc", events[0].categories); 189 EXPECT_EQ("cc", events[0].categories);
190 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp); 190 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp);
191 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[0].duration); 191 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[0].duration);
192 192
193 EXPECT_EQ(EventType::COMPLETE, events[1].type); 193 EXPECT_EQ(EventType::COMPLETE, events[1].type);
194 EXPECT_EQ("t2 event", events[1].name); 194 EXPECT_EQ("t2 event", events[1].name);
195 EXPECT_EQ("cc", events[1].categories); 195 EXPECT_EQ("cc", events[1].categories);
196 EXPECT_EQ(base::TimeTicks::FromInternalValue(2), events[1].timestamp); 196 EXPECT_EQ(base::TimeTicks::FromInternalValue(2), events[1].timestamp);
197 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[1].duration); 197 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[1].duration);
198 } 198 }
199 199
200 TEST(GetEventsTest, AsyncEventIdIsString) { 200 TEST(GetEventsTest, AsyncEventIdIsString) {
201 std::vector<std::string> event_specs(2); 201 std::vector<std::string> event_specs(2);
202 event_specs[0] = 202 event_specs[0] =
203 "{\"tid\":1001,\"id\":\"a\",\"ts\":1,\"ph\":\"S\",\"cat\":\"cc\"," 203 "{\"tid\":1001,\"id\":\"a\",\"ts\":1,\"ph\":\"S\",\"cat\":\"cc\","
204 "\"name\":\"t1 event\"}"; 204 "\"name\":\"t1 event\"}";
205 event_specs[1] = 205 event_specs[1] =
206 "{\"tid\":1003,\"id\":\"a\",\"ts\":3,\"ph\":\"F\",\"cat\":\"cc\"," 206 "{\"tid\":1003,\"id\":\"a\",\"ts\":3,\"ph\":\"F\",\"cat\":\"cc\","
207 "\"name\":\"t1 event\"}"; 207 "\"name\":\"t1 event\"}";
208 208
209 std::string trace_json = "[" + JoinString(event_specs, ',') + "]"; 209 std::string trace_json = "[" + base::JoinString(event_specs, ",") + "]";
210 std::vector<Event> events; 210 std::vector<Event> events;
211 ASSERT_TRUE(GetEvents(trace_json, &events)); 211 ASSERT_TRUE(GetEvents(trace_json, &events));
212 ASSERT_EQ(1u, events.size()); 212 ASSERT_EQ(1u, events.size());
213 213
214 EXPECT_EQ(EventType::COMPLETE, events[0].type); 214 EXPECT_EQ(EventType::COMPLETE, events[0].type);
215 EXPECT_EQ("t1 event", events[0].name); 215 EXPECT_EQ("t1 event", events[0].name);
216 EXPECT_EQ("cc", events[0].categories); 216 EXPECT_EQ("cc", events[0].categories);
217 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp); 217 EXPECT_EQ(base::TimeTicks::FromInternalValue(1), events[0].timestamp);
218 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[0].duration); 218 EXPECT_EQ(base::TimeDelta::FromInternalValue(2), events[0].duration);
219 } 219 }
220 220
221 } // namespace 221 } // namespace
222 222
223 } // namespace benchmark 223 } // namespace benchmark
OLDNEW
« no previous file with comments | « apps/benchmark/benchmark_app.cc ('k') | base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698