OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/debug/activity_analyzer.h" | 5 #include "base/debug/activity_analyzer.h" |
6 | 6 |
7 #include <atomic> | 7 #include <atomic> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 EXPECT_EQ(string1b, user_data.at("sref1").GetStringReference().data()); | 307 EXPECT_EQ(string1b, user_data.at("sref1").GetStringReference().data()); |
308 EXPECT_EQ(strlen(string1b), | 308 EXPECT_EQ(strlen(string1b), |
309 user_data.at("sref1").GetStringReference().size()); | 309 user_data.at("sref1").GetStringReference().size()); |
310 } | 310 } |
311 | 311 |
312 ASSERT_TRUE(tracker->CreateSnapshot(&tracker_snapshot)); | 312 ASSERT_TRUE(tracker->CreateSnapshot(&tracker_snapshot)); |
313 ASSERT_EQ(0U, tracker_snapshot.activity_stack.size()); | 313 ASSERT_EQ(0U, tracker_snapshot.activity_stack.size()); |
314 } | 314 } |
315 | 315 |
316 TEST_F(ActivityAnalyzerTest, GlobalUserDataTest) { | 316 TEST_F(ActivityAnalyzerTest, GlobalUserDataTest) { |
| 317 const int64_t pid = GetCurrentProcId(); |
317 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0); | 318 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0); |
318 | 319 |
319 const char string1[] = "foo"; | 320 const char string1[] = "foo"; |
320 const char string2[] = "bar"; | 321 const char string2[] = "bar"; |
321 | 322 |
322 PersistentMemoryAllocator* allocator = | 323 PersistentMemoryAllocator* allocator = |
323 GlobalActivityTracker::Get()->allocator(); | 324 GlobalActivityTracker::Get()->allocator(); |
324 GlobalActivityAnalyzer global_analyzer(MakeUnique<PersistentMemoryAllocator>( | 325 GlobalActivityAnalyzer global_analyzer(MakeUnique<PersistentMemoryAllocator>( |
325 const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true)); | 326 const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true)); |
326 | 327 |
327 ActivityUserData& global_data = GlobalActivityTracker::Get()->global_data(); | 328 ActivityUserData& process_data = GlobalActivityTracker::Get()->process_data(); |
328 global_data.Set("raw", "foo", 3); | 329 ASSERT_NE(0U, process_data.id()); |
329 global_data.SetString("string", "bar"); | 330 process_data.Set("raw", "foo", 3); |
330 global_data.SetChar("char", '9'); | 331 process_data.SetString("string", "bar"); |
331 global_data.SetInt("int", -9999); | 332 process_data.SetChar("char", '9'); |
332 global_data.SetUint("uint", 9999); | 333 process_data.SetInt("int", -9999); |
333 global_data.SetBool("bool", true); | 334 process_data.SetUint("uint", 9999); |
334 global_data.SetReference("ref", string1, sizeof(string1)); | 335 process_data.SetBool("bool", true); |
335 global_data.SetStringReference("sref", string2); | 336 process_data.SetReference("ref", string1, sizeof(string1)); |
| 337 process_data.SetStringReference("sref", string2); |
336 | 338 |
| 339 int64_t first_pid = global_analyzer.GetFirstProcess(); |
| 340 DCHECK_EQ(pid, first_pid); |
337 const ActivityUserData::Snapshot& snapshot = | 341 const ActivityUserData::Snapshot& snapshot = |
338 global_analyzer.GetGlobalDataSnapshot(); | 342 global_analyzer.GetProcessDataSnapshot(pid); |
339 ASSERT_TRUE(ContainsKey(snapshot, "raw")); | 343 ASSERT_TRUE(ContainsKey(snapshot, "raw")); |
340 EXPECT_EQ("foo", snapshot.at("raw").Get().as_string()); | 344 EXPECT_EQ("foo", snapshot.at("raw").Get().as_string()); |
341 ASSERT_TRUE(ContainsKey(snapshot, "string")); | 345 ASSERT_TRUE(ContainsKey(snapshot, "string")); |
342 EXPECT_EQ("bar", snapshot.at("string").GetString().as_string()); | 346 EXPECT_EQ("bar", snapshot.at("string").GetString().as_string()); |
343 ASSERT_TRUE(ContainsKey(snapshot, "char")); | 347 ASSERT_TRUE(ContainsKey(snapshot, "char")); |
344 EXPECT_EQ('9', snapshot.at("char").GetChar()); | 348 EXPECT_EQ('9', snapshot.at("char").GetChar()); |
345 ASSERT_TRUE(ContainsKey(snapshot, "int")); | 349 ASSERT_TRUE(ContainsKey(snapshot, "int")); |
346 EXPECT_EQ(-9999, snapshot.at("int").GetInt()); | 350 EXPECT_EQ(-9999, snapshot.at("int").GetInt()); |
347 ASSERT_TRUE(ContainsKey(snapshot, "uint")); | 351 ASSERT_TRUE(ContainsKey(snapshot, "uint")); |
348 EXPECT_EQ(9999U, snapshot.at("uint").GetUint()); | 352 EXPECT_EQ(9999U, snapshot.at("uint").GetUint()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 const ActivityUserData::Snapshot& pdata1 = | 498 const ActivityUserData::Snapshot& pdata1 = |
495 analyzer.GetProcessDataSnapshot(pid1); | 499 analyzer.GetProcessDataSnapshot(pid1); |
496 const ActivityUserData::Snapshot& pdata2 = | 500 const ActivityUserData::Snapshot& pdata2 = |
497 analyzer.GetProcessDataSnapshot(pid2); | 501 analyzer.GetProcessDataSnapshot(pid2); |
498 EXPECT_EQ(1001, pdata1.at("pid").GetInt()); | 502 EXPECT_EQ(1001, pdata1.at("pid").GetInt()); |
499 EXPECT_EQ(2002, pdata2.at("pid").GetInt()); | 503 EXPECT_EQ(2002, pdata2.at("pid").GetInt()); |
500 } | 504 } |
501 | 505 |
502 } // namespace debug | 506 } // namespace debug |
503 } // namespace base | 507 } // namespace base |
OLD | NEW |