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

Side by Side Diff: base/tracked_objects_unittest.cc

Issue 8894022: Detect child tasks born during a profiled tasks (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
« base/tracked_objects.cc ('K') | « base/tracked_objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Test of classes in the tracked_objects.h classes. 5 // Test of classes in the tracked_objects.h classes.
6 6
7 #include "base/tracked_objects.h" 7 #include "base/tracked_objects.h"
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 28 matching lines...) Expand all
39 return; 39 return;
40 40
41 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. 41 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
42 ThreadData* data = ThreadData::Get(); 42 ThreadData* data = ThreadData::Get();
43 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. 43 EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
44 EXPECT_TRUE(data); 44 EXPECT_TRUE(data);
45 EXPECT_TRUE(!data->next()); 45 EXPECT_TRUE(!data->next());
46 EXPECT_EQ(data, ThreadData::Get()); 46 EXPECT_EQ(data, ThreadData::Get());
47 ThreadData::BirthMap birth_map; 47 ThreadData::BirthMap birth_map;
48 ThreadData::DeathMap death_map; 48 ThreadData::DeathMap death_map;
49 data->SnapshotMaps(false, &birth_map, &death_map); 49 ThreadData::ParentChildSet parent_child_set;
50 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
50 EXPECT_EQ(0u, birth_map.size()); 51 EXPECT_EQ(0u, birth_map.size());
51 EXPECT_EQ(0u, death_map.size()); 52 EXPECT_EQ(0u, death_map.size());
53 EXPECT_EQ(0u, parent_child_set.size());
52 // Cleanup with no leaking. 54 // Cleanup with no leaking.
53 ShutdownSingleThreadedCleanup(false); 55 ShutdownSingleThreadedCleanup(false);
54 56
55 // Do it again, just to be sure we reset state completely. 57 // Do it again, just to be sure we reset state completely.
56 ThreadData::InitializeAndSetTrackingStatus(true); 58 ThreadData::InitializeAndSetTrackingStatus(true);
57 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread. 59 EXPECT_FALSE(ThreadData::first()); // No activity even on this thread.
58 data = ThreadData::Get(); 60 data = ThreadData::Get();
59 EXPECT_TRUE(ThreadData::first()); // Now class was constructed. 61 EXPECT_TRUE(ThreadData::first()); // Now class was constructed.
60 EXPECT_TRUE(data); 62 EXPECT_TRUE(data);
61 EXPECT_TRUE(!data->next()); 63 EXPECT_TRUE(!data->next());
62 EXPECT_EQ(data, ThreadData::Get()); 64 EXPECT_EQ(data, ThreadData::Get());
63 birth_map.clear(); 65 birth_map.clear();
64 death_map.clear(); 66 death_map.clear();
65 data->SnapshotMaps(false, &birth_map, &death_map); 67 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
66 EXPECT_EQ(0u, birth_map.size()); 68 EXPECT_EQ(0u, birth_map.size());
67 EXPECT_EQ(0u, death_map.size()); 69 EXPECT_EQ(0u, death_map.size());
70 EXPECT_EQ(0u, parent_child_set.size());
68 } 71 }
69 72
70 TEST_F(TrackedObjectsTest, TinyStartupShutdown) { 73 TEST_F(TrackedObjectsTest, TinyStartupShutdown) {
71 if (!ThreadData::InitializeAndSetTrackingStatus(true)) 74 if (!ThreadData::InitializeAndSetTrackingStatus(true))
72 return; 75 return;
73 76
74 // Instigate tracking on a single tracked object, on our thread. 77 // Instigate tracking on a single tracked object, on our thread.
75 const Location& location = FROM_HERE; 78 const Location& location = FROM_HERE;
76 ThreadData::TallyABirthIfActive(location); 79 Births* first_birth = ThreadData::TallyABirthIfActive(location);
77 80
78 ThreadData* data = ThreadData::first(); 81 ThreadData* data = ThreadData::first();
79 ASSERT_TRUE(data); 82 ASSERT_TRUE(data);
80 EXPECT_TRUE(!data->next()); 83 EXPECT_TRUE(!data->next());
81 EXPECT_EQ(data, ThreadData::Get()); 84 EXPECT_EQ(data, ThreadData::Get());
82 ThreadData::BirthMap birth_map; 85 ThreadData::BirthMap birth_map;
83 ThreadData::DeathMap death_map; 86 ThreadData::DeathMap death_map;
84 data->SnapshotMaps(false, &birth_map, &death_map); 87 ThreadData::ParentChildSet parent_child_set;
88 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
85 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. 89 EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
86 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. 90 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth.
87 EXPECT_EQ(0u, death_map.size()); // No deaths. 91 EXPECT_EQ(0u, death_map.size()); // No deaths.
92 EXPECT_EQ(0u, parent_child_set.size()); // No children.
88 93
89 94
90 // Now instigate another birth, and a first death at the same location. 95 // Now instigate another birth, while we are timing the run of the first
96 // execution.
97 TrackedTime start_time =
98 ThreadData::NowForStartOfRun(first_birth);
99 // Create a child (using the same birth location).
91 // TrackingInfo will call TallyABirth() during construction. 100 // TrackingInfo will call TallyABirth() during construction.
92 base::TimeTicks kBogusStartTime; 101 base::TimeTicks kBogusBirthTime;
93 base::TrackingInfo pending_task(location, kBogusStartTime); 102 base::TrackingInfo pending_task(location, kBogusBirthTime);
94 TrackedTime kBogusStartRunTime; 103 // Finally conclude the outer run.
95 TrackedTime kBogusEndRunTime; 104 TrackedTime end_time = ThreadData::NowForEndOfRun();
96 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, kBogusStartRunTime, 105 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, start_time,
97 kBogusEndRunTime); 106 end_time);
98 107
99 birth_map.clear(); 108 birth_map.clear();
100 death_map.clear(); 109 death_map.clear();
101 data->SnapshotMaps(false, &birth_map, &death_map); 110 parent_child_set.clear();
111 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
102 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. 112 EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
103 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. 113 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births.
104 EXPECT_EQ(1u, death_map.size()); // 1 location. 114 EXPECT_EQ(1u, death_map.size()); // 1 location.
105 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death. 115 EXPECT_EQ(1, death_map.begin()->second.count()); // 1 death.
116 if (ThreadData::tracking_parent_child_status()) {
117 EXPECT_EQ(1u, parent_child_set.size()); // 1 child.
118 EXPECT_EQ(parent_child_set.begin()->first,
119 parent_child_set.begin()->second);
120 } else {
121 EXPECT_EQ(0u, parent_child_set.size()); // no stats.
122 }
106 123
107 // The births were at the same location as the one known death. 124 // The births were at the same location as the one known death.
108 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first); 125 EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first);
109 } 126 }
110 127
128 TEST_F(TrackedObjectsTest, ParentChildTest) {
129 if (!ThreadData::InitializeAndSetTrackingStatus(true))
130 return;
131 if (!ThreadData::tracking_parent_child_status())
132 return; // Feature not compiled in.
133
134 // Instigate tracking on a single tracked object, on our thread.
135 const int kFakeLineNumber = 1776;
136 const char* kFile = "FixedUnitTestFileName";
137 const char* kFunction = "ParentChildTest";
138 Location location(kFunction, kFile, kFakeLineNumber, NULL);
139 Births* first_birth = ThreadData::TallyABirthIfActive(location);
140
141 // Now instigate another birth, while we are timing the run of the first
142 // execution.
143 TrackedTime start_time =
144 ThreadData::NowForStartOfRun(first_birth);
145 // Create a child (using the same birth location).
146 // TrackingInfo will call TallyABirth() during construction.
147 base::TimeTicks kBogusBirthTime;
148 base::TrackingInfo pending_task(location, kBogusBirthTime);
149
150 // Don't conclude the run, so that we don't use the actual timer that we
151 // started for the outer profile. This way the JSON will not include some
152 // random time.
153
154
ramant (doing other things) 2011/12/13 19:14:45 nit: extra line.
jar (doing other things) 2011/12/13 20:29:10 Done.
155 ThreadData* data = ThreadData::first();
156 ASSERT_TRUE(data);
157 EXPECT_TRUE(!data->next());
158 EXPECT_EQ(data, ThreadData::Get());
159
160 ThreadData::BirthMap birth_map;
161 ThreadData::DeathMap death_map;
162 ThreadData::ParentChildSet parent_child_set;
163
164 data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
165 EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
166 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births.
167 EXPECT_EQ(0u, death_map.size()); // No status yet.
168 // Just like TinyStartupShutdown test.
169 EXPECT_EQ(1u, parent_child_set.size()); // 1 child.
170 EXPECT_EQ(parent_child_set.begin()->first,
171 parent_child_set.begin()->second);
172
173 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
174 std::string json;
175 base::JSONWriter::Write(value.get(), false, &json);
176 std::string birth_only_result = "{"
177 "\"descendants\":["
178 "{"
179 "\"child_location\":{"
180 "\"file_name\":\"FixedUnitTestFileName\","
181 "\"function_name\":\"ParentChildTest\","
182 "\"line_number\":1776"
183 "},"
184 "\"child_thread\":\"WorkerThread-1\","
185 "\"parent_location\":{"
186 "\"file_name\":\"FixedUnitTestFileName\","
187 "\"function_name\":\"ParentChildTest\","
188 "\"line_number\":1776"
189 "},"
190 "\"parent_thread\":\"WorkerThread-1\""
191 "}"
192 "],"
193 "\"list\":["
194 "{"
195 "\"birth_thread\":\"WorkerThread-1\","
196 "\"death_data\":{"
197 "\"count\":2,"
198 "\"queue_ms\":0,"
199 "\"queue_ms_max\":0,"
200 "\"queue_ms_sample\":0,"
201 "\"run_ms\":0,"
202 "\"run_ms_max\":0,"
203 "\"run_ms_sample\":0"
204 "},"
205 "\"death_thread\":\"Still_Alive\","
206 "\"location\":{"
207 "\"file_name\":\"FixedUnitTestFileName\","
208 "\"function_name\":\"ParentChildTest\","
209 "\"line_number\":1776"
210 "}"
211 "}"
212 "]"
213 "}";
214 EXPECT_EQ(json, birth_only_result);
215 }
216
111 TEST_F(TrackedObjectsTest, DeathDataTest) { 217 TEST_F(TrackedObjectsTest, DeathDataTest) {
112 if (!ThreadData::InitializeAndSetTrackingStatus(true)) 218 if (!ThreadData::InitializeAndSetTrackingStatus(true))
113 return; 219 return;
114 220
115 scoped_ptr<DeathData> data(new DeathData()); 221 scoped_ptr<DeathData> data(new DeathData());
116 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL)); 222 ASSERT_NE(data, reinterpret_cast<DeathData*>(NULL));
117 EXPECT_EQ(data->run_duration_sum(), 0); 223 EXPECT_EQ(data->run_duration_sum(), 0);
118 EXPECT_EQ(data->run_duration_sample(), 0); 224 EXPECT_EQ(data->run_duration_sample(), 0);
119 EXPECT_EQ(data->queue_duration_sum(), 0); 225 EXPECT_EQ(data->queue_duration_sum(), 0);
120 EXPECT_EQ(data->queue_duration_sample(), 0); 226 EXPECT_EQ(data->queue_duration_sample(), 0);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 const char* kFunction = "BirthOnlyToValueWorkerThread"; 283 const char* kFunction = "BirthOnlyToValueWorkerThread";
178 Location location(kFunction, kFile, kFakeLineNumber, NULL); 284 Location location(kFunction, kFile, kFakeLineNumber, NULL);
179 Births* birth = ThreadData::TallyABirthIfActive(location); 285 Births* birth = ThreadData::TallyABirthIfActive(location);
180 // We should now see a NULL birth record. 286 // We should now see a NULL birth record.
181 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); 287 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL));
182 288
183 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 289 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
184 std::string json; 290 std::string json;
185 base::JSONWriter::Write(value.get(), false, &json); 291 base::JSONWriter::Write(value.get(), false, &json);
186 std::string birth_only_result = "{" 292 std::string birth_only_result = "{"
293 "\"descendants\":["
294 "],"
187 "\"list\":[" 295 "\"list\":["
188 "]" 296 "]"
189 "}"; 297 "}";
190 EXPECT_EQ(json, birth_only_result); 298 EXPECT_EQ(json, birth_only_result);
191 } 299 }
192 300
193 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) { 301 TEST_F(TrackedObjectsTest, DeactivatedBirthOnlyToValueMainThread) {
194 // Start in the deactivated state. 302 // Start in the deactivated state.
195 if (!ThreadData::InitializeAndSetTrackingStatus(false)) 303 if (!ThreadData::InitializeAndSetTrackingStatus(false))
196 return; 304 return;
197 305
198 // Use a well named thread. 306 // Use a well named thread.
199 ThreadData::InitializeThreadContext("SomeMainThreadName"); 307 ThreadData::InitializeThreadContext("SomeMainThreadName");
200 const int kFakeLineNumber = 173; 308 const int kFakeLineNumber = 173;
201 const char* kFile = "FixedFileName"; 309 const char* kFile = "FixedFileName";
202 const char* kFunction = "BirthOnlyToValueMainThread"; 310 const char* kFunction = "BirthOnlyToValueMainThread";
203 Location location(kFunction, kFile, kFakeLineNumber, NULL); 311 Location location(kFunction, kFile, kFakeLineNumber, NULL);
204 // Do not delete birth. We don't own it. 312 // Do not delete birth. We don't own it.
205 Births* birth = ThreadData::TallyABirthIfActive(location); 313 Births* birth = ThreadData::TallyABirthIfActive(location);
206 // We expect to not get a birth record. 314 // We expect to not get a birth record.
207 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL)); 315 EXPECT_EQ(birth, reinterpret_cast<Births*>(NULL));
208 316
209 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 317 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
210 std::string json; 318 std::string json;
211 base::JSONWriter::Write(value.get(), false, &json); 319 base::JSONWriter::Write(value.get(), false, &json);
212 std::string birth_only_result = "{" 320 std::string birth_only_result = "{"
321 "\"descendants\":["
322 "],"
213 "\"list\":[" 323 "\"list\":["
214 "]" 324 "]"
215 "}"; 325 "}";
216 EXPECT_EQ(json, birth_only_result); 326 EXPECT_EQ(json, birth_only_result);
217 } 327 }
218 328
219 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) { 329 TEST_F(TrackedObjectsTest, BirthOnlyToValueWorkerThread) {
220 if (!ThreadData::InitializeAndSetTrackingStatus(true)) 330 if (!ThreadData::InitializeAndSetTrackingStatus(true))
221 return; 331 return;
222 // We don't initialize system with a thread name, so we're viewed as a worker 332 // We don't initialize system with a thread name, so we're viewed as a worker
223 // thread. 333 // thread.
224 const int kFakeLineNumber = 173; 334 const int kFakeLineNumber = 173;
225 const char* kFile = "FixedFileName"; 335 const char* kFile = "FixedFileName";
226 const char* kFunction = "BirthOnlyToValueWorkerThread"; 336 const char* kFunction = "BirthOnlyToValueWorkerThread";
227 Location location(kFunction, kFile, kFakeLineNumber, NULL); 337 Location location(kFunction, kFile, kFakeLineNumber, NULL);
228 Births* birth = ThreadData::TallyABirthIfActive(location); 338 Births* birth = ThreadData::TallyABirthIfActive(location);
229 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); 339 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL));
230 340
231 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 341 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
232 std::string json; 342 std::string json;
233 base::JSONWriter::Write(value.get(), false, &json); 343 base::JSONWriter::Write(value.get(), false, &json);
234 std::string birth_only_result = "{" 344 std::string birth_only_result = "{"
345 "\"descendants\":["
346 "],"
235 "\"list\":[" 347 "\"list\":["
236 "{" 348 "{"
237 "\"birth_thread\":\"WorkerThread-1\"," 349 "\"birth_thread\":\"WorkerThread-1\","
238 "\"death_data\":{" 350 "\"death_data\":{"
239 "\"count\":1," 351 "\"count\":1,"
240 "\"queue_ms\":0," 352 "\"queue_ms\":0,"
241 "\"queue_ms_max\":0," 353 "\"queue_ms_max\":0,"
242 "\"queue_ms_sample\":0," 354 "\"queue_ms_sample\":0,"
243 "\"run_ms\":0," 355 "\"run_ms\":0,"
244 "\"run_ms_max\":0," 356 "\"run_ms_max\":0,"
(...skipping 22 matching lines...) Expand all
267 const char* kFunction = "BirthOnlyToValueMainThread"; 379 const char* kFunction = "BirthOnlyToValueMainThread";
268 Location location(kFunction, kFile, kFakeLineNumber, NULL); 380 Location location(kFunction, kFile, kFakeLineNumber, NULL);
269 // Do not delete birth. We don't own it. 381 // Do not delete birth. We don't own it.
270 Births* birth = ThreadData::TallyABirthIfActive(location); 382 Births* birth = ThreadData::TallyABirthIfActive(location);
271 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL)); 383 EXPECT_NE(birth, reinterpret_cast<Births*>(NULL));
272 384
273 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 385 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
274 std::string json; 386 std::string json;
275 base::JSONWriter::Write(value.get(), false, &json); 387 base::JSONWriter::Write(value.get(), false, &json);
276 std::string birth_only_result = "{" 388 std::string birth_only_result = "{"
389 "\"descendants\":["
390 "],"
277 "\"list\":[" 391 "\"list\":["
278 "{" 392 "{"
279 "\"birth_thread\":\"SomeMainThreadName\"," 393 "\"birth_thread\":\"SomeMainThreadName\","
280 "\"death_data\":{" 394 "\"death_data\":{"
281 "\"count\":1," 395 "\"count\":1,"
282 "\"queue_ms\":0," 396 "\"queue_ms\":0,"
283 "\"queue_ms_max\":0," 397 "\"queue_ms_max\":0,"
284 "\"queue_ms_sample\":0," 398 "\"queue_ms_sample\":0,"
285 "\"run_ms\":0," 399 "\"run_ms\":0,"
286 "\"run_ms_max\":0," 400 "\"run_ms_max\":0,"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 const TrackedTime kStartOfRun = TrackedTime() + 436 const TrackedTime kStartOfRun = TrackedTime() +
323 Duration::FromMilliseconds(5); 437 Duration::FromMilliseconds(5);
324 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 438 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
325 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 439 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task,
326 kStartOfRun, kEndOfRun); 440 kStartOfRun, kEndOfRun);
327 441
328 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 442 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
329 std::string json; 443 std::string json;
330 base::JSONWriter::Write(value.get(), false, &json); 444 base::JSONWriter::Write(value.get(), false, &json);
331 std::string one_line_result = "{" 445 std::string one_line_result = "{"
446 "\"descendants\":["
447 "],"
332 "\"list\":[" 448 "\"list\":["
333 "{" 449 "{"
334 "\"birth_thread\":\"SomeMainThreadName\"," 450 "\"birth_thread\":\"SomeMainThreadName\","
335 "\"death_data\":{" 451 "\"death_data\":{"
336 "\"count\":1," 452 "\"count\":1,"
337 "\"queue_ms\":4," 453 "\"queue_ms\":4,"
338 "\"queue_ms_max\":4," 454 "\"queue_ms_max\":4,"
339 "\"queue_ms_sample\":4," 455 "\"queue_ms_sample\":4,"
340 "\"run_ms\":2," 456 "\"run_ms\":2,"
341 "\"run_ms_max\":2," 457 "\"run_ms_max\":2,"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 const TrackedTime kStartOfRun = TrackedTime() + 500 const TrackedTime kStartOfRun = TrackedTime() +
385 Duration::FromMilliseconds(5); 501 Duration::FromMilliseconds(5);
386 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 502 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
387 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 503 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task,
388 kStartOfRun, kEndOfRun); 504 kStartOfRun, kEndOfRun);
389 505
390 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 506 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
391 std::string json; 507 std::string json;
392 base::JSONWriter::Write(value.get(), false, &json); 508 base::JSONWriter::Write(value.get(), false, &json);
393 std::string one_line_result = "{" 509 std::string one_line_result = "{"
510 "\"descendants\":["
511 "],"
394 "\"list\":[" 512 "\"list\":["
395 "{" 513 "{"
396 "\"birth_thread\":\"SomeMainThreadName\"," 514 "\"birth_thread\":\"SomeMainThreadName\","
397 "\"death_data\":{" 515 "\"death_data\":{"
398 "\"count\":1," 516 "\"count\":1,"
399 "\"queue_ms\":4," 517 "\"queue_ms\":4,"
400 "\"queue_ms_max\":4," 518 "\"queue_ms_max\":4,"
401 "\"queue_ms_sample\":4," 519 "\"queue_ms_sample\":4,"
402 "\"run_ms\":2," 520 "\"run_ms\":2,"
403 "\"run_ms_max\":2," 521 "\"run_ms_max\":2,"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 const TrackedTime kStartOfRun = TrackedTime() + 559 const TrackedTime kStartOfRun = TrackedTime() +
442 Duration::FromMilliseconds(5); 560 Duration::FromMilliseconds(5);
443 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 561 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
444 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, 562 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task,
445 kStartOfRun, kEndOfRun); 563 kStartOfRun, kEndOfRun);
446 564
447 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 565 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
448 std::string json; 566 std::string json;
449 base::JSONWriter::Write(value.get(), false, &json); 567 base::JSONWriter::Write(value.get(), false, &json);
450 std::string one_line_result = "{" 568 std::string one_line_result = "{"
569 "\"descendants\":["
570 "],"
451 "\"list\":[" 571 "\"list\":["
452 "]" 572 "]"
453 "}"; 573 "}";
454 EXPECT_EQ(one_line_result, json); 574 EXPECT_EQ(one_line_result, json);
455 } 575 }
456 576
457 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) { 577 TEST_F(TrackedObjectsTest, LifeCycleToValueWorkerThread) {
458 if (!ThreadData::InitializeAndSetTrackingStatus(true)) 578 if (!ThreadData::InitializeAndSetTrackingStatus(true))
459 return; 579 return;
460 580
(...skipping 13 matching lines...) Expand all
474 Duration::FromMilliseconds(5); 594 Duration::FromMilliseconds(5);
475 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7); 595 const TrackedTime kEndOfRun = TrackedTime() + Duration::FromMilliseconds(7);
476 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted, 596 ThreadData::TallyRunOnWorkerThreadIfTracking(birth, kTimePosted,
477 kStartOfRun, kEndOfRun); 597 kStartOfRun, kEndOfRun);
478 598
479 // Call for the ToValue, but tell it to not the maxes after scanning. 599 // Call for the ToValue, but tell it to not the maxes after scanning.
480 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 600 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
481 std::string json; 601 std::string json;
482 base::JSONWriter::Write(value.get(), false, &json); 602 base::JSONWriter::Write(value.get(), false, &json);
483 std::string one_line_result = "{" 603 std::string one_line_result = "{"
604 "\"descendants\":["
605 "],"
484 "\"list\":[" 606 "\"list\":["
485 "{" 607 "{"
486 "\"birth_thread\":\"WorkerThread-1\"," 608 "\"birth_thread\":\"WorkerThread-1\","
487 "\"death_data\":{" 609 "\"death_data\":{"
488 "\"count\":1," 610 "\"count\":1,"
489 "\"queue_ms\":4," 611 "\"queue_ms\":4,"
490 "\"queue_ms_max\":4," 612 "\"queue_ms_max\":4,"
491 "\"queue_ms_sample\":4," 613 "\"queue_ms_sample\":4,"
492 "\"run_ms\":2," 614 "\"run_ms\":2,"
493 "\"run_ms_max\":2," 615 "\"run_ms_max\":2,"
(...skipping 16 matching lines...) Expand all
510 value.reset(ThreadData::ToValue(true)); 632 value.reset(ThreadData::ToValue(true));
511 base::JSONWriter::Write(value.get(), false, &json); 633 base::JSONWriter::Write(value.get(), false, &json);
512 // Result should be unchanged. 634 // Result should be unchanged.
513 EXPECT_EQ(one_line_result, json); 635 EXPECT_EQ(one_line_result, json);
514 636
515 // Call for the ToValue, and now we'll see the result of the last translation, 637 // Call for the ToValue, and now we'll see the result of the last translation,
516 // as the max will have been pushed back to zero. 638 // as the max will have been pushed back to zero.
517 value.reset(ThreadData::ToValue(false)); 639 value.reset(ThreadData::ToValue(false));
518 base::JSONWriter::Write(value.get(), false, &json); 640 base::JSONWriter::Write(value.get(), false, &json);
519 std::string one_line_result_with_zeros = "{" 641 std::string one_line_result_with_zeros = "{"
642 "\"descendants\":["
643 "],"
520 "\"list\":[" 644 "\"list\":["
521 "{" 645 "{"
522 "\"birth_thread\":\"WorkerThread-1\"," 646 "\"birth_thread\":\"WorkerThread-1\","
523 "\"death_data\":{" 647 "\"death_data\":{"
524 "\"count\":1," 648 "\"count\":1,"
525 "\"queue_ms\":4," 649 "\"queue_ms\":4,"
526 "\"queue_ms_max\":0," // Note zero here. 650 "\"queue_ms_max\":0," // Note zero here.
527 "\"queue_ms_sample\":4," 651 "\"queue_ms_sample\":4,"
528 "\"run_ms\":2," 652 "\"run_ms\":2,"
529 "\"run_ms_max\":0," // Note zero here. 653 "\"run_ms_max\":0," // Note zero here.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 base::TrackingInfo pending_task2(location, kDelayedStartTime); 697 base::TrackingInfo pending_task2(location, kDelayedStartTime);
574 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 698 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
575 699
576 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, 700 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2,
577 kStartOfRun, kEndOfRun); 701 kStartOfRun, kEndOfRun);
578 702
579 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 703 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
580 std::string json; 704 std::string json;
581 base::JSONWriter::Write(value.get(), false, &json); 705 base::JSONWriter::Write(value.get(), false, &json);
582 std::string one_line_result = "{" 706 std::string one_line_result = "{"
707 "\"descendants\":["
708 "],"
583 "\"list\":[" 709 "\"list\":["
584 "{" 710 "{"
585 "\"birth_thread\":\"SomeFileThreadName\"," 711 "\"birth_thread\":\"SomeFileThreadName\","
586 "\"death_data\":{" 712 "\"death_data\":{"
587 "\"count\":2," 713 "\"count\":2,"
588 "\"queue_ms\":8," 714 "\"queue_ms\":8,"
589 "\"queue_ms_max\":4," 715 "\"queue_ms_max\":4,"
590 "\"queue_ms_sample\":4," 716 "\"queue_ms_sample\":4,"
591 "\"run_ms\":4," 717 "\"run_ms\":4,"
592 "\"run_ms_max\":2," 718 "\"run_ms_max\":2,"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL); 758 Location second_location(kFunction, kFile, kSecondFakeLineNumber, NULL);
633 759
634 // TrackingInfo will call TallyABirth() during construction. 760 // TrackingInfo will call TallyABirth() during construction.
635 base::TrackingInfo pending_task2(second_location, kDelayedStartTime); 761 base::TrackingInfo pending_task2(second_location, kDelayedStartTime);
636 pending_task2.time_posted = kTimePosted; // Overwrite implied Now(). 762 pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
637 763
638 scoped_ptr<base::Value> value(ThreadData::ToValue(false)); 764 scoped_ptr<base::Value> value(ThreadData::ToValue(false));
639 std::string json; 765 std::string json;
640 base::JSONWriter::Write(value.get(), false, &json); 766 base::JSONWriter::Write(value.get(), false, &json);
641 std::string one_line_result = "{" 767 std::string one_line_result = "{"
768 "\"descendants\":["
769 "],"
642 "\"list\":[" 770 "\"list\":["
643 "{" 771 "{"
644 "\"birth_thread\":\"SomeFileThreadName\"," 772 "\"birth_thread\":\"SomeFileThreadName\","
645 "\"death_data\":{" 773 "\"death_data\":{"
646 "\"count\":1," 774 "\"count\":1,"
647 "\"queue_ms\":4," 775 "\"queue_ms\":4,"
648 "\"queue_ms_max\":4," 776 "\"queue_ms_max\":4,"
649 "\"queue_ms_sample\":4," 777 "\"queue_ms_sample\":4,"
650 "\"run_ms\":2," 778 "\"run_ms\":2,"
651 "\"run_ms_max\":2," 779 "\"run_ms_max\":2,"
(...skipping 24 matching lines...) Expand all
676 "\"line_number\":999" 804 "\"line_number\":999"
677 "}" 805 "}"
678 "}" 806 "}"
679 "]" 807 "]"
680 "}"; 808 "}";
681 EXPECT_EQ(one_line_result, json); 809 EXPECT_EQ(one_line_result, json);
682 } 810 }
683 811
684 812
685 } // namespace tracked_objects 813 } // namespace tracked_objects
OLDNEW
« base/tracked_objects.cc ('K') | « base/tracked_objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698