forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivity_analyzer_unittest.cc
546 lines (461 loc) · 19.8 KB
/
activity_analyzer_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/debug/activity_analyzer.h"
#include <atomic>
#include <memory>
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/debug/activity_tracker.h"
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ptr_util.h"
#include "base/pending_task.h"
#include "base/process/process.h"
#include "base/stl_util.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/synchronization/spin_wait.h"
#include "base/threading/platform_thread.h"
#include "base/threading/simple_thread.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace debug {
namespace {
class TestActivityTracker : public ThreadActivityTracker {
public:
TestActivityTracker(std::unique_ptr<char[]> memory, size_t mem_size)
: ThreadActivityTracker(memset(memory.get(), 0, mem_size), mem_size),
mem_segment_(std::move(memory)) {}
~TestActivityTracker() override = default;
private:
std::unique_ptr<char[]> mem_segment_;
};
} // namespace
class ActivityAnalyzerTest : public testing::Test {
public:
const int kMemorySize = 1 << 20; // 1MiB
const int kStackSize = 1 << 10; // 1KiB
ActivityAnalyzerTest() = default;
~ActivityAnalyzerTest() override {
GlobalActivityTracker* global_tracker = GlobalActivityTracker::Get();
if (global_tracker) {
global_tracker->ReleaseTrackerForCurrentThreadForTesting();
delete global_tracker;
}
}
std::unique_ptr<ThreadActivityTracker> CreateActivityTracker() {
std::unique_ptr<char[]> memory(new char[kStackSize]);
return std::make_unique<TestActivityTracker>(std::move(memory), kStackSize);
}
template <typename Function>
void AsOtherProcess(int64_t pid, Function function) {
std::unique_ptr<GlobalActivityTracker> old_global =
GlobalActivityTracker::ReleaseForTesting();
ASSERT_TRUE(old_global);
PersistentMemoryAllocator* old_allocator = old_global->allocator();
std::unique_ptr<PersistentMemoryAllocator> new_allocator(
std::make_unique<PersistentMemoryAllocator>(
const_cast<void*>(old_allocator->data()), old_allocator->size(), 0,
0, "", false));
GlobalActivityTracker::CreateWithAllocator(std::move(new_allocator), 3,
pid);
function();
GlobalActivityTracker::ReleaseForTesting();
GlobalActivityTracker::SetForTesting(std::move(old_global));
}
static void DoNothing() {}
};
TEST_F(ActivityAnalyzerTest, ThreadAnalyzerConstruction) {
std::unique_ptr<ThreadActivityTracker> tracker = CreateActivityTracker();
{
ThreadActivityAnalyzer analyzer(*tracker);
EXPECT_TRUE(analyzer.IsValid());
EXPECT_EQ(PlatformThread::GetName(), analyzer.GetThreadName());
}
// TODO(bcwhite): More tests once Analyzer does more.
}
// GlobalActivityAnalyzer tests below.
namespace {
class SimpleActivityThread : public SimpleThread {
public:
SimpleActivityThread(const std::string& name,
const void* source,
Activity::Type activity,
const ActivityData& data)
: SimpleThread(name, Options()),
source_(source),
activity_(activity),
data_(data),
ready_(false),
exit_(false),
exit_condition_(&lock_) {}
~SimpleActivityThread() override = default;
void Run() override {
ThreadActivityTracker::ActivityId id =
GlobalActivityTracker::Get()
->GetOrCreateTrackerForCurrentThread()
->PushActivity(source_, activity_, data_);
{
AutoLock auto_lock(lock_);
ready_.store(true, std::memory_order_release);
while (!exit_.load(std::memory_order_relaxed))
exit_condition_.Wait();
}
GlobalActivityTracker::Get()->GetTrackerForCurrentThread()->PopActivity(id);
}
void Exit() {
AutoLock auto_lock(lock_);
exit_.store(true, std::memory_order_relaxed);
exit_condition_.Signal();
}
void WaitReady() {
SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(ready_.load(std::memory_order_acquire));
}
private:
const void* source_;
Activity::Type activity_;
ActivityData data_;
std::atomic<bool> ready_;
std::atomic<bool> exit_;
Lock lock_;
ConditionVariable exit_condition_;
DISALLOW_COPY_AND_ASSIGN(SimpleActivityThread);
};
} // namespace
TEST_F(ActivityAnalyzerTest, GlobalAnalyzerConstruction) {
GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0);
GlobalActivityTracker::Get()->process_data().SetString("foo", "bar");
PersistentMemoryAllocator* allocator =
GlobalActivityTracker::Get()->allocator();
GlobalActivityAnalyzer analyzer(std::make_unique<PersistentMemoryAllocator>(
const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true));
// The only thread at this point is the test thread of this process.
const int64_t pid = analyzer.GetFirstProcess();
ASSERT_NE(0, pid);
ThreadActivityAnalyzer* ta1 = analyzer.GetFirstAnalyzer(pid);
ASSERT_TRUE(ta1);
EXPECT_FALSE(analyzer.GetNextAnalyzer());
ThreadActivityAnalyzer::ThreadKey tk1 = ta1->GetThreadKey();
EXPECT_EQ(ta1, analyzer.GetAnalyzerForThread(tk1));
EXPECT_EQ(0, analyzer.GetNextProcess());
// Create a second thread that will do something.
SimpleActivityThread t2("t2", nullptr, Activity::ACT_TASK,
ActivityData::ForTask(11));
t2.Start();
t2.WaitReady();
// Now there should be two. Calling GetFirstProcess invalidates any
// previously returned analyzer pointers.
ASSERT_EQ(pid, analyzer.GetFirstProcess());
EXPECT_TRUE(analyzer.GetFirstAnalyzer(pid));
EXPECT_TRUE(analyzer.GetNextAnalyzer());
EXPECT_FALSE(analyzer.GetNextAnalyzer());
EXPECT_EQ(0, analyzer.GetNextProcess());
// Let thread exit.
t2.Exit();
t2.Join();
// Now there should be only one again.
ASSERT_EQ(pid, analyzer.GetFirstProcess());
ThreadActivityAnalyzer* ta2 = analyzer.GetFirstAnalyzer(pid);
ASSERT_TRUE(ta2);
EXPECT_FALSE(analyzer.GetNextAnalyzer());
ThreadActivityAnalyzer::ThreadKey tk2 = ta2->GetThreadKey();
EXPECT_EQ(ta2, analyzer.GetAnalyzerForThread(tk2));
EXPECT_EQ(tk1, tk2);
EXPECT_EQ(0, analyzer.GetNextProcess());
// Verify that there is process data.
const ActivityUserData::Snapshot& data_snapshot =
analyzer.GetProcessDataSnapshot(pid);
ASSERT_LE(1U, data_snapshot.size());
EXPECT_EQ("bar", data_snapshot.at("foo").GetString());
}
TEST_F(ActivityAnalyzerTest, GlobalAnalyzerFromSharedMemory) {
SharedMemoryHandle handle1;
SharedMemoryHandle handle2;
{
std::unique_ptr<SharedMemory> shmem(new SharedMemory());
ASSERT_TRUE(shmem->CreateAndMapAnonymous(kMemorySize));
handle1 = shmem->handle().Duplicate();
ASSERT_TRUE(handle1.IsValid());
handle2 = shmem->handle().Duplicate();
ASSERT_TRUE(handle2.IsValid());
}
GlobalActivityTracker::CreateWithSharedMemoryHandle(handle1, kMemorySize, 0,
"", 3);
GlobalActivityTracker::Get()->process_data().SetString("foo", "bar");
std::unique_ptr<GlobalActivityAnalyzer> analyzer =
GlobalActivityAnalyzer::CreateWithSharedMemoryHandle(handle2,
kMemorySize);
const int64_t pid = analyzer->GetFirstProcess();
ASSERT_NE(0, pid);
const ActivityUserData::Snapshot& data_snapshot =
analyzer->GetProcessDataSnapshot(pid);
ASSERT_LE(1U, data_snapshot.size());
EXPECT_EQ("bar", data_snapshot.at("foo").GetString());
}
TEST_F(ActivityAnalyzerTest, UserDataSnapshotTest) {
GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0);
ThreadActivityAnalyzer::Snapshot tracker_snapshot;
const char string1a[] = "string1a";
const char string1b[] = "string1b";
const char string2a[] = "string2a";
const char string2b[] = "string2b";
PersistentMemoryAllocator* allocator =
GlobalActivityTracker::Get()->allocator();
GlobalActivityAnalyzer global_analyzer(
std::make_unique<PersistentMemoryAllocator>(
const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "",
true));
ThreadActivityTracker* tracker =
GlobalActivityTracker::Get()->GetOrCreateTrackerForCurrentThread();
{
ScopedActivity activity1(1, 11, 111);
ActivityUserData& user_data1 = activity1.user_data();
user_data1.Set("raw1", "foo1", 4);
user_data1.SetString("string1", "bar1");
user_data1.SetChar("char1", '1');
user_data1.SetInt("int1", -1111);
user_data1.SetUint("uint1", 1111);
user_data1.SetBool("bool1", true);
user_data1.SetReference("ref1", string1a, sizeof(string1a));
user_data1.SetStringReference("sref1", string1b);
{
ScopedActivity activity2(2, 22, 222);
ActivityUserData& user_data2 = activity2.user_data();
user_data2.Set("raw2", "foo2", 4);
user_data2.SetString("string2", "bar2");
user_data2.SetChar("char2", '2');
user_data2.SetInt("int2", -2222);
user_data2.SetUint("uint2", 2222);
user_data2.SetBool("bool2", false);
user_data2.SetReference("ref2", string2a, sizeof(string2a));
user_data2.SetStringReference("sref2", string2b);
ASSERT_TRUE(tracker->CreateSnapshot(&tracker_snapshot));
ASSERT_EQ(2U, tracker_snapshot.activity_stack.size());
ThreadActivityAnalyzer analyzer(*tracker);
analyzer.AddGlobalInformation(&global_analyzer);
const ThreadActivityAnalyzer::Snapshot& analyzer_snapshot =
analyzer.activity_snapshot();
ASSERT_EQ(2U, analyzer_snapshot.user_data_stack.size());
const ActivityUserData::Snapshot& user_data =
analyzer_snapshot.user_data_stack.at(1);
EXPECT_EQ(8U, user_data.size());
ASSERT_TRUE(ContainsKey(user_data, "raw2"));
EXPECT_EQ("foo2", user_data.at("raw2").Get().as_string());
ASSERT_TRUE(ContainsKey(user_data, "string2"));
EXPECT_EQ("bar2", user_data.at("string2").GetString().as_string());
ASSERT_TRUE(ContainsKey(user_data, "char2"));
EXPECT_EQ('2', user_data.at("char2").GetChar());
ASSERT_TRUE(ContainsKey(user_data, "int2"));
EXPECT_EQ(-2222, user_data.at("int2").GetInt());
ASSERT_TRUE(ContainsKey(user_data, "uint2"));
EXPECT_EQ(2222U, user_data.at("uint2").GetUint());
ASSERT_TRUE(ContainsKey(user_data, "bool2"));
EXPECT_FALSE(user_data.at("bool2").GetBool());
ASSERT_TRUE(ContainsKey(user_data, "ref2"));
EXPECT_EQ(string2a, user_data.at("ref2").GetReference().data());
EXPECT_EQ(sizeof(string2a), user_data.at("ref2").GetReference().size());
ASSERT_TRUE(ContainsKey(user_data, "sref2"));
EXPECT_EQ(string2b, user_data.at("sref2").GetStringReference().data());
EXPECT_EQ(strlen(string2b),
user_data.at("sref2").GetStringReference().size());
}
ASSERT_TRUE(tracker->CreateSnapshot(&tracker_snapshot));
ASSERT_EQ(1U, tracker_snapshot.activity_stack.size());
ThreadActivityAnalyzer analyzer(*tracker);
analyzer.AddGlobalInformation(&global_analyzer);
const ThreadActivityAnalyzer::Snapshot& analyzer_snapshot =
analyzer.activity_snapshot();
ASSERT_EQ(1U, analyzer_snapshot.user_data_stack.size());
const ActivityUserData::Snapshot& user_data =
analyzer_snapshot.user_data_stack.at(0);
EXPECT_EQ(8U, user_data.size());
EXPECT_EQ("foo1", user_data.at("raw1").Get().as_string());
EXPECT_EQ("bar1", user_data.at("string1").GetString().as_string());
EXPECT_EQ('1', user_data.at("char1").GetChar());
EXPECT_EQ(-1111, user_data.at("int1").GetInt());
EXPECT_EQ(1111U, user_data.at("uint1").GetUint());
EXPECT_TRUE(user_data.at("bool1").GetBool());
EXPECT_EQ(string1a, user_data.at("ref1").GetReference().data());
EXPECT_EQ(sizeof(string1a), user_data.at("ref1").GetReference().size());
EXPECT_EQ(string1b, user_data.at("sref1").GetStringReference().data());
EXPECT_EQ(strlen(string1b),
user_data.at("sref1").GetStringReference().size());
}
ASSERT_TRUE(tracker->CreateSnapshot(&tracker_snapshot));
ASSERT_EQ(0U, tracker_snapshot.activity_stack.size());
}
TEST_F(ActivityAnalyzerTest, GlobalUserDataTest) {
const int64_t pid = GetCurrentProcId();
GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0);
const char string1[] = "foo";
const char string2[] = "bar";
PersistentMemoryAllocator* allocator =
GlobalActivityTracker::Get()->allocator();
GlobalActivityAnalyzer global_analyzer(
std::make_unique<PersistentMemoryAllocator>(
const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "",
true));
ActivityUserData& process_data = GlobalActivityTracker::Get()->process_data();
ASSERT_NE(0U, process_data.id());
process_data.Set("raw", "foo", 3);
process_data.SetString("string", "bar");
process_data.SetChar("char", '9');
process_data.SetInt("int", -9999);
process_data.SetUint("uint", 9999);
process_data.SetBool("bool", true);
process_data.SetReference("ref", string1, sizeof(string1));
process_data.SetStringReference("sref", string2);
int64_t first_pid = global_analyzer.GetFirstProcess();
DCHECK_EQ(pid, first_pid);
const ActivityUserData::Snapshot& snapshot =
global_analyzer.GetProcessDataSnapshot(pid);
ASSERT_TRUE(ContainsKey(snapshot, "raw"));
EXPECT_EQ("foo", snapshot.at("raw").Get().as_string());
ASSERT_TRUE(ContainsKey(snapshot, "string"));
EXPECT_EQ("bar", snapshot.at("string").GetString().as_string());
ASSERT_TRUE(ContainsKey(snapshot, "char"));
EXPECT_EQ('9', snapshot.at("char").GetChar());
ASSERT_TRUE(ContainsKey(snapshot, "int"));
EXPECT_EQ(-9999, snapshot.at("int").GetInt());
ASSERT_TRUE(ContainsKey(snapshot, "uint"));
EXPECT_EQ(9999U, snapshot.at("uint").GetUint());
ASSERT_TRUE(ContainsKey(snapshot, "bool"));
EXPECT_TRUE(snapshot.at("bool").GetBool());
ASSERT_TRUE(ContainsKey(snapshot, "ref"));
EXPECT_EQ(string1, snapshot.at("ref").GetReference().data());
EXPECT_EQ(sizeof(string1), snapshot.at("ref").GetReference().size());
ASSERT_TRUE(ContainsKey(snapshot, "sref"));
EXPECT_EQ(string2, snapshot.at("sref").GetStringReference().data());
EXPECT_EQ(strlen(string2), snapshot.at("sref").GetStringReference().size());
}
TEST_F(ActivityAnalyzerTest, GlobalModulesTest) {
GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0);
GlobalActivityTracker* global = GlobalActivityTracker::Get();
PersistentMemoryAllocator* allocator = global->allocator();
GlobalActivityAnalyzer global_analyzer(
std::make_unique<PersistentMemoryAllocator>(
const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "",
true));
GlobalActivityTracker::ModuleInfo info1;
info1.is_loaded = true;
info1.address = 0x12345678;
info1.load_time = 1111;
info1.size = 0xABCDEF;
info1.timestamp = 111;
info1.age = 11;
info1.identifier[0] = 1;
info1.file = "anything";
info1.debug_file = "elsewhere";
global->RecordModuleInfo(info1);
std::vector<GlobalActivityTracker::ModuleInfo> modules1;
modules1 = global_analyzer.GetModules(global_analyzer.GetFirstProcess());
ASSERT_EQ(1U, modules1.size());
GlobalActivityTracker::ModuleInfo& stored1a = modules1[0];
EXPECT_EQ(info1.is_loaded, stored1a.is_loaded);
EXPECT_EQ(info1.address, stored1a.address);
EXPECT_NE(info1.load_time, stored1a.load_time);
EXPECT_EQ(info1.size, stored1a.size);
EXPECT_EQ(info1.timestamp, stored1a.timestamp);
EXPECT_EQ(info1.age, stored1a.age);
EXPECT_EQ(info1.identifier[0], stored1a.identifier[0]);
EXPECT_EQ(info1.file, stored1a.file);
EXPECT_EQ(info1.debug_file, stored1a.debug_file);
info1.is_loaded = false;
global->RecordModuleInfo(info1);
modules1 = global_analyzer.GetModules(global_analyzer.GetFirstProcess());
ASSERT_EQ(1U, modules1.size());
GlobalActivityTracker::ModuleInfo& stored1b = modules1[0];
EXPECT_EQ(info1.is_loaded, stored1b.is_loaded);
EXPECT_EQ(info1.address, stored1b.address);
EXPECT_NE(info1.load_time, stored1b.load_time);
EXPECT_EQ(info1.size, stored1b.size);
EXPECT_EQ(info1.timestamp, stored1b.timestamp);
EXPECT_EQ(info1.age, stored1b.age);
EXPECT_EQ(info1.identifier[0], stored1b.identifier[0]);
EXPECT_EQ(info1.file, stored1b.file);
EXPECT_EQ(info1.debug_file, stored1b.debug_file);
GlobalActivityTracker::ModuleInfo info2;
info2.is_loaded = true;
info2.address = 0x87654321;
info2.load_time = 2222;
info2.size = 0xFEDCBA;
info2.timestamp = 222;
info2.age = 22;
info2.identifier[0] = 2;
info2.file = "nothing";
info2.debug_file = "farewell";
global->RecordModuleInfo(info2);
std::vector<GlobalActivityTracker::ModuleInfo> modules2;
modules2 = global_analyzer.GetModules(global_analyzer.GetFirstProcess());
ASSERT_EQ(2U, modules2.size());
GlobalActivityTracker::ModuleInfo& stored2 = modules2[1];
EXPECT_EQ(info2.is_loaded, stored2.is_loaded);
EXPECT_EQ(info2.address, stored2.address);
EXPECT_NE(info2.load_time, stored2.load_time);
EXPECT_EQ(info2.size, stored2.size);
EXPECT_EQ(info2.timestamp, stored2.timestamp);
EXPECT_EQ(info2.age, stored2.age);
EXPECT_EQ(info2.identifier[0], stored2.identifier[0]);
EXPECT_EQ(info2.file, stored2.file);
EXPECT_EQ(info2.debug_file, stored2.debug_file);
}
TEST_F(ActivityAnalyzerTest, GlobalLogMessages) {
GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 0);
PersistentMemoryAllocator* allocator =
GlobalActivityTracker::Get()->allocator();
GlobalActivityAnalyzer analyzer(std::make_unique<PersistentMemoryAllocator>(
const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true));
GlobalActivityTracker::Get()->RecordLogMessage("hello world");
GlobalActivityTracker::Get()->RecordLogMessage("foo bar");
std::vector<std::string> messages = analyzer.GetLogMessages();
ASSERT_EQ(2U, messages.size());
EXPECT_EQ("hello world", messages[0]);
EXPECT_EQ("foo bar", messages[1]);
}
TEST_F(ActivityAnalyzerTest, GlobalMultiProcess) {
GlobalActivityTracker::CreateWithLocalMemory(kMemorySize, 0, "", 3, 1001);
GlobalActivityTracker* global = GlobalActivityTracker::Get();
PersistentMemoryAllocator* allocator = global->allocator();
EXPECT_EQ(1001, global->process_id());
int64_t process_id;
int64_t create_stamp;
ActivityUserData::GetOwningProcessId(
GlobalActivityTracker::Get()->process_data().GetBaseAddress(),
&process_id, &create_stamp);
ASSERT_EQ(1001, process_id);
GlobalActivityTracker::Get()->process_data().SetInt("pid",
global->process_id());
GlobalActivityAnalyzer analyzer(std::make_unique<PersistentMemoryAllocator>(
const_cast<void*>(allocator->data()), allocator->size(), 0, 0, "", true));
AsOtherProcess(2002, [&global]() {
ASSERT_NE(global, GlobalActivityTracker::Get());
EXPECT_EQ(2002, GlobalActivityTracker::Get()->process_id());
int64_t process_id;
int64_t create_stamp;
ActivityUserData::GetOwningProcessId(
GlobalActivityTracker::Get()->process_data().GetBaseAddress(),
&process_id, &create_stamp);
ASSERT_EQ(2002, process_id);
GlobalActivityTracker::Get()->process_data().SetInt(
"pid", GlobalActivityTracker::Get()->process_id());
});
ASSERT_EQ(global, GlobalActivityTracker::Get());
EXPECT_EQ(1001, GlobalActivityTracker::Get()->process_id());
const int64_t pid1 = analyzer.GetFirstProcess();
ASSERT_EQ(1001, pid1);
const int64_t pid2 = analyzer.GetNextProcess();
ASSERT_EQ(2002, pid2);
EXPECT_EQ(0, analyzer.GetNextProcess());
const ActivityUserData::Snapshot& pdata1 =
analyzer.GetProcessDataSnapshot(pid1);
const ActivityUserData::Snapshot& pdata2 =
analyzer.GetProcessDataSnapshot(pid2);
EXPECT_EQ(1001, pdata1.at("pid").GetInt());
EXPECT_EQ(2002, pdata2.at("pid").GetInt());
}
} // namespace debug
} // namespace base