• 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(new GlobalArgsTracker(&context));
38     context.args_tracker.reset(new ArgsTracker(&context));
39     context.process_tracker.reset(new ProcessTracker(&context));
40     context.event_tracker.reset(new EventTracker(&context));
41     context.track_tracker.reset(new TrackTracker(&context));
42   }
43 
44  protected:
45   TraceProcessorContext context;
46 };
47 
TEST_F(EventTrackerTest,CounterDuration)48 TEST_F(EventTrackerTest, CounterDuration) {
49   uint32_t cpu = 3;
50   int64_t timestamp = 100;
51   StringId name_id = kNullStringId;
52 
53   TrackId track = context.track_tracker->InternCpuCounterTrack(name_id, cpu);
54   context.event_tracker->PushCounter(timestamp, 1000, track);
55   context.event_tracker->PushCounter(timestamp + 1, 4000, track);
56   context.event_tracker->PushCounter(timestamp + 3, 5000, track);
57   context.event_tracker->PushCounter(timestamp + 9, 1000, track);
58 
59   ASSERT_EQ(context.storage->counter_track_table().row_count(), 1ul);
60 
61   ASSERT_EQ(context.storage->counter_table().row_count(), 4ul);
62   ASSERT_EQ(context.storage->counter_table().ts()[0], timestamp);
63   ASSERT_DOUBLE_EQ(context.storage->counter_table().value()[0], 1000);
64 
65   ASSERT_EQ(context.storage->counter_table().ts()[1], timestamp + 1);
66   ASSERT_DOUBLE_EQ(context.storage->counter_table().value()[1], 4000);
67 
68   ASSERT_EQ(context.storage->counter_table().ts()[2], timestamp + 3);
69   ASSERT_DOUBLE_EQ(context.storage->counter_table().value()[2], 5000);
70 }
71 
72 }  // namespace
73 }  // namespace trace_processor
74 }  // namespace perfetto
75