1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "src/trace_processor/importers/common/event_tracker.h"
18
19 #include <cstdint>
20 #include <memory>
21
22 #include "src/trace_processor/importers/common/args_tracker.h"
23 #include "src/trace_processor/importers/common/cpu_tracker.h"
24 #include "src/trace_processor/importers/common/global_args_tracker.h"
25 #include "src/trace_processor/importers/common/machine_tracker.h"
26 #include "src/trace_processor/importers/common/process_tracker.h"
27 #include "src/trace_processor/importers/common/track_tracker.h"
28 #include "src/trace_processor/importers/common/tracks.h"
29 #include "src/trace_processor/importers/common/tracks_common.h"
30 #include "src/trace_processor/storage/trace_storage.h"
31 #include "test/gtest_and_gmock.h"
32
33 namespace perfetto::trace_processor {
34 namespace {
35
36 using ::testing::_;
37 using ::testing::InSequence;
38 using ::testing::Invoke;
39
40 class EventTrackerTest : public ::testing::Test {
41 public:
EventTrackerTest()42 EventTrackerTest() {
43 context.storage = std::make_shared<TraceStorage>();
44 context.global_args_tracker =
45 std::make_unique<GlobalArgsTracker>(context.storage.get());
46 context.args_tracker = std::make_unique<ArgsTracker>(&context);
47 context.process_tracker = std::make_unique<ProcessTracker>(&context);
48 context.event_tracker = std::make_unique<EventTracker>(&context);
49 context.track_tracker = std::make_unique<TrackTracker>(&context);
50 context.machine_tracker = std::make_unique<MachineTracker>(&context, 0);
51 context.cpu_tracker = std::make_unique<CpuTracker>(&context);
52 }
53
54 protected:
55 TraceProcessorContext context;
56 };
57
TEST_F(EventTrackerTest,CounterDuration)58 TEST_F(EventTrackerTest, CounterDuration) {
59 uint32_t cpu = 3;
60 int64_t timestamp = 100;
61
62 TrackId track = context.track_tracker->InternTrack(
63 tracks::kCpuFrequencyBlueprint, tracks::Dimensions(cpu));
64 context.event_tracker->PushCounter(timestamp, 1000, track);
65 context.event_tracker->PushCounter(timestamp + 1, 4000, track);
66 context.event_tracker->PushCounter(timestamp + 3, 5000, track);
67 context.event_tracker->PushCounter(timestamp + 9, 1000, track);
68
69 ASSERT_EQ(context.storage->track_table().row_count(), 1ul);
70
71 const auto& counter = context.storage->counter_table();
72 ASSERT_EQ(counter.row_count(), 4ul);
73
74 auto rr = counter[0];
75 ASSERT_EQ(rr.ts(), timestamp);
76 ASSERT_DOUBLE_EQ(rr.value(), 1000);
77
78 rr = counter[1];
79 ASSERT_EQ(rr.ts(), timestamp + 1);
80 ASSERT_DOUBLE_EQ(rr.value(), 4000);
81
82 rr = counter[2];
83 ASSERT_EQ(rr.ts(), timestamp + 3);
84 ASSERT_DOUBLE_EQ(rr.value(), 5000);
85 }
86
87 } // namespace
88 } // namespace perfetto::trace_processor
89