File: arc_system_model_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (169 lines) | stat: -rw-r--r-- 7,308 bytes parent folder | download | duplicates (7)
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
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ash/arc/tracing/arc_system_model.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace arc {

using ArcSystemModelTest = testing::Test;

TEST_F(ArcSystemModelTest, TrimByTimestampCPU) {
  ArcSystemModel model;

  constexpr uint64_t trim_timestamp = 25;
  constexpr int idle_tid = 0;
  constexpr int non_idle_tid = 100;

  // Second event is before |trim_timestamp|. First event should be discard,
  // second should be preserved but with clamped timestamp to |trim_timestamp|.
  AddAllCpuEvent(&model.all_cpu_events(), 0 /* cpu_id */, 10 /* timestamp */,
                 ArcCpuEvent::Type::kIdleIn, idle_tid);
  AddAllCpuEvent(&model.all_cpu_events(), 0 /* cpu_id */, 20 /* timestamp */,
                 ArcCpuEvent::Type::kWakeUp, non_idle_tid);
  AddAllCpuEvent(&model.all_cpu_events(), 0 /* cpu_id */, 30 /* timestamp */,
                 ArcCpuEvent::Type::kIdleOut, idle_tid);

  // All events are after |trim_timestamp|. Everything should be preserved.
  AddAllCpuEvent(&model.all_cpu_events(), 1 /* cpu_id */, 32 /* timestamp */,
                 ArcCpuEvent::Type::kIdleIn, idle_tid);
  AddAllCpuEvent(&model.all_cpu_events(), 1 /* cpu_id */, 42 /* timestamp */,
                 ArcCpuEvent::Type::kWakeUp, non_idle_tid);
  AddAllCpuEvent(&model.all_cpu_events(), 1 /* cpu_id */, 52 /* timestamp */,
                 ArcCpuEvent::Type::kIdleOut, idle_tid);

  // Second event is exactly |on trim_timestamp|. First even should be
  // discarded.
  AddAllCpuEvent(&model.all_cpu_events(), 2 /* cpu_id */, 15 /* timestamp */,
                 ArcCpuEvent::Type::kIdleIn, idle_tid);
  AddAllCpuEvent(&model.all_cpu_events(), 2 /* cpu_id */, 25 /* timestamp */,
                 ArcCpuEvent::Type::kWakeUp, non_idle_tid);
  AddAllCpuEvent(&model.all_cpu_events(), 2 /* cpu_id */, 35 /* timestamp */,
                 ArcCpuEvent::Type::kIdleOut, idle_tid);

  // All events are before |trim_timestamp|. Last one should be preserved but
  // with clamped timestamp to |trim_timestamp|.
  AddAllCpuEvent(&model.all_cpu_events(), 3 /* cpu_id */, 10 /* timestamp */,
                 ArcCpuEvent::Type::kIdleIn, idle_tid);
  AddAllCpuEvent(&model.all_cpu_events(), 3 /* cpu_id */, 15 /* timestamp */,
                 ArcCpuEvent::Type::kWakeUp, non_idle_tid);
  AddAllCpuEvent(&model.all_cpu_events(), 3 /* cpu_id */, 20 /* timestamp */,
                 ArcCpuEvent::Type::kIdleOut, idle_tid);

  model.Trim(trim_timestamp);

  ASSERT_EQ(4U, model.all_cpu_events().size());
  const CpuEvents& cpu_events_0 = model.all_cpu_events()[0 /* cpu_id */];
  const CpuEvents& cpu_events_1 = model.all_cpu_events()[1 /* cpu_id */];
  const CpuEvents& cpu_events_2 = model.all_cpu_events()[2 /* cpu_id */];
  const CpuEvents& cpu_events_3 = model.all_cpu_events()[3 /* cpu_id */];

  ASSERT_EQ(2U, cpu_events_0.size());
  EXPECT_EQ(ArcCpuEvent::Type::kWakeUp, cpu_events_0[0].type);
  EXPECT_EQ(trim_timestamp, cpu_events_0[0].timestamp);

  ASSERT_EQ(3U, cpu_events_1.size());
  EXPECT_EQ(ArcCpuEvent::Type::kIdleIn, cpu_events_1[0].type);
  EXPECT_EQ(32u, cpu_events_1[0].timestamp);

  ASSERT_EQ(2U, cpu_events_2.size());
  EXPECT_EQ(ArcCpuEvent::Type::kWakeUp, cpu_events_2[0].type);
  EXPECT_EQ(trim_timestamp, cpu_events_2[0].timestamp);

  ASSERT_EQ(1U, cpu_events_3.size());
  EXPECT_EQ(ArcCpuEvent::Type::kIdleOut, cpu_events_3[0].type);
  EXPECT_EQ(trim_timestamp, cpu_events_3[0].timestamp);
}

TEST_F(ArcSystemModelTest, TrimByTimestampMemory) {
  ArcSystemModel model;

  constexpr uint64_t trim_timestamp = 25;

  // First of ArcValueEvent::Type::kMemTotal should be clamped to
  // |trim_timestamp|.
  model.memory_events().emplace_back(
      0 /* timestamp */, ArcValueEvent::Type::kMemTotal, 100 /* value */);
  model.memory_events().emplace_back(
      0 /* timestamp */, ArcValueEvent::Type::kMemUsed, 20 /* value */);
  model.memory_events().emplace_back(
      0 /* timestamp */, ArcValueEvent::Type::kSwapRead, 0 /* value */);

  model.memory_events().emplace_back(
      10 /* timestamp */, ArcValueEvent::Type::kSwapRead, 1 /* value */);

  model.memory_events().emplace_back(
      20 /* timestamp */, ArcValueEvent::Type::kSwapRead, 2 /* value */);

  // Second of |ArcValueEvent::Type::kMemUsed| is exactly on |trim_timestamp|.
  // First |ArcValueEvent::Type::kMemUsed| should be discarded.
  model.memory_events().emplace_back(
      25 /* timestamp */, ArcValueEvent::Type::kMemUsed, 30 /* value */);

  // We have 3 |ArcValueEvent::Type::kSwapRead| before. Two first should be
  // discarded and third one should be clamped to |trim_timestamp|.
  model.memory_events().emplace_back(
      30 /* timestamp */, ArcValueEvent::Type::kSwapRead, 3 /* value */);

  model.memory_events().emplace_back(
      40 /* timestamp */, ArcValueEvent::Type::kSwapRead, 4 /* value */);

  model.memory_events().emplace_back(
      50 /* timestamp */, ArcValueEvent::Type::kMemTotal, 100 /* value */);
  model.memory_events().emplace_back(
      50 /* timestamp */, ArcValueEvent::Type::kMemUsed, 40 /* value */);
  model.memory_events().emplace_back(
      50 /* timestamp */, ArcValueEvent::Type::kSwapRead, 5 /* value */);

  EXPECT_EQ(11u, model.memory_events().size());

  model.Trim(trim_timestamp);

  ASSERT_EQ(8u, model.memory_events().size());
  EXPECT_EQ(ArcValueEvent(trim_timestamp, ArcValueEvent::Type::kMemTotal, 100),
            model.memory_events()[0]);
  EXPECT_EQ(ArcValueEvent(trim_timestamp, ArcValueEvent::Type::kSwapRead, 2),
            model.memory_events()[1]);
  EXPECT_EQ(ArcValueEvent(trim_timestamp, ArcValueEvent::Type::kMemUsed, 30),
            model.memory_events()[2]);

  EXPECT_EQ(ArcValueEvent(30, ArcValueEvent::Type::kSwapRead, 3),
            model.memory_events()[3]);
  EXPECT_EQ(ArcValueEvent(40, ArcValueEvent::Type::kSwapRead, 4),
            model.memory_events()[4]);

  EXPECT_EQ(ArcValueEvent(50, ArcValueEvent::Type::kMemTotal, 100),
            model.memory_events()[5]);
  EXPECT_EQ(ArcValueEvent(50, ArcValueEvent::Type::kMemUsed, 40),
            model.memory_events()[6]);
  EXPECT_EQ(ArcValueEvent(50, ArcValueEvent::Type::kSwapRead, 5),
            model.memory_events()[7]);
}

TEST_F(ArcSystemModelTest, CloseRange) {
  ArcSystemModel model;

  model.memory_events().emplace_back(
      0 /* timestamp */, ArcValueEvent::Type::kGpuFrequency, 100 /* value */);
  model.memory_events().emplace_back(
      0 /* timestamp */, ArcValueEvent::Type::kCpuTemperature, 20 /* value */);
  model.memory_events().emplace_back(
      100 /* timestamp */, ArcValueEvent::Type::kGpuFrequency, 150 /* value */);
  model.memory_events().emplace_back(200 /* timestamp */,
                                     ArcValueEvent::Type::kCpuTemperature,
                                     50 /* value */);

  EXPECT_EQ(4u, model.memory_events().size());

  model.CloseRangeForValueEvents(200 /* timestamp */);

  // kGpuFrequency is extended.
  ASSERT_EQ(5u, model.memory_events().size());
  EXPECT_EQ(ArcValueEvent(200 /* timestamp */,
                          ArcValueEvent::Type::kGpuFrequency, 150 /* value */),
            model.memory_events().back());
}

}  // namespace arc