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

Side by Side Diff: base/debug/activity_analyzer_unittest.cc

Issue 2566983009: Support storing information about what modules are loaded in the process. (Closed)
Patch Set: changed GUID to generic 'identifier'; noted it and others as 'opaque' with no defined meaning Created 3 years, 11 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 | « base/debug/activity_analyzer.cc ('k') | base/debug/activity_tracker.h » ('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 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/bind.h" 10 #include "base/bind.h"
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 ASSERT_TRUE(ContainsKey(snapshot, "bool")); 314 ASSERT_TRUE(ContainsKey(snapshot, "bool"));
315 EXPECT_TRUE(snapshot.at("bool").GetBool()); 315 EXPECT_TRUE(snapshot.at("bool").GetBool());
316 ASSERT_TRUE(ContainsKey(snapshot, "ref")); 316 ASSERT_TRUE(ContainsKey(snapshot, "ref"));
317 EXPECT_EQ(string1, snapshot.at("ref").GetReference().data()); 317 EXPECT_EQ(string1, snapshot.at("ref").GetReference().data());
318 EXPECT_EQ(sizeof(string1), snapshot.at("ref").GetReference().size()); 318 EXPECT_EQ(sizeof(string1), snapshot.at("ref").GetReference().size());
319 ASSERT_TRUE(ContainsKey(snapshot, "sref")); 319 ASSERT_TRUE(ContainsKey(snapshot, "sref"));
320 EXPECT_EQ(string2, snapshot.at("sref").GetStringReference().data()); 320 EXPECT_EQ(string2, snapshot.at("sref").GetStringReference().data());
321 EXPECT_EQ(strlen(string2), snapshot.at("sref").GetStringReference().size()); 321 EXPECT_EQ(strlen(string2), snapshot.at("sref").GetStringReference().size());
322 } 322 }
323 323
324 TEST_F(ActivityAnalyzerTest, GlobalModulesTest) {
325 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3);
326
327 PersistentMemoryAllocator* allocator =
328 GlobalActivityTracker::Get()->allocator();
329 GlobalActivityAnalyzer global_analyzer(MakeUnique<PersistentMemoryAllocator>(
330 const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true));
331
332 GlobalActivityTracker::ModuleInfo info1;
333 info1.is_loaded = true;
334 info1.address = 0x12345678;
335 info1.load_time = 1111;
336 info1.size = 0xABCDEF;
337 info1.timestamp = 111;
338 info1.age = 11;
339 info1.identifier[0] = 1;
340 info1.file = "anything";
341 info1.debug_file = "elsewhere";
342
343 GlobalActivityTracker::Get()->RecordModuleInfo(info1);
344 std::vector<GlobalActivityTracker::ModuleInfo> modules1;
345 modules1 = global_analyzer.GetModules();
346 ASSERT_EQ(1U, modules1.size());
347 GlobalActivityTracker::ModuleInfo& stored1a = modules1[0];
348 EXPECT_EQ(info1.is_loaded, stored1a.is_loaded);
349 EXPECT_EQ(info1.address, stored1a.address);
350 EXPECT_NE(info1.load_time, stored1a.load_time);
351 EXPECT_EQ(info1.size, stored1a.size);
352 EXPECT_EQ(info1.timestamp, stored1a.timestamp);
353 EXPECT_EQ(info1.age, stored1a.age);
354 EXPECT_EQ(info1.identifier[0], stored1a.identifier[0]);
355 EXPECT_EQ(info1.file, stored1a.file);
356 EXPECT_EQ(info1.debug_file, stored1a.debug_file);
357
358 info1.is_loaded = false;
359 GlobalActivityTracker::Get()->RecordModuleInfo(info1);
360 modules1 = global_analyzer.GetModules();
361 ASSERT_EQ(1U, modules1.size());
362 GlobalActivityTracker::ModuleInfo& stored1b = modules1[0];
363 EXPECT_EQ(info1.is_loaded, stored1b.is_loaded);
364 EXPECT_EQ(info1.address, stored1b.address);
365 EXPECT_NE(info1.load_time, stored1b.load_time);
366 EXPECT_EQ(info1.size, stored1b.size);
367 EXPECT_EQ(info1.timestamp, stored1b.timestamp);
368 EXPECT_EQ(info1.age, stored1b.age);
369 EXPECT_EQ(info1.identifier[0], stored1b.identifier[0]);
370 EXPECT_EQ(info1.file, stored1b.file);
371 EXPECT_EQ(info1.debug_file, stored1b.debug_file);
372
373 GlobalActivityTracker::ModuleInfo info2;
374 info2.is_loaded = true;
375 info2.address = 0x87654321;
376 info2.load_time = 2222;
377 info2.size = 0xFEDCBA;
378 info2.timestamp = 222;
379 info2.age = 22;
380 info2.identifier[0] = 2;
381 info2.file = "nothing";
382 info2.debug_file = "farewell";
383
384 GlobalActivityTracker::Get()->RecordModuleInfo(info2);
385 std::vector<GlobalActivityTracker::ModuleInfo> modules2;
386 modules2 = global_analyzer.GetModules();
387 ASSERT_EQ(2U, modules2.size());
388 GlobalActivityTracker::ModuleInfo& stored2 = modules2[1];
389 EXPECT_EQ(info2.is_loaded, stored2.is_loaded);
390 EXPECT_EQ(info2.address, stored2.address);
391 EXPECT_NE(info2.load_time, stored2.load_time);
392 EXPECT_EQ(info2.size, stored2.size);
393 EXPECT_EQ(info2.timestamp, stored2.timestamp);
394 EXPECT_EQ(info2.age, stored2.age);
395 EXPECT_EQ(info2.identifier[0], stored2.identifier[0]);
396 EXPECT_EQ(info2.file, stored2.file);
397 EXPECT_EQ(info2.debug_file, stored2.debug_file);
398 }
399
324 TEST_F(ActivityAnalyzerTest, GlobalLogMessages) { 400 TEST_F(ActivityAnalyzerTest, GlobalLogMessages) {
325 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3); 401 GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3);
326 402
327 PersistentMemoryAllocator* allocator = 403 PersistentMemoryAllocator* allocator =
328 GlobalActivityTracker::Get()->allocator(); 404 GlobalActivityTracker::Get()->allocator();
329 GlobalActivityAnalyzer analyzer(MakeUnique<PersistentMemoryAllocator>( 405 GlobalActivityAnalyzer analyzer(MakeUnique<PersistentMemoryAllocator>(
330 const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true)); 406 const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true));
331 407
332 GlobalActivityTracker::Get()->RecordLogMessage("hello world"); 408 GlobalActivityTracker::Get()->RecordLogMessage("hello world");
333 GlobalActivityTracker::Get()->RecordLogMessage("foo bar"); 409 GlobalActivityTracker::Get()->RecordLogMessage("foo bar");
334 410
335 std::vector<std::string> messages = analyzer.GetLogMessages(); 411 std::vector<std::string> messages = analyzer.GetLogMessages();
336 ASSERT_EQ(2U, messages.size()); 412 ASSERT_EQ(2U, messages.size());
337 EXPECT_EQ("hello world", messages[0]); 413 EXPECT_EQ("hello world", messages[0]);
338 EXPECT_EQ("foo bar", messages[1]); 414 EXPECT_EQ("foo bar", messages[1]);
339 } 415 }
340 416
341 } // namespace debug 417 } // namespace debug
342 } // namespace base 418 } // namespace base
OLDNEW
« no previous file with comments | « base/debug/activity_analyzer.cc ('k') | base/debug/activity_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698