This repository was archived by the owner on Jan 31, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathSamplingDataPostProcessorTest.cpp
More file actions
1693 lines (1494 loc) · 94.2 KB
/
Copy pathSamplingDataPostProcessorTest.cpp
File metadata and controls
1693 lines (1494 loc) · 94.2 KB
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2021 The Orbit 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 <absl/container/flat_hash_set.h>
#include <absl/hash/hash.h>
#include <absl/types/span.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <algorithm>
#include <cstdint>
#include <filesystem>
#include <functional>
#include <memory>
#include <optional>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
#include "ClientData/CallstackEvent.h"
#include "ClientData/CallstackInfo.h"
#include "ClientData/CallstackType.h"
#include "ClientData/CaptureData.h"
#include "ClientData/LinuxAddressInfo.h"
#include "ClientData/ModuleAndFunctionLookup.h"
#include "ClientData/ModuleIdentifierProvider.h"
#include "ClientData/ModuleManager.h"
#include "ClientData/PostProcessedSamplingData.h"
#include "ClientModel/SamplingDataPostProcessor.h"
#include "GrpcProtos/capture.pb.h"
#include "OrbitBase/Sort.h"
#include "OrbitBase/ThreadConstants.h"
using orbit_client_data::CallstackCount;
using orbit_client_data::CallstackEvent;
using orbit_client_data::CallstackInfo;
using orbit_client_data::CallstackType;
using orbit_client_data::CaptureData;
using orbit_client_data::LinuxAddressInfo;
using orbit_client_data::ModuleManager;
using orbit_client_data::PostProcessedSamplingData;
using orbit_client_data::SampledFunction;
using orbit_client_data::SortedCallstackReport;
using orbit_client_data::ThreadSampleData;
using orbit_grpc_protos::CaptureStarted;
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::Pointwise;
using ::testing::UnorderedElementsAre;
namespace orbit_client_model {
namespace {
SampledFunction MakeSampledFunction(std::string name, std::string module_path, uint32_t exclusive,
float exclusive_percent, uint32_t inclusive,
float inclusive_percent, uint32_t unwind_errors,
float unwind_errors_percent, uint64_t absolute_address) {
SampledFunction sampled_function;
sampled_function.name = std::move(name);
sampled_function.module_path = std::move(module_path);
sampled_function.exclusive = exclusive;
sampled_function.exclusive_percent = exclusive_percent;
sampled_function.inclusive = inclusive;
sampled_function.inclusive_percent = inclusive_percent;
sampled_function.unwind_errors = unwind_errors;
sampled_function.unwind_errors_percent = unwind_errors_percent;
sampled_function.absolute_address = absolute_address;
sampled_function.function = nullptr;
return sampled_function;
}
bool SampledFunctionsAreEqual(const SampledFunction& lhs, const SampledFunction& rhs) {
return lhs.name == rhs.name && lhs.module_path == rhs.module_path &&
lhs.exclusive == rhs.exclusive && lhs.exclusive_percent == rhs.exclusive_percent &&
lhs.inclusive == rhs.inclusive && lhs.inclusive_percent == rhs.inclusive_percent &&
lhs.unwind_errors == rhs.unwind_errors &&
lhs.unwind_errors_percent == rhs.unwind_errors_percent &&
lhs.absolute_address == rhs.absolute_address && lhs.function == rhs.function;
}
MATCHER_P(SampledFunctionEq, that, "") {
const SampledFunction& lhs = arg;
const SampledFunction& rhs = that;
return SampledFunctionsAreEqual(lhs, rhs);
}
bool CallstackIdToCallstackEventPairsAreEqual(
const std::pair<uint64_t, std::vector<CallstackEvent>>& lhs,
const std::pair<uint64_t, std::vector<CallstackEvent>>& rhs) {
auto callstack_events_projector = [](const CallstackEvent& event) {
return std::make_tuple(event.timestamp_ns(), event.callstack_id(), event.thread_id());
};
auto callstack_events_equal = [&callstack_events_projector](const CallstackEvent& lhs,
const CallstackEvent& rhs) {
return callstack_events_projector(lhs) == callstack_events_projector(rhs);
};
std::vector<CallstackEvent> lhs_events = lhs.second;
orbit_base::sort(lhs_events.begin(), lhs_events.end(), callstack_events_projector);
std::vector<CallstackEvent> rhs_events = rhs.second;
orbit_base::sort(rhs_events.begin(), rhs_events.end(), callstack_events_projector);
return lhs.first == rhs.first &&
std::equal(lhs_events.begin(), lhs_events.end(), rhs_events.begin(), rhs_events.end(),
callstack_events_equal);
};
MATCHER_P(CallstackIdToCallstackEventsEq, that, "") {
const std::pair<uint64_t, std::vector<CallstackEvent>>& lhs = arg;
const std::pair<uint64_t, std::vector<CallstackEvent>>& rhs = that;
return CallstackIdToCallstackEventPairsAreEqual(lhs, rhs);
}
SortedCallstackReport MakeSortedCallstackReport(
absl::Span<const std::pair<int, uint64_t>> counts_and_callstack_ids) {
SortedCallstackReport report{};
for (const auto& [count, callstack_id] : counts_and_callstack_ids) {
report.total_callstack_count += count;
CallstackCount callstack_count;
callstack_count.count = count;
callstack_count.callstack_id = callstack_id;
report.callstack_counts.push_back(callstack_count);
}
return report;
}
MATCHER_P(SortedCallstackReportEq, that, "") {
const SortedCallstackReport& lhs = arg;
const SortedCallstackReport& rhs = that;
// `SortedCallstackReport::callstacks_counts` is sorted only by `CallstackCount::count` (in
// descending order), hence the order is not unique. Sort again considering
// `CallstackCount::callstack_id`, too (also descending, it doesn't matter which way), to
// facilitate the comparison of `SortedCallstackReport`s for equality.
auto callstack_count_projector = [](const CallstackCount& callstack_count) {
return std::make_pair(callstack_count.count, callstack_count.callstack_id);
};
std::vector<CallstackCount> lhs_resorted_callstacks_counts = lhs.callstack_counts;
orbit_base::sort(lhs_resorted_callstacks_counts.begin(), lhs_resorted_callstacks_counts.end(),
callstack_count_projector, std::greater<>{});
std::vector<CallstackCount> rhs_resorted_callstacks_counts = rhs.callstack_counts;
orbit_base::sort(rhs_resorted_callstacks_counts.begin(), rhs_resorted_callstacks_counts.end(),
callstack_count_projector, std::greater<>{});
auto callstack_count_equal = [&callstack_count_projector](const CallstackCount& lhs,
const CallstackCount& rhs) {
return callstack_count_projector(lhs) == callstack_count_projector(rhs);
};
return lhs.total_callstack_count == rhs.total_callstack_count &&
std::equal(lhs_resorted_callstacks_counts.begin(), lhs_resorted_callstacks_counts.end(),
rhs_resorted_callstacks_counts.begin(), rhs_resorted_callstacks_counts.end(),
callstack_count_equal);
}
class SamplingDataPostProcessorTest : public ::testing::Test {
protected:
void SetUp() override {}
void TearDown() override {}
orbit_client_data::ModuleIdentifierProvider module_identifier_provider_{};
CaptureData capture_data_{CaptureStarted{}, std::filesystem::path{},
absl::flat_hash_set<uint64_t>{}, CaptureData::DataSource::kLiveCapture,
&module_identifier_provider_};
void AddCallstackInfo(uint64_t callstack_id, absl::Span<const uint64_t> callstack_frames,
CallstackType callstack_type) {
CallstackInfo callstack_info{{callstack_frames.begin(), callstack_frames.end()},
callstack_type};
capture_data_.AddUniqueCallstack(callstack_id, std::move(callstack_info));
}
void AddCallstackEvent(uint64_t callstack_id, uint32_t thread_id) {
current_callstack_timestamp_ns_ += 100;
CallstackEvent callstack_event{current_callstack_timestamp_ns_, callstack_id, thread_id};
capture_data_.AddCallstackEvent(callstack_event);
}
void AddAddressInfo(std::string module_path, std::string function_name, uint64_t absolute_address,
uint64_t offset_in_function) {
LinuxAddressInfo linux_address_info{absolute_address, offset_in_function,
std::move(module_path), std::move(function_name)};
capture_data_.InsertAddressInfo(std::move(linux_address_info));
}
static const inline std::string kModulePath = "/path/to/module";
static const inline std::string kFunction1Name = "function1";
static constexpr uint64_t kFunction1StartAbsoluteAddress = 0x10;
static constexpr uint64_t kFunction1Instruction1AbsoluteAddress = 0x11;
static constexpr uint64_t kFunction1Instruction1OffsetInFunction =
kFunction1Instruction1AbsoluteAddress - kFunction1StartAbsoluteAddress;
static const inline std::string kFunction2Name = "function2";
static constexpr uint64_t kFunction2StartAbsoluteAddress = 0x20;
static constexpr uint64_t kFunction2Instruction1AbsoluteAddress = 0x21;
static constexpr uint64_t kFunction2Instruction1OffsetInFunction =
kFunction2Instruction1AbsoluteAddress - kFunction2StartAbsoluteAddress;
static const inline std::string kFunction3Name = "function3";
static constexpr uint64_t kFunction3StartAbsoluteAddress = 0x30;
static constexpr uint64_t kFunction3Instruction1AbsoluteAddress = 0x31;
static constexpr uint64_t kFunction3Instruction1OffsetInFunction =
kFunction3Instruction1AbsoluteAddress - kFunction3StartAbsoluteAddress;
static constexpr uint64_t kFunction3Instruction2AbsoluteAddress = 0x32;
static constexpr uint64_t kFunction3Instruction2OffsetInFunction =
kFunction3Instruction2AbsoluteAddress - kFunction3StartAbsoluteAddress;
static const inline std::string kFunction4Name = "function4";
static constexpr uint64_t kFunction4StartAbsoluteAddress = 0x40;
static constexpr uint64_t kFunction4Instruction1AbsoluteAddress = 0x41;
static constexpr uint64_t kFunction4Instruction1OffsetInFunction =
kFunction4Instruction1AbsoluteAddress - kFunction4StartAbsoluteAddress;
void AddAllAddressInfos() {
AddAddressInfo(kModulePath, kFunction1Name, kFunction1Instruction1AbsoluteAddress,
kFunction1Instruction1OffsetInFunction);
AddAddressInfo(kModulePath, kFunction2Name, kFunction2Instruction1AbsoluteAddress,
kFunction2Instruction1OffsetInFunction);
AddAddressInfo(kModulePath, kFunction3Name, kFunction3Instruction1AbsoluteAddress,
kFunction3Instruction1OffsetInFunction);
AddAddressInfo(kModulePath, kFunction3Name, kFunction3Instruction2AbsoluteAddress,
kFunction3Instruction2OffsetInFunction);
AddAddressInfo(kModulePath, kFunction4Name, kFunction4Instruction1AbsoluteAddress,
kFunction4Instruction1OffsetInFunction);
}
// See AddCallstackEventsAllInThreadId1 for the meaning of the letters next to the frames.
static constexpr uint64_t kCallstack1Id = 1;
static const inline std::vector<uint64_t> kCallstack1Frames{
kFunction3Instruction1AbsoluteAddress, // C
kFunction2Instruction1AbsoluteAddress, // B
kFunction1Instruction1AbsoluteAddress, // A
};
static const inline std::vector<uint64_t> kCallstack1ResolvedFrames{
kFunction3StartAbsoluteAddress,
kFunction2StartAbsoluteAddress,
kFunction1StartAbsoluteAddress,
};
static constexpr uint64_t kCallstack2Id = 2;
static const inline std::vector<uint64_t> kCallstack2Frames{
kFunction4Instruction1AbsoluteAddress, // D
kFunction3Instruction1AbsoluteAddress, // C
kFunction2Instruction1AbsoluteAddress, // B
kFunction1Instruction1AbsoluteAddress, // A
};
static const inline std::vector<uint64_t> kCallstack2ResolvedFrames{
kFunction4StartAbsoluteAddress,
kFunction3StartAbsoluteAddress,
kFunction2StartAbsoluteAddress,
kFunction1StartAbsoluteAddress,
};
static constexpr uint64_t kCallstack3Id = 3;
static const inline std::vector<uint64_t> kCallstack3Frames{
kFunction3Instruction2AbsoluteAddress, // C'
kFunction3Instruction1AbsoluteAddress, // C
kFunction1Instruction1AbsoluteAddress, // A
};
static const inline std::vector<uint64_t> kCallstack3ResolvedFrames{
kFunction3StartAbsoluteAddress,
kFunction3StartAbsoluteAddress,
kFunction1StartAbsoluteAddress,
};
static constexpr uint64_t kCallstack4Id = 4;
static const inline std::vector<uint64_t> kCallstack4Frames{
kFunction3Instruction1AbsoluteAddress, // C
kFunction3Instruction1AbsoluteAddress, // C
kFunction1Instruction1AbsoluteAddress, // A
};
static const inline std::vector<uint64_t> kCallstack4ResolvedFrames{
kFunction3StartAbsoluteAddress,
kFunction3StartAbsoluteAddress,
kFunction1StartAbsoluteAddress,
};
void AddAllCallstackInfos(CallstackType callstack_type) {
AddCallstackInfo(kCallstack1Id, kCallstack1Frames, callstack_type);
AddCallstackInfo(kCallstack2Id, kCallstack2Frames, callstack_type);
AddCallstackInfo(kCallstack3Id, kCallstack3Frames, callstack_type);
AddCallstackInfo(kCallstack4Id, kCallstack4Frames, callstack_type);
}
void AddAllCallstackInfosWithMixedCallstackTypes() {
AddCallstackInfo(kCallstack1Id, kCallstack1Frames, CallstackType::kDwarfUnwindingError);
AddCallstackInfo(kCallstack2Id, kCallstack2Frames, CallstackType::kComplete);
AddCallstackInfo(kCallstack3Id, kCallstack3Frames, CallstackType::kComplete);
AddCallstackInfo(kCallstack4Id, kCallstack4Frames,
CallstackType::kFilteredByMajorityOutermostFrame);
}
static constexpr int32_t kThreadId1 = 42;
static constexpr int32_t kThreadId2 = 43;
static constexpr int32_t kThreadIdNotSampled = 99;
void AddCallstackEventsAllInThreadId1() {
// Let:
// A = kFunction1Instruction1AbsoluteAddress,
// B = kFunction2Instruction1AbsoluteAddress,
// C = kFunction3Instruction1AbsoluteAddress,
// C' = kFunction3Instruction2AbsoluteAddress,
// D = kFunction4Instruction1AbsoluteAddress.
// These are the CallstackEvents that are added, innermost frame at the top. Note that:
// - the first and second CallstackEvents have the same Callstack;
// - the last CallstackEvent has two identical frames;
// - the number under each CallstackEvent is the callstack id.
// D
// C C C C' C
// B B B C C
// A A A A A
// ---------------------
// 1 1 2 3 4
//
// Note that when the CallstackInfos are added with AddAllCallstackInfosWithMixedCallstackTypes,
// for statistics and selection the added CallstackEvents are effectively the following. The 'E'
// indicates which CallstackEvents refer to a non-kComplete CallstackInfo.
// D
// C C'
// B C
// C C A A C
// ---------------------
// 1 1 2 3 4
// E E E
AddCallstackEvent(kCallstack1Id, kThreadId1);
AddCallstackEvent(kCallstack1Id,
kThreadId1); // Intentionally two CallstackEvents with the same CallstackInfo
AddCallstackEvent(kCallstack2Id, kThreadId1);
AddCallstackEvent(kCallstack3Id, kThreadId1);
AddCallstackEvent(kCallstack4Id, kThreadId1);
}
void AddCallstackEventsInThreadId1And2() {
// Like above, but with CallstackEvents split between kThreadId1 and kThreadId2 as follows:
// kThreadId1 | kThreadId2
// D
// C C | C C' C
// B B | B C C
// A A | A A A
// ----------------------------
// 1 2 | 1 3 4
//
// When the CallstackInfos are added with AddAllCallstackInfosWithMixedCallstackTypes:
// kThreadId1 | kThreadId2
// D
// C | C'
// B | C
// C A | C A C
// ----------------------------
// 1 2 | 1 3 4
// E | E E
AddCallstackEvent(kCallstack1Id, kThreadId1);
AddCallstackEvent(kCallstack2Id, kThreadId1);
AddCallstackEvent(kCallstack1Id, kThreadId2);
AddCallstackEvent(kCallstack3Id, kThreadId2);
AddCallstackEvent(kCallstack4Id, kThreadId2);
}
void SetPostProcessedSamplingData() {
orbit_client_data::ModuleManager module_manager{&module_identifier_provider_};
ppsd_ = CreatePostProcessedSamplingData(capture_data_.GetCallstackData(), capture_data_,
module_manager);
}
PostProcessedSamplingData ppsd_;
void VerifyNoCallstackInfos() {
EXPECT_DEATH((void)ppsd_.GetResolvedCallstack(kCallstack1Id), "");
EXPECT_DEATH((void)ppsd_.GetResolvedCallstack(kCallstack2Id), "");
EXPECT_DEATH((void)ppsd_.GetResolvedCallstack(kCallstack3Id), "");
EXPECT_DEATH((void)ppsd_.GetResolvedCallstack(kCallstack4Id), "");
}
void VerifyAllCallstackInfos(CallstackType expected_callstack_type) {
{
const CallstackInfo& resolved_callstack_1 = ppsd_.GetResolvedCallstack(kCallstack1Id);
EXPECT_THAT(resolved_callstack_1.frames(), Pointwise(Eq(), kCallstack1ResolvedFrames));
EXPECT_EQ(resolved_callstack_1.type(), expected_callstack_type);
}
{
const CallstackInfo& resolved_callstack_2 = ppsd_.GetResolvedCallstack(kCallstack2Id);
EXPECT_THAT(resolved_callstack_2.frames(), Pointwise(Eq(), kCallstack2ResolvedFrames));
EXPECT_EQ(resolved_callstack_2.type(), expected_callstack_type);
}
{
const CallstackInfo& resolved_callstack_3 = ppsd_.GetResolvedCallstack(kCallstack3Id);
EXPECT_THAT(resolved_callstack_3.frames(), Pointwise(Eq(), kCallstack3ResolvedFrames));
EXPECT_EQ(resolved_callstack_3.type(), expected_callstack_type);
}
{
const CallstackInfo& resolved_callstack_4 = ppsd_.GetResolvedCallstack(kCallstack4Id);
EXPECT_THAT(resolved_callstack_4.frames(), Pointwise(Eq(), kCallstack4ResolvedFrames));
EXPECT_EQ(resolved_callstack_4.type(), expected_callstack_type);
}
}
void VerifyAllCallstackInfosWithMixedCallstackTypes() {
{
const CallstackInfo& resolved_callstack_1 = ppsd_.GetResolvedCallstack(kCallstack1Id);
EXPECT_THAT(resolved_callstack_1.frames(), Pointwise(Eq(), kCallstack1ResolvedFrames));
EXPECT_EQ(resolved_callstack_1.type(), CallstackType::kDwarfUnwindingError);
}
{
const CallstackInfo& resolved_callstack_2 = ppsd_.GetResolvedCallstack(kCallstack2Id);
EXPECT_THAT(resolved_callstack_2.frames(), Pointwise(Eq(), kCallstack2ResolvedFrames));
EXPECT_EQ(resolved_callstack_2.type(), CallstackType::kComplete);
}
{
const CallstackInfo& resolved_callstack_3 = ppsd_.GetResolvedCallstack(kCallstack3Id);
EXPECT_THAT(resolved_callstack_3.frames(), Pointwise(Eq(), kCallstack3ResolvedFrames));
EXPECT_EQ(resolved_callstack_3.type(), CallstackType::kComplete);
}
{
const CallstackInfo& resolved_callstack_4 = ppsd_.GetResolvedCallstack(kCallstack4Id);
EXPECT_THAT(resolved_callstack_4.frames(), Pointwise(Eq(), kCallstack4ResolvedFrames));
EXPECT_EQ(resolved_callstack_4.type(), CallstackType::kFilteredByMajorityOutermostFrame);
}
}
void VerifyAllCallstackInfosWithoutAddressInfos(CallstackType expected_callstack_type) {
{
const CallstackInfo& resolved_callstack_1 = ppsd_.GetResolvedCallstack(kCallstack1Id);
EXPECT_THAT(resolved_callstack_1.frames(), Pointwise(Eq(), kCallstack1Frames));
EXPECT_EQ(resolved_callstack_1.type(), expected_callstack_type);
}
{
const CallstackInfo& resolved_callstack_2 = ppsd_.GetResolvedCallstack(kCallstack2Id);
EXPECT_THAT(resolved_callstack_2.frames(), Pointwise(Eq(), kCallstack2Frames));
EXPECT_EQ(resolved_callstack_2.type(), expected_callstack_type);
}
{
const CallstackInfo& resolved_callstack_3 = ppsd_.GetResolvedCallstack(kCallstack3Id);
EXPECT_THAT(resolved_callstack_3.frames(), Pointwise(Eq(), kCallstack3Frames));
EXPECT_EQ(resolved_callstack_3.type(), expected_callstack_type);
}
{
const CallstackInfo& resolved_callstack_4 = ppsd_.GetResolvedCallstack(kCallstack4Id);
EXPECT_THAT(resolved_callstack_4.frames(), Pointwise(Eq(), kCallstack4Frames));
EXPECT_EQ(resolved_callstack_4.type(), expected_callstack_type);
}
}
static void VerifyThreadSampleDataForCallstackEventsAllInTheSameThread(
const ThreadSampleData& actual_thread_sample_data, uint32_t expected_thread_id) {
EXPECT_EQ(actual_thread_sample_data.thread_id, expected_thread_id);
EXPECT_EQ(actual_thread_sample_data.samples_count, 5);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 0);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id, std::vector<CallstackEvent>{{100, kCallstack1Id, kThreadId1},
{200, kCallstack1Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack2Id, std::vector<CallstackEvent>{{300, kCallstack2Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack3Id, std::vector<CallstackEvent>{{400, kCallstack3Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack4Id, std::vector<CallstackEvent>{{500, kCallstack4Id, kThreadId1}}))));
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction2Instruction1AbsoluteAddress, 3),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1StartAbsoluteAddress, 5),
std::make_pair(kFunction2StartAbsoluteAddress, 3),
std::make_pair(kFunction3StartAbsoluteAddress, 5),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
UnorderedElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 4),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(5, kFunction1StartAbsoluteAddress),
std::make_pair(3, kFunction2StartAbsoluteAddress),
std::make_pair(5, kFunction3StartAbsoluteAddress),
std::make_pair(1, kFunction4StartAbsoluteAddress)));
EXPECT_THAT(
actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(
SampledFunctionEq(MakeSampledFunction(kFunction1Name, kModulePath, 0, 0.0f, 5, 100.0f,
0, 0.0f, kFunction1StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction2Name, kModulePath, 0, 0.0f, 3, 60.0f, 0,
0.0f, kFunction2StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction3Name, kModulePath, 4, 80.0f, 5, 100.0f,
0, 0.0f, kFunction3StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction4Name, kModulePath, 1, 20.0f, 1, 20.0f,
0, 0.0f, kFunction4StartAbsoluteAddress))));
}
static void VerifyThreadSampleDataForCallstackEventsAllInTheSameThreadWithMixedCallstackTypes(
const ThreadSampleData& actual_thread_sample_data, uint32_t expected_thread_id) {
EXPECT_EQ(actual_thread_sample_data.thread_id, expected_thread_id);
EXPECT_EQ(actual_thread_sample_data.samples_count, 5);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 3);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id,
std::vector<CallstackEvent>{CallstackEvent{100, kCallstack1Id, kThreadId1},
CallstackEvent{200, kCallstack1Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack2Id, std::vector<CallstackEvent>{{300, kCallstack2Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack3Id, std::vector<CallstackEvent>{{400, kCallstack3Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack4Id,
std::vector<CallstackEvent>{CallstackEvent{500, kCallstack4Id, kThreadId1}}))));
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 2),
std::make_pair(kFunction2Instruction1AbsoluteAddress, 1),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1StartAbsoluteAddress, 2),
std::make_pair(kFunction2StartAbsoluteAddress, 1),
std::make_pair(kFunction3StartAbsoluteAddress, 5),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
UnorderedElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 4),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(2, kFunction1StartAbsoluteAddress),
std::make_pair(1, kFunction2StartAbsoluteAddress),
std::make_pair(5, kFunction3StartAbsoluteAddress),
std::make_pair(1, kFunction4StartAbsoluteAddress)));
EXPECT_THAT(
actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(
SampledFunctionEq(MakeSampledFunction(kFunction1Name, kModulePath, 0, 0.0f, 2, 40.0f, 0,
0.0f, kFunction1StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction2Name, kModulePath, 0, 0.0f, 1, 20.0f, 0,
0.0f, kFunction2StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction3Name, kModulePath, 4, 80.0f, 5, 100.0f,
3, 60.0f, kFunction3StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction4Name, kModulePath, 1, 20.0f, 1, 20.0f,
0, 0.0f, kFunction4StartAbsoluteAddress))));
}
static void
VerifyThreadSampleDataForCallstackEventsAllInTheSameThreadWithOnlyNonCompleteCallstackInfos(
const ThreadSampleData& actual_thread_sample_data, uint32_t expected_thread_id) {
EXPECT_EQ(actual_thread_sample_data.thread_id, expected_thread_id);
EXPECT_EQ(actual_thread_sample_data.samples_count, 5);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 5);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id, std::vector<CallstackEvent>{{100, kCallstack1Id, kThreadId1},
{200, kCallstack1Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack2Id, std::vector<CallstackEvent>{{300, kCallstack2Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack3Id, std::vector<CallstackEvent>{{400, kCallstack3Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack4Id, std::vector<CallstackEvent>{{500, kCallstack4Id, kThreadId1}}))));
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction3Instruction1AbsoluteAddress, 3),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 4),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
UnorderedElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 4),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(4, kFunction3StartAbsoluteAddress),
std::make_pair(1, kFunction4StartAbsoluteAddress)));
EXPECT_THAT(
actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(
SampledFunctionEq(MakeSampledFunction(kFunction3Name, kModulePath, 4, 80.0f, 4, 80.0f,
4, 80.0f, kFunction3StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction4Name, kModulePath, 1, 20.0f, 1, 20.0f,
1, 20.0f, kFunction4StartAbsoluteAddress))));
}
static void VerifyThreadSampleDataForCallstackEventsAllInTheSameThreadWithoutAddressInfos(
const ThreadSampleData& actual_thread_sample_data, uint32_t expected_thread_id) {
EXPECT_EQ(actual_thread_sample_data.thread_id, expected_thread_id);
EXPECT_EQ(actual_thread_sample_data.samples_count, 5);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 0);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id, std::vector<CallstackEvent>{{100, kCallstack1Id, kThreadId1},
{200, kCallstack1Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack2Id, std::vector<CallstackEvent>{{300, kCallstack2Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack3Id, std::vector<CallstackEvent>{{400, kCallstack3Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack4Id, std::vector<CallstackEvent>{{500, kCallstack4Id, kThreadId1}}))));
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction2Instruction1AbsoluteAddress, 3),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction2Instruction1AbsoluteAddress, 3),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
UnorderedElementsAre(std::make_pair(kFunction3Instruction1AbsoluteAddress, 3),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(5, kFunction1Instruction1AbsoluteAddress),
std::make_pair(3, kFunction2Instruction1AbsoluteAddress),
std::make_pair(5, kFunction3Instruction1AbsoluteAddress),
std::make_pair(1, kFunction3Instruction2AbsoluteAddress),
std::make_pair(1, kFunction4Instruction1AbsoluteAddress)));
EXPECT_THAT(
actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(SampledFunctionEq(MakeSampledFunction(
orbit_client_data::kUnknownFunctionOrModuleName,
orbit_client_data::kUnknownFunctionOrModuleName, 0, 0.0f, 5,
100.0f, 0, 0.0f, kFunction1Instruction1AbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(
orbit_client_data::kUnknownFunctionOrModuleName,
orbit_client_data::kUnknownFunctionOrModuleName, 0, 0.0f, 3, 60.0f,
0, 0.0f, kFunction2Instruction1AbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(
orbit_client_data::kUnknownFunctionOrModuleName,
orbit_client_data::kUnknownFunctionOrModuleName, 3, 60.0f, 5,
100.0f, 0, 0.0f, kFunction3Instruction1AbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(
orbit_client_data::kUnknownFunctionOrModuleName,
orbit_client_data::kUnknownFunctionOrModuleName, 1, 20.0f, 1,
20.0f, 0, 0.0f, kFunction3Instruction2AbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(
orbit_client_data::kUnknownFunctionOrModuleName,
orbit_client_data::kUnknownFunctionOrModuleName, 1, 20.0f, 1,
20.0f, 0, 0.0f, kFunction4Instruction1AbsoluteAddress))));
}
static void VerifyThreadSampleDataForCallstackEventsInThreadId1(
const ThreadSampleData& actual_thread_sample_data) {
EXPECT_EQ(actual_thread_sample_data.thread_id, kThreadId1);
EXPECT_EQ(actual_thread_sample_data.samples_count, 2);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 0);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id, std::vector<CallstackEvent>{{100, kCallstack1Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack2Id, std::vector<CallstackEvent>{{200, kCallstack2Id, kThreadId1}}))));
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 2),
std::make_pair(kFunction2Instruction1AbsoluteAddress, 2),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 2),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1StartAbsoluteAddress, 2),
std::make_pair(kFunction2StartAbsoluteAddress, 2),
std::make_pair(kFunction3StartAbsoluteAddress, 2),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
UnorderedElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 1),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(2, kFunction1StartAbsoluteAddress),
std::make_pair(2, kFunction2StartAbsoluteAddress),
std::make_pair(2, kFunction3StartAbsoluteAddress),
std::make_pair(1, kFunction4StartAbsoluteAddress)));
EXPECT_THAT(
actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(
SampledFunctionEq(MakeSampledFunction(kFunction1Name, kModulePath, 0, 0.0f, 2, 100.0f,
0, 0.0f, kFunction1StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction2Name, kModulePath, 0, 0.0f, 2, 100.0f,
0, 0.0f, kFunction2StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction3Name, kModulePath, 1, 50.0f, 2, 100.0f,
0, 0.0f, kFunction3StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction4Name, kModulePath, 1, 50.0f, 1, 50.0f,
0, 0.0f, kFunction4StartAbsoluteAddress))));
}
static void VerifyThreadSampleDataForCallstackEventsInThreadId2(
const ThreadSampleData& actual_thread_sample_data) {
EXPECT_EQ(actual_thread_sample_data.thread_id, kThreadId2);
EXPECT_EQ(actual_thread_sample_data.samples_count, 3);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 0);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id, std::vector<CallstackEvent>{{300, kCallstack1Id, kThreadId2}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack3Id, std::vector<CallstackEvent>{{400, kCallstack3Id, kThreadId2}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack4Id, std::vector<CallstackEvent>{{500, kCallstack4Id, kThreadId2}}))));
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 3),
std::make_pair(kFunction2Instruction1AbsoluteAddress, 1),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 3),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1StartAbsoluteAddress, 3),
std::make_pair(kFunction2StartAbsoluteAddress, 1),
std::make_pair(kFunction3StartAbsoluteAddress, 3)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
ElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 3)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(3, kFunction1StartAbsoluteAddress),
std::make_pair(1, kFunction2StartAbsoluteAddress),
std::make_pair(3, kFunction3StartAbsoluteAddress)));
EXPECT_THAT(
actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(
SampledFunctionEq(MakeSampledFunction(kFunction1Name, kModulePath, 0, 0.0f, 3, 100.0f,
0, 0.0f, kFunction1StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction2Name, kModulePath, 0, 0.0f, 1,
100.0f / 3, 0, 0.0f,
kFunction2StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction3Name, kModulePath, 3, 100.0f, 3, 100.0f,
0, 0.0f, kFunction3StartAbsoluteAddress))));
}
static void VerifySummaryThreadSampleDataForCallstackEventsInThreadId1And2(
const ThreadSampleData& actual_thread_sample_data, uint32_t expected_thread_id) {
EXPECT_EQ(actual_thread_sample_data.thread_id, expected_thread_id);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id, std::vector<CallstackEvent>{{100, kCallstack1Id, kThreadId1},
{300, kCallstack1Id, kThreadId2}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack2Id, std::vector<CallstackEvent>{{200, kCallstack2Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack3Id, std::vector<CallstackEvent>{{400, kCallstack3Id, kThreadId2}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack4Id, std::vector<CallstackEvent>{{500, kCallstack4Id, kThreadId2}}))));
EXPECT_EQ(actual_thread_sample_data.samples_count, 5);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 0);
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction2Instruction1AbsoluteAddress, 3),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1StartAbsoluteAddress, 5),
std::make_pair(kFunction2StartAbsoluteAddress, 3),
std::make_pair(kFunction3StartAbsoluteAddress, 5),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
UnorderedElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 4),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(5, kFunction1StartAbsoluteAddress),
std::make_pair(3, kFunction2StartAbsoluteAddress),
std::make_pair(5, kFunction3StartAbsoluteAddress),
std::make_pair(1, kFunction4StartAbsoluteAddress)));
EXPECT_THAT(
actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(
SampledFunctionEq(MakeSampledFunction(kFunction1Name, kModulePath, 0, 0.0f, 5, 100.0f,
0, 0.0f, kFunction1StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction2Name, kModulePath, 0, 0.0f, 3, 60.0f, 0,
0.0f, kFunction2StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction3Name, kModulePath, 4, 80.0f, 5, 100.0f,
0, 0.0f, kFunction3StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction4Name, kModulePath, 1, 20.0f, 1, 20.0f,
0, 0.0f, kFunction4StartAbsoluteAddress))));
}
static void VerifyThreadSampleDataForCallstackEventsInThreadId1WithMixedCallstackTypes(
const ThreadSampleData& actual_thread_sample_data) {
EXPECT_EQ(actual_thread_sample_data.thread_id, kThreadId1);
EXPECT_EQ(actual_thread_sample_data.samples_count, 2);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 1);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id, std::vector<CallstackEvent>{{100, kCallstack1Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack2Id, std::vector<CallstackEvent>{{200, kCallstack2Id, kThreadId1}}))));
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 1),
std::make_pair(kFunction2Instruction1AbsoluteAddress, 1),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 2),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1StartAbsoluteAddress, 1),
std::make_pair(kFunction2StartAbsoluteAddress, 1),
std::make_pair(kFunction3StartAbsoluteAddress, 2),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
UnorderedElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 1),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(1, kFunction1StartAbsoluteAddress),
std::make_pair(1, kFunction2StartAbsoluteAddress),
std::make_pair(2, kFunction3StartAbsoluteAddress),
std::make_pair(1, kFunction4StartAbsoluteAddress)));
EXPECT_THAT(
actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(
SampledFunctionEq(MakeSampledFunction(kFunction1Name, kModulePath, 0, 0.0f, 1, 50.0f, 0,
0.0f, kFunction1StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction2Name, kModulePath, 0, 0.0f, 1, 50.0f, 0,
0.0f, kFunction2StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction3Name, kModulePath, 1, 50.0f, 2, 100.0f,
1, 50.0f, kFunction3StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction4Name, kModulePath, 1, 50.0f, 1, 50.0f,
0, 0.0f, kFunction4StartAbsoluteAddress))));
}
static void VerifyThreadSampleDataForCallstackEventsInThreadId2WithMixedCallstackTypes(
const ThreadSampleData& actual_thread_sample_data) {
EXPECT_EQ(actual_thread_sample_data.thread_id, kThreadId2);
EXPECT_EQ(actual_thread_sample_data.samples_count, 3);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 2);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id, std::vector<CallstackEvent>{{300, kCallstack1Id, kThreadId2}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack3Id, std::vector<CallstackEvent>{{400, kCallstack3Id, kThreadId2}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack4Id, std::vector<CallstackEvent>{{500, kCallstack4Id, kThreadId2}}))));
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 1),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 3),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1StartAbsoluteAddress, 1),
std::make_pair(kFunction3StartAbsoluteAddress, 3)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
ElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 3)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(1, kFunction1StartAbsoluteAddress),
std::make_pair(3, kFunction3StartAbsoluteAddress)));
EXPECT_THAT(actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(SampledFunctionEq(MakeSampledFunction(
kFunction1Name, kModulePath, 0, 0.0f, 1, 100.0f / 3, 0,
0.0f, kFunction1StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(
kFunction3Name, kModulePath, 3, 100.0f, 3, 100.0f, 2,
2 * 100.0f / 3, kFunction3StartAbsoluteAddress))));
}
static void VerifyThreadSampleDataForCallstackEventsInThreadId1And2WithMixedCallstackTypes(
const ThreadSampleData& actual_thread_sample_data, uint32_t expected_thread_id) {
EXPECT_EQ(actual_thread_sample_data.thread_id, expected_thread_id);
EXPECT_EQ(actual_thread_sample_data.samples_count, 5);
EXPECT_EQ(actual_thread_sample_data.unwinding_errors_count, 3);
EXPECT_THAT(
actual_thread_sample_data.sampled_callstack_id_to_events,
UnorderedElementsAre(
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack1Id, std::vector<CallstackEvent>{{100, kCallstack1Id, kThreadId1},
{300, kCallstack1Id, kThreadId2}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack2Id, std::vector<CallstackEvent>{{200, kCallstack2Id, kThreadId1}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack3Id, std::vector<CallstackEvent>{{400, kCallstack3Id, kThreadId2}})),
CallstackIdToCallstackEventsEq(std::make_pair(
kCallstack4Id, std::vector<CallstackEvent>{{500, kCallstack4Id, kThreadId2}}))));
EXPECT_THAT(actual_thread_sample_data.sampled_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1Instruction1AbsoluteAddress, 2),
std::make_pair(kFunction2Instruction1AbsoluteAddress, 1),
std::make_pair(kFunction3Instruction1AbsoluteAddress, 5),
std::make_pair(kFunction3Instruction2AbsoluteAddress, 1),
std::make_pair(kFunction4Instruction1AbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_count,
UnorderedElementsAre(std::make_pair(kFunction1StartAbsoluteAddress, 2),
std::make_pair(kFunction2StartAbsoluteAddress, 1),
std::make_pair(kFunction3StartAbsoluteAddress, 5),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.resolved_address_to_exclusive_count,
UnorderedElementsAre(std::make_pair(kFunction3StartAbsoluteAddress, 4),
std::make_pair(kFunction4StartAbsoluteAddress, 1)));
EXPECT_THAT(actual_thread_sample_data.sorted_count_to_resolved_address,
UnorderedElementsAre(std::make_pair(2, kFunction1StartAbsoluteAddress),
std::make_pair(1, kFunction2StartAbsoluteAddress),
std::make_pair(5, kFunction3StartAbsoluteAddress),
std::make_pair(1, kFunction4StartAbsoluteAddress)));
EXPECT_THAT(
actual_thread_sample_data.sampled_functions,
UnorderedElementsAre(
SampledFunctionEq(MakeSampledFunction(kFunction1Name, kModulePath, 0, 0.0f, 2, 40.0f, 0,
0.0f, kFunction1StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction2Name, kModulePath, 0, 0.0f, 1, 20.0f, 0,
0.0f, kFunction2StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction3Name, kModulePath, 4, 80.0f, 5, 100.0f,
3, 60.0f, kFunction3StartAbsoluteAddress)),
SampledFunctionEq(MakeSampledFunction(kFunction4Name, kModulePath, 1, 20.0f, 1, 20.0f,
0, 0.0f, kFunction4StartAbsoluteAddress))));
}
void VerifyGetCountOfFunction() {
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction1StartAbsoluteAddress), 5);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction1Instruction1AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction2StartAbsoluteAddress), 3);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction2Instruction1AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3StartAbsoluteAddress), 5);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3Instruction1AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3Instruction2AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction4StartAbsoluteAddress), 1);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction4Instruction1AbsoluteAddress), 0);
}
void VerifyGetCountOfFunctionWithOnlyNonCompleteCallstackInfos() {
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction1StartAbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction1Instruction1AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction2StartAbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction2Instruction1AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3StartAbsoluteAddress), 4);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3Instruction1AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3Instruction2AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction4StartAbsoluteAddress), 1);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction4Instruction1AbsoluteAddress), 0);
}
void VerifyGetCountOfFunctionWithMixedCallstackTypes() {
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction1StartAbsoluteAddress), 2);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction1Instruction1AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction2StartAbsoluteAddress), 1);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction2Instruction1AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3StartAbsoluteAddress), 5);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3Instruction1AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3Instruction2AbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction4StartAbsoluteAddress), 1);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction4Instruction1AbsoluteAddress), 0);
}
void VerifyGetCountOfFunctionWithoutAddressInfos() {
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction1StartAbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction1Instruction1AbsoluteAddress), 5);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction2StartAbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction2Instruction1AbsoluteAddress), 3);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3StartAbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3Instruction1AbsoluteAddress), 5);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction3Instruction2AbsoluteAddress), 1);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction4StartAbsoluteAddress), 0);
EXPECT_EQ(ppsd_.GetCountOfFunction(kFunction4Instruction1AbsoluteAddress), 1);
}
void VerifyEmptySortedCallstackReport(uint32_t thread_id) {
EXPECT_THAT(*ppsd_.GetSortedCallstackReportFromFunctionAddresses({}, thread_id),
SortedCallstackReportEq(MakeSortedCallstackReport({})));
EXPECT_THAT(*ppsd_.GetSortedCallstackReportFromFunctionAddresses(
{kFunction1StartAbsoluteAddress}, thread_id),
SortedCallstackReportEq(MakeSortedCallstackReport({})));
EXPECT_THAT(*ppsd_.GetSortedCallstackReportFromFunctionAddresses(
{kFunction2StartAbsoluteAddress}, thread_id),
SortedCallstackReportEq(MakeSortedCallstackReport({})));
EXPECT_THAT(*ppsd_.GetSortedCallstackReportFromFunctionAddresses(
{kFunction3StartAbsoluteAddress}, thread_id),
SortedCallstackReportEq(MakeSortedCallstackReport({})));
EXPECT_THAT(*ppsd_.GetSortedCallstackReportFromFunctionAddresses(
{kFunction4StartAbsoluteAddress}, thread_id),
SortedCallstackReportEq(MakeSortedCallstackReport({})));
EXPECT_THAT(*ppsd_.GetSortedCallstackReportFromFunctionAddresses(
{kFunction1StartAbsoluteAddress, kFunction2StartAbsoluteAddress,
kFunction3StartAbsoluteAddress, kFunction4StartAbsoluteAddress},
thread_id),
SortedCallstackReportEq(MakeSortedCallstackReport({})));
// Also test the non-"Start" addresses.