| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> |
| 10 | 11 |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
| 13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 14 #include "base/tracking_info.h" | 15 #include "base/tracking_info.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 17 |
| 17 const int kLineNumber = 1776; | 18 const int kLineNumber = 1776; |
| 18 const char kFile[] = "FixedUnitTestFileName"; | 19 const char kFile[] = "FixedUnitTestFileName"; |
| 19 const char kWorkerThreadName[] = "WorkerThread-1"; | 20 const char kWorkerThreadName[] = "WorkerThread-1"; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 data->SnapshotMaps(0, &birth_map, &deaths); | 178 data->SnapshotMaps(0, &birth_map, &deaths); |
| 178 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 179 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 179 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. | 180 EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth. |
| 180 EXPECT_EQ(0u, deaths.size()); // No deaths. | 181 EXPECT_EQ(0u, deaths.size()); // No deaths. |
| 181 | 182 |
| 182 | 183 |
| 183 // Now instigate another birth, while we are timing the run of the first | 184 // Now instigate another birth, while we are timing the run of the first |
| 184 // execution. | 185 // execution. |
| 185 // Create a child (using the same birth location). | 186 // Create a child (using the same birth location). |
| 186 // TrackingInfo will call TallyABirth() during construction. | 187 // TrackingInfo will call TallyABirth() during construction. |
| 187 const int32 start_time = 1; | 188 const int32_t start_time = 1; |
| 188 base::TimeTicks kBogusBirthTime = base::TimeTicks() + | 189 base::TimeTicks kBogusBirthTime = base::TimeTicks() + |
| 189 base::TimeDelta::FromMilliseconds(start_time); | 190 base::TimeDelta::FromMilliseconds(start_time); |
| 190 base::TrackingInfo pending_task(location, kBogusBirthTime); | 191 base::TrackingInfo pending_task(location, kBogusBirthTime); |
| 191 SetTestTime(1); | 192 SetTestTime(1); |
| 192 TaskStopwatch stopwatch; | 193 TaskStopwatch stopwatch; |
| 193 stopwatch.Start(); | 194 stopwatch.Start(); |
| 194 // Finally conclude the outer run. | 195 // Finally conclude the outer run. |
| 195 const int32 time_elapsed = 1000; | 196 const int32_t time_elapsed = 1000; |
| 196 SetTestTime(start_time + time_elapsed); | 197 SetTestTime(start_time + time_elapsed); |
| 197 stopwatch.Stop(); | 198 stopwatch.Stop(); |
| 198 | 199 |
| 199 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); | 200 ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch); |
| 200 | 201 |
| 201 birth_map.clear(); | 202 birth_map.clear(); |
| 202 deaths.clear(); | 203 deaths.clear(); |
| 203 data->SnapshotMaps(0, &birth_map, &deaths); | 204 data->SnapshotMaps(0, &birth_map, &deaths); |
| 204 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. | 205 EXPECT_EQ(1u, birth_map.size()); // 1 birth location. |
| 205 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. | 206 EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ASSERT_NE(data, nullptr); | 244 ASSERT_NE(data, nullptr); |
| 244 EXPECT_EQ(data->run_duration_sum(), 0); | 245 EXPECT_EQ(data->run_duration_sum(), 0); |
| 245 EXPECT_EQ(data->run_duration_max(), 0); | 246 EXPECT_EQ(data->run_duration_max(), 0); |
| 246 EXPECT_EQ(data->run_duration_sample(), 0); | 247 EXPECT_EQ(data->run_duration_sample(), 0); |
| 247 EXPECT_EQ(data->queue_duration_sum(), 0); | 248 EXPECT_EQ(data->queue_duration_sum(), 0); |
| 248 EXPECT_EQ(data->queue_duration_max(), 0); | 249 EXPECT_EQ(data->queue_duration_max(), 0); |
| 249 EXPECT_EQ(data->queue_duration_sample(), 0); | 250 EXPECT_EQ(data->queue_duration_sample(), 0); |
| 250 EXPECT_EQ(data->count(), 0); | 251 EXPECT_EQ(data->count(), 0); |
| 251 EXPECT_EQ(nullptr, data->last_phase_snapshot()); | 252 EXPECT_EQ(nullptr, data->last_phase_snapshot()); |
| 252 | 253 |
| 253 int32 run_ms = 42; | 254 int32_t run_ms = 42; |
| 254 int32 queue_ms = 8; | 255 int32_t queue_ms = 8; |
| 255 | 256 |
| 256 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. | 257 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. |
| 257 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); | 258 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
| 258 EXPECT_EQ(data->run_duration_sum(), run_ms); | 259 EXPECT_EQ(data->run_duration_sum(), run_ms); |
| 259 EXPECT_EQ(data->run_duration_max(), run_ms); | 260 EXPECT_EQ(data->run_duration_max(), run_ms); |
| 260 EXPECT_EQ(data->run_duration_sample(), run_ms); | 261 EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 261 EXPECT_EQ(data->queue_duration_sum(), queue_ms); | 262 EXPECT_EQ(data->queue_duration_sum(), queue_ms); |
| 262 EXPECT_EQ(data->queue_duration_max(), queue_ms); | 263 EXPECT_EQ(data->queue_duration_max(), queue_ms); |
| 263 EXPECT_EQ(data->queue_duration_sample(), queue_ms); | 264 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
| 264 EXPECT_EQ(data->count(), 1); | 265 EXPECT_EQ(data->count(), 1); |
| 265 EXPECT_EQ(nullptr, data->last_phase_snapshot()); | 266 EXPECT_EQ(nullptr, data->last_phase_snapshot()); |
| 266 | 267 |
| 267 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); | 268 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
| 268 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); | 269 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); |
| 269 EXPECT_EQ(data->run_duration_max(), run_ms); | 270 EXPECT_EQ(data->run_duration_max(), run_ms); |
| 270 EXPECT_EQ(data->run_duration_sample(), run_ms); | 271 EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 271 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); | 272 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); |
| 272 EXPECT_EQ(data->queue_duration_max(), queue_ms); | 273 EXPECT_EQ(data->queue_duration_max(), queue_ms); |
| 273 EXPECT_EQ(data->queue_duration_sample(), queue_ms); | 274 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
| 274 EXPECT_EQ(data->count(), 2); | 275 EXPECT_EQ(data->count(), 2); |
| 275 EXPECT_EQ(nullptr, data->last_phase_snapshot()); | 276 EXPECT_EQ(nullptr, data->last_phase_snapshot()); |
| 276 } | 277 } |
| 277 | 278 |
| 278 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) { | 279 TEST_F(TrackedObjectsTest, DeathDataTest2Phases) { |
| 279 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); | 280 ThreadData::InitializeAndSetTrackingStatus(ThreadData::PROFILING_ACTIVE); |
| 280 | 281 |
| 281 scoped_ptr<DeathData> data(new DeathData()); | 282 scoped_ptr<DeathData> data(new DeathData()); |
| 282 ASSERT_NE(data, nullptr); | 283 ASSERT_NE(data, nullptr); |
| 283 | 284 |
| 284 int32 run_ms = 42; | 285 int32_t run_ms = 42; |
| 285 int32 queue_ms = 8; | 286 int32_t queue_ms = 8; |
| 286 | 287 |
| 287 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. | 288 const int kUnrandomInt = 0; // Fake random int that ensure we sample data. |
| 288 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); | 289 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
| 289 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); | 290 data->RecordDeath(queue_ms, run_ms, kUnrandomInt); |
| 290 | 291 |
| 291 data->OnProfilingPhaseCompleted(123); | 292 data->OnProfilingPhaseCompleted(123); |
| 292 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); | 293 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms); |
| 293 EXPECT_EQ(data->run_duration_max(), 0); | 294 EXPECT_EQ(data->run_duration_max(), 0); |
| 294 EXPECT_EQ(data->run_duration_sample(), run_ms); | 295 EXPECT_EQ(data->run_duration_sample(), run_ms); |
| 295 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); | 296 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms); |
| 296 EXPECT_EQ(data->queue_duration_max(), 0); | 297 EXPECT_EQ(data->queue_duration_max(), 0); |
| 297 EXPECT_EQ(data->queue_duration_sample(), queue_ms); | 298 EXPECT_EQ(data->queue_duration_sample(), queue_ms); |
| 298 EXPECT_EQ(data->count(), 2); | 299 EXPECT_EQ(data->count(), 2); |
| 299 ASSERT_NE(nullptr, data->last_phase_snapshot()); | 300 ASSERT_NE(nullptr, data->last_phase_snapshot()); |
| 300 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase); | 301 EXPECT_EQ(123, data->last_phase_snapshot()->profiling_phase); |
| 301 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count); | 302 EXPECT_EQ(2, data->last_phase_snapshot()->death_data.count); |
| 302 EXPECT_EQ(2 * run_ms, | 303 EXPECT_EQ(2 * run_ms, |
| 303 data->last_phase_snapshot()->death_data.run_duration_sum); | 304 data->last_phase_snapshot()->death_data.run_duration_sum); |
| 304 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max); | 305 EXPECT_EQ(run_ms, data->last_phase_snapshot()->death_data.run_duration_max); |
| 305 EXPECT_EQ(run_ms, | 306 EXPECT_EQ(run_ms, |
| 306 data->last_phase_snapshot()->death_data.run_duration_sample); | 307 data->last_phase_snapshot()->death_data.run_duration_sample); |
| 307 EXPECT_EQ(2 * queue_ms, | 308 EXPECT_EQ(2 * queue_ms, |
| 308 data->last_phase_snapshot()->death_data.queue_duration_sum); | 309 data->last_phase_snapshot()->death_data.queue_duration_sum); |
| 309 EXPECT_EQ(queue_ms, | 310 EXPECT_EQ(queue_ms, |
| 310 data->last_phase_snapshot()->death_data.queue_duration_max); | 311 data->last_phase_snapshot()->death_data.queue_duration_max); |
| 311 EXPECT_EQ(queue_ms, | 312 EXPECT_EQ(queue_ms, |
| 312 data->last_phase_snapshot()->death_data.queue_duration_sample); | 313 data->last_phase_snapshot()->death_data.queue_duration_sample); |
| 313 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev); | 314 EXPECT_EQ(nullptr, data->last_phase_snapshot()->prev); |
| 314 | 315 |
| 315 int32 run_ms1 = 21; | 316 int32_t run_ms1 = 21; |
| 316 int32 queue_ms1 = 4; | 317 int32_t queue_ms1 = 4; |
| 317 | 318 |
| 318 data->RecordDeath(queue_ms1, run_ms1, kUnrandomInt); | 319 data->RecordDeath(queue_ms1, run_ms1, kUnrandomInt); |
| 319 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms + run_ms1); | 320 EXPECT_EQ(data->run_duration_sum(), run_ms + run_ms + run_ms1); |
| 320 EXPECT_EQ(data->run_duration_max(), run_ms1); | 321 EXPECT_EQ(data->run_duration_max(), run_ms1); |
| 321 EXPECT_EQ(data->run_duration_sample(), run_ms1); | 322 EXPECT_EQ(data->run_duration_sample(), run_ms1); |
| 322 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms + queue_ms1); | 323 EXPECT_EQ(data->queue_duration_sum(), queue_ms + queue_ms + queue_ms1); |
| 323 EXPECT_EQ(data->queue_duration_max(), queue_ms1); | 324 EXPECT_EQ(data->queue_duration_max(), queue_ms1); |
| 324 EXPECT_EQ(data->queue_duration_sample(), queue_ms1); | 325 EXPECT_EQ(data->queue_duration_sample(), queue_ms1); |
| 325 EXPECT_EQ(data->count(), 3); | 326 EXPECT_EQ(data->count(), 3); |
| 326 ASSERT_NE(nullptr, data->last_phase_snapshot()); | 327 ASSERT_NE(nullptr, data->last_phase_snapshot()); |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max); | 1178 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_max); |
| 1178 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); | 1179 EXPECT_EQ(2, process_data_phase.tasks[t1].death_data.run_duration_sample); |
| 1179 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); | 1180 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sum); |
| 1180 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); | 1181 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_max); |
| 1181 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); | 1182 EXPECT_EQ(1, process_data_phase.tasks[t1].death_data.queue_duration_sample); |
| 1182 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); | 1183 EXPECT_EQ(kMainThreadName, process_data_phase.tasks[t1].death_thread_name); |
| 1183 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); | 1184 EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id); |
| 1184 } | 1185 } |
| 1185 | 1186 |
| 1186 } // namespace tracked_objects | 1187 } // namespace tracked_objects |
| OLD | NEW |