• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "perfetto/base/logging.h"
20 #include "src/trace_processor/importers/common/args_tracker.h"
21 #include "src/trace_processor/importers/common/process_tracker.h"
22 #include "src/trace_processor/importers/common/track_tracker.h"
23 #include "test/gtest_and_gmock.h"
24 
25 namespace perfetto {
26 namespace trace_processor {
27 namespace {
28 
29 using ::testing::_;
30 using ::testing::InSequence;
31 using ::testing::Invoke;
32 
33 class EventTrackerTest : public ::testing::Test {
34  public:
EventTrackerTest()35   EventTrackerTest() {
36     context.storage.reset(new TraceStorage());
37     context.global_args_tracker.reset(
38         new GlobalArgsTracker(context.storage.get()));
39     context.args_tracker.reset(new ArgsTracker(&context));
40     context.process_tracker.reset(new ProcessTracker(&context));
41     context.event_tracker.reset(new EventTracker(&context));
42     context.track_tracker.reset(new TrackTracker(&context));
43   }
44 
45  protected:
46   TraceProcessorContext context;
47 };
48 
TEST_F(EventTrackerTest,CounterDuration)49 TEST_F(EventTrackerTest, CounterDuration) {
50   uint32_t cpu = 3;
51   int64_t timestamp = 100;
52   StringId name_id = kNullStringId;
53 
54   TrackId track = context.track_tracker->InternCpuCounterTrack(name_id, cpu);
55   context.event_tracker->PushCounter(timestamp, 1000, track);
56   context.event_tracker->PushCounter(timestamp + 1, 4000, track);
57   context.event_tracker->PushCounter(timestamp + 3, 5000, track);
58   context.event_tracker->PushCounter(timestamp + 9, 1000, track);
59 
60   ASSERT_EQ(context.storage->counter_track_table().row_count(), 1ul);
61 
62   ASSERT_EQ(context.storage->counter_table().row_count(), 4ul);
63   ASSERT_EQ(context.storage->counter_table().ts()[0], timestamp);
64   ASSERT_DOUBLE_EQ(context.storage->counter_table().value()[0], 1000);
65 
66   ASSERT_EQ(context.storage->counter_table().ts()[1], timestamp + 1);
67   ASSERT_DOUBLE_EQ(context.storage->counter_table().value()[1], 4000);
68 
69   ASSERT_EQ(context.storage->counter_table().ts()[2], timestamp + 3);
70   ASSERT_DOUBLE_EQ(context.storage->counter_table().value()[2], 5000);
71 }
72 
73 }  // namespace
74 }  // namespace trace_processor
75 }  // namespace perfetto
76