1 /*
2 * Copyright (C) 2017 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/traced/probes/ftrace/cpu_reader.h"
18
19 #include <string.h>
20 #include <sys/stat.h>
21 #include <sys/syscall.h>
22
23 #include "perfetto/base/build_config.h"
24 #include "perfetto/ext/base/utils.h"
25 #include "perfetto/protozero/proto_utils.h"
26 #include "perfetto/protozero/scattered_heap_buffer.h"
27 #include "perfetto/protozero/scattered_stream_writer.h"
28 #include "protos/perfetto/trace/ftrace/generic.pbzero.h"
29 #include "src/base/test/tmp_dir_tree.h"
30 #include "src/traced/probes/ftrace/event_info.h"
31 #include "src/traced/probes/ftrace/ftrace_config_muxer.h"
32 #include "src/traced/probes/ftrace/ftrace_procfs.h"
33 #include "src/traced/probes/ftrace/proto_translation_table.h"
34 #include "src/traced/probes/ftrace/test/cpu_reader_support.h"
35 #include "src/tracing/core/trace_writer_for_testing.h"
36 #include "test/gtest_and_gmock.h"
37
38 #include "protos/perfetto/trace/ftrace/dpu.gen.h"
39 #include "protos/perfetto/trace/ftrace/f2fs.gen.h"
40 #include "protos/perfetto/trace/ftrace/ftrace.gen.h"
41 #include "protos/perfetto/trace/ftrace/ftrace_event.gen.h"
42 #include "protos/perfetto/trace/ftrace/ftrace_event.pbzero.h"
43 #include "protos/perfetto/trace/ftrace/ftrace_event_bundle.gen.h"
44 #include "protos/perfetto/trace/ftrace/ftrace_event_bundle.pbzero.h"
45 #include "protos/perfetto/trace/ftrace/ftrace_stats.gen.h"
46 #include "protos/perfetto/trace/ftrace/ftrace_stats.pbzero.h"
47 #include "protos/perfetto/trace/ftrace/generic.gen.h"
48 #include "protos/perfetto/trace/ftrace/power.gen.h"
49 #include "protos/perfetto/trace/ftrace/raw_syscalls.gen.h"
50 #include "protos/perfetto/trace/ftrace/sched.gen.h"
51 #include "protos/perfetto/trace/ftrace/task.gen.h"
52 #include "protos/perfetto/trace/trace_packet.gen.h"
53 #include "src/traced/probes/ftrace/test/test_messages.gen.h"
54 #include "src/traced/probes/ftrace/test/test_messages.pbzero.h"
55
56 using protozero::proto_utils::ProtoSchemaType;
57 using testing::_;
58 using testing::AnyNumber;
59 using testing::Contains;
60 using testing::Each;
61 using testing::ElementsAre;
62 using testing::ElementsAreArray;
63 using testing::EndsWith;
64 using testing::Eq;
65 using testing::IsEmpty;
66 using testing::NiceMock;
67 using testing::Not;
68 using testing::Pair;
69 using testing::Property;
70 using testing::Return;
71 using testing::SizeIs;
72 using testing::StartsWith;
73
74 namespace perfetto {
75 namespace {
76
77 using FtraceParseStatus = protos::pbzero::FtraceParseStatus;
78
EmptyConfig()79 FtraceDataSourceConfig EmptyConfig() {
80 return FtraceDataSourceConfig{EventFilter{},
81 EventFilter{},
82 DisabledCompactSchedConfigForTesting(),
83 std::nullopt,
84 {},
85 {},
86 {},
87 false /*symbolize_ksyms*/,
88 50u,
89 {}};
90 }
91
92 constexpr uint64_t kNanoInSecond = 1000 * 1000 * 1000;
93 constexpr uint64_t kNanoInMicro = 1000;
94
WithinOneMicrosecond(uint64_t actual_ns,uint64_t expected_s,uint64_t expected_us)95 ::testing::AssertionResult WithinOneMicrosecond(uint64_t actual_ns,
96 uint64_t expected_s,
97 uint64_t expected_us) {
98 // Round to closest us.
99 uint64_t actual_us = (actual_ns + kNanoInMicro / 2) / kNanoInMicro;
100 uint64_t total_expected_us = expected_s * 1000 * 1000 + expected_us;
101 if (actual_us == total_expected_us)
102 return ::testing::AssertionSuccess();
103
104 return ::testing::AssertionFailure()
105 << actual_ns / kNanoInSecond << "."
106 << (actual_ns % kNanoInSecond) / kNanoInMicro << " vs. " << expected_s
107 << "." << expected_us;
108 }
109
110 class MockFtraceProcfs : public FtraceProcfs {
111 public:
MockFtraceProcfs()112 MockFtraceProcfs() : FtraceProcfs("/root/") {
113 ON_CALL(*this, NumberOfCpus()).WillByDefault(Return(1));
114 ON_CALL(*this, WriteToFile(_, _)).WillByDefault(Return(true));
115 ON_CALL(*this, ClearFile(_)).WillByDefault(Return(true));
116 EXPECT_CALL(*this, NumberOfCpus()).Times(AnyNumber());
117 }
118
119 MOCK_METHOD(bool,
120 WriteToFile,
121 (const std::string& path, const std::string& str),
122 (override));
123 MOCK_METHOD(char, ReadOneCharFromFile, (const std::string& path), (override));
124 MOCK_METHOD(bool, ClearFile, (const std::string& path), (override));
125 MOCK_METHOD(std::string,
126 ReadFileIntoString,
127 (const std::string& path),
128 (const, override));
129 MOCK_METHOD(size_t, NumberOfCpus, (), (const, override));
130 };
131
132 class CpuReaderTableTest : public ::testing::Test {
133 protected:
134 NiceMock<MockFtraceProcfs> ftrace_;
135 };
136
137 // Single class to manage the whole protozero -> scattered stream -> chunks ->
138 // single buffer -> real proto dance. Has a method: writer() to get an
139 // protozero ftrace bundle writer and a method ParseProto() to attempt to
140 // parse whatever has been written so far into a proto message.
141 template <class ZeroT, class ProtoT>
142 class ProtoProvider {
143 public:
ProtoProvider(size_t chunk_size)144 explicit ProtoProvider(size_t chunk_size) : chunk_size_(chunk_size) {}
145 ~ProtoProvider() = default;
146
writer()147 ZeroT* writer() { return writer_.get(); }
ResetWriter()148 void ResetWriter() { writer_.Reset(); }
149
150 // Stitch together the scattered chunks into a single buffer then attempt
151 // to parse the buffer as a FtraceEventBundle. Returns the FtraceEventBundle
152 // on success and nullptr on failure.
ParseProto()153 std::unique_ptr<ProtoT> ParseProto() {
154 auto bundle = std::make_unique<ProtoT>();
155 std::vector<uint8_t> buffer = writer_.SerializeAsArray();
156 if (!bundle->ParseFromArray(buffer.data(), buffer.size()))
157 return nullptr;
158 return bundle;
159 }
160
161 private:
162 ProtoProvider(const ProtoProvider&) = delete;
163 ProtoProvider& operator=(const ProtoProvider&) = delete;
164
165 size_t chunk_size_;
166 protozero::HeapBuffered<ZeroT> writer_;
167 };
168
169 using BundleProvider = ProtoProvider<protos::pbzero::FtraceEventBundle,
170 protos::gen::FtraceEventBundle>;
171
172 class BinaryWriter {
173 public:
BinaryWriter()174 BinaryWriter()
175 : size_(base::GetSysPageSize()),
176 page_(new uint8_t[size_]),
177 ptr_(page_.get()) {}
178
179 template <typename T>
Write(T t)180 void Write(T t) {
181 memcpy(ptr_, &t, sizeof(T));
182 ptr_ += sizeof(T);
183 PERFETTO_CHECK(ptr_ < ptr_ + size_);
184 }
185
WriteFixedString(size_t n,const char * s)186 void WriteFixedString(size_t n, const char* s) {
187 size_t length = strlen(s);
188 PERFETTO_CHECK(length < n);
189 char c;
190 while ((c = *s++)) {
191 Write<char>(c);
192 }
193 Write<char>('\0');
194 for (size_t i = 0; i < n - length - 1; i++) {
195 Write<char>('\xff');
196 }
197 }
198
GetCopy()199 std::unique_ptr<uint8_t[]> GetCopy() {
200 std::unique_ptr<uint8_t[]> buffer(new uint8_t[written()]);
201 memcpy(buffer.get(), page_.get(), written());
202 return buffer;
203 }
204
written()205 size_t written() { return static_cast<size_t>(ptr_ - page_.get()); }
206
207 private:
208 size_t size_;
209 std::unique_ptr<uint8_t[]> page_;
210 uint8_t* ptr_;
211 };
212
TEST(PageFromXxdTest,OneLine)213 TEST(PageFromXxdTest, OneLine) {
214 std::string text = R"(
215 00000000: 0000 0000 0000 0000 0000 0000 0000 0000 ................
216 00000000: 0000 0000 5600 0000 0000 0000 0000 0000 ................
217 )";
218 auto page = PageFromXxd(text);
219 EXPECT_EQ(page.get()[0x14], 0x56);
220 }
221
TEST(PageFromXxdTest,ManyLines)222 TEST(PageFromXxdTest, ManyLines) {
223 std::string text = R"(
224 00000000: 1234 0000 0000 0000 0000 0000 0000 0056 ................
225 00000010: 7800 0000 0000 0000 0000 0000 0000 009a ................
226 00000020: 0000 0000 bc00 0000 00de 0000 0000 009a ................
227 )";
228 auto page = PageFromXxd(text);
229 EXPECT_EQ(page.get()[0x00], 0x12);
230 EXPECT_EQ(page.get()[0x01], 0x34);
231 EXPECT_EQ(page.get()[0x0f], 0x56);
232 EXPECT_EQ(page.get()[0x10], 0x78);
233 EXPECT_EQ(page.get()[0x1f], 0x9a);
234 EXPECT_EQ(page.get()[0x24], 0xbc);
235 EXPECT_EQ(page.get()[0x29], 0xde);
236 }
237
TEST(CpuReaderTest,BinaryWriter)238 TEST(CpuReaderTest, BinaryWriter) {
239 BinaryWriter writer;
240 writer.Write<uint64_t>(1);
241 writer.Write<uint32_t>(2);
242 writer.Write<uint16_t>(3);
243 writer.Write<uint8_t>(4);
244 auto buffer = writer.GetCopy();
245 EXPECT_EQ(buffer.get()[0], 1);
246 EXPECT_EQ(buffer.get()[1], 0);
247 EXPECT_EQ(buffer.get()[2], 0);
248 EXPECT_EQ(buffer.get()[3], 0);
249 EXPECT_EQ(buffer.get()[4], 0);
250 EXPECT_EQ(buffer.get()[5], 0);
251 EXPECT_EQ(buffer.get()[6], 0);
252 EXPECT_EQ(buffer.get()[7], 0);
253 EXPECT_EQ(buffer.get()[8], 2);
254 }
255
TEST(ReadAndAdvanceTest,Number)256 TEST(ReadAndAdvanceTest, Number) {
257 uint64_t expected = 42;
258 uint64_t actual = 0;
259 uint8_t buffer[8] = {};
260 const uint8_t* start = buffer;
261 const uint8_t* ptr = buffer;
262 memcpy(&buffer, &expected, 8);
263 EXPECT_TRUE(CpuReader::ReadAndAdvance<uint64_t>(&ptr, ptr + 8, &actual));
264 EXPECT_EQ(ptr, start + 8);
265 EXPECT_EQ(actual, expected);
266 }
267
TEST(ReadAndAdvanceTest,PlainStruct)268 TEST(ReadAndAdvanceTest, PlainStruct) {
269 struct PlainStruct {
270 uint64_t timestamp;
271 uint64_t length;
272 };
273
274 uint64_t expected[2] = {42, 999};
275 PlainStruct actual;
276 uint8_t buffer[16] = {};
277 const uint8_t* start = buffer;
278 const uint8_t* ptr = buffer;
279 memcpy(&buffer, &expected, 16);
280 EXPECT_TRUE(CpuReader::ReadAndAdvance<PlainStruct>(&ptr, ptr + 16, &actual));
281 EXPECT_EQ(ptr, start + 16);
282 EXPECT_EQ(actual.timestamp, 42ul);
283 EXPECT_EQ(actual.length, 999ul);
284 }
285
TEST(ReadAndAdvanceTest,ComplexStruct)286 TEST(ReadAndAdvanceTest, ComplexStruct) {
287 struct ComplexStruct {
288 uint64_t timestamp;
289 uint32_t length;
290 uint32_t : 24;
291 uint32_t overwrite : 8;
292 };
293
294 uint64_t expected[2] = {42, 0xcdffffffabababab};
295 ComplexStruct actual = {};
296 uint8_t buffer[16] = {};
297 const uint8_t* start = buffer;
298 const uint8_t* ptr = buffer;
299 memcpy(&buffer, &expected, 16);
300 EXPECT_TRUE(
301 CpuReader::ReadAndAdvance<ComplexStruct>(&ptr, ptr + 16, &actual));
302 EXPECT_EQ(ptr, start + 16);
303 EXPECT_EQ(actual.timestamp, 42ul);
304 EXPECT_EQ(actual.length, 0xabababab);
305 EXPECT_EQ(actual.overwrite, 0xCDu);
306 }
307
TEST(ReadAndAdvanceTest,Overruns)308 TEST(ReadAndAdvanceTest, Overruns) {
309 uint64_t result = 42;
310 uint8_t buffer[7] = {};
311 const uint8_t* start = buffer;
312 const uint8_t* ptr = buffer;
313 EXPECT_FALSE(CpuReader::ReadAndAdvance<uint64_t>(&ptr, ptr + 7, &result));
314 EXPECT_EQ(ptr, start);
315 EXPECT_EQ(result, 42ul);
316 }
317
TEST(ReadAndAdvanceTest,AtEnd)318 TEST(ReadAndAdvanceTest, AtEnd) {
319 uint8_t result = 42;
320 uint8_t buffer[8] = {};
321 const uint8_t* start = buffer;
322 const uint8_t* ptr = buffer;
323 EXPECT_FALSE(CpuReader::ReadAndAdvance<uint8_t>(&ptr, ptr, &result));
324 EXPECT_EQ(ptr, start);
325 EXPECT_EQ(result, 42);
326 }
327
TEST(ReadAndAdvanceTest,Underruns)328 TEST(ReadAndAdvanceTest, Underruns) {
329 uint64_t expected = 42;
330 uint64_t actual = 0;
331 uint8_t buffer[9] = {};
332 const uint8_t* start = buffer;
333 const uint8_t* ptr = buffer;
334 memcpy(&buffer, &expected, 8);
335 EXPECT_TRUE(CpuReader::ReadAndAdvance<uint64_t>(&ptr, ptr + 8, &actual));
336 EXPECT_EQ(ptr, start + 8);
337 EXPECT_EQ(actual, expected);
338 }
339
TEST(ParsePageHeaderTest,WithOverrun)340 TEST(ParsePageHeaderTest, WithOverrun) {
341 std::string text = R"(
342 00000000: 3ef3 db77 67a2 0100 f00f 0080 ffff ffff
343 )";
344 auto page = PageFromXxd(text);
345
346 // parse as if we're on a 32 bit kernel (4 byte "commit" field)
347 {
348 const uint8_t* ptr = page.get();
349 auto ret = CpuReader::ParsePageHeader(&ptr, 4u);
350 ASSERT_TRUE(ret.has_value());
351 CpuReader::PageHeader parsed = ret.value();
352
353 ASSERT_EQ(parsed.timestamp, 0x0001A26777DBF33Eull); // first 8 bytes
354 ASSERT_EQ(parsed.size, 0x0ff0u); // 4080
355 ASSERT_TRUE(parsed.lost_events);
356
357 // pointer advanced past the header (8+4 bytes)
358 ASSERT_EQ(ptr, page.get() + 12);
359 }
360
361 // parse as if we're on a 64 bit kernel (8 byte "commit" field)
362 {
363 const uint8_t* ptr = page.get();
364 auto ret = CpuReader::ParsePageHeader(&ptr, 8u);
365 ASSERT_TRUE(ret.has_value());
366 CpuReader::PageHeader parsed = ret.value();
367
368 ASSERT_EQ(parsed.timestamp, 0x0001A26777DBF33Eull); // first 8 bytes
369 ASSERT_EQ(parsed.size, 0x0ff0u); // 4080
370 ASSERT_TRUE(parsed.lost_events);
371
372 // pointer advanced past the header (8+8 bytes)
373 ASSERT_EQ(ptr, page.get() + 16);
374 }
375 }
376
377 // clang-format off
378 // # tracer: nop
379 // #
380 // # entries-in-buffer/entries-written: 1/1 #P:8
381 // #
382 // # _-----=> irqs-off
383 // # / _----=> need-resched
384 // # | / _---=> hardirq/softirq
385 // # || / _--=> preempt-depth
386 // # ||| / delay
387 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
388 // # | | | |||| | |
389 // sh-28712 [000] ...1 608934.535199: tracing_mark_write: Hello, world!
390 // clang-format on
391
392 static ExamplePage g_single_print{
393 "synthetic",
394 R"(
395 00000000: ba12 6a33 c628 0200 2c00 0000 0000 0000 ..j3.(..,.......
396 00000010: def0 ec67 8d21 0000 0800 0000 0500 0001 ...g.!..........
397 00000020: 2870 0000 ac5d 1661 86ff ffff 4865 6c6c (p...].a....Hell
398 00000030: 6f2c 2077 6f72 6c64 210a 00ff 0000 0000 o, world!.......
399 )",
400 };
401
402 class CpuReaderParsePagePayloadTest : public testing::Test {
403 protected:
CreateBundler(const FtraceDataSourceConfig & ds_config)404 CpuReader::Bundler* CreateBundler(const FtraceDataSourceConfig& ds_config) {
405 PERFETTO_CHECK(!bundler_.has_value());
406 writer_.emplace();
407 compact_sched_buf_ = std::make_unique<CompactSchedBuffer>();
408 bundler_.emplace(&writer_.value(), &metadata_, /*symbolizer=*/nullptr,
409 /*cpu=*/0,
410 /*ftrace_clock_snapshot=*/nullptr,
411 protos::pbzero::FTRACE_CLOCK_UNSPECIFIED,
412 compact_sched_buf_.get(), ds_config.compact_sched.enabled,
413 /*last_read_event_ts=*/0);
414 return &bundler_.value();
415 }
416
GetBundle()417 protos::gen::FtraceEventBundle GetBundle() {
418 PERFETTO_CHECK(bundler_.has_value());
419 PERFETTO_CHECK(writer_.has_value());
420 bundler_.reset();
421 protos::gen::FtraceEventBundle bundle =
422 writer_->GetOnlyTracePacket().ftrace_events();
423 writer_.reset();
424 return bundle;
425 }
426
AllTracePackets()427 std::vector<protos::gen::TracePacket> AllTracePackets() {
428 PERFETTO_CHECK(bundler_.has_value());
429 PERFETTO_CHECK(writer_.has_value());
430 bundler_.reset();
431 std::vector<protos::gen::TracePacket> packets =
432 writer_->GetAllTracePackets();
433 writer_.reset();
434 return packets;
435 }
436
437 FtraceMetadata metadata_;
438 std::optional<TraceWriterForTesting> writer_;
439 std::unique_ptr<CompactSchedBuffer> compact_sched_buf_;
440 std::optional<CpuReader::Bundler> bundler_;
441 uint64_t last_read_event_ts_ = 0;
442 };
443
TEST_F(CpuReaderParsePagePayloadTest,ParseSinglePrint)444 TEST_F(CpuReaderParsePagePayloadTest, ParseSinglePrint) {
445 const ExamplePage* test_case = &g_single_print;
446
447 ProtoTranslationTable* table = GetTable(test_case->name);
448 auto page = PageFromXxd(test_case->data);
449
450 FtraceDataSourceConfig ds_config = EmptyConfig();
451 ds_config.event_filter.AddEnabledEvent(
452 table->EventToFtraceId(GroupAndName("ftrace", "print")));
453
454 const uint8_t* parse_pos = page.get();
455 std::optional<CpuReader::PageHeader> page_header =
456 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
457
458 const uint8_t* page_end = page.get() + base::GetSysPageSize();
459 ASSERT_TRUE(page_header.has_value());
460 EXPECT_EQ(44ul, page_header->size);
461 EXPECT_FALSE(page_header->lost_events);
462 EXPECT_LE(parse_pos + page_header->size, page_end);
463
464 FtraceParseStatus status = CpuReader::ParsePagePayload(
465 parse_pos, &page_header.value(), table, &ds_config,
466 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
467
468 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
469
470 auto bundle = GetBundle();
471 ASSERT_EQ(bundle.event().size(), 1u);
472 const protos::gen::FtraceEvent& event = bundle.event()[0];
473 EXPECT_EQ(event.pid(), 28712ul);
474 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 608934, 535199));
475 EXPECT_EQ(event.print().buf(), "Hello, world!\n");
476 }
477
478 // clang-format off
479 // # tracer: nop
480 // #
481 // # entries-in-buffer/entries-written: 2/2 #P:8
482 // #
483 // # _-----=> irqs-off
484 // # / _----=> need-resched
485 // # | / _---=> hardirq/softirq
486 // # || / _--=> preempt-depth
487 // # ||| / delay
488 // # TASK-PID TGID CPU# |||| TIMESTAMP FUNCTION
489 // # | | | | |||| | |
490 // echo-6908 ( 6908) [000] ...1 282762.884473: tracing_mark_write: qwertyuiopqwrtyuiopqwertyuiopqwertyuiopqwer[...]
491 // echo-6908 ( 6908) [000] ...1 282762.884492: tracing_mark_write:
492 // clang-format on
493
494 static ExamplePage g_really_long_event{
495 "synthetic",
496 R"(
497 00000000: 6be0 48dd 2b01 0100 e403 0000 0000 0000 k.H.+...........
498 00000010: 1e00 0000 0000 0000 0000 0000 c003 0000 ................
499 00000020: 0500 0001 fc1a 0000 4096 3615 9cff ffff [email protected].....
500 00000030: 7177 6572 7479 7569 6f70 7177 7274 7975 qwertyuiopqwrtyu
501 00000040: 696f 7071 7765 7274 7975 696f 7071 7765 iopqwertyuiopqwe
502 00000050: 7274 7975 696f 7071 7765 7274 7975 696f rtyuiopqwertyuio
503 00000060: 7071 7772 7479 7569 6f70 7177 6572 7479 pqwrtyuiopqwerty
504 00000070: 7569 6f70 7177 6572 7479 7569 6f71 7765 uiopqwertyuioqwe
505 00000080: 7274 7975 696f 7071 7772 7479 7569 6f70 rtyuiopqwrtyuiop
506 00000090: 7177 6572 7479 7569 6f70 7177 6572 7479 qwertyuiopqwerty
507 000000a0: 7569 6f71 7765 7274 7975 696f 7071 7772 uioqwertyuiopqwr
508 000000b0: 7479 7569 6f70 7177 6572 7479 7569 6f70 tyuiopqwertyuiop
509 000000c0: 7177 6572 7479 7569 6f70 7070 7177 6572 qwertyuiopppqwer
510 000000d0: 7479 7569 6f70 7177 7274 7975 696f 7071 tyuiopqwrtyuiopq
511 000000e0: 7765 7274 7975 696f 7071 7765 7274 7975 wertyuiopqwertyu
512 000000f0: 696f 7071 7765 7274 7975 696f 7071 7772 iopqwertyuiopqwr
513 00000100: 7479 7569 6f70 7177 6572 7479 7569 6f70 tyuiopqwertyuiop
514 00000110: 7177 6572 7479 7569 6f71 7765 7274 7975 qwertyuioqwertyu
515 00000120: 696f 7071 7772 7479 7569 6f70 7177 6572 iopqwrtyuiopqwer
516 00000130: 7479 7569 6f70 7177 6572 7479 7569 6f71 tyuiopqwertyuioq
517 00000140: 7765 7274 7975 696f 7071 7772 7479 7569 wertyuiopqwrtyui
518 00000150: 6f70 7177 6572 7479 7569 6f70 7177 6572 opqwertyuiopqwer
519 00000160: 7479 7569 6f70 7070 7177 6572 7479 7569 tyuiopppqwertyui
520 00000170: 6f70 7177 7274 7975 696f 7071 7765 7274 opqwrtyuiopqwert
521 00000180: 7975 696f 7071 7765 7274 7975 696f 7071 yuiopqwertyuiopq
522 00000190: 7765 7274 7975 696f 7071 7772 7479 7569 wertyuiopqwrtyui
523 000001a0: 6f70 7177 6572 7479 7569 6f70 7177 6572 opqwertyuiopqwer
524 000001b0: 7479 7569 6f71 7765 7274 7975 696f 7071 tyuioqwertyuiopq
525 000001c0: 7772 7479 7569 6f70 7177 6572 7479 7569 wrtyuiopqwertyui
526 000001d0: 6f70 7177 6572 7479 7569 6f71 7765 7274 opqwertyuioqwert
527 000001e0: 7975 696f 7071 7772 7479 7569 6f70 7177 yuiopqwrtyuiopqw
528 000001f0: 6572 7479 7569 6f70 7177 6572 7479 7569 ertyuiopqwertyui
529 00000200: 6f70 7070 7177 6572 7479 7569 6f70 7177 opppqwertyuiopqw
530 00000210: 7274 7975 696f 7071 7765 7274 7975 696f rtyuiopqwertyuio
531 00000220: 7071 7765 7274 7975 696f 7071 7765 7274 pqwertyuiopqwert
532 00000230: 7975 696f 7071 7772 7479 7569 6f70 7177 yuiopqwrtyuiopqw
533 00000240: 6572 7479 7569 6f70 7177 6572 7479 7569 ertyuiopqwertyui
534 00000250: 6f71 7765 7274 7975 696f 7071 7772 7479 oqwertyuiopqwrty
535 00000260: 7569 6f70 7177 6572 7479 7569 6f70 7177 uiopqwertyuiopqw
536 00000270: 6572 7479 7569 6f71 7765 7274 7975 696f ertyuioqwertyuio
537 00000280: 7071 7772 7479 7569 6f70 7177 6572 7479 pqwrtyuiopqwerty
538 00000290: 7569 6f70 7177 6572 7479 7569 6f70 7070 uiopqwertyuioppp
539 000002a0: 7177 6572 7479 7569 6f70 7177 7274 7975 qwertyuiopqwrtyu
540 000002b0: 696f 7071 7765 7274 7975 696f 7071 7765 iopqwertyuiopqwe
541 000002c0: 7274 7975 696f 7071 7765 7274 7975 696f rtyuiopqwertyuio
542 000002d0: 7071 7772 7479 7569 6f70 7177 6572 7479 pqwrtyuiopqwerty
543 000002e0: 7569 6f70 7177 6572 7479 7569 6f71 7765 uiopqwertyuioqwe
544 000002f0: 7274 7975 696f 7071 7772 7479 7569 6f70 rtyuiopqwrtyuiop
545 00000300: 7177 6572 7479 7569 6f70 7177 6572 7479 qwertyuiopqwerty
546 00000310: 7569 6f71 7765 7274 7975 696f 7071 7772 uioqwertyuiopqwr
547 00000320: 7479 7569 6f70 7177 6572 7479 7569 6f70 tyuiopqwertyuiop
548 00000330: 7177 6572 7479 7569 6f70 7070 7177 6572 qwertyuiopppqwer
549 00000340: 7479 7569 6f70 7177 7274 7975 696f 7071 tyuiopqwrtyuiopq
550 00000350: 7765 7274 7975 696f 7071 7765 7274 7975 wertyuiopqwertyu
551 00000360: 696f 7071 7765 7274 7975 696f 7071 7772 iopqwertyuiopqwr
552 00000370: 7479 7569 6f70 7177 6572 7479 7569 6f70 tyuiopqwertyuiop
553 00000380: 7177 6572 7479 7569 6f71 7765 7274 7975 qwertyuioqwertyu
554 00000390: 696f 7071 7772 7479 7569 6f70 7177 6572 iopqwrtyuiopqwer
555 000003a0: 7479 7569 6f70 7177 6572 7479 7569 6f71 tyuiopqwertyuioq
556 000003b0: 7765 7274 7975 696f 7071 7772 7479 7569 wertyuiopqwrtyui
557 000003c0: 6f70 7177 6572 7479 7569 6f70 7177 6572 opqwertyuiopqwer
558 000003d0: 7479 7569 6f70 7070 0a00 5115 6562 0900 tyuioppp..Q.eb..
559 000003e0: 0500 0001 fc1a 0000 4096 3615 9cff ffff [email protected].....
560 000003f0: 0a00 0000 0000 0000 0000 0000 0000 0000 ................
561 00000400: 0000 0000 0000 0000 0000 0000 0000 0000 ................
562 00000410: 0000 0000 0000 0000 0000 0000 0000 0000 ................
563 00000420: 0000 0000 0000 0000 0000 0000 0000 0000 ................
564 )",
565 };
566
TEST_F(CpuReaderParsePagePayloadTest,ReallyLongEvent)567 TEST_F(CpuReaderParsePagePayloadTest, ReallyLongEvent) {
568 const ExamplePage* test_case = &g_really_long_event;
569
570 ProtoTranslationTable* table = GetTable(test_case->name);
571 auto page = PageFromXxd(test_case->data);
572
573 FtraceDataSourceConfig ds_config = EmptyConfig();
574 ds_config.event_filter.AddEnabledEvent(
575 table->EventToFtraceId(GroupAndName("ftrace", "print")));
576
577 const uint8_t* parse_pos = page.get();
578 std::optional<CpuReader::PageHeader> page_header =
579 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
580
581 const uint8_t* page_end = page.get() + base::GetSysPageSize();
582 ASSERT_TRUE(page_header.has_value());
583 EXPECT_FALSE(page_header->lost_events);
584 EXPECT_LE(parse_pos + page_header->size, page_end);
585
586 CpuReader::ParsePagePayload(parse_pos, &page_header.value(), table,
587 &ds_config, CreateBundler(ds_config), &metadata_,
588 &last_read_event_ts_);
589
590 auto bundle = GetBundle();
591 const protos::gen::FtraceEvent& long_print = bundle.event()[0];
592 EXPECT_THAT(long_print.print().buf(), StartsWith("qwerty"));
593 EXPECT_THAT(long_print.print().buf(), EndsWith("ppp\n"));
594 const protos::gen::FtraceEvent& newline = bundle.event()[1];
595 EXPECT_EQ(newline.print().buf(), "\n");
596 }
597
598 // This event is as the event for ParseSinglePrint above except the string
599 // is extended and not null terminated.
600 static ExamplePage g_single_print_non_null_terminated{
601 "synthetic",
602 R"(
603 00000000: ba12 6a33 c628 0200 2c00 0000 0000 0000 ..j3.(..,.......
604 00000010: def0 ec67 8d21 0000 0800 0000 0500 0001 ...g.!..........
605 00000020: 2870 0000 ac5d 1661 86ff ffff 4865 6c6c (p...].a....Hell
606 00000030: 6f2c 2077 6f72 6c64 2161 6161 6161 6161 o, world!aaaaaaa
607 00000040: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa
608 )",
609 };
610
TEST_F(CpuReaderParsePagePayloadTest,ParseSinglePrintNonNullTerminated)611 TEST_F(CpuReaderParsePagePayloadTest, ParseSinglePrintNonNullTerminated) {
612 const ExamplePage* test_case = &g_single_print_non_null_terminated;
613
614 ProtoTranslationTable* table = GetTable(test_case->name);
615 auto page = PageFromXxd(test_case->data);
616
617 FtraceDataSourceConfig ds_config = EmptyConfig();
618 ds_config.event_filter.AddEnabledEvent(
619 table->EventToFtraceId(GroupAndName("ftrace", "print")));
620
621 const uint8_t* parse_pos = page.get();
622 std::optional<CpuReader::PageHeader> page_header =
623 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
624
625 const uint8_t* page_end = page.get() + base::GetSysPageSize();
626 ASSERT_TRUE(page_header.has_value());
627 EXPECT_FALSE(page_header->lost_events);
628 EXPECT_LE(parse_pos + page_header->size, page_end);
629
630 FtraceParseStatus status = CpuReader::ParsePagePayload(
631 parse_pos, &page_header.value(), table, &ds_config,
632 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
633
634 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
635
636 auto bundle = GetBundle();
637 ASSERT_EQ(bundle.event().size(), 1u);
638 const protos::gen::FtraceEvent& event = bundle.event()[0];
639 EXPECT_EQ(event.pid(), 28712ul);
640 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 608934, 535199));
641 EXPECT_EQ(event.print().buf(), "Hello, world!aaa");
642 }
643
644 static ExamplePage g_single_print_zero_size{
645 "synthetic",
646 R"(
647 00000000: ba12 6a33 c628 0200 2c00 0000 0000 0000 ..j3.(..,.......
648 00000010: def0 ec67 8d21 0000 0800 0000 0500 0001 ...g.!..........
649 00000020: 2870 0000 ac5d 1661 86ff ffff 0000 0000 (p...].a........
650 00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
651 00000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
652 )",
653 };
654
TEST_F(CpuReaderParsePagePayloadTest,ParseSinglePrintZeroSize)655 TEST_F(CpuReaderParsePagePayloadTest, ParseSinglePrintZeroSize) {
656 const ExamplePage* test_case = &g_single_print_zero_size;
657
658 ProtoTranslationTable* table = GetTable(test_case->name);
659 auto page = PageFromXxd(test_case->data);
660
661 FtraceDataSourceConfig ds_config = EmptyConfig();
662 ds_config.event_filter.AddEnabledEvent(
663 table->EventToFtraceId(GroupAndName("ftrace", "print")));
664
665 const uint8_t* parse_pos = page.get();
666 std::optional<CpuReader::PageHeader> page_header =
667 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
668
669 const uint8_t* page_end = page.get() + base::GetSysPageSize();
670 ASSERT_TRUE(page_header.has_value());
671 EXPECT_FALSE(page_header->lost_events);
672 EXPECT_LE(parse_pos + page_header->size, page_end);
673
674 FtraceParseStatus status = CpuReader::ParsePagePayload(
675 parse_pos, &page_header.value(), table, &ds_config,
676 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
677
678 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
679
680 auto bundle = GetBundle();
681 ASSERT_EQ(bundle.event().size(), 1u);
682 const protos::gen::FtraceEvent& event = bundle.event()[0];
683 EXPECT_EQ(event.pid(), 28712ul);
684 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 608934, 535199));
685 EXPECT_TRUE(event.print().has_buf());
686 EXPECT_EQ(event.print().buf(), "");
687 }
688
TEST_F(CpuReaderParsePagePayloadTest,FilterByEvent)689 TEST_F(CpuReaderParsePagePayloadTest, FilterByEvent) {
690 const ExamplePage* test_case = &g_single_print;
691
692 ProtoTranslationTable* table = GetTable(test_case->name);
693 auto page = PageFromXxd(test_case->data);
694
695 FtraceDataSourceConfig ds_config = EmptyConfig();
696
697 const uint8_t* parse_pos = page.get();
698 std::optional<CpuReader::PageHeader> page_header =
699 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
700
701 ASSERT_TRUE(page_header.has_value());
702 EXPECT_FALSE(page_header->lost_events);
703
704 FtraceParseStatus status = CpuReader::ParsePagePayload(
705 parse_pos, &page_header.value(), table, &ds_config,
706 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
707
708 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
709
710 EXPECT_THAT(AllTracePackets(), IsEmpty());
711 }
712
713 // clang-format off
714 // # tracer: nop
715 // #
716 // # entries-in-buffer/entries-written: 3/3 #P:8
717 // #
718 // # _-----=> irqs-off
719 // # / _----=> need-resched
720 // # | / _---=> hardirq/softirq
721 // # || / _--=> preempt-depth
722 // # ||| / delay
723 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
724 // # | | | |||| | |
725 // sh-30693 [000] ...1 615436.216806: tracing_mark_write: Hello, world!
726 // sh-30693 [000] ...1 615486.377232: tracing_mark_write: Good afternoon, world!
727 // sh-30693 [000] ...1 615495.632679: tracing_mark_write: Goodbye, world!
728 // clang-format on
729
730 static ExamplePage g_three_prints{
731 "synthetic",
732 R"(
733 00000000: a3ab 1569 bc2f 0200 9400 0000 0000 0000 ...i./..........
734 00000010: 1e00 0000 0000 0000 0800 0000 0500 0001 ................
735 00000020: e577 0000 ac5d 1661 86ff ffff 4865 6c6c .w...].a....Hell
736 00000030: 6f2c 2077 6f72 6c64 210a 0000 5e32 6bb9 o, world!...^2k.
737 00000040: 7501 0000 0b00 0000 0500 0001 e577 0000 u............w..
738 00000050: ac5d 1661 86ff ffff 476f 6f64 2061 6674 .].a....Good aft
739 00000060: 6572 6e6f 6f6e 2c20 776f 726c 6421 0a00 ernoon, world!..
740 00000070: 0000 0000 9e6a 5df5 4400 0000 0900 0000 .....j].D.......
741 00000080: 0500 0001 e577 0000 ac5d 1661 86ff ffff .....w...].a....
742 00000090: 476f 6f64 6279 652c 2077 6f72 6c64 210a Goodbye, world!.
743 000000a0: 0051 0000 0000 0000 0000 0000 0000 0000 .Q..............
744 )",
745 };
746
TEST_F(CpuReaderParsePagePayloadTest,ParseThreePrint)747 TEST_F(CpuReaderParsePagePayloadTest, ParseThreePrint) {
748 const ExamplePage* test_case = &g_three_prints;
749
750 ProtoTranslationTable* table = GetTable(test_case->name);
751 auto page = PageFromXxd(test_case->data);
752
753 FtraceDataSourceConfig ds_config = EmptyConfig();
754 ds_config.event_filter.AddEnabledEvent(
755 table->EventToFtraceId(GroupAndName("ftrace", "print")));
756
757 const uint8_t* parse_pos = page.get();
758 std::optional<CpuReader::PageHeader> page_header =
759 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
760
761 const uint8_t* page_end = page.get() + base::GetSysPageSize();
762 ASSERT_TRUE(page_header.has_value());
763 EXPECT_FALSE(page_header->lost_events);
764 EXPECT_LE(parse_pos + page_header->size, page_end);
765
766 FtraceParseStatus status = CpuReader::ParsePagePayload(
767 parse_pos, &page_header.value(), table, &ds_config,
768 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
769
770 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
771
772 auto bundle = GetBundle();
773 ASSERT_EQ(bundle.event().size(), 3u);
774
775 {
776 const protos::gen::FtraceEvent& event = bundle.event()[0];
777 EXPECT_EQ(event.pid(), 30693ul);
778 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 615436, 216806));
779 EXPECT_EQ(event.print().buf(), "Hello, world!\n");
780 }
781
782 {
783 const protos::gen::FtraceEvent& event = bundle.event()[1];
784 EXPECT_EQ(event.pid(), 30693ul);
785 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 615486, 377232));
786 EXPECT_EQ(event.print().buf(), "Good afternoon, world!\n");
787 }
788
789 {
790 const protos::gen::FtraceEvent& event = bundle.event()[2];
791 EXPECT_EQ(event.pid(), 30693ul);
792 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 615495, 632679));
793 EXPECT_EQ(event.print().buf(), "Goodbye, world!\n");
794 }
795 }
796
TEST_F(CpuReaderParsePagePayloadTest,ParsePrintWithAndWithoutFilter)797 TEST_F(CpuReaderParsePagePayloadTest, ParsePrintWithAndWithoutFilter) {
798 using FtraceEventBundle = protos::gen::FtraceEventBundle;
799 using FtraceEvent = protos::gen::FtraceEvent;
800 using PrintFtraceEvent = protos::gen::PrintFtraceEvent;
801
802 const ExamplePage* test_case = &g_three_prints;
803
804 ProtoTranslationTable* table = GetTable(test_case->name);
805 auto page = PageFromXxd(test_case->data);
806
807 const uint8_t* parse_pos = page.get();
808 std::optional<CpuReader::PageHeader> page_header =
809 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
810
811 const uint8_t* page_end = page.get() + base::GetSysPageSize();
812 ASSERT_TRUE(page_header.has_value());
813 ASSERT_FALSE(page_header->lost_events);
814 ASSERT_LE(parse_pos + page_header->size, page_end);
815 {
816 FtraceDataSourceConfig ds_config_no_filter = EmptyConfig();
817 ds_config_no_filter.event_filter.AddEnabledEvent(
818 table->EventToFtraceId(GroupAndName("ftrace", "print")));
819
820 FtraceParseStatus status = CpuReader::ParsePagePayload(
821 parse_pos, &page_header.value(), table, &ds_config_no_filter,
822 CreateBundler(ds_config_no_filter), &metadata_, &last_read_event_ts_);
823 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
824
825 auto bundle = GetBundle();
826 EXPECT_THAT(
827 bundle,
828 Property(
829 &FtraceEventBundle::event,
830 ElementsAre(
831 Property(&FtraceEvent::print,
832 Property(&PrintFtraceEvent::buf, "Hello, world!\n")),
833 Property(&FtraceEvent::print,
834 Property(&PrintFtraceEvent::buf,
835 "Good afternoon, world!\n")),
836 Property(&FtraceEvent::print, Property(&PrintFtraceEvent::buf,
837 "Goodbye, world!\n")))));
838 }
839
840 {
841 FtraceDataSourceConfig ds_config_with_filter = EmptyConfig();
842 ds_config_with_filter.event_filter.AddEnabledEvent(
843 table->EventToFtraceId(GroupAndName("ftrace", "print")));
844
845 FtraceConfig::PrintFilter conf;
846 auto* rule = conf.add_rules();
847 rule->set_prefix("Good ");
848 rule->set_allow(false);
849 ds_config_with_filter.print_filter =
850 FtracePrintFilterConfig::Create(conf, table);
851 ASSERT_TRUE(ds_config_with_filter.print_filter.has_value());
852
853 FtraceParseStatus status = CpuReader::ParsePagePayload(
854 parse_pos, &page_header.value(), table, &ds_config_with_filter,
855 CreateBundler(ds_config_with_filter), &metadata_, &last_read_event_ts_);
856 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
857
858 auto bundle = GetBundle();
859 EXPECT_THAT(
860 bundle,
861 Property(
862 &FtraceEventBundle::event,
863 ElementsAre(
864 Property(&FtraceEvent::print,
865 Property(&PrintFtraceEvent::buf, "Hello, world!\n")),
866 Property(&FtraceEvent::print, Property(&PrintFtraceEvent::buf,
867 "Goodbye, world!\n")))));
868 }
869 }
870
TEST(CpuReaderTest,ProcessPagesForDataSourceNoEmptyPackets)871 TEST(CpuReaderTest, ProcessPagesForDataSourceNoEmptyPackets) {
872 const ExamplePage* test_case = &g_three_prints;
873
874 ProtoTranslationTable* table = GetTable(test_case->name);
875 auto page = PageFromXxd(test_case->data);
876
877 std::vector<const void*> test_page_order = {
878 page.get(), page.get(), page.get(), page.get(),
879 page.get(), page.get(), page.get(), page.get()};
880
881 // Prepare a buffer with 8 contiguous pages, with the above contents.
882 static constexpr size_t kTestPages = 8;
883
884 std::unique_ptr<uint8_t[]> buf(
885 new uint8_t[base::GetSysPageSize() * kTestPages]());
886 for (size_t i = 0; i < kTestPages; i++) {
887 void* dest = buf.get() + (i * base::GetSysPageSize());
888 memcpy(dest, static_cast<const void*>(test_page_order[i]),
889 base::GetSysPageSize());
890 }
891 auto compact_sched_buf = std::make_unique<CompactSchedBuffer>();
892
893 {
894 FtraceMetadata metadata{};
895 FtraceDataSourceConfig with_filter = EmptyConfig();
896 with_filter.event_filter.AddEnabledEvent(
897 table->EventToFtraceId(GroupAndName("ftrace", "print")));
898
899 FtraceConfig::PrintFilter conf;
900 auto* rule = conf.add_rules();
901 rule->set_prefix("");
902 rule->set_allow(false);
903 with_filter.print_filter = FtracePrintFilterConfig::Create(conf, table);
904 ASSERT_TRUE(with_filter.print_filter.has_value());
905
906 TraceWriterForTesting trace_writer;
907 base::FlatSet<protos::pbzero::FtraceParseStatus> parse_errors;
908 uint64_t last_read_event_ts = 0;
909 bool success = CpuReader::ProcessPagesForDataSource(
910 &trace_writer, &metadata, /*cpu=*/1, &with_filter, &parse_errors,
911 &last_read_event_ts, buf.get(), kTestPages, compact_sched_buf.get(),
912 table,
913 /*symbolizer=*/nullptr,
914 /*ftrace_clock_snapshot=*/nullptr,
915 protos::pbzero::FTRACE_CLOCK_UNSPECIFIED);
916
917 EXPECT_TRUE(success);
918
919 // Check that the data source doesn't emit any packet, not even empty
920 // packets.
921 EXPECT_THAT(trace_writer.GetAllTracePackets(), IsEmpty());
922 }
923
924 {
925 FtraceMetadata metadata{};
926 FtraceDataSourceConfig without_filter = EmptyConfig();
927 without_filter.event_filter.AddEnabledEvent(
928 table->EventToFtraceId(GroupAndName("ftrace", "print")));
929
930 TraceWriterForTesting trace_writer;
931 base::FlatSet<protos::pbzero::FtraceParseStatus> parse_errors;
932 uint64_t last_read_event_ts = 0;
933 bool success = CpuReader::ProcessPagesForDataSource(
934 &trace_writer, &metadata, /*cpu=*/1, &without_filter, &parse_errors,
935 &last_read_event_ts, buf.get(), kTestPages, compact_sched_buf.get(),
936 table,
937 /*symbolizer=*/nullptr,
938 /*ftrace_clock_snapshot=*/nullptr,
939 protos::pbzero::FTRACE_CLOCK_UNSPECIFIED);
940
941 EXPECT_TRUE(success);
942
943 EXPECT_THAT(trace_writer.GetAllTracePackets(), Not(IsEmpty()));
944 }
945 }
946
947 // clang-format off
948 // # tracer: nop
949 // #
950 // # entries-in-buffer/entries-written: 6/6 #P:8
951 // #
952 // # _-----=> irqs-off
953 // # / _----=> need-resched
954 // # | / _---=> hardirq/softirq
955 // # || / _--=> preempt-depth
956 // # ||| / delay
957 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
958 // # | | | |||| | |
959 // ksoftirqd/0-3 [000] d..3 1045157.722134: sched_switch: prev_comm=ksoftirqd/0 prev_pid=3 prev_prio=120 prev_state=S ==> next_comm=sleep next_pid=3733 next_prio=120
960 // sleep-3733 [000] d..3 1045157.725035: sched_switch: prev_comm=sleep prev_pid=3733 prev_prio=120 prev_state=R+ ==> next_comm=rcuop/0 next_pid=10 next_prio=120
961 // rcu_preempt-7 [000] d..3 1045157.725182: sched_switch: prev_comm=rcu_preempt prev_pid=7 prev_prio=120 prev_state=S ==> next_comm=sleep next_pid=3733 next_prio=120
962 // sleep-3733 [000] d..3 1045157.725671: sched_switch: prev_comm=sleep prev_pid=3733 prev_prio=120 prev_state=R+ ==> next_comm=sh next_pid=3513 next_prio=120
963 // sh-3513 [000] d..3 1045157.726668: sched_switch: prev_comm=sh prev_pid=3513 prev_prio=120 prev_state=S ==> next_comm=sleep next_pid=3733 next_prio=120
964 // sleep-3733 [000] d..3 1045157.726697: sched_switch: prev_comm=sleep prev_pid=3733 prev_prio=120 prev_state=x ==> next_comm=kworker/u16:3 next_pid=3681 next_prio=120
965 // clang-format on
966
967 static ExamplePage g_six_sched_switch{
968 "synthetic",
969 R"(
970 00000000: 2b16 c3be 90b6 0300 a001 0000 0000 0000 +...............
971 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ............/...
972 00000020: 0300 0000 6b73 6f66 7469 7271 642f 3000 ....ksoftirqd/0.
973 00000030: 0000 0000 0300 0000 7800 0000 0100 0000 ........x.......
974 00000040: 0000 0000 736c 6565 7000 722f 3000 0000 ....sleep.r/0...
975 00000050: 0000 0000 950e 0000 7800 0000 b072 8805 ........x....r..
976 00000060: 2f00 0103 950e 0000 736c 6565 7000 722f /.......sleep.r/
977 00000070: 3000 0000 0000 0000 950e 0000 7800 0000 0...........x...
978 00000080: 0008 0000 0000 0000 7263 756f 702f 3000 ........rcuop/0.
979 00000090: 0000 0000 0000 0000 0a00 0000 7800 0000 ............x...
980 000000a0: f0b0 4700 2f00 0103 0700 0000 7263 755f ..G./.......rcu_
981 000000b0: 7072 6565 6d70 7400 0000 0000 0700 0000 preempt.........
982 000000c0: 7800 0000 0100 0000 0000 0000 736c 6565 x...........slee
983 000000d0: 7000 722f 3000 0000 0000 0000 950e 0000 p.r/0...........
984 000000e0: 7800 0000 1001 ef00 2f00 0103 950e 0000 x......./.......
985 000000f0: 736c 6565 7000 722f 3000 0000 0000 0000 sleep.r/0.......
986 00000100: 950e 0000 7800 0000 0008 0000 0000 0000 ....x...........
987 00000110: 7368 0064 0065 722f 3000 0000 0000 0000 sh.d.er/0.......
988 00000120: b90d 0000 7800 0000 f0c7 e601 2f00 0103 ....x......./...
989 00000130: b90d 0000 7368 0064 0065 722f 3000 0000 ....sh.d.er/0...
990 00000140: 0000 0000 b90d 0000 7800 0000 0100 0000 ........x.......
991 00000150: 0000 0000 736c 6565 7000 722f 3000 0000 ....sleep.r/0...
992 00000160: 0000 0000 950e 0000 7800 0000 d030 0e00 ........x....0..
993 00000170: 2f00 0103 950e 0000 736c 6565 7000 722f /.......sleep.r/
994 00000180: 3000 0000 0000 0000 950e 0000 7800 0000 0...........x...
995 00000190: 4000 0000 0000 0000 6b77 6f72 6b65 722f @.......kworker/
996 000001a0: 7531 363a 3300 0000 610e 0000 7800 0000 u16:3...a...x...
997 000001b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
998 )",
999 };
1000
TEST_F(CpuReaderParsePagePayloadTest,ParseSixSchedSwitch)1001 TEST_F(CpuReaderParsePagePayloadTest, ParseSixSchedSwitch) {
1002 const ExamplePage* test_case = &g_six_sched_switch;
1003
1004 ProtoTranslationTable* table = GetTable(test_case->name);
1005 auto page = PageFromXxd(test_case->data);
1006
1007 FtraceDataSourceConfig ds_config = EmptyConfig();
1008 ds_config.event_filter.AddEnabledEvent(
1009 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
1010
1011 const uint8_t* parse_pos = page.get();
1012 std::optional<CpuReader::PageHeader> page_header =
1013 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
1014
1015 const uint8_t* page_end = page.get() + base::GetSysPageSize();
1016 ASSERT_TRUE(page_header.has_value());
1017 EXPECT_FALSE(page_header->lost_events);
1018 EXPECT_LE(parse_pos + page_header->size, page_end);
1019
1020 FtraceParseStatus status = CpuReader::ParsePagePayload(
1021 parse_pos, &page_header.value(), table, &ds_config,
1022 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
1023
1024 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
1025 EXPECT_EQ(last_read_event_ts_, 1'045'157'726'697'236ULL);
1026
1027 auto bundle = GetBundle();
1028 EXPECT_EQ(0u, bundle.previous_bundle_end_timestamp());
1029 ASSERT_EQ(bundle.event().size(), 6u);
1030 {
1031 const protos::gen::FtraceEvent& event = bundle.event()[1];
1032 EXPECT_EQ(event.pid(), 3733ul);
1033 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 1045157, 725035));
1034 EXPECT_EQ(event.sched_switch().prev_comm(), "sleep");
1035 EXPECT_EQ(event.sched_switch().prev_pid(), 3733);
1036 EXPECT_EQ(event.sched_switch().prev_prio(), 120);
1037 EXPECT_EQ(event.sched_switch().next_comm(), "rcuop/0");
1038 EXPECT_EQ(event.sched_switch().next_pid(), 10);
1039 EXPECT_EQ(event.sched_switch().next_prio(), 120);
1040 }
1041 }
1042
TEST_F(CpuReaderParsePagePayloadTest,ParseSixSchedSwitchCompactFormat)1043 TEST_F(CpuReaderParsePagePayloadTest, ParseSixSchedSwitchCompactFormat) {
1044 const ExamplePage* test_case = &g_six_sched_switch;
1045
1046 ProtoTranslationTable* table = GetTable(test_case->name);
1047 auto page = PageFromXxd(test_case->data);
1048
1049 FtraceDataSourceConfig ds_config{EventFilter{},
1050 EventFilter{},
1051 EnabledCompactSchedConfigForTesting(),
1052 std::nullopt,
1053 {},
1054 {},
1055 {},
1056 false /* symbolize_ksyms*/,
1057 false /*preserve_ftrace_buffer*/,
1058 {}};
1059 ds_config.event_filter.AddEnabledEvent(
1060 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
1061
1062 const uint8_t* parse_pos = page.get();
1063 std::optional<CpuReader::PageHeader> page_header =
1064 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
1065
1066 const uint8_t* page_end = page.get() + base::GetSysPageSize();
1067 ASSERT_TRUE(page_header.has_value());
1068 EXPECT_FALSE(page_header->lost_events);
1069 EXPECT_LE(parse_pos + page_header->size, page_end);
1070
1071 FtraceParseStatus status = CpuReader::ParsePagePayload(
1072 parse_pos, &page_header.value(), table, &ds_config,
1073 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
1074
1075 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
1076 EXPECT_EQ(last_read_event_ts_, 1'045'157'726'697'236ULL);
1077
1078 // sched switch fields were buffered:
1079 EXPECT_LT(0u, bundler_->compact_sched_buf()->sched_switch().size());
1080 EXPECT_LT(0u,
1081 bundler_->compact_sched_buf()->interner().interned_comms_size());
1082
1083 // Write the buffer out & check the serialized format:
1084 auto bundle = GetBundle();
1085
1086 const auto& compact_sched = bundle.compact_sched();
1087 EXPECT_EQ(0u, bundle.previous_bundle_end_timestamp());
1088
1089 EXPECT_EQ(6u, compact_sched.switch_timestamp().size());
1090 EXPECT_EQ(6u, compact_sched.switch_prev_state().size());
1091 EXPECT_EQ(6u, compact_sched.switch_next_pid().size());
1092 EXPECT_EQ(6u, compact_sched.switch_next_prio().size());
1093 // 4 unique interned next_comm strings:
1094 EXPECT_EQ(4u, compact_sched.intern_table().size());
1095 EXPECT_EQ(6u, compact_sched.switch_next_comm_index().size());
1096
1097 // First event exactly as expected (absolute timestamp):
1098 EXPECT_TRUE(WithinOneMicrosecond(compact_sched.switch_timestamp()[0], 1045157,
1099 722134));
1100 EXPECT_EQ(1, compact_sched.switch_prev_state()[0]);
1101 EXPECT_EQ(3733, compact_sched.switch_next_pid()[0]);
1102 EXPECT_EQ(120, compact_sched.switch_next_prio()[0]);
1103 auto comm_intern_idx = compact_sched.switch_next_comm_index()[0];
1104 std::string next_comm = compact_sched.intern_table()[comm_intern_idx];
1105 EXPECT_EQ("sleep", next_comm);
1106 }
1107
1108 // clang-format off
1109 // # tracer: nop
1110 // #
1111 // # entries-in-buffer/entries-written: 23/23 #P:8
1112 // #
1113 // # _-----=> irqs-off/BH-disabled
1114 // # / _----=> need-resched
1115 // # | / _---=> hardirq/softirq
1116 // # || / _--=> preempt-depth
1117 // # ||| / _-=> migrate-disable
1118 // # |||| / delay
1119 // # TASK-PID CPU# ||||| TIMESTAMP FUNCTION
1120 // # | | | ||||| | |
1121 // <idle>-0 [000] d..2. 701500.111507: sched_switch: prev_comm=swapper/0 prev_pid=0 prev_prio=120 prev_state=R ==> next_comm=bash next_pid=219057 next_prio=120
1122 // ls-219057 [000] d..3. 701500.115222: sched_waking: comm=kworker/u16:17 pid=203967 prio=120 target_cpu=006
1123 // ls-219057 [000] d..3. 701500.115327: sched_waking: comm=kworker/u16:17 pid=203967 prio=120 target_cpu=006
1124 // ls-219057 [000] d..3. 701500.115412: sched_waking: comm=kworker/u16:5 pid=205556 prio=120 target_cpu=004
1125 // ls-219057 [000] d..3. 701500.115416: sched_waking: comm=kworker/u16:17 pid=203967 prio=120 target_cpu=006
1126 // ls-219057 [000] dN.5. 701500.115801: sched_waking: comm=bash pid=217958 prio=120 target_cpu=006
1127 // ls-219057 [000] d..2. 701500.115817: sched_switch: prev_comm=ls prev_pid=219057 prev_prio=120 prev_state=Z ==> next_comm=swapper/0 next_pid=0 next_prio=120
1128 // clang-format on
1129
1130 static ExamplePage g_sched_page{
1131 "synthetic_alt",
1132 R"(
1133 00000000: 67ce f4b8 027e 0200 5801 0000 0000 0000 g....~..X.......
1134 00000010: 1e00 0000 0000 0000 1000 0000 3d01 0102 ............=...
1135 00000020: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1136 00000030: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1137 00000040: 0000 0000 6261 7368 0000 0000 0000 0000 ....bash........
1138 00000050: 0000 0000 b157 0300 7800 0000 a9d2 1507 .....W..x.......
1139 00000060: 4001 0103 b157 0300 6b77 6f72 6b65 722f @....W..kworker/
1140 00000070: 7531 363a 3137 0000 bf1c 0300 7800 0000 u16:17......x...
1141 00000080: 0600 0000 c953 3300 4001 0103 b157 0300 [email protected]..
1142 00000090: 6b77 6f72 6b65 722f 7531 363a 3137 0000 kworker/u16:17..
1143 000000a0: bf1c 0300 7800 0000 0600 0000 0981 2900 ....x.........).
1144 000000b0: 4001 0103 b157 0300 6b77 6f72 6b65 722f @....W..kworker/
1145 000000c0: 7531 363a 3500 0000 f422 0300 7800 0000 u16:5...."..x...
1146 000000d0: 0400 0000 89e0 0100 4001 0103 b157 0300 ........@....W..
1147 000000e0: 6b77 6f72 6b65 722f 7531 363a 3137 0000 kworker/u16:17..
1148 000000f0: bf1c 0300 7800 0000 0600 0000 e92c bc00 ....x........,..
1149 00000100: 4001 2505 b157 0300 6261 7368 0000 0000 @.%..W..bash....
1150 00000110: 0000 0000 0000 0000 6653 0300 7800 0000 ........fS..x...
1151 00000120: 0600 0000 10f8 0700 3d01 0102 b157 0300 ........=....W..
1152 00000130: 6c73 0000 0000 0000 0000 0000 0000 0000 ls..............
1153 00000140: b157 0300 7800 0000 2000 0000 0000 0000 .W..x... .......
1154 00000150: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1155 00000160: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
1156 )",
1157 };
1158
TEST_F(CpuReaderParsePagePayloadTest,ParseCompactSchedSwitchAndWaking)1159 TEST_F(CpuReaderParsePagePayloadTest, ParseCompactSchedSwitchAndWaking) {
1160 const ExamplePage* test_case = &g_sched_page;
1161
1162 ProtoTranslationTable* table = GetTable(test_case->name);
1163 auto page = PageFromXxd(test_case->data);
1164
1165 FtraceDataSourceConfig ds_config{EventFilter{},
1166 EventFilter{},
1167 EnabledCompactSchedConfigForTesting(),
1168 std::nullopt,
1169 {},
1170 {},
1171 {},
1172 false /* symbolize_ksyms*/,
1173 false /*preserve_ftrace_buffer*/,
1174 {}};
1175 ds_config.event_filter.AddEnabledEvent(
1176 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
1177 ds_config.event_filter.AddEnabledEvent(
1178 table->EventToFtraceId(GroupAndName("sched", "sched_waking")));
1179
1180 const uint8_t* parse_pos = page.get();
1181 std::optional<CpuReader::PageHeader> page_header =
1182 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
1183
1184 const uint8_t* page_end = page.get() + base::GetSysPageSize();
1185 ASSERT_TRUE(page_header.has_value());
1186 EXPECT_FALSE(page_header->lost_events);
1187 EXPECT_LE(parse_pos + page_header->size, page_end);
1188
1189 FtraceParseStatus status = CpuReader::ParsePagePayload(
1190 parse_pos, &page_header.value(), table, &ds_config,
1191 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
1192
1193 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
1194
1195 // sched fields were buffered:
1196 EXPECT_LT(0u, bundler_->compact_sched_buf()->sched_switch().size());
1197 EXPECT_LT(0u, bundler_->compact_sched_buf()->sched_waking().size());
1198 EXPECT_LT(0u,
1199 bundler_->compact_sched_buf()->interner().interned_comms_size());
1200
1201 // Write the buffer out & check the serialized format:
1202 auto bundle = GetBundle();
1203 const auto& compact_sched = bundle.compact_sched();
1204 // 2 sched_switch events:
1205 EXPECT_EQ(2u, compact_sched.switch_timestamp().size());
1206 EXPECT_EQ(2u, compact_sched.switch_prev_state().size());
1207 EXPECT_EQ(2u, compact_sched.switch_next_pid().size());
1208 EXPECT_EQ(2u, compact_sched.switch_next_prio().size());
1209 EXPECT_EQ(2u, compact_sched.switch_next_comm_index().size());
1210 // 5 sched_waking events:
1211 EXPECT_EQ(5u, compact_sched.waking_timestamp().size());
1212 EXPECT_EQ(5u, compact_sched.waking_pid().size());
1213 EXPECT_EQ(5u, compact_sched.waking_target_cpu().size());
1214 EXPECT_EQ(5u, compact_sched.waking_prio().size());
1215 EXPECT_EQ(5u, compact_sched.waking_comm_index().size());
1216 EXPECT_EQ(5u, compact_sched.waking_common_flags().size());
1217 // 4 unique interned comm strings:
1218 EXPECT_EQ(4u, compact_sched.intern_table().size());
1219
1220 // First sched waking as expected:
1221 EXPECT_EQ(compact_sched.waking_timestamp()[0], 701500115221756ull);
1222 EXPECT_EQ(compact_sched.waking_pid()[0], 203967);
1223 EXPECT_EQ(compact_sched.waking_target_cpu()[0], 6);
1224 EXPECT_EQ(compact_sched.waking_prio()[0], 120);
1225 EXPECT_EQ(compact_sched.waking_common_flags()[0], 1u);
1226 auto comm_intern_idx = compact_sched.waking_comm_index()[0];
1227 std::string comm = compact_sched.intern_table()[comm_intern_idx];
1228 EXPECT_EQ("kworker/u16:17", comm);
1229 }
1230
1231 TEST_F(CpuReaderParsePagePayloadTest, ParseKprobeAndKretprobe) {
1232 char kprobe_fuse_file_write_iter_page[] =
1233 R"(
1234 00000000: b31b bfe2 a513 0000 1400 0000 0000 0000 ................
1235 00000010: 0400 0000 ff05 48ff 8a33 0000 443d 0e91 ......H..3..D=..
1236 00000020: ffff ffff 0000 0000 0000 0000 0000 0000 ................
1237 )";
1238
1239 std::unique_ptr<uint8_t[]> page =
1240 PageFromXxd(kprobe_fuse_file_write_iter_page);
1241
1242 base::TmpDirTree ftrace;
1243 ftrace.AddFile("available_events", "perfetto_kprobes:fuse_file_write_iter\n");
1244 ftrace.AddDir("events");
1245 ftrace.AddFile(
1246 "events/header_page",
1247 R"( field: u64 timestamp; offset:0; size:8; signed:0;
1248 field: local_t commit; offset:8; size:8; signed:1;
1249 field: int overwrite; offset:8; size:1; signed:1;
1250 field: char data; offset:16; size:4080; signed:1;
1251 )");
1252 ftrace.AddDir("events/perfetto_kprobes");
1253 ftrace.AddDir("events/perfetto_kprobes/fuse_file_write_iter");
1254 ftrace.AddFile("events/perfetto_kprobes/fuse_file_write_iter/format",
1255 R"format(name: fuse_file_write_iter
1256 ID: 1535
1257 format:
1258 field:unsigned short common_type; offset:0; size:2; signed:0;
1259 field:unsigned char common_flags; offset:2; size:1; signed:0;
1260 field:unsigned char common_preempt_count; offset:3; size:1; signed:0;
1261 field:int common_pid; offset:4; size:4; signed:1;
1262
1263 field:unsigned long __probe_ip; offset:8; size:8; signed:0;
1264
1265 print fmt: "(%lx)", REC->__probe_ip
1266 )format");
1267 ftrace.AddFile("trace", "");
1268
1269 std::unique_ptr<FtraceProcfs> ftrace_procfs =
1270 FtraceProcfs::Create(ftrace.path() + "/");
1271 ASSERT_NE(ftrace_procfs.get(), nullptr);
1272 std::unique_ptr<ProtoTranslationTable> table = ProtoTranslationTable::Create(
1273 ftrace_procfs.get(), GetStaticEventInfo(), GetStaticCommonFieldsInfo());
1274 table->GetOrCreateKprobeEvent(
1275 GroupAndName("perfetto_kprobes", "fuse_file_write_iter"));
1276
1277 auto ftrace_evt_id = static_cast<uint32_t>(table->EventToFtraceId(
1278 GroupAndName("perfetto_kprobes", "fuse_file_write_iter")));
1279 FtraceDataSourceConfig ds_config = EmptyConfig();
1280 ds_config.event_filter.AddEnabledEvent(ftrace_evt_id);
1281 ds_config.kprobes[ftrace_evt_id] =
1282 protos::pbzero::KprobeEvent::KprobeType::KPROBE_TYPE_INSTANT;
1283
1284 const uint8_t* parse_pos = page.get();
1285 std::optional<CpuReader::PageHeader> page_header =
1286 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
1287
1288 const uint8_t* page_end = page.get() + base::GetSysPageSize();
1289 ASSERT_TRUE(page_header.has_value());
1290 EXPECT_FALSE(page_header->lost_events);
1291 EXPECT_LE(parse_pos + page_header->size, page_end);
1292
1293 FtraceParseStatus status = CpuReader::ParsePagePayload(
1294 parse_pos, &page_header.value(), table.get(), &ds_config,
1295 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
1296
1297 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
1298
1299 // Write the buffer out & check the serialized format:
1300 auto bundle = GetBundle();
1301 ASSERT_EQ(bundle.event_size(), 1);
1302 EXPECT_EQ(bundle.event()[0].kprobe_event().name(), "fuse_file_write_iter");
1303 EXPECT_EQ(bundle.event()[0].kprobe_event().type(),
1304 protos::gen::KprobeEvent::KPROBE_TYPE_INSTANT);
1305 }
1306
TEST_F(CpuReaderTableTest,ParseAllFields)1307 TEST_F(CpuReaderTableTest, ParseAllFields) {
1308 using FakeEventProvider =
1309 ProtoProvider<pbzero::FakeFtraceEvent, gen::FakeFtraceEvent>;
1310
1311 uint16_t ftrace_event_id = 102;
1312
1313 std::vector<Field> common_fields;
1314 {
1315 common_fields.emplace_back(Field{});
1316 Field* field = &common_fields.back();
1317 field->ftrace_offset = 4;
1318 field->ftrace_size = 4;
1319 field->ftrace_type = kFtraceCommonPid32;
1320 field->proto_field_id = 2;
1321 field->proto_field_type = ProtoSchemaType::kInt32;
1322 SetTranslationStrategy(field->ftrace_type, field->proto_field_type,
1323 &field->strategy);
1324 }
1325
1326 std::vector<Event> events;
1327 events.emplace_back(Event{});
1328 {
1329 Event* event = &events.back();
1330 event->name = "";
1331 event->group = "";
1332 event->proto_field_id = 42;
1333 event->ftrace_event_id = ftrace_event_id;
1334
1335 {
1336 // uint32 -> uint32
1337 event->fields.emplace_back(Field{});
1338 Field* field = &event->fields.back();
1339 field->ftrace_offset = 8;
1340 field->ftrace_size = 4;
1341 field->ftrace_type = kFtraceUint32;
1342 field->proto_field_id = 1;
1343 field->proto_field_type = ProtoSchemaType::kUint32;
1344 }
1345
1346 {
1347 // pid32 -> uint32
1348 event->fields.emplace_back(Field{});
1349 Field* field = &event->fields.back();
1350 field->ftrace_offset = 12;
1351 field->ftrace_size = 4;
1352 field->ftrace_type = kFtracePid32;
1353 field->proto_field_id = 2;
1354 field->proto_field_type = ProtoSchemaType::kInt32;
1355 }
1356
1357 {
1358 // dev32 -> uint64
1359 event->fields.emplace_back(Field{});
1360 Field* field = &event->fields.back();
1361 field->ftrace_offset = 16;
1362 field->ftrace_size = 4;
1363 field->ftrace_type = kFtraceDevId32;
1364 field->proto_field_id = 3;
1365 field->proto_field_type = ProtoSchemaType::kUint64;
1366 }
1367
1368 {
1369 // ino_t (32bit) -> uint64
1370 event->fields.emplace_back(Field{});
1371 Field* field = &event->fields.back();
1372 field->ftrace_offset = 20;
1373 field->ftrace_size = 4;
1374 field->ftrace_type = kFtraceInode32;
1375 field->proto_field_id = 4;
1376 field->proto_field_type = ProtoSchemaType::kUint64;
1377 }
1378
1379 {
1380 // dev64 -> uint64
1381 event->fields.emplace_back(Field{});
1382 Field* field = &event->fields.back();
1383 field->ftrace_offset = 24;
1384 field->ftrace_size = 8;
1385 field->ftrace_type = kFtraceDevId64;
1386 field->proto_field_id = 5;
1387 field->proto_field_type = ProtoSchemaType::kUint64;
1388 }
1389
1390 {
1391 // ino_t (64bit) -> uint64
1392 event->fields.emplace_back(Field{});
1393 Field* field = &event->fields.back();
1394 field->ftrace_offset = 32;
1395 field->ftrace_size = 8;
1396 field->ftrace_type = kFtraceInode64;
1397 field->proto_field_id = 6;
1398 field->proto_field_type = ProtoSchemaType::kUint64;
1399 }
1400
1401 {
1402 // char[16] -> string
1403 event->fields.emplace_back(Field{});
1404 Field* field = &event->fields.back();
1405 field->ftrace_offset = 40;
1406 field->ftrace_size = 16;
1407 field->ftrace_type = kFtraceFixedCString;
1408 field->proto_field_id = 500;
1409 field->proto_field_type = ProtoSchemaType::kString;
1410 }
1411
1412 {
1413 // char* -> string
1414 event->fields.emplace_back(Field{});
1415 Field* field = &event->fields.back();
1416 field->ftrace_offset = 56;
1417 field->ftrace_size = 8;
1418 field->ftrace_type = kFtraceStringPtr;
1419 field->proto_field_id = 503;
1420 field->proto_field_type = ProtoSchemaType::kString;
1421 }
1422
1423 {
1424 // dataloc -> string
1425 event->fields.emplace_back(Field{});
1426 Field* field = &event->fields.back();
1427 field->ftrace_offset = 65;
1428 field->ftrace_size = 4;
1429 field->ftrace_type = kFtraceDataLoc;
1430 field->proto_field_id = 502;
1431 field->proto_field_type = ProtoSchemaType::kString;
1432 }
1433
1434 {
1435 // char -> string
1436 event->fields.emplace_back(Field{});
1437 Field* field = &event->fields.back();
1438 field->ftrace_offset = 69;
1439 field->ftrace_size = 0;
1440 field->ftrace_type = kFtraceCString;
1441 field->proto_field_id = 501;
1442 field->proto_field_type = ProtoSchemaType::kString;
1443 }
1444
1445 for (Field& field : event->fields) {
1446 SetTranslationStrategy(field.ftrace_type, field.proto_field_type,
1447 &field.strategy);
1448 }
1449 }
1450
1451 PrintkMap printk_formats;
1452 printk_formats.insert(0xffffff8504f51b23, "my_printk_format_string");
1453 ProtoTranslationTable table(
1454 &ftrace_, events, std::move(common_fields),
1455 ProtoTranslationTable::DefaultPageHeaderSpecForTesting(),
1456 InvalidCompactSchedEventFormatForTesting(), printk_formats);
1457 FtraceDataSourceConfig ds_config = EmptyConfig();
1458
1459 FakeEventProvider provider(base::GetSysPageSize());
1460
1461 BinaryWriter writer;
1462
1463 // Must use the bit masks to translate between kernel and userspace device ids
1464 // to generate the below examples
1465 const uint32_t kKernelBlockDeviceId = 271581216;
1466
1467 const BlockDeviceID kUserspaceBlockDeviceId =
1468 CpuReader::TranslateBlockDeviceIDToUserspace<BlockDeviceID>(
1469 kKernelBlockDeviceId);
1470 const uint64_t k64BitKernelBlockDeviceId = 4442450946;
1471 const BlockDeviceID k64BitUserspaceBlockDeviceId =
1472 CpuReader::TranslateBlockDeviceIDToUserspace<uint64_t>(
1473 k64BitKernelBlockDeviceId);
1474
1475 writer.Write<int32_t>(1001); // Common field.
1476 writer.Write<int32_t>(9999); // Common pid
1477 writer.Write<int32_t>(1003); // Uint32 field
1478 writer.Write<int32_t>(97); // Pid
1479 writer.Write<int32_t>(kKernelBlockDeviceId); // Dev id
1480 writer.Write<int32_t>(98); // Inode 32
1481 writer.Write<int64_t>(k64BitKernelBlockDeviceId); // Dev id 64
1482 writer.Write<int64_t>(99u); // Inode 64
1483 writer.WriteFixedString(16, "Hello");
1484 writer.Write<uint64_t>(0xffffff8504f51b23ULL); // char* (printk formats)
1485 writer.Write<uint8_t>(0); // Deliberately mis-aligning.
1486 writer.Write<uint32_t>(40 | 6 << 16);
1487 writer.WriteFixedString(300, "Goodbye");
1488
1489 auto input = writer.GetCopy();
1490 auto length = writer.written();
1491 FtraceMetadata metadata{};
1492
1493 ASSERT_TRUE(CpuReader::ParseEvent(ftrace_event_id, input.get(),
1494 input.get() + length, &table, &ds_config,
1495 provider.writer(), &metadata));
1496
1497 auto event = provider.ParseProto();
1498 ASSERT_TRUE(event);
1499 EXPECT_EQ(event->common_pid(), 9999ul);
1500 EXPECT_TRUE(event->has_all_fields());
1501 EXPECT_EQ(event->all_fields().field_uint32(), 1003u);
1502 EXPECT_EQ(event->all_fields().field_pid(), 97);
1503 EXPECT_EQ(event->all_fields().field_dev_32(),
1504 static_cast<uint32_t>(kUserspaceBlockDeviceId));
1505 EXPECT_EQ(event->all_fields().field_inode_32(), 98u);
1506 // TODO(primiano): for some reason this fails on mac.
1507 #if !PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE)
1508 EXPECT_EQ(event->all_fields().field_dev_64(), k64BitUserspaceBlockDeviceId);
1509 #endif
1510 EXPECT_EQ(event->all_fields().field_inode_64(), 99u);
1511 EXPECT_EQ(event->all_fields().field_char_16(), "Hello");
1512 EXPECT_EQ(event->all_fields().field_char(), "Goodbye");
1513 EXPECT_EQ(event->all_fields().field_data_loc(), "Hello");
1514 EXPECT_EQ(event->all_fields().field_char_star(), "my_printk_format_string");
1515 EXPECT_THAT(metadata.pids, Contains(97));
1516 EXPECT_EQ(metadata.inode_and_device.size(), 2U);
1517 EXPECT_THAT(metadata.inode_and_device,
1518 Contains(Pair(98u, kUserspaceBlockDeviceId)));
1519 EXPECT_THAT(metadata.inode_and_device,
1520 Contains(Pair(99u, k64BitUserspaceBlockDeviceId)));
1521 }
1522
1523 TEST(CpuReaderTest, SysEnterEvent) {
1524 BinaryWriter writer;
1525 ProtoTranslationTable* table = GetTable("synthetic");
1526 FtraceDataSourceConfig ds_config = EmptyConfig();
1527
1528 const auto kSysEnterId = static_cast<uint16_t>(
1529 table->EventToFtraceId(GroupAndName("raw_syscalls", "sys_enter")));
1530 ASSERT_GT(kSysEnterId, 0ul);
1531 constexpr uint32_t kPid = 23;
1532 constexpr uint32_t kFd = 7;
1533 constexpr auto kSyscall = SYS_close;
1534
1535 writer.Write<int32_t>(1001); // Common field.
1536 writer.Write<int32_t>(kPid); // Common pid
1537 writer.Write<int64_t>(kSyscall); // id
1538 for (uint32_t i = 0; i < 6; ++i) {
1539 writer.Write<uint64_t>(kFd + i); // args
1540 }
1541
1542 auto input = writer.GetCopy();
1543 auto length = writer.written();
1544
1545 BundleProvider bundle_provider(base::GetSysPageSize());
1546 FtraceMetadata metadata{};
1547
1548 ASSERT_TRUE(CpuReader::ParseEvent(
1549 kSysEnterId, input.get(), input.get() + length, table, &ds_config,
1550 bundle_provider.writer()->add_event(), &metadata));
1551
1552 std::unique_ptr<protos::gen::FtraceEventBundle> a =
1553 bundle_provider.ParseProto();
1554 ASSERT_NE(a, nullptr);
1555 ASSERT_EQ(a->event().size(), 1u);
1556 const auto& event = a->event()[0].sys_enter();
1557 EXPECT_EQ(event.id(), kSyscall);
1558 for (uint32_t i = 0; i < 6; ++i) {
1559 EXPECT_EQ(event.args()[i], kFd + i);
1560 }
1561 }
1562
1563 // MacOS fails on this ...but MacOS will never use cpu_reader so it's
1564 // not a big problem.
1565 #if PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE)
1566 #define MAYBE_SysExitEvent DISABLED_SysExitEvent
1567 #else
1568 #define MAYBE_SysExitEvent SysExitEvent
1569 #endif
1570 TEST(CpuReaderTest, MAYBE_SysExitEvent) {
1571 BinaryWriter writer;
1572 ProtoTranslationTable* table = GetTable("synthetic");
1573 FtraceDataSourceConfig ds_config = EmptyConfig();
1574 const auto syscalls = SyscallTable::FromCurrentArch();
1575
1576 const auto kSysExitId = static_cast<uint16_t>(
1577 table->EventToFtraceId(GroupAndName("raw_syscalls", "sys_exit")));
1578 ASSERT_GT(kSysExitId, 0ul);
1579 constexpr pid_t kPid = 23;
1580 constexpr int64_t kFd = 2;
1581
1582 ds_config.syscalls_returning_fd =
1583 FtraceConfigMuxer::GetSyscallsReturningFds(syscalls);
1584 ASSERT_FALSE(ds_config.syscalls_returning_fd.empty());
1585 const auto syscall_id = *ds_config.syscalls_returning_fd.begin();
1586
1587 writer.Write<int32_t>(1001); // Common field.
1588 writer.Write<int32_t>(kPid); // Common pid
1589 writer.Write<int64_t>(syscall_id); // id
1590 writer.Write<int64_t>(kFd); // ret
1591
1592 auto input = writer.GetCopy();
1593 auto length = writer.written();
1594 BundleProvider bundle_provider(base::GetSysPageSize());
1595 FtraceMetadata metadata{};
1596
1597 ASSERT_TRUE(CpuReader::ParseEvent(
1598 kSysExitId, input.get(), input.get() + length, table, &ds_config,
1599 bundle_provider.writer()->add_event(), &metadata));
1600
1601 std::unique_ptr<protos::gen::FtraceEventBundle> a =
1602 bundle_provider.ParseProto();
1603 ASSERT_NE(a, nullptr);
1604 ASSERT_EQ(a->event().size(), 1u);
1605 const auto& event = a->event()[0].sys_exit();
1606 EXPECT_EQ(event.id(), syscall_id);
1607 EXPECT_EQ(event.ret(), kFd);
1608 EXPECT_THAT(metadata.fds, Contains(std::make_pair(kPid, kFd)));
1609 }
1610
1611 TEST(CpuReaderTest, TaskRenameEvent) {
1612 BundleProvider bundle_provider(base::GetSysPageSize());
1613
1614 BinaryWriter writer;
1615 ProtoTranslationTable* table = GetTable("android_seed_N2F62_3.10.49");
1616 FtraceDataSourceConfig ds_config = EmptyConfig();
1617
1618 constexpr uint32_t kTaskRenameId = 19;
1619
1620 writer.Write<int32_t>(1001); // Common field.
1621 writer.Write<int32_t>(9999); // Common pid
1622 writer.Write<int32_t>(9999); // Pid
1623 writer.WriteFixedString(16, "Hello"); // Old Comm
1624 writer.WriteFixedString(16, "Goodbye"); // New Comm
1625 writer.Write<uint64_t>(10); // flags
1626 writer.Write<int16_t>(10); // oom_score_adj
1627
1628 auto input = writer.GetCopy();
1629 auto length = writer.written();
1630 FtraceMetadata metadata{};
1631
1632 ASSERT_TRUE(CpuReader::ParseEvent(kTaskRenameId, input.get(),
1633 input.get() + length, table, &ds_config,
1634 bundle_provider.writer(), &metadata));
1635 EXPECT_THAT(metadata.rename_pids, Contains(9999));
1636 EXPECT_THAT(metadata.pids, Contains(9999));
1637 }
1638
1639 // Regression test for b/205763418: Kernels without f0a515780393("tracing: Don't
1640 // make assumptions about length of string on task rename") can output non
1641 // zero-terminated strings in some cases. Even though it's a kernel bug, there's
1642 // no point in rejecting that.
1643 TEST(CpuReaderTest, EventNonZeroTerminated) {
1644 BundleProvider bundle_provider(base::GetSysPageSize());
1645
1646 BinaryWriter writer;
1647 ProtoTranslationTable* table = GetTable("android_seed_N2F62_3.10.49");
1648 FtraceDataSourceConfig ds_config = EmptyConfig();
1649
1650 constexpr uint32_t kTaskRenameId = 19;
1651
1652 writer.Write<int32_t>(1001); // Common field.
1653 writer.Write<int32_t>(9999); // Common pid
1654 writer.Write<int32_t>(9999); // Pid
1655 writer.WriteFixedString(16, "Hello"); // Old Comm
1656 std::array<char, 16> newcomm;
1657 memcpy(&newcomm, "0123456789abcdef", sizeof newcomm);
1658 writer.Write(newcomm); // New Comm - not null terminated
1659 writer.Write<uint64_t>(10); // flags
1660 writer.Write<int16_t>(10); // oom_score_adj
1661
1662 auto input = writer.GetCopy();
1663 auto length = writer.written();
1664 FtraceMetadata metadata{};
1665
1666 ASSERT_TRUE(CpuReader::ParseEvent(
1667 kTaskRenameId, input.get(), input.get() + length, table, &ds_config,
1668 bundle_provider.writer()->add_event(), &metadata));
1669 std::unique_ptr<protos::gen::FtraceEventBundle> a =
1670 bundle_provider.ParseProto();
1671 ASSERT_NE(a, nullptr);
1672 ASSERT_EQ(a->event().size(), 1u);
1673 ASSERT_EQ(a->event()[0].task_rename().newcomm(), "0123456789abcdef");
1674 }
1675
1676 // Page with a single sched_switch, no data loss.
1677 static char g_switch_page[] =
1678 R"(
1679 00000000: 2b16 c3be 90b6 0300 4c00 0000 0000 0000 ................
1680 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ................
1681 00000020: 0300 0000 6b73 6f66 7469 7271 642f 3000 ................
1682 00000030: 0000 0000 0300 0000 7800 0000 0100 0000 ................
1683 00000040: 0000 0000 736c 6565 7000 722f 3000 0000 ................
1684 00000050: 0000 0000 950e 0000 7800 0000 0000 0000 ................
1685 )";
1686
1687 // Page with a single sched_switch, header has data loss flag set.
1688 static char g_switch_page_lost_events[] =
1689 R"(
1690 00000000: 2b16 c3be 90b6 0300 4c00 0080 ffff ffff ................
1691 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ................
1692 00000020: 0300 0000 6b73 6f66 7469 7271 642f 3000 ................
1693 00000030: 0000 0000 0300 0000 7800 0000 0100 0000 ................
1694 00000040: 0000 0000 736c 6565 7000 722f 3000 0000 ................
1695 00000050: 0000 0000 950e 0000 7800 0000 0000 0000 ................
1696 )";
1697
1698 // Page with invalid data.
1699 static char g_invalid_page[] =
1700 R"(
1701 00000000: 2b16 c3be 90b6 0300 4b00 0000 0000 0000 ................
1702 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ................
1703 00000020: 0300 0000 6b73 6f66 7469 7271 642f 3000 ................
1704 00000030: 0000 0000 0300 0000 7800 0000 0100 0000 ................
1705 00000040: 0000 0000 736c 6565 7000 722f 3000 0000 ................
1706 00000050: 0000 0000 950e 0000 7800 0000 0000 0000 ................
1707 )";
1708
1709 TEST(CpuReaderTest, NewPacketOnLostEvents) {
1710 auto page_ok = PageFromXxd(g_switch_page);
1711 auto page_loss = PageFromXxd(g_switch_page_lost_events);
1712
1713 std::vector<const void*> test_page_order = {
1714 page_ok.get(), page_ok.get(), page_ok.get(), page_loss.get(),
1715 page_loss.get(), page_ok.get(), page_ok.get(), page_ok.get()};
1716
1717 // Prepare a buffer with 8 contiguous pages, with the above contents.
1718 static constexpr size_t kTestPages = 8;
1719
1720 std::unique_ptr<uint8_t[]> buf(
1721 new uint8_t[base::GetSysPageSize() * kTestPages]());
1722 for (size_t i = 0; i < kTestPages; i++) {
1723 void* dest = buf.get() + (i * base::GetSysPageSize());
1724 memcpy(dest, static_cast<const void*>(test_page_order[i]),
1725 base::GetSysPageSize());
1726 }
1727
1728 ProtoTranslationTable* table = GetTable("synthetic");
1729 FtraceMetadata metadata{};
1730 FtraceDataSourceConfig ds_config = EmptyConfig();
1731 ds_config.event_filter.AddEnabledEvent(
1732 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
1733
1734 TraceWriterForTesting trace_writer;
1735 auto compact_sched_buf = std::make_unique<CompactSchedBuffer>();
1736 base::FlatSet<protos::pbzero::FtraceParseStatus> parse_errors;
1737 uint64_t last_read_event_ts = 0;
1738 bool success = CpuReader::ProcessPagesForDataSource(
1739 &trace_writer, &metadata, /*cpu=*/1, &ds_config, &parse_errors,
1740 &last_read_event_ts, buf.get(), kTestPages, compact_sched_buf.get(),
1741 table, /*symbolizer=*/nullptr,
1742 /*ftrace_clock_snapshot=*/nullptr,
1743 protos::pbzero::FTRACE_CLOCK_UNSPECIFIED);
1744
1745 EXPECT_TRUE(success);
1746
1747 // Each packet should contain the parsed contents of a contiguous run of pages
1748 // without data loss.
1749 // So we should get three packets (each page has 1 event):
1750 // [3 events] [1 event] [4 events].
1751 auto packets = trace_writer.GetAllTracePackets();
1752
1753 ASSERT_EQ(3u, packets.size());
1754 EXPECT_FALSE(packets[0].ftrace_events().lost_events());
1755 EXPECT_EQ(3u, packets[0].ftrace_events().event().size());
1756
1757 EXPECT_TRUE(packets[1].ftrace_events().lost_events());
1758 EXPECT_EQ(1u, packets[1].ftrace_events().event().size());
1759
1760 EXPECT_TRUE(packets[2].ftrace_events().lost_events());
1761 EXPECT_EQ(4u, packets[2].ftrace_events().event().size());
1762 }
1763
1764 TEST(CpuReaderTest, ProcessPagesForDataSourceError) {
1765 auto page_ok = PageFromXxd(g_switch_page);
1766 auto page_err = PageFromXxd(g_invalid_page);
1767
1768 std::vector<const void*> test_page_order = {
1769 page_ok.get(), page_ok.get(), page_ok.get(), page_err.get(),
1770 page_ok.get(), page_ok.get(), page_err.get(), page_ok.get()};
1771
1772 // Prepare a buffer with 8 contiguous pages, with the above contents.
1773 static constexpr size_t kTestPages = 8;
1774
1775 std::unique_ptr<uint8_t[]> buf(
1776 new uint8_t[base::GetSysPageSize() * kTestPages]());
1777 for (size_t i = 0; i < kTestPages; i++) {
1778 void* dest = buf.get() + (i * base::GetSysPageSize());
1779 memcpy(dest, static_cast<const void*>(test_page_order[i]),
1780 base::GetSysPageSize());
1781 }
1782
1783 ProtoTranslationTable* table = GetTable("synthetic");
1784 FtraceMetadata metadata{};
1785 FtraceDataSourceConfig ds_config = EmptyConfig();
1786 ds_config.event_filter.AddEnabledEvent(
1787 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
1788
1789 TraceWriterForTesting trace_writer;
1790 auto compact_sched_buf = std::make_unique<CompactSchedBuffer>();
1791 base::FlatSet<protos::pbzero::FtraceParseStatus> parse_errors;
1792 uint64_t last_read_event_ts = 0;
1793 bool success = CpuReader::ProcessPagesForDataSource(
1794 &trace_writer, &metadata, /*cpu=*/1, &ds_config, &parse_errors,
1795 &last_read_event_ts, buf.get(), kTestPages, compact_sched_buf.get(),
1796 table, /*symbolizer=*/nullptr,
1797 /*ftrace_clock_snapshot=*/nullptr,
1798 protos::pbzero::FTRACE_CLOCK_UNSPECIFIED);
1799
1800 EXPECT_FALSE(success);
1801
1802 EXPECT_EQ(
1803 parse_errors.count(FtraceParseStatus::FTRACE_STATUS_ABI_END_OVERFLOW),
1804 1u);
1805
1806 // 2 invalid pages -> 2 serialised parsing errors
1807 std::vector<protos::gen::TracePacket> packets =
1808 trace_writer.GetAllTracePackets();
1809 ASSERT_EQ(packets.size(), 1u);
1810 protos::gen::FtraceEventBundle bundle = packets[0].ftrace_events();
1811 using Bundle = protos::gen::FtraceEventBundle;
1812 using Error = Bundle::FtraceError;
1813 using protos::gen::FtraceParseStatus::FTRACE_STATUS_ABI_END_OVERFLOW;
1814 EXPECT_THAT(
1815 bundle,
1816 Property(&Bundle::error,
1817 ElementsAre(
1818 Property(&Error::status, FTRACE_STATUS_ABI_END_OVERFLOW),
1819 Property(&Error::status, FTRACE_STATUS_ABI_END_OVERFLOW))));
1820 }
1821
1822 // Page containing an absolute timestamp (RINGBUF_TYPE_TIME_STAMP).
1823 static char g_abs_timestamp[] =
1824 R"(
1825 00000000: 8949 fbfb 38e4 0400 6407 0000 0000 0000 .I..8...d.......
1826 00000010: 5032 0a2d 3b01 0100 0000 0000 7377 6170 P2.-;.......swap
1827 00000020: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1828 00000030: 7800 0000 0000 0000 0000 0000 6776 6673 x...........gvfs
1829 00000040: 2d61 6663 2d76 6f6c 756d 6500 6483 0000 -afc-volume.d...
1830 00000050: 7800 0000 f0de 1700 3b01 0100 6483 0000 x.......;...d...
1831 00000060: 6776 6673 2d61 6663 2d76 6f6c 756d 6500 gvfs-afc-volume.
1832 00000070: 6483 0000 7800 0000 0100 0000 0000 0000 d...x...........
1833 00000080: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1834 00000090: 0000 0000 7800 0000 aaa1 5c08 0401 1100 ....x.....\.....
1835 000000a0: 0000 0000 88fc 31eb 029f ffff 609e d3c0 ......1.....`...
1836 000000b0: ffff ffff 0076 b4a1 029f ffff 0020 0000 .....v....... ..
1837 000000c0: ffff ffff e477 1700 0301 1100 0000 0000 .....w..........
1838 000000d0: 88fc 31eb 029f ffff aa26 0100 3e01 1100 ..1......&..>...
1839 000000e0: 0000 0000 6b77 6f72 6b65 722f 7538 3a35 ....kworker/u8:5
1840 000000f0: 0000 0000 24c0 0c00 7800 0000 0100 0000 ....$...x.......
1841 00000100: 0300 0000 90e6 e700 3b01 0100 0000 0000 ........;.......
1842 00000110: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1843 00000120: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
1844 00000130: 6b77 6f72 6b65 722f 7538 3a35 0000 0000 kworker/u8:5....
1845 00000140: 24c0 0c00 7800 0000 aa56 0300 3e01 0100 $...x....V..>...
1846 00000150: 24c0 0c00 6b77 6f72 6b65 722f 7538 3a31 $...kworker/u8:1
1847 00000160: 0000 0000 8eb5 0c00 7800 0000 0100 0000 ........x.......
1848 00000170: 0300 0000 06eb 0300 0201 0000 24c0 0c00 ............$...
1849 00000180: 6026 f22a 049f ffff f0e4 4cc0 ffff ffff `&.*......L.....
1850 00000190: ca45 0f00 3e01 0100 24c0 0c00 646d 6372 .E..>...$...dmcr
1851 000001a0: 7970 745f 7772 6974 652f 3200 2601 0000 ypt_write/2.&...
1852 000001b0: 7800 0000 0100 0000 0100 0000 c617 0200 x...............
1853 000001c0: 0101 0000 24c0 0c00 6026 f22a 049f ffff ....$...`&.*....
1854 000001d0: f0e4 4cc0 ffff ffff a47c 0000 0301 0100 ..L......|......
1855 000001e0: 24c0 0c00 6015 f22a 049f ffff 0685 0000 $...`..*........
1856 000001f0: 0201 0000 24c0 0c00 a05d f22a 049f ffff ....$....].*....
1857 00000200: f0e4 4cc0 ffff ffff c6dd 0800 0101 0000 ..L.............
1858 00000210: 24c0 0c00 a05d f22a 049f ffff f0e4 4cc0 $....].*......L.
1859 00000220: ffff ffff 8444 0000 0301 0100 24c0 0c00 .....D......$...
1860 00000230: 6059 f22a 049f ffff e672 0000 0201 0000 `Y.*.....r......
1861 00000240: 24c0 0c00 e050 f22a 049f ffff f0e4 4cc0 $....P.*......L.
1862 00000250: ffff ffff 4673 0a00 0101 0000 24c0 0c00 ....Fs......$...
1863 00000260: e050 f22a 049f ffff f0e4 4cc0 ffff ffff .P.*......L.....
1864 00000270: 04ca 0000 0301 0100 24c0 0c00 2000 f22a ........$... ..*
1865 00000280: 049f ffff 86b1 0000 0201 0000 24c0 0c00 ............$...
1866 00000290: 6015 f22a 049f ffff f0e4 4cc0 ffff ffff `..*......L.....
1867 000002a0: e640 0c00 0101 0000 24c0 0c00 6015 f22a .@......$...`..*
1868 000002b0: 049f ffff f0e4 4cc0 ffff ffff 64b4 0000 ......L.....d...
1869 000002c0: 0301 0100 24c0 0c00 2011 f22a 049f ffff ....$... ..*....
1870 000002d0: 66b9 0000 0201 0000 24c0 0c00 a06e f22a f.......$....n.*
1871 000002e0: 049f ffff f0e4 4cc0 ffff ffff 6ae1 4200 ......L.....j.B.
1872 000002f0: 3e01 1100 24c0 0c00 6a62 6432 2f64 6d2d >...$...jbd2/dm-
1873 00000300: 312d 3800 0000 0000 6a01 0000 7800 0000 1-8.....j...x...
1874 00000310: 0100 0000 0300 0000 269b 0400 0101 0000 ........&.......
1875 00000320: 24c0 0c00 a06e f22a 049f ffff f0e4 4cc0 $....n.*......L.
1876 00000330: ffff ffff ff9d 6fb6 1f87 9c00 1000 0000 ......o.........
1877 00000340: 3b01 0100 24c0 0c00 6b77 6f72 6b65 722f ;...$...kworker/
1878 00000350: 7538 3a35 0000 0000 24c0 0c00 7800 0000 u8:5....$...x...
1879 00000360: 8000 0000 0000 0000 7377 6170 7065 722f ........swapper/
1880 00000370: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1881 00000380: 6ad2 3802 0401 1100 0000 0000 c800 384b j.8...........8K
1882 00000390: 029f ffff 7018 75c0 ffff ffff 00ac edce ....p.u.........
1883 000003a0: 039f ffff 0020 0000 0000 0000 c4de 0000 ..... ..........
1884 000003b0: 0301 1100 0000 0000 c800 384b 029f ffff ..........8K....
1885 000003c0: 8a27 0100 3e01 1100 0000 0000 6b77 6f72 .'..>.......kwor
1886 000003d0: 6b65 722f 303a 3200 0000 0000 48b4 0c00 ker/0:2.....H...
1887 000003e0: 7800 0000 0100 0000 0000 0000 706d 0800 x...........pm..
1888 000003f0: 3b01 0100 0000 0000 7377 6170 7065 722f ;.......swapper/
1889 00000400: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1890 00000410: 0000 0000 0000 0000 6b77 6f72 6b65 722f ........kworker/
1891 00000420: 303a 3200 0000 0000 48b4 0c00 7800 0000 0:2.....H...x...
1892 00000430: 4636 0200 0201 0000 48b4 0c00 c800 384b F6......H.....8K
1893 00000440: 029f ffff 7018 75c0 ffff ffff ca56 0500 ....p.u......V..
1894 00000450: 0401 0100 48b4 0c00 606a ad55 029f ffff ....H...`j.U....
1895 00000460: f0e4 4cc0 ffff ffff 002c 04d0 039f ffff ..L......,......
1896 00000470: 0020 0000 ffff ffff e435 0000 0301 0100 . .......5......
1897 00000480: 48b4 0c00 606a ad55 029f ffff ca67 0000 H...`j.U.....g..
1898 00000490: 3e01 0100 48b4 0c00 6b77 6f72 6b65 722f >...H...kworker/
1899 000004a0: 7538 3a35 0000 0000 24c0 0c00 7800 0000 u8:5....$...x...
1900 000004b0: 0100 0000 0000 0000 e6fc 0200 0101 0000 ................
1901 000004c0: 48b4 0c00 c800 384b 029f ffff 7018 75c0 H.....8K....p.u.
1902 000004d0: ffff ffff 708f 0200 3b01 0100 48b4 0c00 ....p...;...H...
1903 000004e0: 6b77 6f72 6b65 722f 303a 3200 0000 0000 kworker/0:2.....
1904 000004f0: 48b4 0c00 7800 0000 8000 0000 0000 0000 H...x...........
1905 00000500: 6b77 6f72 6b65 722f 7538 3a35 0000 0000 kworker/u8:5....
1906 00000510: 24c0 0c00 7800 0000 0614 0100 0201 0000 $...x...........
1907 00000520: 24c0 0c00 606a ad55 029f ffff f0e4 4cc0 $...`j.U......L.
1908 00000530: ffff ffff ea7e 0c00 3e01 0100 24c0 0c00 .....~..>...$...
1909 00000540: 646d 6372 7970 745f 7772 6974 652f 3200 dmcrypt_write/2.
1910 00000550: 2601 0000 7800 0000 0100 0000 0100 0000 &...x...........
1911 00000560: 4645 0200 0101 0000 24c0 0c00 606a ad55 FE......$...`j.U
1912 00000570: 029f ffff f0e4 4cc0 ffff ffff b043 0900 ......L......C..
1913 00000580: 3b01 0100 24c0 0c00 6b77 6f72 6b65 722f ;...$...kworker/
1914 00000590: 7538 3a35 0000 0000 24c0 0c00 7800 0000 u8:5....$...x...
1915 000005a0: 8000 0000 0000 0000 7377 6170 7065 722f ........swapper/
1916 000005b0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1917 000005c0: ca7a 3900 0401 1100 0000 0000 48bc d5a1 .z9.........H...
1918 000005d0: 029f ffff 10e2 62bb ffff ffff 00e0 40d0 ......b.......@.
1919 000005e0: 039f ffff 0020 0000 0000 0000 c4bb 0000 ..... ..........
1920 000005f0: 0301 1100 0000 0000 48bc d5a1 029f ffff ........H.......
1921 00000600: 2aea 0000 3e01 1100 0000 0000 6b77 6f72 *...>.......kwor
1922 00000610: 6b65 722f 303a 3148 0000 0000 cfc1 0c00 ker/0:1H........
1923 00000620: 6400 0000 0100 0000 0000 0000 90bb 0600 d...............
1924 00000630: 3b01 0100 0000 0000 7377 6170 7065 722f ;.......swapper/
1925 00000640: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1926 00000650: 0000 0000 0000 0000 6b77 6f72 6b65 722f ........kworker/
1927 00000660: 303a 3148 0000 0000 cfc1 0c00 6400 0000 0:1H........d...
1928 00000670: 8617 0200 0201 0000 cfc1 0c00 48bc d5a1 ............H...
1929 00000680: 029f ffff 10e2 62bb ffff ffff c68f 0400 ......b.........
1930 00000690: 0101 0000 cfc1 0c00 48bc d5a1 029f ffff ........H.......
1931 000006a0: 10e2 62bb ffff ffff b063 0300 3b01 0100 ..b......c..;...
1932 000006b0: cfc1 0c00 6b77 6f72 6b65 722f 303a 3148 ....kworker/0:1H
1933 000006c0: 0000 0000 cfc1 0c00 6400 0000 8000 0000 ........d.......
1934 000006d0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1935 000006e0: 0000 0000 0000 0000 7800 0000 4a10 ad01 ........x...J...
1936 000006f0: 3e01 1100 0000 0000 6a62 6432 2f64 6d2d >.......jbd2/dm-
1937 00000700: 312d 3800 0000 0000 6a01 0000 7800 0000 1-8.....j...x...
1938 00000710: 0100 0000 0300 0000 ea27 b900 3e01 1100 .........'..>...
1939 00000720: 0000 0000 7263 755f 7363 6865 6400 0000 ....rcu_sched...
1940 00000730: 0000 0000 0d00 0000 7800 0000 0100 0000 ........x.......
1941 00000740: 0200 0000 3d00 0000 2c00 0000 0000 0000 ....=...,.......
1942 00000750: 0000 0000 0000 0000 0000 0000 0000 0000 ................
1943 00000760: 0000 0000 0000 0000 0000 0000 0000 0000 ................
1944 00000770: 0000 0000 0000 0000 0000 0000 0000 0000 ................
1945 )";
1946
TEST_F(CpuReaderParsePagePayloadTest,ParseAbsoluteTimestamp)1947 TEST_F(CpuReaderParsePagePayloadTest, ParseAbsoluteTimestamp) {
1948 auto page = PageFromXxd(g_abs_timestamp);
1949
1950 // Hand-build a translation table that handles sched_switch for this test
1951 // page. We cannot reuse the test data format file, since the ftrace id for
1952 // sched_switch in this page is different.
1953 std::vector<Field> common_fields;
1954 { // common_pid
1955 common_fields.emplace_back(Field{});
1956 Field* field = &common_fields.back();
1957 field->ftrace_offset = 4;
1958 field->ftrace_size = 4;
1959 field->ftrace_type = kFtraceCommonPid32;
1960 field->proto_field_id = 2;
1961 field->proto_field_type = ProtoSchemaType::kInt32;
1962 SetTranslationStrategy(field->ftrace_type, field->proto_field_type,
1963 &field->strategy);
1964 }
1965 using Switch = protos::gen::SchedSwitchFtraceEvent;
1966 Event sched_switch_event{
1967 "sched_switch",
1968 "sched",
1969 {
1970 {8, 16, FtraceFieldType::kFtraceFixedCString, "prev_comm",
1971 Switch::kPrevCommFieldNumber, ProtoSchemaType::kString,
1972 TranslationStrategy::kInvalidTranslationStrategy},
1973 {24, 4, FtraceFieldType::kFtracePid32, "prev_pid",
1974 Switch::kPrevPidFieldNumber, ProtoSchemaType::kInt32,
1975 TranslationStrategy::kInvalidTranslationStrategy},
1976 {28, 4, FtraceFieldType::kFtraceInt32, "prev_prio",
1977 Switch::kPrevPrioFieldNumber, ProtoSchemaType::kInt32,
1978 TranslationStrategy::kInvalidTranslationStrategy},
1979 {32, 8, FtraceFieldType::kFtraceInt64, "prev_state",
1980 Switch::kPrevStateFieldNumber, ProtoSchemaType::kInt64,
1981 TranslationStrategy::kInvalidTranslationStrategy},
1982 {40, 16, FtraceFieldType::kFtraceFixedCString, "next_comm",
1983 Switch::kNextCommFieldNumber, ProtoSchemaType::kString,
1984 TranslationStrategy::kInvalidTranslationStrategy},
1985 {56, 4, FtraceFieldType::kFtracePid32, "next_pid",
1986 Switch::kNextPidFieldNumber, ProtoSchemaType::kInt32,
1987 TranslationStrategy::kInvalidTranslationStrategy},
1988 {60, 4, FtraceFieldType::kFtraceInt32, "next_prio",
1989 Switch::kNextPrioFieldNumber, ProtoSchemaType::kInt32,
1990 TranslationStrategy::kInvalidTranslationStrategy},
1991 },
1992 /*ftrace_event_id=*/315,
1993 /*proto_field_id=*/4,
1994 /*size=*/64};
1995 for (Field& field : sched_switch_event.fields) {
1996 SetTranslationStrategy(field.ftrace_type, field.proto_field_type,
1997 &field.strategy);
1998 }
1999 std::vector<Event> events;
2000 events.emplace_back(std::move(sched_switch_event));
2001
2002 NiceMock<MockFtraceProcfs> mock_ftrace;
2003 PrintkMap printk_formats;
2004 ProtoTranslationTable translation_table(
2005 &mock_ftrace, events, std::move(common_fields),
2006 ProtoTranslationTable::DefaultPageHeaderSpecForTesting(),
2007 InvalidCompactSchedEventFormatForTesting(), printk_formats);
2008 ProtoTranslationTable* table = &translation_table;
2009
2010 FtraceDataSourceConfig ds_config = EmptyConfig();
2011 ds_config.event_filter.AddEnabledEvent(
2012 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
2013
2014 const uint8_t* parse_pos = page.get();
2015 std::optional<CpuReader::PageHeader> page_header =
2016 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
2017
2018 const uint8_t* page_end = page.get() + base::GetSysPageSize();
2019 ASSERT_TRUE(page_header.has_value());
2020 EXPECT_FALSE(page_header->lost_events);
2021 EXPECT_LE(parse_pos + page_header->size, page_end);
2022
2023 FtraceParseStatus status = CpuReader::ParsePagePayload(
2024 parse_pos, &page_header.value(), table, &ds_config,
2025 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
2026
2027 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
2028
2029 auto bundle = GetBundle();
2030
2031 // There should be 9 sched_switch events within the above page.
2032 // We assert that all of their timestamps are exactly as expected.
2033 //
2034 // The key record that we're testing is an absolute timestamp
2035 // (RINGBUF_TYPE_TIME_STAMP) between the 3rd and 4th sched_switch events.
2036 //
2037 // This timestamp record starts at 0x334 bytes into the page.
2038 // The event header (first 4 bytes): 0xb66f9dff
2039 // -> type (bottom 5 bits): 31 (RINGBUF_TYPE_TIME_STAMP)
2040 // -> bottom 27 bits of ts: 0x5b37cef
2041 // Next 4 bytes have the top bits (28..59) of ts.
2042 // -> post-shift: 0x4e438f8000000
2043 // Adding the two parts of the timestamp, we get: 1376833332542703.
2044 //
2045 // The next event (sched_switch at 0x33c) after this timestamp has a
2046 // delta-timestamp of 0 in its event header, so we expect the 4th
2047 // sched_switch to have a timestamp of exactly 1376833332542703.
2048 EXPECT_EQ(bundle.event().size(), 9u);
2049
2050 std::vector<uint64_t> switch_timestamps;
2051 for (const auto& e : bundle.event())
2052 switch_timestamps.push_back(e.timestamp());
2053
2054 uint64_t expected_timestamps[] = {
2055 1376833327307547ull, 1376833327356434ull, 1376833332265799ull,
2056 1376833332542703ull, 1376833333729055ull, 1376833333757142ull,
2057 1376833333808564ull, 1376833333943445ull, 1376833333964012ull};
2058
2059 ASSERT_THAT(switch_timestamps,
2060 testing::ElementsAreArray(expected_timestamps));
2061 }
2062
TEST(CpuReaderTest,TranslateBlockDeviceIDToUserspace)2063 TEST(CpuReaderTest, TranslateBlockDeviceIDToUserspace) {
2064 const uint32_t kKernelBlockDeviceId = 271581216;
2065 const BlockDeviceID kUserspaceBlockDeviceId = 66336;
2066 const uint64_t k64BitKernelBlockDeviceId = 4442450946;
2067 const BlockDeviceID k64BitUserspaceBlockDeviceId =
2068 static_cast<BlockDeviceID>(17594983681026ULL);
2069
2070 EXPECT_EQ(CpuReader::TranslateBlockDeviceIDToUserspace<uint32_t>(
2071 kKernelBlockDeviceId),
2072 kUserspaceBlockDeviceId);
2073 EXPECT_EQ(CpuReader::TranslateBlockDeviceIDToUserspace<uint64_t>(
2074 k64BitKernelBlockDeviceId),
2075 k64BitUserspaceBlockDeviceId);
2076 }
2077
2078 // clang-format off
2079 // # tracer: nop
2080 // #
2081 // # entries-in-buffer/entries-written: 1041/238740 #P:8
2082 // #
2083 // # _-----=> irqs-off
2084 // # / _----=> need-resched
2085 // # | / _---=> hardirq/softirq
2086 // # || / _--=> preempt-depth
2087 // # ||| / delay
2088 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
2089 // # | | | |||| | |
2090 // android.bg-1668 [000] ...1 174991.234105: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2091 // android.bg-1668 [000] ...1 174991.234108: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2092 // android.bg-1668 [000] ...1 174991.234118: ext4_da_write_begin: dev 259,32 ino 2883605 pos 20480 len 4096 flags 0
2093 // android.bg-1668 [000] ...1 174991.234126: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2094 // android.bg-1668 [000] ...1 174991.234133: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 5
2095 // android.bg-1668 [000] ...1 174991.234135: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [5/4294967290) 576460752303423487 H0x10
2096 // android.bg-1668 [000] ...2 174991.234140: ext4_da_reserve_space: dev 259,32 ino 2883605 mode 0100600 i_blocks 8 reserved_data_blocks 6 reserved_meta_blocks 0
2097 // android.bg-1668 [000] ...1 174991.234142: ext4_es_insert_extent: dev 259,32 ino 2883605 es [5/1) mapped 576460752303423487 status D
2098 // android.bg-1668 [000] ...1 174991.234153: ext4_da_write_end: dev 259,32 ino 2883605 pos 20480 len 4096 copied 4096
2099 // android.bg-1668 [000] ...1 174991.234158: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2100 // android.bg-1668 [000] ...1 174991.234160: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2101 // android.bg-1668 [000] ...1 174991.234170: ext4_da_write_begin: dev 259,32 ino 2883605 pos 24576 len 2968 flags 0
2102 // android.bg-1668 [000] ...1 174991.234178: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2103 // android.bg-1668 [000] ...1 174991.234184: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 6
2104 // android.bg-1668 [000] ...1 174991.234187: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [6/4294967289) 576460752303423487 H0x10
2105 // android.bg-1668 [000] ...2 174991.234191: ext4_da_reserve_space: dev 259,32 ino 2883605 mode 0100600 i_blocks 8 reserved_data_blocks 7 reserved_meta_blocks 0
2106 // android.bg-1668 [000] ...1 174991.234193: ext4_es_insert_extent: dev 259,32 ino 2883605 es [6/1) mapped 576460752303423487 status D
2107 // android.bg-1668 [000] ...1 174991.234203: ext4_da_write_end: dev 259,32 ino 2883605 pos 24576 len 2968 copied 2968
2108 // android.bg-1668 [000] ...1 174991.234209: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2109 // android.bg-1668 [000] ...1 174991.234211: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2110 // android.bg-1668 [000] ...1 174991.234262: ext4_sync_file_enter: dev 259,32 ino 2883605 parent 2883592 datasync 0
2111 // android.bg-1668 [000] ...1 174991.234270: ext4_writepages: dev 259,32 ino 2883605 nr_to_write 9223372036854775807 pages_skipped 0 range_start 0 range_end 9223372036854775807 sync_mode 1 for_kupdate 0 range_cyclic 0 writeback_index 0
2112 // android.bg-1668 [000] ...1 174991.234287: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_writepages+0x6a4/0x119c
2113 // android.bg-1668 [000] ...1 174991.234294: ext4_da_write_pages: dev 259,32 ino 2883605 first_page 0 nr_to_write 9223372036854775807 sync_mode 1
2114 // android.bg-1668 [000] ...1 174991.234319: ext4_da_write_pages_extent: dev 259,32 ino 2883605 lblk 0 len 7 flags 0x200
2115 // android.bg-1668 [000] ...1 174991.234322: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 0
2116 // android.bg-1668 [000] ...1 174991.234324: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [0/7) 576460752303423487 D0x10
2117 // android.bg-1668 [000] ...1 174991.234328: ext4_ext_map_blocks_enter: dev 259,32 ino 2883605 lblk 0 len 7 flags CREATE|DELALLOC|METADATA_NOFAIL
2118 // android.bg-1668 [000] ...1 174991.234341: ext4_request_blocks: dev 259,32 ino 2883605 flags HINT_DATA|DELALLOC_RESV|USE_RESV len 7 lblk 0 goal 11567104 lleft 0 lright 0 pleft 0 pright 0
2119 // android.bg-1668 [000] ...1 174991.234394: ext4_mballoc_prealloc: dev 259,32 inode 2883605 orig 353/0/7@0 result 65/25551/7@0
2120 // android.bg-1668 [000] ...1 174991.234400: ext4_allocate_blocks: dev 259,32 ino 2883605 flags HINT_DATA|DELALLOC_RESV|USE_RESV len 7 block 2155471 lblk 0 goal 11567104 lleft 0 lright 0 pleft 0 pright 0
2121 // android.bg-1668 [000] ...1 174991.234409: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller __ext4_ext_dirty+0x104/0x170
2122 // android.bg-1668 [000] ...1 174991.234420: ext4_get_reserved_cluster_alloc: dev 259,32 ino 2883605 lblk 0 len 7
2123 // android.bg-1668 [000] ...2 174991.234426: ext4_da_update_reserve_space: dev 259,32 ino 2883605 mode 0100600 i_blocks 8 used_blocks 7 reserved_data_blocks 7 reserved_meta_blocks 0 allocated_meta_blocks 0 quota_claim 1
2124 // android.bg-1668 [000] ...1 174991.234434: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_mark_dquot_dirty+0x80/0xd4
2125 // android.bg-1668 [000] ...1 174991.234441: ext4_es_lookup_extent_enter: dev 259,32 ino 3 lblk 1
2126 // android.bg-1668 [000] ...1 174991.234445: ext4_es_lookup_extent_exit: dev 259,32 ino 3 found 1 [0/2) 9255 W0x10
2127 // android.bg-1668 [000] ...1 174991.234456: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_mark_dquot_dirty+0x80/0xd4
2128 // android.bg-1668 [000] ...1 174991.234460: ext4_es_lookup_extent_enter: dev 259,32 ino 4 lblk 1
2129 // android.bg-1668 [000] ...1 174991.234463: ext4_es_lookup_extent_exit: dev 259,32 ino 4 found 1 [0/2) 9257 W0x10
2130 // android.bg-1668 [000] ...1 174991.234471: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2131 // android.bg-1668 [000] ...1 174991.234474: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2132 // android.bg-1668 [000] ...1 174991.234481: ext4_ext_map_blocks_exit: dev 259,32 ino 2883605 flags CREATE|DELALLOC|METADATA_NOFAIL lblk 0 pblk 2155471 len 7 mflags NM ret 7
2133 // android.bg-1668 [000] ...1 174991.234484: ext4_es_insert_extent: dev 259,32 ino 2883605 es [0/7) mapped 2155471 status W
2134 // android.bg-1668 [000] ...1 174991.234547: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_writepages+0xdc0/0x119c
2135 // android.bg-1668 [000] ...1 174991.234604: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_writepages+0x6a4/0x119c
2136 // android.bg-1668 [000] ...1 174991.234609: ext4_da_write_pages: dev 259,32 ino 2883605 first_page 7 nr_to_write 9223372036854775800 sync_mode 1
2137 // android.bg-1668 [000] ...1 174991.234876: ext4_writepages_result: dev 259,32 ino 2883605 ret 0 pages_written 7 pages_skipped 0 sync_mode 1 writeback_index 7
2138 // Profile Saver-5504 [000] ...1 175002.711928: ext4_discard_preallocations: dev 259,32 ino 1311176
2139 // Profile Saver-5504 [000] ...1 175002.714165: ext4_begin_ordered_truncate: dev 259,32 ino 1311176 new_size 0
2140 // Profile Saver-5504 [000] ...1 175002.714172: ext4_journal_start: dev 259,32 blocks, 3 rsv_blocks, 0 caller ext4_setattr+0x5b4/0x788
2141 // Profile Saver-5504 [000] ...1 175002.714218: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_setattr+0x65c/0x788
2142 // Profile Saver-5504 [000] ...1 175002.714277: ext4_invalidatepage: dev 259,32 ino 1311176 page_index 0 offset 0 length 4096
2143 // Profile Saver-5504 [000] ...1 175002.714281: ext4_releasepage: dev 259,32 ino 1311176 page_index 0
2144 // Profile Saver-5504 [000] ...1 175002.714295: ext4_invalidatepage: dev 259,32 ino 1311176 page_index 1 offset 0 length 4096
2145 // Profile Saver-5504 [000] ...1 175002.714296: ext4_releasepage: dev 259,32 ino 1311176 page_index 1
2146 // Profile Saver-5504 [000] ...1 175002.714315: ext4_truncate_enter: dev 259,32 ino 1311176 blocks 24
2147 // Profile Saver-5504 [000] ...1 175002.714318: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_truncate+0x258/0x4b8
2148 // Profile Saver-5504 [000] ...1 175002.714322: ext4_discard_preallocations: dev 259,32 ino 1311176
2149 // Profile Saver-5504 [000] ...1 175002.714324: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_ext_truncate+0x24/0xc8
2150 // Profile Saver-5504 [000] ...1 175002.714328: ext4_es_remove_extent: dev 259,32 ino 1311176 es [0/4294967295)
2151 // Profile Saver-5504 [000] ...1 175002.714335: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_ext_remove_space+0x60/0x1180
2152 // Profile Saver-5504 [000] ...1 175002.714338: ext4_ext_remove_space: dev 259,32 ino 1311176 since 0 end 4294967294 depth 0
2153 // Profile Saver-5504 [000] ...1 175002.714347: ext4_ext_rm_leaf: dev 259,32 ino 1311176 start_lblk 0 last_extent [0(5276994), 2]partial_cluster 0
2154 // Profile Saver-5504 [000] ...1 175002.714351: ext4_remove_blocks: dev 259,32 ino 1311176 extent [0(5276994), 2]from 0 to 1 partial_cluster 0
2155 // Profile Saver-5504 [000] ...1 175002.714354: ext4_free_blocks: dev 259,32 ino 1311176 mode 0100600 block 5276994 count 2 flags 1ST_CLUSTER
2156 // Profile Saver-5504 [000] ...1 175002.714365: ext4_mballoc_free: dev 259,32 inode 1311176 extent 161/1346/2
2157 // Profile Saver-5504 [000] ...1 175002.714382: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_mark_dquot_dirty+0x80/0xd4
2158 // Profile Saver-5504 [000] ...1 175002.714391: ext4_es_lookup_extent_enter: dev 259,32 ino 3 lblk 4
2159 // Profile Saver-5504 [000] ...1 175002.714394: ext4_es_lookup_extent_exit: dev 259,32 ino 3 found 1 [4/1) 557094 W0x10
2160 // Profile Saver-5504 [000] ...1 175002.714402: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_mark_dquot_dirty+0x80/0xd4
2161 // Profile Saver-5504 [000] ...1 175002.714404: ext4_es_lookup_extent_enter: dev 259,32 ino 4 lblk 8
2162 // Profile Saver-5504 [000] ...1 175002.714406: ext4_es_lookup_extent_exit: dev 259,32 ino 4 found 1 [8/3) 7376914 W0x10
2163 // Profile Saver-5504 [000] ...1 175002.714413: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2164 // Profile Saver-5504 [000] ...1 175002.714414: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2165 // Profile Saver-5504 [000] ...1 175002.714420: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller __ext4_ext_dirty+0x104/0x170
2166 // Profile Saver-5504 [000] ...1 175002.714423: ext4_ext_remove_space_done: dev 259,32 ino 1311176 since 0 end 4294967294 depth 0 partial 0 remaining_entries 0
2167 // Profile Saver-5504 [000] ...1 175002.714425: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller __ext4_ext_dirty+0x104/0x170
2168 // Profile Saver-5504 [000] ...1 175002.714433: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_truncate+0x3c4/0x4b8
2169 // Profile Saver-5504 [000] ...1 175002.714436: ext4_truncate_exit: dev 259,32 ino 1311176 blocks 8
2170 // Profile Saver-5504 [000] ...1 175002.714437: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2171 // Profile Saver-5504 [000] ...1 175002.714438: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2172 // Profile Saver-5504 [000] ...1 175002.714462: ext4_da_write_begin: dev 259,32 ino 1311176 pos 0 len 4 flags 0
2173 // Profile Saver-5504 [000] ...1 175002.714472: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2174 // Profile Saver-5504 [000] ...1 175002.714477: ext4_es_lookup_extent_enter: dev 259,32 ino 1311176 lblk 0
2175 // Profile Saver-5504 [000] ...1 175002.714477: ext4_es_lookup_extent_exit: dev 259,32 ino 1311176 found 0 [0/0) 0
2176 // Profile Saver-5504 [000] ...1 175002.714480: ext4_ext_map_blocks_enter: dev 259,32 ino 1311176 lblk 0 len 1 flags
2177 // Profile Saver-5504 [000] ...1 175002.714485: ext4_es_find_delayed_extent_range_enter: dev 259,32 ino 1311176 lblk 0
2178 // Profile Saver-5504 [000] ...1 175002.714488: ext4_es_find_delayed_extent_range_exit: dev 259,32 ino 1311176 es [0/0) mapped 0 status
2179 // Profile Saver-5504 [000] ...1 175002.714490: ext4_es_insert_extent: dev 259,32 ino 1311176 es [0/4294967295) mapped 576460752303423487 status H
2180 // Profile Saver-5504 [000] ...1 175002.714495: ext4_ext_map_blocks_exit: dev 259,32 ino 1311176 flags lblk 0 pblk 4294967296 len 1 mflags ret 0
2181 // Profile Saver-5504 [000] ...2 175002.714501: ext4_da_reserve_space: dev 259,32 ino 1311176 mode 0100600 i_blocks 8 reserved_data_blocks 1 reserved_meta_blocks 0
2182 // Profile Saver-5504 [000] ...1 175002.714505: ext4_es_insert_extent: dev 259,32 ino 1311176 es [0/1) mapped 576460752303423487 status D
2183 // Profile Saver-5504 [000] ...1 175002.714513: ext4_da_write_end: dev 259,32 ino 1311176 pos 0 len 4 copied 4
2184 // Profile Saver-5504 [000] ...1 175002.714519: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2185 // Profile Saver-5504 [000] ...1 175002.714520: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2186 // Profile Saver-5504 [000] ...1 175002.714527: ext4_da_write_begin: dev 259,32 ino 1311176 pos 4 len 4 flags 0
2187 // Profile Saver-5504 [000] ...1 175002.714529: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2188 // Profile Saver-5504 [000] ...1 175002.714531: ext4_da_write_end: dev 259,32 ino 1311176 pos 4 len 4 copied 4
2189 // Profile Saver-5504 [000] ...1 175002.714532: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2190 // Profile Saver-5504 [000] ...1 175002.714532: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2191 // Profile Saver-5504 [000] ...1 175002.715313: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2192 // Profile Saver-5504 [000] ...1 175002.715322: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2193 // Profile Saver-5504 [000] ...1 175002.723849: ext4_da_write_begin: dev 259,32 ino 1311176 pos 8 len 5 flags 0
2194 // Profile Saver-5504 [000] ...1 175002.723862: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2195 // Profile Saver-5504 [000] ...1 175002.723873: ext4_da_write_end: dev 259,32 ino 1311176 pos 8 len 5 copied 5
2196 // Profile Saver-5504 [000] ...1 175002.723877: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2197 // Profile Saver-5504 [000] ...1 175002.723879: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2198 // Profile Saver-5504 [000] ...1 175002.726857: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2199 // Profile Saver-5504 [000] ...1 175002.726867: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2200 // Profile Saver-5504 [000] ...1 175002.726881: ext4_da_write_begin: dev 259,32 ino 1311176 pos 13 len 4 flags 0
2201 // Profile Saver-5504 [000] ...1 175002.726883: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2202 // Profile Saver-5504 [000] ...1 175002.726890: ext4_da_write_end: dev 259,32 ino 1311176 pos 13 len 4 copied 4
2203 // Profile Saver-5504 [000] ...1 175002.726892: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2204 // Profile Saver-5504 [000] ...1 175002.726892: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2205 // Profile Saver-5504 [000] ...1 175002.726900: ext4_da_write_begin: dev 259,32 ino 1311176 pos 17 len 4079 flags 0
2206 // Profile Saver-5504 [000] ...1 175002.726901: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2207 // Profile Saver-5504 [000] ...1 175002.726904: ext4_da_write_end: dev 259,32 ino 1311176 pos 17 len 4079 copied 4079
2208 // Profile Saver-5504 [000] ...1 175002.726905: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2209 // Profile Saver-5504 [000] ...1 175002.726906: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2210 // Profile Saver-5504 [000] ...1 175002.726908: ext4_da_write_begin: dev 259,32 ino 1311176 pos 4096 len 2780 flags 0
2211 // Profile Saver-5504 [000] ...1 175002.726916: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2212 // Profile Saver-5504 [000] ...1 175002.726921: ext4_es_lookup_extent_enter: dev 259,32 ino 1311176 lblk 1
2213 // Profile Saver-5504 [000] ...1 175002.726924: ext4_es_lookup_extent_exit: dev 259,32 ino 1311176 found 1 [1/4294967294) 576460752303423487 H0x10
2214 // Profile Saver-5504 [000] ...2 175002.726931: ext4_da_reserve_space: dev 259,32 ino 1311176 mode 0100600 i_blocks 8 reserved_data_blocks 2 reserved_meta_blocks 0
2215 // Profile Saver-5504 [000] ...1 175002.726933: ext4_es_insert_extent: dev 259,32 ino 1311176 es [1/1) mapped 576460752303423487 status D
2216 // Profile Saver-5504 [000] ...1 175002.726940: ext4_da_write_end: dev 259,32 ino 1311176 pos 4096 len 2780 copied 2780
2217 // Profile Saver-5504 [000] ...1 175002.726941: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2218 // Profile Saver-5504 [000] ...1 175002.726942: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2219 // d.process.acor-27885 [000] ...1 175018.227675: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2220 // d.process.acor-27885 [000] ...1 175018.227699: ext4_mark_inode_dirty: dev 259,32 ino 3278189 caller ext4_dirty_inode+0x48/0x68
2221 // d.process.acor-27885 [000] ...1 175018.227839: ext4_sync_file_enter: dev 259,32 ino 3278183 parent 3277001 datasync 1
2222 // d.process.acor-27885 [000] ...1 175018.227847: ext4_writepages: dev 259,32 ino 3278183 nr_to_write 9223372036854775807 pages_skipped 0 range_start 0 range_end 9223372036854775807 sync_mode 1 for_kupdate 0 range_cyclic 0 writeback_index 2
2223 // d.process.acor-27885 [000] ...1 175018.227852: ext4_writepages_result: dev 259,32 ino 3278183 ret 0 pages_written 0 pages_skipped 0 sync_mode 1 writeback_index 2
2224 // clang-format on
2225
2226 static ExamplePage g_full_page_sched_switch{
2227 "synthetic",
2228 R"(
2229 00000000: 31f2 7622 1a00 0000 b40f 0000 0000 0000 1.v"............
2230 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ............/...
2231 00000020: 140d 0000 4a69 7420 7468 7265 6164 2070 ....Jit thread p
2232 00000030: 6f6f 6c00 140d 0000 8100 0000 0008 0000 ool.............
2233 00000040: 0000 0000 4576 656e 7454 6872 6561 6400 ....EventThread.
2234 00000050: 6572 0000 7002 0000 6100 0000 f057 0e00 er..p...a....W..
2235 00000060: 2f00 0103 7002 0000 4576 656e 7454 6872 /...p...EventThr
2236 00000070: 6561 6400 6572 0000 7002 0000 6100 0000 ead.er..p...a...
2237 00000080: 0100 0000 0000 0000 4a69 7420 7468 7265 ........Jit thre
2238 00000090: 6164 2070 6f6f 6c00 140d 0000 8100 0000 ad pool.........
2239 000000a0: 50c2 0910 2f00 0103 140d 0000 4a69 7420 P.../.......Jit
2240 000000b0: 7468 7265 6164 2070 6f6f 6c00 140d 0000 thread pool.....
2241 000000c0: 8100 0000 0100 0000 0000 0000 7377 6170 ............swap
2242 000000d0: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2243 000000e0: 7800 0000 901a c80e 2f00 0103 0000 0000 x......./.......
2244 000000f0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2245 00000100: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
2246 00000110: 4469 7370 5379 6e63 0069 6e67 6572 0000 DispSync.inger..
2247 00000120: 6f02 0000 6100 0000 1064 1e00 2f00 0103 o...a....d../...
2248 00000130: 6f02 0000 4469 7370 5379 6e63 0069 6e67 o...DispSync.ing
2249 00000140: 6572 0000 6f02 0000 6100 0000 0100 0000 er..o...a.......
2250 00000150: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2251 00000160: 0000 0000 0000 0000 7800 0000 9074 8600 ........x....t..
2252 00000170: 2f00 0103 0000 0000 7377 6170 7065 722f /.......swapper/
2253 00000180: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2254 00000190: 0000 0000 0000 0000 4576 656e 7454 6872 ........EventThr
2255 000001a0: 6561 6400 6572 0000 7002 0000 6100 0000 ead.er..p...a...
2256 000001b0: d071 0b00 2f00 0103 7002 0000 4576 656e .q../...p...Even
2257 000001c0: 7454 6872 6561 6400 6572 0000 7002 0000 tThread.er..p...
2258 000001d0: 6100 0000 0100 0000 0000 0000 7377 6170 a...........swap
2259 000001e0: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2260 000001f0: 7800 0000 10cd 4504 2f00 0103 0000 0000 x.....E./.......
2261 00000200: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2262 00000210: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
2263 00000220: 7375 676f 763a 3000 0000 0000 0000 0000 sugov:0.........
2264 00000230: 3802 0000 3100 0000 30d6 1300 2f00 0103 8...1...0.../...
2265 00000240: 3802 0000 7375 676f 763a 3000 0000 0000 8...sugov:0.....
2266 00000250: 0000 0000 3802 0000 3100 0000 0100 0000 ....8...1.......
2267 00000260: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2268 00000270: 0000 0000 0000 0000 7800 0000 3049 a202 ........x...0I..
2269 00000280: 2f00 0103 0000 0000 7377 6170 7065 722f /.......swapper/
2270 00000290: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2271 000002a0: 0000 0000 0000 0000 4469 7370 5379 6e63 ........DispSync
2272 000002b0: 0069 6e67 6572 0000 6f02 0000 6100 0000 .inger..o...a...
2273 000002c0: d07a 1000 2f00 0103 6f02 0000 4469 7370 .z../...o...Disp
2274 000002d0: 5379 6e63 0069 6e67 6572 0000 6f02 0000 Sync.inger..o...
2275 000002e0: 6100 0000 0100 0000 0000 0000 7377 6170 a...........swap
2276 000002f0: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2277 00000300: 7800 0000 d085 1100 2f00 0103 0000 0000 x......./.......
2278 00000310: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2279 00000320: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
2280 00000330: 7375 7266 6163 6566 6c69 6e67 6572 0000 surfaceflinger..
2281 00000340: 4b02 0000 6200 0000 907a f000 2f00 0103 K...b....z../...
2282 00000350: 4b02 0000 7375 7266 6163 6566 6c69 6e67 K...surfacefling
2283 00000360: 6572 0000 4b02 0000 6200 0000 0100 0000 er..K...b.......
2284 00000370: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2285 00000380: 0000 0000 0000 0000 7800 0000 305a 6400 ........x...0Zd.
2286 00000390: 2f00 0103 0000 0000 7377 6170 7065 722f /.......swapper/
2287 000003a0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2288 000003b0: 0000 0000 0000 0000 6d64 7373 5f66 6230 ........mdss_fb0
2289 000003c0: 0000 0000 0000 0000 5714 0000 5300 0000 ........W...S...
2290 000003d0: 10b1 9e03 2f00 0103 5714 0000 6d64 7373 ..../...W...mdss
2291 000003e0: 5f66 6230 0000 0000 0000 0000 5714 0000 _fb0........W...
2292 000003f0: 5300 0000 0200 0000 0000 0000 6b73 6f66 S...........ksof
2293 00000400: 7469 7271 642f 3000 0000 0000 0300 0000 tirqd/0.........
2294 00000410: 7800 0000 90bb 9900 2f00 0103 0300 0000 x......./.......
2295 00000420: 6b73 6f66 7469 7271 642f 3000 0000 0000 ksoftirqd/0.....
2296 00000430: 0300 0000 7800 0000 0100 0000 0000 0000 ....x...........
2297 00000440: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2298 00000450: 0000 0000 7800 0000 701e 5305 2f00 0103 ....x...p.S./...
2299 00000460: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2300 00000470: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
2301 00000480: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
2302 00000490: 3600 0000 6401 0000 7800 0000 90a1 2900 6...d...x.....).
2303 000004a0: 2f00 0103 6401 0000 6b77 6f72 6b65 722f /...d...kworker/
2304 000004b0: 7531 363a 3600 0000 6401 0000 7800 0000 u16:6...d...x...
2305 000004c0: 0200 0000 0000 0000 7377 6170 7065 722f ........swapper/
2306 000004d0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2307 000004e0: b0e5 4f04 2f00 0103 0000 0000 7377 6170 ..O./.......swap
2308 000004f0: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2309 00000500: 7800 0000 0000 0000 0000 0000 4269 6e64 x...........Bind
2310 00000510: 6572 3a32 3136 385f 3135 0000 e614 0000 er:2168_15......
2311 00000520: 7800 0000 b0bd 7c00 2f00 0103 e614 0000 x.....|./.......
2312 00000530: 4269 6e64 6572 3a32 3136 385f 3135 0000 Binder:2168_15..
2313 00000540: e614 0000 7800 0000 0100 0000 0000 0000 ....x...........
2314 00000550: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2315 00000560: 0000 0000 7800 0000 d0bd 7e01 2f00 0103 ....x.....~./...
2316 00000570: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2317 00000580: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
2318 00000590: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
2319 000005a0: 3900 0000 e204 0000 7800 0000 7016 0800 9.......x...p...
2320 000005b0: 2f00 0103 e204 0000 6b77 6f72 6b65 722f /.......kworker/
2321 000005c0: 7531 363a 3900 0000 e204 0000 7800 0000 u16:9.......x...
2322 000005d0: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
2323 000005e0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2324 000005f0: 1004 5200 2f00 0103 0000 0000 7377 6170 ..R./.......swap
2325 00000600: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2326 00000610: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
2327 00000620: 6b65 722f 7531 363a 3900 0000 e204 0000 ker/u16:9.......
2328 00000630: 7800 0000 d0db 0700 2f00 0103 e204 0000 x......./.......
2329 00000640: 6b77 6f72 6b65 722f 7531 363a 3900 0000 kworker/u16:9...
2330 00000650: e204 0000 7800 0000 0100 0000 0000 0000 ....x...........
2331 00000660: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2332 00000670: 0000 0000 7800 0000 b0a2 8c00 2f00 0103 ....x......./...
2333 00000680: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2334 00000690: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
2335 000006a0: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
2336 000006b0: 3900 0000 e204 0000 7800 0000 d02b 0400 9.......x....+..
2337 000006c0: 2f00 0103 e204 0000 6b77 6f72 6b65 722f /.......kworker/
2338 000006d0: 7531 363a 3900 0000 e204 0000 7800 0000 u16:9.......x...
2339 000006e0: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
2340 000006f0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2341 00000700: d064 ef05 2f00 0103 0000 0000 7377 6170 .d../.......swap
2342 00000710: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2343 00000720: 7800 0000 0000 0000 0000 0000 4469 7370 x...........Disp
2344 00000730: 5379 6e63 0069 6e67 6572 0000 6f02 0000 Sync.inger..o...
2345 00000740: 6100 0000 f07d 1b00 2f00 0103 6f02 0000 a....}../...o...
2346 00000750: 4469 7370 5379 6e63 0069 6e67 6572 0000 DispSync.inger..
2347 00000760: 6f02 0000 6100 0000 0100 0000 0000 0000 o...a...........
2348 00000770: 6b73 6f66 7469 7271 642f 3000 0000 0000 ksoftirqd/0.....
2349 00000780: 0300 0000 7800 0000 304c 2000 2f00 0103 ....x...0L ./...
2350 00000790: 0300 0000 6b73 6f66 7469 7271 642f 3000 ....ksoftirqd/0.
2351 000007a0: 0000 0000 0300 0000 7800 0000 0100 0000 ........x.......
2352 000007b0: 0000 0000 6465 7832 6f61 7400 3935 5f33 ....dex2oat.95_3
2353 000007c0: 0000 0000 341f 0000 8200 0000 700b 0700 ....4.......p...
2354 000007d0: 2f00 0103 341f 0000 6465 7832 6f61 7400 /...4...dex2oat.
2355 000007e0: 3935 5f33 0000 0000 341f 0000 8200 0000 95_3....4.......
2356 000007f0: 0000 0000 0000 0000 7375 676f 763a 3000 ........sugov:0.
2357 00000800: 0000 0000 0000 0000 3802 0000 3100 0000 ........8...1...
2358 00000810: 50b0 0600 2f00 0103 3802 0000 7375 676f P.../...8...sugo
2359 00000820: 763a 3000 0000 0000 0000 0000 3802 0000 v:0.........8...
2360 00000830: 3100 0000 0008 0000 0000 0000 6d69 6772 1...........migr
2361 00000840: 6174 696f 6e2f 3000 0000 0000 0d00 0000 ation/0.........
2362 00000850: 0000 0000 d09c 0600 2f00 0103 0d00 0000 ......../.......
2363 00000860: 6d69 6772 6174 696f 6e2f 3000 0000 0000 migration/0.....
2364 00000870: 0d00 0000 0000 0000 0100 0000 0000 0000 ................
2365 00000880: 7375 676f 763a 3000 0000 0000 0000 0000 sugov:0.........
2366 00000890: 3802 0000 3100 0000 7061 1900 2f00 0103 8...1...pa../...
2367 000008a0: 3802 0000 7375 676f 763a 3000 0000 0000 8...sugov:0.....
2368 000008b0: 0000 0000 3802 0000 3100 0000 0100 0000 ....8...1.......
2369 000008c0: 0000 0000 6465 7832 6f61 7400 3935 5f33 ....dex2oat.95_3
2370 000008d0: 0000 0000 341f 0000 8200 0000 f03c 5600 ....4........<V.
2371 000008e0: 2f00 0103 341f 0000 6465 7832 6f61 7400 /...4...dex2oat.
2372 000008f0: 3935 5f33 0000 0000 341f 0000 8200 0000 95_3....4.......
2373 00000900: 0200 0000 0000 0000 7377 6170 7065 722f ........swapper/
2374 00000910: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2375 00000920: 5013 c400 2f00 0103 0000 0000 7377 6170 P.../.......swap
2376 00000930: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2377 00000940: 7800 0000 0000 0000 0000 0000 616e 6472 x...........andr
2378 00000950: 6f69 642e 6861 7264 7761 7200 d20a 0000 oid.hardwar.....
2379 00000960: 7800 0000 30c9 1300 2f00 0103 d20a 0000 x...0.../.......
2380 00000970: 616e 6472 6f69 642e 6861 7264 7761 7200 android.hardwar.
2381 00000980: d20a 0000 7800 0000 0100 0000 0000 0000 ....x...........
2382 00000990: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2383 000009a0: 0000 0000 7800 0000 7097 c000 2f00 0103 ....x...p.../...
2384 000009b0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2385 000009c0: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
2386 000009d0: 0000 0000 616e 6472 6f69 642e 6861 7264 ....android.hard
2387 000009e0: 7761 7200 d20a 0000 7800 0000 305c 0c00 war.....x...0\..
2388 000009f0: 2f00 0103 d20a 0000 616e 6472 6f69 642e /.......android.
2389 00000a00: 6861 7264 7761 7200 d20a 0000 7800 0000 hardwar.....x...
2390 00000a10: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
2391 00000a20: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2392 00000a30: d0aa 1401 2f00 0103 0000 0000 7377 6170 ..../.......swap
2393 00000a40: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2394 00000a50: 7800 0000 0000 0000 0000 0000 616e 6472 x...........andr
2395 00000a60: 6f69 642e 6861 7264 7761 7200 d20a 0000 oid.hardwar.....
2396 00000a70: 7800 0000 903b 0c00 2f00 0103 d20a 0000 x....;../.......
2397 00000a80: 616e 6472 6f69 642e 6861 7264 7761 7200 android.hardwar.
2398 00000a90: d20a 0000 7800 0000 0100 0000 0000 0000 ....x...........
2399 00000aa0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2400 00000ab0: 0000 0000 7800 0000 f024 5401 2f00 0103 ....x....$T./...
2401 00000ac0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2402 00000ad0: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
2403 00000ae0: 0000 0000 616e 6472 6f69 642e 6861 7264 ....android.hard
2404 00000af0: 7761 7200 d20a 0000 7800 0000 f0f3 0b00 war.....x.......
2405 00000b00: 2f00 0103 d20a 0000 616e 6472 6f69 642e /.......android.
2406 00000b10: 6861 7264 7761 7200 d20a 0000 7800 0000 hardwar.....x...
2407 00000b20: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
2408 00000b30: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2409 00000b40: d0b5 bf02 2f00 0103 0000 0000 7377 6170 ..../.......swap
2410 00000b50: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2411 00000b60: 7800 0000 0000 0000 0000 0000 4469 7370 x...........Disp
2412 00000b70: 5379 6e63 0069 6e67 6572 0000 6f02 0000 Sync.inger..o...
2413 00000b80: 6100 0000 90cd 1400 2f00 0103 6f02 0000 a......./...o...
2414 00000b90: 4469 7370 5379 6e63 0069 6e67 6572 0000 DispSync.inger..
2415 00000ba0: 6f02 0000 6100 0000 0100 0000 0000 0000 o...a...........
2416 00000bb0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2417 00000bc0: 0000 0000 7800 0000 50a6 1100 2f00 0103 ....x...P.../...
2418 00000bd0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2419 00000be0: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
2420 00000bf0: 0000 0000 7375 7266 6163 6566 6c69 6e67 ....surfacefling
2421 00000c00: 6572 0000 4b02 0000 6200 0000 b04c 4200 er..K...b....LB.
2422 00000c10: 2f00 0103 4b02 0000 7375 7266 6163 6566 /...K...surfacef
2423 00000c20: 6c69 6e67 6572 0000 4b02 0000 6200 0000 linger..K...b...
2424 00000c30: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
2425 00000c40: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2426 00000c50: b025 060a 2f00 0103 0000 0000 7377 6170 .%../.......swap
2427 00000c60: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2428 00000c70: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
2429 00000c80: 6b65 722f 7531 363a 3600 0000 6401 0000 ker/u16:6...d...
2430 00000c90: 7800 0000 d0b6 0600 2f00 0103 6401 0000 x......./...d...
2431 00000ca0: 6b77 6f72 6b65 722f 7531 363a 3600 0000 kworker/u16:6...
2432 00000cb0: 6401 0000 7800 0000 0100 0000 0000 0000 d...x...........
2433 00000cc0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2434 00000cd0: 0000 0000 7800 0000 f0a0 5800 2f00 0103 ....x.....X./...
2435 00000ce0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2436 00000cf0: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
2437 00000d00: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
2438 00000d10: 3600 0000 6401 0000 7800 0000 f07a 1300 6...d...x....z..
2439 00000d20: 2f00 0103 6401 0000 6b77 6f72 6b65 722f /...d...kworker/
2440 00000d30: 7531 363a 3600 0000 6401 0000 7800 0000 u16:6...d...x...
2441 00000d40: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
2442 00000d50: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2443 00000d60: b080 b101 2f00 0103 0000 0000 7377 6170 ..../.......swap
2444 00000d70: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2445 00000d80: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
2446 00000d90: 6b65 722f 7531 363a 3600 0000 6401 0000 ker/u16:6...d...
2447 00000da0: 7800 0000 103c 1200 2f00 0103 6401 0000 x....<../...d...
2448 00000db0: 6b77 6f72 6b65 722f 7531 363a 3600 0000 kworker/u16:6...
2449 00000dc0: 6401 0000 7800 0000 0100 0000 0000 0000 d...x...........
2450 00000dd0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2451 00000de0: 0000 0000 7800 0000 50ea 3800 2f00 0103 ....x...P.8./...
2452 00000df0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2453 00000e00: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
2454 00000e10: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
2455 00000e20: 3600 0000 6401 0000 7800 0000 5032 0400 6...d...x...P2..
2456 00000e30: 2f00 0103 6401 0000 6b77 6f72 6b65 722f /...d...kworker/
2457 00000e40: 7531 363a 3600 0000 6401 0000 7800 0000 u16:6...d...x...
2458 00000e50: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
2459 00000e60: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2460 00000e70: 70f5 9000 2f00 0103 0000 0000 7377 6170 p.../.......swap
2461 00000e80: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2462 00000e90: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
2463 00000ea0: 6b65 722f 7531 363a 3600 0000 6401 0000 ker/u16:6...d...
2464 00000eb0: 7800 0000 10d7 0300 2f00 0103 6401 0000 x......./...d...
2465 00000ec0: 6b77 6f72 6b65 722f 7531 363a 3600 0000 kworker/u16:6...
2466 00000ed0: 6401 0000 7800 0000 0100 0000 0000 0000 d...x...........
2467 00000ee0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
2468 00000ef0: 0000 0000 7800 0000 907c 0900 2f00 0103 ....x....|../...
2469 00000f00: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
2470 00000f10: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
2471 00000f20: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
2472 00000f30: 3600 0000 6401 0000 7800 0000 7082 0300 6...d...x...p...
2473 00000f40: 2f00 0103 6401 0000 6b77 6f72 6b65 722f /...d...kworker/
2474 00000f50: 7531 363a 3600 0000 6401 0000 7800 0000 u16:6...d...x...
2475 00000f60: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
2476 00000f70: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2477 00000f80: f0ec 2100 2f00 0103 0000 0000 7377 6170 ..!./.......swap
2478 00000f90: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2479 00000fa0: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
2480 00000fb0: 6b65 722f 7531 363a 3600 0000 6401 0000 ker/u16:6...d...
2481 00000fc0: 7800 0000 0000 0000 0000 0000 0000 0000 x...............
2482 00000fd0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2483 00000fe0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2484 00000ff0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2485 )",
2486 };
2487
TEST_F(CpuReaderParsePagePayloadTest,ParseFullPageSchedSwitch)2488 TEST_F(CpuReaderParsePagePayloadTest, ParseFullPageSchedSwitch) {
2489 const ExamplePage* test_case = &g_full_page_sched_switch;
2490
2491 ProtoTranslationTable* table = GetTable(test_case->name);
2492 auto page = PageFromXxd(test_case->data);
2493
2494 FtraceDataSourceConfig ds_config = EmptyConfig();
2495 ds_config.event_filter.AddEnabledEvent(
2496 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
2497
2498 const uint8_t* parse_pos = page.get();
2499 std::optional<CpuReader::PageHeader> page_header =
2500 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
2501
2502 const uint8_t* page_end = page.get() + base::GetSysPageSize();
2503 ASSERT_TRUE(page_header.has_value());
2504 EXPECT_FALSE(page_header->lost_events);
2505 EXPECT_LE(parse_pos + page_header->size, page_end);
2506
2507 FtraceParseStatus status = CpuReader::ParsePagePayload(
2508 parse_pos, &page_header.value(), table, &ds_config,
2509 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
2510
2511 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
2512
2513 auto bundle = GetBundle();
2514 EXPECT_EQ(bundle.event().size(), 59u);
2515 }
2516
2517 // clang-format off
2518 // # tracer: nop
2519 // #
2520 // # entries-in-buffer/entries-written: 18/18 #P:8
2521 // #
2522 // # _-----=> irqs-off
2523 // # / _----=> need-resched
2524 // # | / _---=> hardirq/softirq
2525 // # || / _--=> preempt-depth
2526 // # ||| / delay
2527 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
2528 // # | | | |||| | |
2529 // <...>-9290 [000] .... 1352.654573: suspend_resume: sync_filesystems[0] end
2530 // <...>-9290 [000] .... 1352.665366: suspend_resume: freeze_processes[0] begin
2531 // <...>-9290 [000] .... 1352.699711: suspend_resume: freeze_processes[0] end
2532 // <...>-9290 [000] .... 1352.699718: suspend_resume: suspend_enter[1] end
2533 // <...>-9290 [000] .... 1352.699723: suspend_resume: dpm_prepare[2] begin
2534 // <...>-9290 [000] .... 1352.703470: suspend_resume: dpm_prepare[2] end
2535 // <...>-9290 [000] .... 1352.703477: suspend_resume: dpm_suspend[2] begin
2536 // <...>-9290 [000] .... 1352.720107: suspend_resume: dpm_resume[16] end
2537 // <...>-9290 [000] .... 1352.720113: suspend_resume: dpm_complete[16] begin
2538 // <...>-9290 [000] .n.. 1352.724540: suspend_resume: dpm_complete[16] end
2539 // <...>-9290 [000] .... 1352.724567: suspend_resume: resume_console[1] begin
2540 // <...>-9290 [000] .... 1352.724570: suspend_resume: resume_console[1] end
2541 // <...>-9290 [000] .... 1352.724574: suspend_resume: thaw_processes[0] begin
2542 // clang-format on
2543
2544 static ExamplePage g_suspend_resume{
2545 "synthetic",
2546 R"(00000000: edba 155a 3201 0000 7401 0000 0000 0000 ...Z2...t.......
2547 00000010: 7e58 22cd 1201 0000 0600 0000 ac00 0000 ~X".............
2548 00000020: 4a24 0000 5a7a f504 85ff ffff 0000 0000 J$..Zz..........
2549 00000030: 0017 0000 c621 9614 ac00 0000 4a24 0000 .....!......J$..
2550 00000040: 1c7a f504 85ff ffff 0000 0000 0100 0000 .z..............
2551 00000050: e6f1 8141 ac00 0000 4a24 0000 1c7a f504 ...A....J$...z..
2552 00000060: 85ff ffff 0000 0000 0000 0000 8682 0300 ................
2553 00000070: ac00 0000 4a24 0000 4c7a f504 85ff ffff ....J$..Lz......
2554 00000080: 0100 0000 0063 755f 0657 0200 ac00 0000 .....cu_.W......
2555 00000090: 4a24 0000 8ad5 0105 85ff ffff 0200 0000 J$..............
2556 000000a0: 0100 0000 06b5 2507 ac00 0000 4a24 0000 ......%.....J$..
2557 000000b0: 8ad5 0105 85ff ffff 0200 0000 0000 0000 ................
2558 000000c0: 460d 0300 ac00 0000 4a24 0000 51d5 0105 F.......J$..Q...
2559 000000d0: 85ff ffff 0200 0000 0117 0000 c63e b81f .............>..
2560 000000e0: ac00 0000 4a24 0000 7fd5 0105 85ff ffff ....J$..........
2561 000000f0: 1000 0000 0010 0b00 a6f9 0200 ac00 0000 ................
2562 00000100: 4a24 0000 96d5 0105 85ff ffff 1000 0000 J$..............
2563 00000110: 01c0 1f00 a6dd 7108 ac00 0400 4a24 0000 ......q.....J$..
2564 00000120: 96d5 0105 85ff ffff 1000 0000 0000 0000 ................
2565 00000130: c6f1 0c00 ac00 0000 4a24 0000 3d7a f504 ........J$..=z..
2566 00000140: 85ff ffff 0100 0000 01ea 24d5 a66c 0100 ..........$..l..
2567 00000150: ac00 0000 4a24 0000 3d7a f504 85ff ffff ....J$..=z......
2568 00000160: 0100 0000 0000 0001 6636 0200 ac00 0000 ........f6......
2569 00000170: 4a24 0000 d178 f504 85ff ffff 0000 0000 J$...x..........
2570 00000180: 0100 0000 0000 0000 0000 0000 0000 0000 ................
2571 00000190: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2572 )"};
2573
TEST_F(CpuReaderParsePagePayloadTest,ParseSuspendResume)2574 TEST_F(CpuReaderParsePagePayloadTest, ParseSuspendResume) {
2575 const ExamplePage* test_case = &g_suspend_resume;
2576
2577 ProtoTranslationTable* table = GetTable(test_case->name);
2578 auto page = PageFromXxd(test_case->data);
2579
2580 FtraceDataSourceConfig ds_config = EmptyConfig();
2581 ds_config.event_filter.AddEnabledEvent(
2582 table->EventToFtraceId(GroupAndName("power", "suspend_resume")));
2583
2584 const uint8_t* parse_pos = page.get();
2585 std::optional<CpuReader::PageHeader> page_header =
2586 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
2587 ASSERT_TRUE(page_header.has_value());
2588
2589 CpuReader::ParsePagePayload(parse_pos, &page_header.value(), table,
2590 &ds_config, CreateBundler(ds_config), &metadata_,
2591 &last_read_event_ts_);
2592 auto bundle = GetBundle();
2593 ASSERT_EQ(bundle.event().size(), 13u);
2594 EXPECT_EQ(bundle.event()[0].suspend_resume().action(), "sync_filesystems");
2595 EXPECT_EQ(bundle.event()[1].suspend_resume().action(), "freeze_processes");
2596 EXPECT_EQ(bundle.event()[2].suspend_resume().action(), "freeze_processes");
2597 EXPECT_EQ(bundle.event()[3].suspend_resume().action(), "suspend_enter");
2598 // dpm_prepare deliberately missing from:
2599 // src/traced/probes/ftrace/test/data/synthetic/printk_formats to ensure we
2600 // handle that case correctly.
2601 EXPECT_EQ(bundle.event()[4].suspend_resume().action(), "");
2602 }
2603
2604 // clang-format off
2605 // # tracer: nop
2606 // #
2607 // # entries-in-buffer/entries-written: 1041/238740 #P:8
2608 // #
2609 // # _-----=> irqs-off
2610 // # / _----=> need-resched
2611 // # | / _---=> hardirq/softirq
2612 // # || / _--=> preempt-depth
2613 // # ||| / delay
2614 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
2615 // # | | | |||| | |
2616 // android.bg-1668 [000] ...1 174991.234105: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2617 // android.bg-1668 [000] ...1 174991.234108: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2618 // android.bg-1668 [000] ...1 174991.234118: ext4_da_write_begin: dev 259,32 ino 2883605 pos 20480 len 4096 flags 0
2619 // android.bg-1668 [000] ...1 174991.234126: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2620 // android.bg-1668 [000] ...1 174991.234133: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 5
2621 // android.bg-1668 [000] ...1 174991.234135: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [5/4294967290) 576460752303423487 H0x10
2622 // android.bg-1668 [000] ...2 174991.234140: ext4_da_reserve_space: dev 259,32 ino 2883605 mode 0100600 i_blocks 8 reserved_data_blocks 6 reserved_meta_blocks 0
2623 // android.bg-1668 [000] ...1 174991.234142: ext4_es_insert_extent: dev 259,32 ino 2883605 es [5/1) mapped 576460752303423487 status D
2624 // android.bg-1668 [000] ...1 174991.234153: ext4_da_write_end: dev 259,32 ino 2883605 pos 20480 len 4096 copied 4096
2625 // android.bg-1668 [000] ...1 174991.234158: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2626 // android.bg-1668 [000] ...1 174991.234160: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2627 // android.bg-1668 [000] ...1 174991.234170: ext4_da_write_begin: dev 259,32 ino 2883605 pos 24576 len 2968 flags 0
2628 // android.bg-1668 [000] ...1 174991.234178: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2629 // android.bg-1668 [000] ...1 174991.234184: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 6
2630 // android.bg-1668 [000] ...1 174991.234187: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [6/4294967289) 576460752303423487 H0x10
2631 // android.bg-1668 [000] ...2 174991.234191: ext4_da_reserve_space: dev 259,32 ino 2883605 mode 0100600 i_blocks 8 reserved_data_blocks 7 reserved_meta_blocks 0
2632 // android.bg-1668 [000] ...1 174991.234193: ext4_es_insert_extent: dev 259,32 ino 2883605 es [6/1) mapped 576460752303423487 status D
2633 // android.bg-1668 [000] ...1 174991.234203: ext4_da_write_end: dev 259,32 ino 2883605 pos 24576 len 2968 copied 2968
2634 // android.bg-1668 [000] ...1 174991.234209: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2635 // android.bg-1668 [000] ...1 174991.234211: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2636 // android.bg-1668 [000] ...1 174991.234262: ext4_sync_file_enter: dev 259,32 ino 2883605 parent 2883592 datasync 0
2637 // android.bg-1668 [000] ...1 174991.234270: ext4_writepages: dev 259,32 ino 2883605 nr_to_write 9223372036854775807 pages_skipped 0 range_start 0 range_end 9223372036854775807 sync_mode 1 for_kupdate 0 range_cyclic 0 writeback_index 0
2638 // android.bg-1668 [000] ...1 174991.234287: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_writepages+0x6a4/0x119c
2639 // android.bg-1668 [000] ...1 174991.234294: ext4_da_write_pages: dev 259,32 ino 2883605 first_page 0 nr_to_write 9223372036854775807 sync_mode 1
2640 // android.bg-1668 [000] ...1 174991.234319: ext4_da_write_pages_extent: dev 259,32 ino 2883605 lblk 0 len 7 flags 0x200
2641 // android.bg-1668 [000] ...1 174991.234322: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 0
2642 // android.bg-1668 [000] ...1 174991.234324: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [0/7) 576460752303423487 D0x10
2643 // android.bg-1668 [000] ...1 174991.234328: ext4_ext_map_blocks_enter: dev 259,32 ino 2883605 lblk 0 len 7 flags CREATE|DELALLOC|METADATA_NOFAIL
2644 // android.bg-1668 [000] ...1 174991.234341: ext4_request_blocks: dev 259,32 ino 2883605 flags HINT_DATA|DELALLOC_RESV|USE_RESV len 7 lblk 0 goal 11567104 lleft 0 lright 0 pleft 0 pright 0
2645 // android.bg-1668 [000] ...1 174991.234394: ext4_mballoc_prealloc: dev 259,32 inode 2883605 orig 353/0/7@0 result 65/25551/7@0
2646 // android.bg-1668 [000] ...1 174991.234400: ext4_allocate_blocks: dev 259,32 ino 2883605 flags HINT_DATA|DELALLOC_RESV|USE_RESV len 7 block 2155471 lblk 0 goal 11567104 lleft 0 lright 0 pleft 0 pright 0
2647 // android.bg-1668 [000] ...1 174991.234409: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller __ext4_ext_dirty+0x104/0x170
2648 // android.bg-1668 [000] ...1 174991.234420: ext4_get_reserved_cluster_alloc: dev 259,32 ino 2883605 lblk 0 len 7
2649 // android.bg-1668 [000] ...2 174991.234426: ext4_da_update_reserve_space: dev 259,32 ino 2883605 mode 0100600 i_blocks 8 used_blocks 7 reserved_data_blocks 7 reserved_meta_blocks 0 allocated_meta_blocks 0 quota_claim 1
2650 // android.bg-1668 [000] ...1 174991.234434: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_mark_dquot_dirty+0x80/0xd4
2651 // android.bg-1668 [000] ...1 174991.234441: ext4_es_lookup_extent_enter: dev 259,32 ino 3 lblk 1
2652 // android.bg-1668 [000] ...1 174991.234445: ext4_es_lookup_extent_exit: dev 259,32 ino 3 found 1 [0/2) 9255 W0x10
2653 // android.bg-1668 [000] ...1 174991.234456: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_mark_dquot_dirty+0x80/0xd4
2654 // android.bg-1668 [000] ...1 174991.234460: ext4_es_lookup_extent_enter: dev 259,32 ino 4 lblk 1
2655 // android.bg-1668 [000] ...1 174991.234463: ext4_es_lookup_extent_exit: dev 259,32 ino 4 found 1 [0/2) 9257 W0x10
2656 // android.bg-1668 [000] ...1 174991.234471: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2657 // android.bg-1668 [000] ...1 174991.234474: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2658 // android.bg-1668 [000] ...1 174991.234481: ext4_ext_map_blocks_exit: dev 259,32 ino 2883605 flags CREATE|DELALLOC|METADATA_NOFAIL lblk 0 pblk 2155471 len 7 mflags NM ret 7
2659 // android.bg-1668 [000] ...1 174991.234484: ext4_es_insert_extent: dev 259,32 ino 2883605 es [0/7) mapped 2155471 status W
2660 // android.bg-1668 [000] ...1 174991.234547: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_writepages+0xdc0/0x119c
2661 // android.bg-1668 [000] ...1 174991.234604: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_writepages+0x6a4/0x119c
2662 // android.bg-1668 [000] ...1 174991.234609: ext4_da_write_pages: dev 259,32 ino 2883605 first_page 7 nr_to_write 9223372036854775800 sync_mode 1
2663 // android.bg-1668 [000] ...1 174991.234876: ext4_writepages_result: dev 259,32 ino 2883605 ret 0 pages_written 7 pages_skipped 0 sync_mode 1 writeback_index 7
2664 // Profile Saver-5504 [000] ...1 175002.711928: ext4_discard_preallocations: dev 259,32 ino 1311176
2665 // Profile Saver-5504 [000] ...1 175002.714165: ext4_begin_ordered_truncate: dev 259,32 ino 1311176 new_size 0
2666 // Profile Saver-5504 [000] ...1 175002.714172: ext4_journal_start: dev 259,32 blocks, 3 rsv_blocks, 0 caller ext4_setattr+0x5b4/0x788
2667 // Profile Saver-5504 [000] ...1 175002.714218: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_setattr+0x65c/0x788
2668 // Profile Saver-5504 [000] ...1 175002.714277: ext4_invalidatepage: dev 259,32 ino 1311176 page_index 0 offset 0 length 4096
2669 // Profile Saver-5504 [000] ...1 175002.714281: ext4_releasepage: dev 259,32 ino 1311176 page_index 0
2670 // Profile Saver-5504 [000] ...1 175002.714295: ext4_invalidatepage: dev 259,32 ino 1311176 page_index 1 offset 0 length 4096
2671 // Profile Saver-5504 [000] ...1 175002.714296: ext4_releasepage: dev 259,32 ino 1311176 page_index 1
2672 // Profile Saver-5504 [000] ...1 175002.714315: ext4_truncate_enter: dev 259,32 ino 1311176 blocks 24
2673 // Profile Saver-5504 [000] ...1 175002.714318: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_truncate+0x258/0x4b8
2674 // Profile Saver-5504 [000] ...1 175002.714322: ext4_discard_preallocations: dev 259,32 ino 1311176
2675 // Profile Saver-5504 [000] ...1 175002.714324: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_ext_truncate+0x24/0xc8
2676 // Profile Saver-5504 [000] ...1 175002.714328: ext4_es_remove_extent: dev 259,32 ino 1311176 es [0/4294967295)
2677 // Profile Saver-5504 [000] ...1 175002.714335: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_ext_remove_space+0x60/0x1180
2678 // Profile Saver-5504 [000] ...1 175002.714338: ext4_ext_remove_space: dev 259,32 ino 1311176 since 0 end 4294967294 depth 0
2679 // Profile Saver-5504 [000] ...1 175002.714347: ext4_ext_rm_leaf: dev 259,32 ino 1311176 start_lblk 0 last_extent [0(5276994), 2]partial_cluster 0
2680 // Profile Saver-5504 [000] ...1 175002.714351: ext4_remove_blocks: dev 259,32 ino 1311176 extent [0(5276994), 2]from 0 to 1 partial_cluster 0
2681 // Profile Saver-5504 [000] ...1 175002.714354: ext4_free_blocks: dev 259,32 ino 1311176 mode 0100600 block 5276994 count 2 flags 1ST_CLUSTER
2682 // Profile Saver-5504 [000] ...1 175002.714365: ext4_mballoc_free: dev 259,32 inode 1311176 extent 161/1346/2
2683 // Profile Saver-5504 [000] ...1 175002.714382: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_mark_dquot_dirty+0x80/0xd4
2684 // Profile Saver-5504 [000] ...1 175002.714391: ext4_es_lookup_extent_enter: dev 259,32 ino 3 lblk 4
2685 // Profile Saver-5504 [000] ...1 175002.714394: ext4_es_lookup_extent_exit: dev 259,32 ino 3 found 1 [4/1) 557094 W0x10
2686 // Profile Saver-5504 [000] ...1 175002.714402: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_mark_dquot_dirty+0x80/0xd4
2687 // Profile Saver-5504 [000] ...1 175002.714404: ext4_es_lookup_extent_enter: dev 259,32 ino 4 lblk 8
2688 // Profile Saver-5504 [000] ...1 175002.714406: ext4_es_lookup_extent_exit: dev 259,32 ino 4 found 1 [8/3) 7376914 W0x10
2689 // Profile Saver-5504 [000] ...1 175002.714413: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2690 // Profile Saver-5504 [000] ...1 175002.714414: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2691 // Profile Saver-5504 [000] ...1 175002.714420: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller __ext4_ext_dirty+0x104/0x170
2692 // Profile Saver-5504 [000] ...1 175002.714423: ext4_ext_remove_space_done: dev 259,32 ino 1311176 since 0 end 4294967294 depth 0 partial 0 remaining_entries 0
2693 // Profile Saver-5504 [000] ...1 175002.714425: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller __ext4_ext_dirty+0x104/0x170
2694 // Profile Saver-5504 [000] ...1 175002.714433: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_truncate+0x3c4/0x4b8
2695 // Profile Saver-5504 [000] ...1 175002.714436: ext4_truncate_exit: dev 259,32 ino 1311176 blocks 8
2696 // Profile Saver-5504 [000] ...1 175002.714437: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2697 // Profile Saver-5504 [000] ...1 175002.714438: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2698 // Profile Saver-5504 [000] ...1 175002.714462: ext4_da_write_begin: dev 259,32 ino 1311176 pos 0 len 4 flags 0
2699 // Profile Saver-5504 [000] ...1 175002.714472: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2700 // Profile Saver-5504 [000] ...1 175002.714477: ext4_es_lookup_extent_enter: dev 259,32 ino 1311176 lblk 0
2701 // Profile Saver-5504 [000] ...1 175002.714477: ext4_es_lookup_extent_exit: dev 259,32 ino 1311176 found 0 [0/0) 0
2702 // Profile Saver-5504 [000] ...1 175002.714480: ext4_ext_map_blocks_enter: dev 259,32 ino 1311176 lblk 0 len 1 flags
2703 // Profile Saver-5504 [000] ...1 175002.714485: ext4_es_find_delayed_extent_range_enter: dev 259,32 ino 1311176 lblk 0
2704 // Profile Saver-5504 [000] ...1 175002.714488: ext4_es_find_delayed_extent_range_exit: dev 259,32 ino 1311176 es [0/0) mapped 0 status
2705 // Profile Saver-5504 [000] ...1 175002.714490: ext4_es_insert_extent: dev 259,32 ino 1311176 es [0/4294967295) mapped 576460752303423487 status H
2706 // Profile Saver-5504 [000] ...1 175002.714495: ext4_ext_map_blocks_exit: dev 259,32 ino 1311176 flags lblk 0 pblk 4294967296 len 1 mflags ret 0
2707 // Profile Saver-5504 [000] ...2 175002.714501: ext4_da_reserve_space: dev 259,32 ino 1311176 mode 0100600 i_blocks 8 reserved_data_blocks 1 reserved_meta_blocks 0
2708 // Profile Saver-5504 [000] ...1 175002.714505: ext4_es_insert_extent: dev 259,32 ino 1311176 es [0/1) mapped 576460752303423487 status D
2709 // Profile Saver-5504 [000] ...1 175002.714513: ext4_da_write_end: dev 259,32 ino 1311176 pos 0 len 4 copied 4
2710 // Profile Saver-5504 [000] ...1 175002.714519: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2711 // Profile Saver-5504 [000] ...1 175002.714520: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2712 // Profile Saver-5504 [000] ...1 175002.714527: ext4_da_write_begin: dev 259,32 ino 1311176 pos 4 len 4 flags 0
2713 // Profile Saver-5504 [000] ...1 175002.714529: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2714 // Profile Saver-5504 [000] ...1 175002.714531: ext4_da_write_end: dev 259,32 ino 1311176 pos 4 len 4 copied 4
2715 // Profile Saver-5504 [000] ...1 175002.714532: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2716 // Profile Saver-5504 [000] ...1 175002.714532: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2717 // Profile Saver-5504 [000] ...1 175002.715313: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2718 // Profile Saver-5504 [000] ...1 175002.715322: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2719 // Profile Saver-5504 [000] ...1 175002.723849: ext4_da_write_begin: dev 259,32 ino 1311176 pos 8 len 5 flags 0
2720 // Profile Saver-5504 [000] ...1 175002.723862: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2721 // Profile Saver-5504 [000] ...1 175002.723873: ext4_da_write_end: dev 259,32 ino 1311176 pos 8 len 5 copied 5
2722 // Profile Saver-5504 [000] ...1 175002.723877: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2723 // Profile Saver-5504 [000] ...1 175002.723879: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2724 // Profile Saver-5504 [000] ...1 175002.726857: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2725 // Profile Saver-5504 [000] ...1 175002.726867: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2726 // Profile Saver-5504 [000] ...1 175002.726881: ext4_da_write_begin: dev 259,32 ino 1311176 pos 13 len 4 flags 0
2727 // Profile Saver-5504 [000] ...1 175002.726883: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2728 // Profile Saver-5504 [000] ...1 175002.726890: ext4_da_write_end: dev 259,32 ino 1311176 pos 13 len 4 copied 4
2729 // Profile Saver-5504 [000] ...1 175002.726892: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2730 // Profile Saver-5504 [000] ...1 175002.726892: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2731 // Profile Saver-5504 [000] ...1 175002.726900: ext4_da_write_begin: dev 259,32 ino 1311176 pos 17 len 4079 flags 0
2732 // Profile Saver-5504 [000] ...1 175002.726901: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2733 // Profile Saver-5504 [000] ...1 175002.726904: ext4_da_write_end: dev 259,32 ino 1311176 pos 17 len 4079 copied 4079
2734 // Profile Saver-5504 [000] ...1 175002.726905: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2735 // Profile Saver-5504 [000] ...1 175002.726906: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2736 // Profile Saver-5504 [000] ...1 175002.726908: ext4_da_write_begin: dev 259,32 ino 1311176 pos 4096 len 2780 flags 0
2737 // Profile Saver-5504 [000] ...1 175002.726916: ext4_journal_start: dev 259,32 blocks, 1 rsv_blocks, 0 caller ext4_da_write_begin+0x3d4/0x518
2738 // Profile Saver-5504 [000] ...1 175002.726921: ext4_es_lookup_extent_enter: dev 259,32 ino 1311176 lblk 1
2739 // Profile Saver-5504 [000] ...1 175002.726924: ext4_es_lookup_extent_exit: dev 259,32 ino 1311176 found 1 [1/4294967294) 576460752303423487 H0x10
2740 // Profile Saver-5504 [000] ...2 175002.726931: ext4_da_reserve_space: dev 259,32 ino 1311176 mode 0100600 i_blocks 8 reserved_data_blocks 2 reserved_meta_blocks 0
2741 // Profile Saver-5504 [000] ...1 175002.726933: ext4_es_insert_extent: dev 259,32 ino 1311176 es [1/1) mapped 576460752303423487 status D
2742 // Profile Saver-5504 [000] ...1 175002.726940: ext4_da_write_end: dev 259,32 ino 1311176 pos 4096 len 2780 copied 2780
2743 // Profile Saver-5504 [000] ...1 175002.726941: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2744 // Profile Saver-5504 [000] ...1 175002.726942: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2745 // d.process.acor-27885 [000] ...1 175018.227675: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2746 // d.process.acor-27885 [000] ...1 175018.227699: ext4_mark_inode_dirty: dev 259,32 ino 3278189 caller ext4_dirty_inode+0x48/0x68
2747 // d.process.acor-27885 [000] ...1 175018.227839: ext4_sync_file_enter: dev 259,32 ino 3278183 parent 3277001 datasync 1
2748 // d.process.acor-27885 [000] ...1 175018.227847: ext4_writepages: dev 259,32 ino 3278183 nr_to_write 9223372036854775807 pages_skipped 0 range_start 0 range_end 9223372036854775807 sync_mode 1 for_kupdate 0 range_cyclic 0 writeback_index 2
2749 // d.process.acor-27885 [000] ...1 175018.227852: ext4_writepages_result: dev 259,32 ino 3278183 ret 0 pages_written 0 pages_skipped 0 sync_mode 1 writeback_index 2
2750 // clang-format on
2751
2752 static ExamplePage g_full_page_ext4{
2753 "synthetic",
2754 R"(
2755 00000000: 50fe 5852 279f 0000 c80f 00c0 ffff ffff P.XR'...........
2756 00000010: 0800 0000 5701 0001 8406 0000 2000 3010 ....W....... .0.
2757 00000020: 566b 0000 8829 e86a 91ff ffff 0200 0000 Vk...).j........
2758 00000030: 0000 0000 2873 0100 1b01 0001 8406 0000 ....(s..........
2759 00000040: 2000 3010 9200 0000 1500 2c00 0000 0000 .0.......,.....
2760 00000050: a029 e86a 91ff ffff 0ac8 0400 1e01 0001 .).j............
2761 00000060: 8406 0000 2000 3010 2866 0100 1500 2c00 .... .0.(f....,.
2762 00000070: 0000 0000 0050 0000 0000 0000 0010 0000 .....P..........
2763 00000080: 0000 0000 a804 0400 5701 0001 8406 0000 ........W.......
2764 00000090: 2000 3010 91ff ffff 586f e86a 91ff ffff .0.....Xo.j....
2765 000000a0: 0100 0000 0000 0000 c83a 0300 6c01 0001 .........:..l...
2766 000000b0: 8406 0000 2000 3010 0000 0000 1500 2c00 .... .0.......,.
2767 000000c0: 0000 0000 0500 0000 5701 0001 ac6c 0100 ........W....l..
2768 000000d0: 6d01 0001 8406 0000 2000 3010 91ff ffff m....... .0.....
2769 000000e0: 1500 2c00 0000 0000 0500 0000 faff ffff ..,.............
2770 000000f0: ffff ffff ffff ff07 184e 0000 0100 0000 .........N......
2771 00000100: ec08 0200 3f01 0002 8406 0000 2000 3010 ....?....... .0.
2772 00000110: 0000 0000 1500 2c00 0000 0000 0800 0000 ......,.........
2773 00000120: 0000 0000 0600 0000 0000 0000 8081 0000 ................
2774 00000130: 0000 0000 ec24 0100 6701 0001 8406 0000 .....$..g.......
2775 00000140: 2000 3010 0000 0000 1500 2c00 0000 0000 .0.......,.....
2776 00000150: 0500 0000 0100 0000 ffff ffff ffff ff07 ................
2777 00000160: 0400 0000 7b04 3200 2a30 0500 2101 0001 ....{.2.*0..!...
2778 00000170: 8406 0000 2000 3010 0000 0000 1500 2c00 .... .0.......,.
2779 00000180: 0000 0000 0050 0000 0000 0000 0010 0000 .....P..........
2780 00000190: 0010 0000 288b 0200 5701 0001 8406 0000 ....(...W.......
2781 000001a0: 2000 3010 0000 0000 8829 e86a 91ff ffff .0......).j....
2782 000001b0: 0200 0000 0000 0000 0832 0100 1b01 0001 .........2......
2783 000001c0: 8406 0000 2000 3010 566b 0000 1500 2c00 .... .0.Vk....,.
2784 000001d0: 0000 0000 a029 e86a 91ff ffff eaa0 0400 .....).j........
2785 000001e0: 1e01 0001 8406 0000 2000 3010 280b 0400 ........ .0.(...
2786 000001f0: 1500 2c00 0000 0000 0060 0000 0000 0000 ..,......`......
2787 00000200: 980b 0000 0000 0000 88d0 0300 5701 0001 ............W...
2788 00000210: 8406 0000 2000 3010 566b 0000 586f e86a .... .0.Vk..Xo.j
2789 00000220: 91ff ffff 0100 0000 0000 0000 c813 0300 ................
2790 00000230: 6c01 0001 8406 0000 2000 3010 566b 0000 l....... .0.Vk..
2791 00000240: 1500 2c00 0000 0000 0600 0000 0000 0000 ..,.............
2792 00000250: ac5f 0100 6d01 0001 8406 0000 2000 3010 ._..m....... .0.
2793 00000260: 1100 3010 1500 2c00 0000 0000 0600 0000 ..0...,.........
2794 00000270: f9ff ffff ffff ffff ffff ff07 185a ea6a .............Z.j
2795 00000280: 0100 0000 4c02 0200 3f01 0002 8406 0000 ....L...?.......
2796 00000290: 2000 3010 566b 0000 1500 2c00 0000 0000 .0.Vk....,.....
2797 000002a0: 0800 0000 0000 0000 0700 0000 0000 0000 ................
2798 000002b0: 8081 0000 6d01 0001 0c0b 0100 6701 0001 ....m.......g...
2799 000002c0: 8406 0000 2000 3010 0000 0000 1500 2c00 .... .0.......,.
2800 000002d0: 0000 0000 0600 0000 0100 0000 ffff ffff ................
2801 000002e0: ffff ff07 049a 0100 5701 0001 aa1c 0500 ........W.......
2802 000002f0: 2101 0001 8406 0000 2000 3010 91ff ffff !....... .0.....
2803 00000300: 1500 2c00 0000 0000 0060 0000 0000 0000 ..,......`......
2804 00000310: 980b 0000 980b 0000 889e 0200 5701 0001 ............W...
2805 00000320: 8406 0000 2000 3010 91ff ffff 8829 e86a .... .0......).j
2806 00000330: 91ff ffff 0200 0000 0000 0000 8838 0100 .............8..
2807 00000340: 1b01 0001 8406 0000 2000 3010 91ff ffff ........ .0.....
2808 00000350: 1500 2c00 0000 0000 a029 e86a 91ff ffff ..,......).j....
2809 00000360: 2ab8 1800 3501 0001 8406 0000 2000 3010 *...5....... .0.
2810 00000370: feff ffff 1500 2c00 0000 0000 0800 2c00 ......,.......,.
2811 00000380: 0000 0000 0000 0000 2000 3010 32fe 0300 ........ .0.2...
2812 00000390: 2201 0001 8406 0000 2000 3010 0000 0000 "....... .0.....
2813 000003a0: 1500 2c00 0000 0000 ffff ffff ffff ff7f ..,.............
2814 000003b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2815 000003c0: ffff ffff ffff ff7f 0000 0000 0000 0000 ................
2816 000003d0: 0100 0000 0000 0000 887e 0800 5701 0001 .........~..W...
2817 000003e0: 8406 0000 2000 3010 7b04 3200 7c3f e86a .... .0.{.2.|?.j
2818 000003f0: 91ff ffff 0a00 0000 0000 0000 ec2d 0300 .............-..
2819 00000400: 2301 0001 8406 0000 2000 3010 7b04 3200 #....... .0.{.2.
2820 00000410: 1500 2c00 0000 0000 0000 0000 0000 0000 ..,.............
2821 00000420: ffff ffff ffff ff7f 0100 0000 3c01 0001 ............<...
2822 00000430: 0a42 0c00 2401 0001 8406 0000 2000 3010 .B..$....... .0.
2823 00000440: 0800 0000 1500 2c00 0000 0000 0000 0000 ......,.........
2824 00000450: 0000 0000 0700 0000 0002 0000 885f 0100 ............._..
2825 00000460: 6c01 0001 8406 0000 2000 3010 0100 0000 l....... .0.....
2826 00000470: 1500 2c00 0000 0000 0000 0000 566b 0000 ..,.........Vk..
2827 00000480: 0c25 0100 6d01 0001 8406 0000 2000 3010 .%..m....... .0.
2828 00000490: 0400 0000 1500 2c00 0000 0000 0000 0000 ......,.........
2829 000004a0: 0700 0000 ffff ffff ffff ff07 1400 0000 ................
2830 000004b0: 0100 0000 caee 0100 5101 0001 8406 0000 ........Q.......
2831 000004c0: 2000 3010 1100 0000 1500 2c00 0000 0000 .0.......,.....
2832 000004d0: 0000 0000 0700 0000 2500 0000 2000 3010 ........%... .0.
2833 000004e0: 323b 0600 3201 0001 8406 0000 2000 3010 2;..2....... .0.
2834 000004f0: c86e 0000 1500 2c00 0000 0000 0700 0000 .n....,.........
2835 00000500: 0000 0000 0000 0000 0000 0000 0080 b000 ................
2836 00000510: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2837 00000520: 0000 0000 2024 0000 0400 0000 ae0a 1a00 .... $..........
2838 00000530: 3a01 0001 8406 0000 2000 3010 0000 0000 :....... .0.....
2839 00000540: 1500 2c00 0000 0000 0000 0000 0000 0000 ..,.............
2840 00000550: 6101 0000 0700 0000 0000 0000 cf63 0000 a............c..
2841 00000560: 4100 0000 0700 0000 b4c5 0200 3301 0001 A...........3...
2842 00000570: 8406 0000 2000 3010 2000 3010 1500 2c00 .... .0. .0...,.
2843 00000580: 0000 0000 cfe3 2000 0000 0000 0700 0000 ...... .........
2844 00000590: 0000 0000 0000 0000 0000 0000 0080 b000 ................
2845 000005a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2846 000005b0: 0000 0000 2024 0000 6c01 0001 4859 0400 .... $..l...HY..
2847 000005c0: 1b01 0001 8406 0000 2000 3010 0000 0000 ........ .0.....
2848 000005d0: 1500 2c00 0000 0000 9c99 ea6a 91ff ffff ..,........j....
2849 000005e0: c850 0500 6001 0001 8406 0000 2000 3010 .P..`....... .0.
2850 000005f0: 0000 0000 1500 2c00 0000 0000 0000 0000 ......,.........
2851 00000600: 0700 0000 2ee6 0200 3e01 0002 8406 0000 ........>.......
2852 00000610: 2000 3010 566b 0000 1500 2c00 0000 0000 .0.Vk....,.....
2853 00000620: 0800 0000 0000 0000 0700 0000 0700 0000 ................
2854 00000630: 0000 0000 0000 0000 0100 0000 8081 3010 ..............0.
2855 00000640: a804 0400 5701 0001 8406 0000 2000 3010 ....W....... .0.
2856 00000650: cb07 3200 885a ea6a 91ff ffff 0100 0000 ..2..Z.j........
2857 00000660: 0000 0000 8875 0300 6c01 0001 8406 0000 .....u..l.......
2858 00000670: 2000 3010 0300 0000 0300 0000 0000 0000 .0.............
2859 00000680: 0100 0000 0100 0000 ccd4 0100 6d01 0001 ............m...
2860 00000690: 8406 0000 2000 3010 cb07 3200 0300 0000 .... .0...2.....
2861 000006a0: 0000 0000 0000 0000 0200 0000 2724 0000 ............'$..
2862 000006b0: 0000 0000 1100 3010 0100 0000 a850 0500 ......0......P..
2863 000006c0: 5701 0001 8406 0000 2000 3010 0000 0000 W....... .0.....
2864 000006d0: 885a ea6a 91ff ffff 0100 0000 0000 0000 .Z.j............
2865 000006e0: 680f 0200 6c01 0001 8406 0000 2000 3010 h...l....... .0.
2866 000006f0: 0000 0000 0400 0000 0000 0000 0100 0000 ................
2867 00000700: 6d01 0001 ac79 0100 6d01 0001 8406 0000 m....y..m.......
2868 00000710: 2000 3010 0000 0000 0400 0000 0000 0000 .0.............
2869 00000720: 0000 0000 0200 0000 2924 0000 0000 0000 ........)$......
2870 00000730: 1143 0200 0100 0000 2818 0400 5701 0001 .C......(...W...
2871 00000740: 8406 0000 2000 3010 0000 0000 8829 e86a .... .0......).j
2872 00000750: 91ff ffff 0200 0000 0000 0000 8838 0100 .............8..
2873 00000760: 1b01 0001 8406 0000 2000 3010 0400 0000 ........ .0.....
2874 00000770: 1500 2c00 0000 0000 a029 e86a 91ff ffff ..,......).j....
2875 00000780: 0e89 0300 5301 0001 8406 0000 2000 3010 ....S....... .0.
2876 00000790: e128 0000 1500 2c00 0000 0000 2500 0000 .(....,.....%...
2877 000007a0: 0000 0000 cfe3 2000 0000 0000 0000 0000 ...... .........
2878 000007b0: 0700 0000 6000 0000 0700 0000 aca0 0100 ....`...........
2879 000007c0: 6701 0001 8406 0000 2000 3010 e128 0000 g....... .0..(..
2880 000007d0: 1500 2c00 0000 0000 0000 0000 0700 0000 ..,.............
2881 000007e0: cfe3 2000 0000 0000 01a2 0800 0000 0000 .. .............
2882 000007f0: 28b2 1e00 1b01 0001 8406 0000 2000 3010 (........... .0.
2883 00000800: e128 0000 1500 2c00 0000 0000 9846 e86a .(....,......F.j
2884 00000810: 91ff ffff 68d2 1b00 5701 0001 8406 0000 ....h...W.......
2885 00000820: 2000 3010 e128 0000 7c3f e86a 91ff ffff .0..(..|?.j....
2886 00000830: 0a00 0000 0000 0000 0c57 0200 2301 0001 .........W..#...
2887 00000840: 8406 0000 2000 3010 006c 0000 1500 2c00 .... .0..l....,.
2888 00000850: 0000 0000 0700 0000 0000 0000 f8ff ffff ................
2889 00000860: ffff ff7f 0100 0000 0000 0000 6e69 8200 ............ni..
2890 00000870: 2501 0001 8406 0000 2000 3010 ca6e 0000 %....... .0..n..
2891 00000880: 1500 2c00 0000 0000 0000 0000 0700 0000 ..,.............
2892 00000890: 0000 0000 0000 0000 0700 0000 0000 0000 ................
2893 000008a0: 0100 0000 0200 3010 3e13 bd82 5500 0000 ......0.>...U...
2894 000008b0: 0600 0000 3001 0001 8015 0000 2000 3010 ....0....... .0.
2895 000008c0: 0000 0000 c801 1400 0000 0000 8860 4404 .............`D.
2896 000008d0: 1c01 0001 8015 0000 2000 3010 2000 0000 ........ .0. ...
2897 000008e0: c801 1400 0000 0000 0000 0000 0000 0000 ................
2898 000008f0: 88a9 0300 5701 0001 8015 0000 2000 3010 ....W....... .0.
2899 00000900: 0400 0000 1c1e e86a 91ff ffff 0300 0000 .......j........
2900 00000910: 0000 0000 a85a 1600 1b01 0001 8015 0000 .....Z..........
2901 00000920: 2000 3010 2000 3010 c801 1400 0000 0000 .0. .0.........
2902 00000930: c41e e86a 91ff ffff ca95 1c00 2901 0001 ...j........)...
2903 00000940: 8015 0000 2000 3010 2000 3010 c801 1400 .... .0. .0.....
2904 00000950: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2905 00000960: 0010 0000 c8fb 0100 2801 0001 8015 0000 ........(.......
2906 00000970: 2000 3010 5101 0001 c801 1400 0000 0000 .0.Q...........
2907 00000980: 0000 0000 0000 0000 6af1 0600 2901 0001 ........j...)...
2908 00000990: 8015 0000 2000 3010 0000 0000 c801 1400 .... .0.........
2909 000009a0: 0000 0000 0100 0000 0000 0000 0000 0000 ................
2910 000009b0: 0010 0000 488f 0000 2801 0001 8015 0000 ....H...(.......
2911 000009c0: 2000 3010 0200 ffff c801 1400 0000 0000 .0.............
2912 000009d0: 0100 0000 0000 0000 483b 0900 4d01 0001 ........H;..M...
2913 000009e0: 8015 0000 2000 3010 0000 0000 c801 1400 .... .0.........
2914 000009f0: 0000 0000 1800 0000 0000 0000 8852 0100 .............R..
2915 00000a00: 5701 0001 8015 0000 2000 3010 e128 0000 W....... .0..(..
2916 00000a10: 9ce9 e76a 91ff ffff 0a00 0000 0000 0000 ...j............
2917 00000a20: e615 0200 3001 0001 8015 0000 2000 3010 ....0....... .0.
2918 00000a30: 0155 0000 c801 1400 0000 0000 68d0 0000 .U..........h...
2919 00000a40: 1b01 0001 8015 0000 2000 3010 6606 3200 ........ .0.f.2.
2920 00000a50: c801 1400 0000 0000 acfa ea6a 91ff ffff ...........j....
2921 00000a60: 6a0f 0200 6901 0001 8015 0000 2000 3010 j...i....... .0.
2922 00000a70: 7106 3200 c801 1400 0000 0000 0000 0000 q.2.............
2923 00000a80: 0000 0000 ffff ffff 0000 0000 e895 0300 ................
2924 00000a90: 5701 0001 8015 0000 2000 3010 0300 0000 W....... .0.....
2925 00000aa0: acbe ea6a 91ff ffff 0100 0000 0000 0000 ...j............
2926 00000ab0: 8a38 0100 6501 0001 8015 0000 2000 3010 .8..e....... .0.
2927 00000ac0: c41e e86a c801 1400 0000 0000 0000 0000 ...j............
2928 00000ad0: feff ffff 0000 0000 0000 0000 ee86 0400 ................
2929 00000ae0: 6301 0001 8015 0000 2000 3010 0000 0000 c....... .0.....
2930 00000af0: c801 1400 0000 0000 0000 0000 0000 0000 ................
2931 00000b00: 0000 0000 0000 0000 4285 5000 0000 0000 ........B.P.....
2932 00000b10: 0200 0000 0000 0000 8e36 0200 6201 0001 .........6..b...
2933 00000b20: 8015 0000 2000 3010 7d55 0000 c801 1400 .... .0.}U......
2934 00000b30: 0000 0000 0000 0000 0100 0000 0000 0000 ................
2935 00000b40: 0000 0000 4285 5000 0000 0000 0000 0000 ....B.P.........
2936 00000b50: 0200 3010 8c5f 0100 3401 0001 8015 0000 ..0.._..4.......
2937 00000b60: 2000 3010 0000 0000 c801 1400 0000 0000 .0.............
2938 00000b70: 4285 5000 0000 0000 0200 0000 0000 0000 B.P.............
2939 00000b80: 1000 0000 8081 0000 aa43 0500 3c01 0001 .........C..<...
2940 00000b90: 8015 0000 2000 3010 2801 0001 c801 1400 .... .0.(.......
2941 00000ba0: 0000 0000 4205 0000 a100 0000 0200 0000 ....B...........
2942 00000bb0: 0200 0000 8871 0800 5701 0001 8015 0000 .....q..W.......
2943 00000bc0: 2000 3010 2000 3010 885a ea6a 91ff ffff .0. .0..Z.j....
2944 00000bd0: 0100 0000 0000 0000 4825 0400 6c01 0001 ........H%..l...
2945 00000be0: 8015 0000 2000 3010 2801 0001 0300 0000 .... .0.(.......
2946 00000bf0: 0000 0000 0400 0000 7106 3200 0c73 0100 ........q.2..s..
2947 00000c00: 6d01 0001 8015 0000 2000 3010 2901 0001 m....... .0.)...
2948 00000c10: 0300 0000 0000 0000 0400 0000 0100 0000 ................
2949 00000c20: 2680 0800 0000 0000 1100 0000 0100 0000 &...............
2950 00000c30: c845 0400 5701 0001 8015 0000 2000 3010 .E..W....... .0.
2951 00000c40: 2000 3010 885a ea6a 91ff ffff 0100 0000 .0..Z.j........
2952 00000c50: 0000 0000 e8c9 0000 6c01 0001 8015 0000 ........l.......
2953 00000c60: 2000 3010 2000 3010 0400 0000 0000 0000 .0. .0.........
2954 00000c70: 0800 0000 0500 0000 6cdd 0000 6d01 0001 ........l...m...
2955 00000c80: 8015 0000 2000 3010 2801 0001 0400 0000 .... .0.(.......
2956 00000c90: 0000 0000 0800 0000 0300 0000 1290 7000 ..............p.
2957 00000ca0: 0000 0000 1100 0000 0100 0000 6875 0300 ............hu..
2958 00000cb0: 5701 0001 8015 0000 2000 3010 7106 3200 W....... .0.q.2.
2959 00000cc0: 8829 e86a 91ff ffff 0200 0000 0000 0000 .).j............
2960 00000cd0: a847 0000 1b01 0001 8015 0000 2000 3010 .G.......... .0.
2961 00000ce0: 9ce9 e76a c801 1400 0000 0000 a029 e86a ...j.........).j
2962 00000cf0: 91ff ffff e83a 0300 1b01 0001 8015 0000 .....:..........
2963 00000d00: 2000 3010 7106 3200 c801 1400 0000 0000 .0.q.2.........
2964 00000d10: 9c99 ea6a 91ff ffff ae93 0100 6601 0001 ...j........f...
2965 00000d20: 8015 0000 2000 3010 acfa ea6a c801 1400 .... .0....j....
2966 00000d30: 0000 0000 0000 0000 feff ffff 0000 0000 ................
2967 00000d40: 2000 3010 0000 0000 0000 0000 0000 0000 .0.............
2968 00000d50: 0000 0000 48b6 0000 1b01 0001 8015 0000 ....H...........
2969 00000d60: 2000 3010 e128 0000 c801 1400 0000 0000 .0..(..........
2970 00000d70: 9c99 ea6a 91ff ffff a8ea 0300 1b01 0001 ...j............
2971 00000d80: 8015 0000 2000 3010 e128 0000 c801 1400 .... .0..(......
2972 00000d90: 0000 0000 08eb e76a 91ff ffff 885f 0100 .......j....._..
2973 00000da0: 4e01 0001 8015 0000 2000 3010 2efe 0300 N....... .0.....
2974 00000db0: c801 1400 0000 0000 0800 0000 0000 0000 ................
2975 00000dc0: e8bc 0000 5701 0001 8015 0000 2000 3010 ....W....... .0.
2976 00000dd0: 0000 0000 8829 e86a 91ff ffff 0200 0000 .....).j........
2977 00000de0: 0000 0000 c895 0000 1b01 0001 8015 0000 ................
2978 00000df0: 2000 3010 2000 3010 c801 1400 0000 0000 .0. .0.........
2979 00000e00: a029 e86a 91ff ffff cab2 0b00 1e01 0001 .).j............
2980 00000e10: 8015 0000 2000 3010 0000 0000 c801 1400 .... .0.........
2981 00000e20: 0000 0000 0000 0000 0000 0000 0400 0000 ................
2982 00000e30: 0000 0000 689a 0400 5701 0001 8015 0000 ....h...W.......
2983 00000e40: 2000 3010 0000 0000 586f e86a 91ff ffff .0.....Xo.j....
2984 00000e50: 0100 0000 0000 0000 8884 0200 6c01 0001 ............l...
2985 00000e60: 8015 0000 2000 3010 8829 e86a c801 1400 .... .0..).j....
2986 00000e70: 0000 0000 0000 0000 4100 0000 ac47 0000 ........A....G..
2987 00000e80: 6d01 0001 8015 0000 2000 3010 e128 0000 m....... .0..(..
2988 00000e90: c801 1400 0000 0000 0000 0000 0000 0000 ................
2989 00000ea0: 0000 0000 0000 0000 001c 0200 0000 0000 ................
2990 00000eb0: 2a66 0100 5101 0001 8015 0000 2000 3010 *f..Q....... .0.
2991 00000ec0: 0000 0000 c801 1400 0000 0000 0000 0000 ................
2992 00000ed0: 0100 0000 0000 0000 2000 3010 087e 0200 ........ .0..~..
2993 00000ee0: 6a01 0001 8015 0000 2000 3010 0100 0000 j....... .0.....
2994 00000ef0: c801 1400 0000 0000 0000 0000 0100 0000 ................
2995 00000f00: 8c11 0100 6b01 0001 8015 0000 2000 3010 ....k....... .0.
2996 00000f10: 1b01 0001 c801 1400 0000 0000 0000 0000 ................
2997 00000f20: 0000 0000 0000 0000 0000 0000 0028 0000 .............(..
2998 00000f30: 2000 3010 8c5f 0100 6701 0001 8015 0000 .0.._..g.......
2999 00000f40: 2000 3010 0000 0000 c801 1400 0000 0000 .0.............
3000 00000f50: 0000 0000 ffff ffff ffff ffff ffff ff07 ................
3001 00000f60: 0800 0000 0700 0000 6e02 0200 5301 0001 ........n...S...
3002 00000f70: 8015 0000 2000 3010 0100 0000 c801 1400 .... .0.........
3003 00000f80: 0000 0000 0000 0000 2000 3010 0000 0000 ........ .0.....
3004 00000f90: 0100 0000 0000 0000 0100 0000 0000 0000 ................
3005 00000fa0: 0000 0000 cc3a 0300 3f01 0002 8015 0000 .....:..?.......
3006 00000fb0: 2000 3010 7106 3200 c801 1400 0000 0000 .0.q.2.........
3007 00000fc0: 0800 0000 0000 0000 0100 0000 0000 0000 ................
3008 00000fd0: 8081 3010 3d00 0000 f542 0000 0000 0000 ..0.=....B......
3009 00000fe0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
3010 00000ff0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
3011 )",
3012 };
3013
TEST_F(CpuReaderParsePagePayloadTest,ParseExt4WithOverwrite)3014 TEST_F(CpuReaderParsePagePayloadTest, ParseExt4WithOverwrite) {
3015 const ExamplePage* test_case = &g_full_page_ext4;
3016
3017 ProtoTranslationTable* table = GetTable(test_case->name);
3018 auto page = PageFromXxd(test_case->data);
3019
3020 FtraceDataSourceConfig ds_config = EmptyConfig();
3021 ds_config.event_filter.AddEnabledEvent(
3022 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
3023
3024 const uint8_t* parse_pos = page.get();
3025 std::optional<CpuReader::PageHeader> page_header =
3026 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
3027
3028 const uint8_t* page_end = page.get() + base::GetSysPageSize();
3029 ASSERT_TRUE(page_header.has_value());
3030 EXPECT_TRUE(page_header->lost_events); // data loss
3031 EXPECT_LE(parse_pos + page_header->size, page_end);
3032
3033 FtraceParseStatus status = CpuReader::ParsePagePayload(
3034 parse_pos, &page_header.value(), table, &ds_config,
3035 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
3036
3037 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
3038
3039 EXPECT_THAT(AllTracePackets(), IsEmpty());
3040 }
3041
3042 // Page with a single event containing a __data_loc entry with value 0x0000
3043 //
3044 // [timestamp ] [32 byte payload next ]
3045 // 00000000: D7 B3 0A 57 CF 02 00 00 20 00 00 00 00 00 00 00 ...W.... .......
3046 // [evt hdr ] [id ]
3047 // 00000010: 67 A6 13 00 0F 06 00 00 3D 01 00 00 45 00 00 00 g.......=...E...
3048 // 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
3049 //
3050 // name: tracing_mark_write
3051 // ID: 1551
3052 // format:
3053 // field:unsigned short common_type; offset:0; size:2; signed:0;
3054 // field:unsigned char common_flags; offset:2; size:1; signed:0;
3055 // field:unsigned char common_preempt_count; offset:3; size:1;
3056 // signed:0; field:int common_pid; offset:4; size:4; signed:1;
3057 //
3058 // field:char type; offset:8; size:1; signed:0;
3059 // field:int pid; offset:12; size:4; signed:1;
3060 // field:__data_loc char[] name; offset:16; size:4; signed:0;
3061 // field:int value; offset:20; size:4; signed:1;
3062 //
3063 static char g_zero_data_loc[] =
3064 R"(
3065 00000000: D7B3 0A57 CF02 0000 2000 0000 0000 0000 ...W.... .......
3066 00000010: 67A6 1300 0F06 0000 3D01 0000 4500 0000 g.......=...E...
3067 00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
3068 00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
3069 )";
3070
3071 TEST_F(CpuReaderParsePagePayloadTest, ZeroLengthDataLoc) {
3072 auto page = PageFromXxd(g_zero_data_loc);
3073
3074 // Hand-build a translation table that handles dpu/tracing_mark_write for this
3075 // test page.
3076 // TODO(rsavitski): look into making these tests less verbose by feeding a
3077 // format string through proto_translation_table to get the format.
3078 std::vector<Field> common_fields;
3079 { // common_pid
3080 common_fields.emplace_back(Field{});
3081 Field* field = &common_fields.back();
3082 field->ftrace_offset = 4;
3083 field->ftrace_size = 4;
3084 field->ftrace_type = kFtraceCommonPid32;
3085 field->proto_field_id = 2;
3086 field->proto_field_type = ProtoSchemaType::kInt32;
3087 SetTranslationStrategy(field->ftrace_type, field->proto_field_type,
3088 &field->strategy);
3089 }
3090 using Dpu = protos::gen::DpuTracingMarkWriteFtraceEvent;
3091 Event evt{"tracing_mark_write",
3092 "dpu",
3093 {
3094 {8, 1, FtraceFieldType::kFtraceUint8, "type",
3095 Dpu::kTypeFieldNumber, ProtoSchemaType::kUint32,
3096 TranslationStrategy::kInvalidTranslationStrategy},
3097 {12, 4, FtraceFieldType::kFtraceInt32, "pid",
3098 Dpu::kPidFieldNumber, ProtoSchemaType::kInt32,
3099 TranslationStrategy::kInvalidTranslationStrategy},
3100 {16, 4, FtraceFieldType::kFtraceDataLoc, "name",
3101 Dpu::kNameFieldNumber, ProtoSchemaType::kString,
3102 TranslationStrategy::kInvalidTranslationStrategy},
3103 {20, 4, FtraceFieldType::kFtraceInt32, "value",
3104 Dpu::kValueFieldNumber, ProtoSchemaType::kInt32,
3105 TranslationStrategy::kInvalidTranslationStrategy},
3106 },
3107 /*ftrace_event_id=*/1551,
3108 /*proto_field_id=*/348,
3109 /*size=*/24};
3110 for (Field& field : evt.fields) {
3111 SetTranslationStrategy(field.ftrace_type, field.proto_field_type,
3112 &field.strategy);
3113 }
3114 std::vector<Event> events;
3115 events.emplace_back(std::move(evt));
3116
3117 NiceMock<MockFtraceProcfs> mock_ftrace;
3118 PrintkMap printk_formats;
3119 ProtoTranslationTable translation_table(
3120 &mock_ftrace, events, std::move(common_fields),
3121 ProtoTranslationTable::DefaultPageHeaderSpecForTesting(),
3122 InvalidCompactSchedEventFormatForTesting(), printk_formats);
3123 ProtoTranslationTable* table = &translation_table;
3124
3125 FtraceDataSourceConfig ds_config = EmptyConfig();
3126 ds_config.event_filter.AddEnabledEvent(
3127 table->EventToFtraceId(GroupAndName("dpu", "tracing_mark_write")));
3128
3129 FtraceMetadata metadata{};
3130 const uint8_t* parse_pos = page.get();
3131 std::optional<CpuReader::PageHeader> page_header =
3132 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
3133
3134 const uint8_t* page_end = page.get() + base::GetSysPageSize();
3135 ASSERT_TRUE(page_header.has_value());
3136 EXPECT_FALSE(page_header->lost_events);
3137 EXPECT_LE(parse_pos + page_header->size, page_end);
3138
3139 FtraceParseStatus status = CpuReader::ParsePagePayload(
3140 parse_pos, &page_header.value(), table, &ds_config,
3141 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
3142
3143 // successfully parsed the whole 32 byte event
3144 ASSERT_EQ(32u, page_header->size);
3145 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
3146
3147 auto bundle = GetBundle();
3148 EXPECT_EQ(bundle.event().size(), 1u);
3149 const protos::gen::FtraceEvent& event = bundle.event()[0];
3150 EXPECT_EQ(event.pid(), 317u);
3151 EXPECT_EQ(event.dpu_tracing_mark_write().type(), 69u);
3152 EXPECT_EQ(event.dpu_tracing_mark_write().pid(), 0);
3153 EXPECT_EQ(event.dpu_tracing_mark_write().value(), 0);
3154 EXPECT_EQ(event.dpu_tracing_mark_write().name(), "");
3155 }
3156
3157 static ExamplePage g_zero_padded{
3158 "synthetic",
3159 R"(
3160 00000000: DBF4 87FE F901 0000 F00F 0000 0000 0000 ................
3161 00000010: 0700 0000 0500 0000 EE02 0000 50AA 4C00 ............P.L.
3162 00000020: AEFF FFFF 457C 3633 390A 0000 0000 0000 ....E|639.......
3163 00000030: E939 1300 0500 0000 EE02 0000 50AA 4C00 .9..........P.L.
3164 00000040: AEFF FFFF 427C 3633 397C 6361 6E63 656C ....B|639|cancel
3165 00000050: 2074 696D 6572 0A00 4753 0A00 0500 0000 timer..GS......
3166 00000060: EE02 0000 50AA 4C00 AEFF FFFF 457C 3633 ....P.L.....E|63
3167 00000070: 390A 0000 0000 0000 C929 0800 0500 0000 9........)......
3168 00000080: EE02 0000 50AA 4C00 AEFF FFFF 437C 3633 ....P.L.....C|63
3169 00000090: 397C 5653 594E 432D 6170 707C 310A 0000 9|VSYNC-app|1...
3170 000000A0: 2A48 0600 6500 0101 EE02 0000 6170 7000 *H..e.......app.
3171 000000B0: 6163 6566 6C69 6E67 6572 0000 EF02 0000 aceflinger......
3172 000000C0: 6100 0000 0100 0000 0200 0000 E94D 1900 a............M..
3173 000000D0: 0500 0000 EE02 0000 50AA 4C00 AEFF FFFF ........P.L.....
3174 000000E0: 437C 3633 397C 5653 502D 6D6F 6465 7C30 C|639|VSP-mode|0
3175 000000F0: 0A00 0000 0DD5 0400 0500 0000 EE02 0000 ................
3176 00000100: 50AA 4C00 AEFF FFFF 437C 3633 397C 5653 P.L.....C|639|VS
3177 00000110: 502D 7469 6D65 506F 696E 747C 3231 3733 P-timePoint|2173
3178 00000120: 3235 3939 3337 3132 360A 0000 2DF1 0300 259937126...-...
3179 00000130: 0500 0000 EE02 0000 50AA 4C00 AEFF FFFF ........P.L.....
3180 00000140: 437C 3633 397C 5653 502D 7072 6564 6963 C|639|VSP-predic
3181 00000150: 7469 6F6E 7C32 3137 3332 3736 3230 3036 tion|21732762006
3182 00000160: 3538 0A00 30B0 0600 0500 0000 EE02 0000 58..0...........
3183 00000170: 50AA 4C00 AEFF FFFF 427C 3633 397C 6170 P.L.....B|639|ap
3184 00000180: 7020 616C 6172 6D20 696E 2031 3632 3633 p alarm in 16263
3185 00000190: 7573 3B20 5653 594E 4320 696E 2034 3732 us; VSYNC in 472
3186 000001A0: 3633 7573 0A00 0000 878F 0300 0500 0000 63us............
3187 000001B0: EE02 0000 50AA 4C00 AEFF FFFF 457C 3633 ....P.L.....E|63
3188 000001C0: 390A 0000 0000 0000 3029 1B00 5B00 0102 9.......0)..[...
3189 000001D0: EE02 0000 5469 6D65 7244 6973 7061 7463 ....TimerDispatc
3190 000001E0: 6800 0000 EE02 0000 6100 0000 0100 0000 h.......a.......
3191 000001F0: 0000 0000 7377 6170 7065 722F 3500 0000 ....swapper/5...
3192 00000200: 0000 0000 0000 0000 7800 0000 10DC 4302 ........x.....C.
3193 00000210: 5B00 0102 0000 0000 7377 6170 7065 722F [.......swapper/
3194 00000220: 3500 0000 0000 0000 0000 0000 7800 0000 5...........x...
3195 00000230: 0000 0000 0000 0000 7263 756F 702F 3200 ........rcuop/2.
3196 00000240: 0000 0000 0000 0000 2000 0000 7800 0000 ........ ...x...
3197 00000250: CA71 0B00 6500 0102 2000 0000 7263 755F .q..e... ...rcu_
3198 00000260: 7072 6565 6D70 7400 0000 0000 0B00 0000 preempt.........
3199 00000270: 7800 0000 0100 0000 0300 0000 0859 0100 x............Y..
3200 00000280: 3700 0102 2000 0000 0B00 0000 0000 0000 7... ...........
3201 00000290: 6899 4200 AEFF FFFF 0000 0000 0000 0000 h.B.............
3202 000002A0: 300F 1B00 5B00 0102 2000 0000 7263 756F 0...[... ...rcuo
3203 000002B0: 702F 3200 0000 0000 0000 0000 2000 0000 p/2......... ...
3204 000002C0: 7800 0000 0100 0000 0000 0000 6E64 726F x...........ndro
3205 000002D0: 6964 2E73 7973 7465 6D75 6900 A009 0000 id.systemui.....
3206 000002E0: 7800 0000 17EC 3100 0500 0000 A009 0000 x.....1.........
3207 000002F0: 50AA 4C00 AEFF FFFF 427C 3234 3634 7C61 P.L.....B|2464|a
3208 00000300: 6E64 726F 6964 2E76 6965 772E 4163 6365 ndroid.view.Acce
3209 00000310: 7373 6962 696C 6974 7949 6E74 6572 6163 ssibilityInterac
3210 00000320: 7469 6F6E 436F 6E74 726F 6C6C 6572 2450 tionController$P
3211 00000330: 7269 7661 7465 4861 6E64 6C65 723A 2023 rivateHandler: #
3212 00000340: 320A 0000 8998 EB00 EA02 0000 A009 0000 2...............
3213 00000350: 4AD7 0C00 2697 0500 CE22 0000 0000 0000 J...&...."......
3214 00000360: 0000 0000 0100 0000 1100 0000 CA45 0400 .............E..
3215 00000370: EB02 0000 A009 0000 4AD7 0C00 0000 0000 ........J.......
3216 00000380: A402 0000 0000 0000 0000 0000 0000 0000 ................
3217 00000390: 0000 0000 0000 0000 CA6C 0400 6500 0104 .........l..e...
3218 000003A0: A009 0000 6269 6E64 6572 3A38 3931 305F ....binder:8910_
3219 000003B0: 3400 6F00 3C2C 0000 7800 0000 0100 0000 4.o.<,..x.......
3220 000003C0: 0400 0000 673C 3400 0500 0000 A009 0000 ....g<4.........
3221 000003D0: 50AA 4C00 AEFF FFFF 457C 3234 3634 0A00 P.L.....E|2464..
3222 000003E0: 0000 0000 10EF 2000 5B00 0102 A009 0000 ...... .[.......
3223 000003F0: 6E64 726F 6964 2E73 7973 7465 6D75 6900 ndroid.systemui.
3224 00000400: A009 0000 7800 0000 0100 0000 0000 0000 ....x...........
3225 00000410: 7377 6170 7065 722F 3500 0000 0000 0000 swapper/5.......
3226 00000420: 0000 0000 7800 0000 D098 ED01 5B00 0102 ....x.......[...
3227 00000430: 0000 0000 7377 6170 7065 722F 3500 0000 ....swapper/5...
3228 00000440: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
3229 00000450: 0000 0000 6E64 726F 6964 2E73 7973 7465 ....ndroid.syste
3230 00000460: 6D75 6900 A009 0000 7800 0000 F761 1F00 mui.....x....a..
3231 00000470: 0500 0000 A009 0000 50AA 4C00 AEFF FFFF ........P.L.....
3232 00000480: 427C 3234 3634 7C61 6E64 726F 6964 2E76 B|2464|android.v
3233 00000490: 6965 772E 4163 6365 7373 6962 696C 6974 iew.Accessibilit
3234 000004A0: 7949 6E74 6572 6163 7469 6F6E 436F 6E74 yInteractionCont
3235 000004B0: 726F 6C6C 6572 2450 7269 7661 7465 4861 roller$PrivateHa
3236 000004C0: 6E64 6C65 723A 2023 320A 0000 E9F6 A500 ndler: #2.......
3237 000004D0: EA02 0000 A009 0000 4ED7 0C00 2697 0500 ........N...&...
3238 000004E0: CE22 0000 0000 0000 0000 0000 0100 0000 ."..............
3239 000004F0: 1100 0000 4A3F 0400 EB02 0000 A009 0000 ....J?..........
3240 00000500: 4ED7 0C00 0000 0000 2802 0000 0000 0000 N.......(.......
3241 00000510: 0000 0000 0000 0000 0000 0000 0000 0000 ................
3242 00000520: EA93 0400 6500 0104 A009 0000 6269 6E64 ....e.......bind
3243 00000530: 6572 3A38 3931 305F 3400 6F00 3C2C 0000 er:8910_4.o.<,..
3244 00000540: 7800 0000 0100 0000 0000 0000 0AD7 3A01 x.............:.
3245 00000550: 3100 1101 A009 0000 B028 39B1 CCFF FFFF 1........(9.....
3246 00000560: A837 F9A8 ADFF FFFF 0010 39B1 CCFF FFFF .7........9.....
3247 00000570: 2000 0000 FFFF FFFF 44F5 0100 2E00 1101 .......D.......
3248 00000580: A009 0000 B028 39B1 CCFF FFFF AA79 0100 .....(9......y..
3249 00000590: 6500 1102 A009 0000 6B77 6F72 6B65 722F e.......kworker/
3250 000005A0: 7531 363A 3130 0000 6001 0000 7800 0000 u16:10..`...x...
3251 000005B0: 0100 0000 0000 0000 8845 0100 3700 1102 .........E..7...
3252 000005C0: A009 0000 6001 0000 0000 0000 7C51 3800 ....`.......|Q8.
3253 000005D0: AEFF FFFF 0000 0000 0000 0000 89DD 7300 ..............s.
3254 000005E0: EA02 0000 A009 0000 50D7 0C00 2697 0500 ........P...&...
3255 000005F0: CE22 0000 0000 0000 0000 0000 0300 0000 ."..............
3256 00000600: 1100 0000 0AD5 0400 EB02 0000 A009 0000 ................
3257 00000610: 50D7 0C00 0000 0000 A404 0000 0000 0000 P...............
3258 00000620: 0000 0000 0000 0000 0000 0000 0000 0000 ................
3259 00000630: 4A7E 0500 6500 0104 A009 0000 6269 6E64 J~..e.......bind
3260 00000640: 6572 3A38 3931 305F 3400 6F00 3C2C 0000 er:8910_4.o.<,..
3261 00000650: 7800 0000 0100 0000 0000 0000 A790 2E00 x...............
3262 00000660: 0500 0000 A009 0000 50AA 4C00 AEFF FFFF ........P.L.....
3263 00000670: 457C 3234 3634 0A00 0000 0000 9048 2800 E|2464.......H(.
3264 00000680: 5B00 0102 A009 0000 6E64 726F 6964 2E73 [.......ndroid.s
3265 00000690: 7973 7465 6D75 6900 A009 0000 7800 0000 ystemui.....x...
3266 000006A0: 0100 0000 0000 0000 7377 6170 7065 722F ........swapper/
3267 000006B0: 3500 0000 0000 0000 0000 0000 7800 0000 5...........x...
3268 000006C0: B043 2100 5B00 0102 0000 0000 7377 6170 .C!.[.......swap
3269 000006D0: 7065 722F 3500 0000 0000 0000 0000 0000 per/5...........
3270 000006E0: 7800 0000 0000 0000 0000 0000 6269 6E64 x...........bind
3271 000006F0: 6572 3A32 3436 345F 3800 6900 EF0C 0000 er:2464_8.i.....
3272 00000700: 7800 0000 834C 0700 F002 0000 EF0C 0000 x....L..........
3273 00000710: 51D7 0C00 AA4E 5D00 6500 0103 EF0C 0000 Q....N].e.......
3274 00000720: 6E64 726F 6964 2E73 7973 7465 6D75 6900 ndroid.systemui.
3275 00000730: A009 0000 7800 0000 0100 0000 0500 0000 ....x...........
3276 00000740: D05E 6800 5B00 0102 EF0C 0000 6269 6E64 .^h.[.......bind
3277 00000750: 6572 3A32 3436 345F 3800 6900 EF0C 0000 er:2464_8.i.....
3278 00000760: 7800 0000 0100 0000 0000 0000 6269 6E64 x...........bind
3279 00000770: 6572 3A31 3936 375F 4200 0000 A20B 0000 er:1967_B.......
3280 00000780: 7000 0000 67CA 0600 E902 0000 A20B 0000 p...g...........
3281 00000790: AF07 0000 A20B 0000 7000 0000 7800 0000 ........p...x...
3282 000007A0: 7800 0000 B006 3B00 5B00 0102 A20B 0000 x.....;.[.......
3283 000007B0: 6269 6E64 6572 3A31 3936 375F 4200 0000 binder:1967_B...
3284 000007C0: A20B 0000 7800 0000 0100 0000 0000 0000 ....x...........
3285 000007D0: 7377 6170 7065 722F 3500 0000 0000 0000 swapper/5.......
3286 000007E0: 0000 0000 7800 0000 108B 5603 5B00 0102 ....x.....V.[...
3287 000007F0: 0000 0000 7377 6170 7065 722F 3500 0000 ....swapper/5...
3288 00000800: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
3289 00000810: 0000 0000 6269 6E64 6572 3A32 3436 345F ....binder:2464_
3290 00000820: 3800 6900 EF0C 0000 7800 0000 831A 0600 8.i.....x.......
3291 00000830: F002 0000 EF0C 0000 56D7 0C00 AAD2 5600 ........V.....V.
3292 00000840: 6500 0103 EF0C 0000 6E64 726F 6964 2E73 e.......ndroid.s
3293 00000850: 7973 7465 6D75 6900 A009 0000 7800 0000 ystemui.....x...
3294 00000860: 0100 0000 0000 0000 B027 4100 5B00 0102 .........'A.[...
3295 00000870: EF0C 0000 6269 6E64 6572 3A32 3436 345F ....binder:2464_
3296 00000880: 3800 6900 EF0C 0000 7800 0000 0100 0000 8.i.....x.......
3297 00000890: 0000 0000 7377 6170 7065 722F 3500 0000 ....swapper/5...
3298 000008A0: 0000 0000 0000 0000 7800 0000 50F4 2A03 ........x...P.*.
3299 000008B0: 5B00 0102 0000 0000 7377 6170 7065 722F [.......swapper/
3300 000008C0: 3500 0000 0000 0000 0000 0000 7800 0000 5...........x...
3301 000008D0: 0000 0000 0000 0000 6269 6E64 6572 3A32 ........binder:2
3302 000008E0: 3436 345F 3800 6900 EF0C 0000 7800 0000 464_8.i.....x...
3303 000008F0: 831A 0600 F002 0000 EF0C 0000 5BD7 0C00 ............[...
3304 00000900: 8A08 5300 6500 0103 EF0C 0000 6E64 726F ..S.e.......ndro
3305 00000910: 6964 2E73 7973 7465 6D75 6900 A009 0000 id.systemui.....
3306 00000920: 7800 0000 0100 0000 0000 0000 B0BE 5000 x.............P.
3307 00000930: 5B00 0102 EF0C 0000 6269 6E64 6572 3A32 [.......binder:2
3308 00000940: 3436 345F 3800 6900 EF0C 0000 7800 0000 464_8.i.....x...
3309 00000950: 0100 0000 0000 0000 7377 6170 7065 722F ........swapper/
3310 00000960: 3500 0000 0000 0000 0000 0000 7800 0000 5...........x...
3311 00000970: 50A1 5A0A 5B00 0102 0000 0000 7377 6170 P.Z.[.......swap
3312 00000980: 7065 722F 3500 0000 0000 0000 0000 0000 per/5...........
3313 00000990: 7800 0000 0000 0000 0000 0000 7263 756F x...........rcuo
3314 000009A0: 702F 3200 0000 0000 0000 0000 2000 0000 p/2......... ...
3315 000009B0: 7800 0000 EA2B 0700 6500 0102 2000 0000 x....+..e... ...
3316 000009C0: 7263 756F 702F 3300 0000 0000 0000 0000 rcuop/3.........
3317 000009D0: 2800 0000 7800 0000 0100 0000 0000 0000 (...x...........
3318 000009E0: 90F9 1B00 5B00 0102 2000 0000 7263 756F ....[... ...rcuo
3319 000009F0: 702F 3200 0000 0000 0000 0000 2000 0000 p/2......... ...
3320 00000A00: 7800 0000 0100 0000 0000 0000 7377 6170 x...........swap
3321 00000A10: 7065 722F 3500 0000 0000 0000 0000 0000 per/5...........
3322 00000A20: 7800 0000 303E D509 5B00 0102 0000 0000 x...0>..[.......
3323 00000A30: 7377 6170 7065 722F 3500 0000 0000 0000 swapper/5.......
3324 00000A40: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
3325 00000A50: 6269 6E64 6572 3A32 3436 345F 3800 6900 binder:2464_8.i.
3326 00000A60: EF0C 0000 7800 0000 03AA 0900 F002 0000 ....x...........
3327 00000A70: EF0C 0000 66D7 0C00 EAFE 7F00 6500 0103 ....f.......e...
3328 00000A80: EF0C 0000 5363 7265 656E 4465 636F 7261 ....ScreenDecora
3329 00000A90: 7469 6F00 840B 0000 7800 0000 0100 0000 tio.....x.......
3330 00000AA0: 0200 0000 7028 4A00 5B00 0102 EF0C 0000 ....p(J.[.......
3331 00000AB0: 6269 6E64 6572 3A32 3436 345F 3800 6900 binder:2464_8.i.
3332 00000AC0: EF0C 0000 7800 0000 0100 0000 0000 0000 ....x...........
3333 00000AD0: 7377 6170 7065 722F 3500 0000 0000 0000 swapper/5.......
3334 00000AE0: 0000 0000 7800 0000 908D 0406 5B00 0102 ....x.......[...
3335 00000AF0: 0000 0000 7377 6170 7065 722F 3500 0000 ....swapper/5...
3336 00000B00: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
3337 00000B10: 0000 0000 6C6F 6764 2E72 6561 6465 722E ....logd.reader.
3338 00000B20: 7065 7200 5B06 0000 8200 0000 AAE6 2400 per.[.........$.
3339 00000B30: 6500 0102 5B06 0000 6C6F 6763 6174 0000 e...[...logcat..
3340 00000B40: 3000 0000 0000 0000 C105 0000 8200 0000 0...............
3341 00000B50: 0100 0000 0500 0000 90DB 2000 5B00 0102 .......... .[...
3342 00000B60: 5B06 0000 6C6F 6764 2E72 6561 6465 722E [...logd.reader.
3343 00000B70: 7065 7200 5B06 0000 8200 0000 0100 0000 per.[...........
3344 00000B80: 0000 0000 6C6F 6763 6174 0000 3000 0000 ....logcat..0...
3345 00000B90: 0000 0000 C105 0000 8200 0000 7060 6100 ............p`a.
3346 00000BA0: 5B00 0102 C105 0000 6C6F 6763 6174 0000 [.......logcat..
3347 00000BB0: 3000 0000 0000 0000 C105 0000 8200 0000 0...............
3348 00000BC0: 0100 0000 0000 0000 7377 6170 7065 722F ........swapper/
3349 00000BD0: 3500 0000 0000 0000 0000 0000 7800 0000 5...........x...
3350 00000BE0: D086 0202 5B00 0102 0000 0000 7377 6170 ....[.......swap
3351 00000BF0: 7065 722F 3500 0000 0000 0000 0000 0000 per/5...........
3352 00000C00: 7800 0000 0000 0000 0000 0000 6170 7000 x...........app.
3353 00000C10: 6163 6566 6C69 6E67 6572 0000 EF02 0000 aceflinger......
3354 00000C20: 6100 0000 2937 2700 0500 0000 EF02 0000 a...)7'.........
3355 00000C30: 50AA 4C00 AEFF FFFF 437C 3633 397C 5653 P.L.....C|639|VS
3356 00000C40: 502D 6D6F 6465 7C30 0A00 0000 8DC3 0300 P-mode|0........
3357 00000C50: 0500 0000 EF02 0000 50AA 4C00 AEFF FFFF ........P.L.....
3358 00000C60: 437C 3633 397C 5653 502D 7469 6D65 506F C|639|VSP-timePo
3359 00000C70: 696E 747C 3231 3733 3238 3530 3139 3236 int|217328501926
3360 00000C80: 340A 0000 6D43 0200 0500 0000 EF02 0000 4...mC..........
3361 00000C90: 50AA 4C00 AEFF FFFF 437C 3633 397C 5653 P.L.....C|639|VS
3362 00000CA0: 502D 7072 6564 6963 7469 6F6E 7C32 3137 P-prediction|217
3363 00000CB0: 3332 3932 3839 3739 3138 0A00 70FE 0600 3292897918..p...
3364 00000CC0: 0500 0000 EF02 0000 50AA 4C00 AEFF FFFF ........P.L.....
3365 00000CD0: 427C 3633 397C 6170 7020 616C 6172 6D20 B|639|app alarm
3366 00000CE0: 696E 2037 3837 3875 733B 2056 5359 4E43 in 7878us; VSYNC
3367 00000CF0: 2069 6E20 3338 3837 3875 730A 0000 0000 in 38878us.....
3368 00000D00: C7AD 0100 0500 0000 EF02 0000 50AA 4C00 ............P.L.
3369 00000D10: AEFF FFFF 457C 3633 390A 0000 0000 0000 ....E|639.......
3370 00000D20: 3028 2B00 5B00 0102 EF02 0000 6170 7000 0(+.[.......app.
3371 00000D30: 6163 6566 6C69 6E67 6572 0000 EF02 0000 aceflinger......
3372 00000D40: 6100 0000 0100 0000 0000 0000 6C6F 6764 a...........logd
3373 00000D50: 2E72 6561 6465 722E 7065 7200 C611 0000 .reader.per.....
3374 00000D60: 8200 0000 8AE1 1A00 6500 0102 C611 0000 ........e.......
3375 00000D70: 6C6F 6763 6174 002F 3000 0000 0000 0000 logcat./0.......
3376 00000D80: BE11 0000 7800 0000 0100 0000 0400 0000 ....x...........
3377 00000D90: 3074 0D00 5B00 0102 C611 0000 6C6F 6764 0t..[.......logd
3378 00000DA0: 2E72 6561 6465 722E 7065 7200 C611 0000 .reader.per.....
3379 00000DB0: 8200 0000 0001 0000 0000 0000 6C6F 6763 ............logc
3380 00000DC0: 6174 002F 3000 0000 0000 0000 BE11 0000 at./0...........
3381 00000DD0: 7800 0000 4A34 3B00 3100 0101 BE11 0000 x...J4;.1.......
3382 00000DE0: 08D4 FF74 CCFF FFFF 40C9 2900 AEFF FFFF ...t....@.).....
3383 00000DF0: 0044 8940 CBFF FFFF 2000 0000 FFFF FFFF .D.@.... .......
3384 00000E00: A486 0100 2E00 0101 BE11 0000 08D4 FF74 ...............t
3385 00000E10: CCFF FFFF EA17 0100 6500 0102 BE11 0000 ........e.......
3386 00000E20: 6B77 6F72 6B65 722F 7531 363A 3130 0000 kworker/u16:10..
3387 00000E30: 6001 0000 7800 0000 0100 0000 0200 0000 `...x...........
3388 00000E40: E8BC 0000 3700 0102 BE11 0000 6001 0000 ....7.......`...
3389 00000E50: 0000 0000 7C51 3800 AEFF FFFF 0000 0000 ....|Q8.........
3390 00000E60: 0000 0000 B074 1600 5B00 0102 BE11 0000 .....t..[.......
3391 00000E70: 6C6F 6763 6174 002F 3000 0000 0000 0000 logcat./0.......
3392 00000E80: BE11 0000 7800 0000 0100 0000 0000 0000 ....x...........
3393 00000E90: 6C6F 6764 2E72 6561 6465 722E 7065 7200 logd.reader.per.
3394 00000EA0: C611 0000 8200 0000 6AFA 0B00 6500 0102 ........j...e...
3395 00000EB0: C611 0000 6C6F 6763 6174 002F 3000 0000 ....logcat./0...
3396 00000EC0: 0000 0000 BE11 0000 7800 0000 0100 0000 ........x.......
3397 00000ED0: 0500 0000 7023 0800 5B00 0102 C611 0000 ....p#..[.......
3398 00000EE0: 6C6F 6764 2E72 6561 6465 722E 7065 7200 logd.reader.per.
3399 00000EF0: C611 0000 8200 0000 0001 0000 0000 0000 ................
3400 00000F00: 6C6F 6763 6174 002F 3000 0000 0000 0000 logcat./0.......
3401 00000F10: BE11 0000 7800 0000 AA6B 1100 3100 0101 ....x....k..1...
3402 00000F20: BE11 0000 08D4 FF74 CCFF FFFF 40C9 2900 .......t....@.).
3403 00000F30: AEFF FFFF 0044 8940 CBFF FFFF 2000 0000 .....D.@.... ...
3404 00000F40: FFFF FFFF 64EA 0000 2E00 0101 BE11 0000 ....d...........
3405 00000F50: 08D4 FF74 CCFF FFFF EABC 0000 6500 0102 ...t........e...
3406 00000F60: BE11 0000 6B77 6F72 6B65 722F 7531 363A ....kworker/u16:
3407 00000F70: 3130 0000 6001 0000 7800 0000 0100 0000 10..`...x.......
3408 00000F80: 0200 0000 48C3 0000 3700 0102 BE11 0000 ....H...7.......
3409 00000F90: 6001 0000 0000 0000 7C51 3800 AEFF FFFF `.......|Q8.....
3410 00000FA0: 0000 0000 0000 0000 90C4 0F00 5B00 0102 ............[...
3411 00000FB0: BE11 0000 6C6F 6763 6174 002F 3000 0000 ....logcat./0...
3412 00000FC0: 0000 0000 BE11 0000 7800 0000 0100 0000 ........x.......
3413 00000FD0: 0000 0000 6C6F 6764 2E72 6561 6465 722E ....logd.reader.
3414 00000FE0: 7065 7200 C611 0000 8200 0000 0000 0000 per.............
3415 00000FF0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
3416 )",
3417 };
3418
3419 // b/204564312: some (mostly 4.19) kernels rarely emit an invalid page, where
3420 // the header says there's valid data, but the contents are a run of zeros
3421 // (which doesn't decode to valid events per the ring buffer ABI). Confirm that
3422 // the error is reported in the ftrace event bundle.
3423 TEST_F(CpuReaderParsePagePayloadTest, InvalidZeroPaddedPage) {
3424 const ExamplePage* test_case = &g_zero_padded;
3425 ProtoTranslationTable* table = GetTable(test_case->name);
3426 auto page = PageFromXxd(test_case->data);
3427
3428 // Don't need enabled events, as the test checks that we can walk the event
3429 // headers down to the end of the page.
3430 FtraceDataSourceConfig ds_config = EmptyConfig();
3431
3432 const uint8_t* parse_pos = page.get();
3433 std::optional<CpuReader::PageHeader> page_header =
3434 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
3435
3436 const uint8_t* page_end = page.get() + base::GetSysPageSize();
3437 ASSERT_TRUE(page_header.has_value());
3438 EXPECT_FALSE(page_header->lost_events);
3439 EXPECT_LE(parse_pos + page_header->size, page_end);
3440
3441 FtraceParseStatus status = CpuReader::ParsePagePayload(
3442 parse_pos, &page_header.value(), table, &ds_config,
3443 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
3444
3445 EXPECT_EQ(0xff0u, page_header->size);
3446 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_ABI_ZERO_DATA_LENGTH);
3447
3448 EXPECT_THAT(AllTracePackets(), IsEmpty());
3449 }
3450
3451 static ExamplePage g_four_byte_commit{
3452 "synthetic",
3453 R"(
3454 00000000: 105B DA5D C100 0000 0400 0000 0000 0000 .[.]............
3455 00000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................
3456 )",
3457 };
3458
TEST_F(CpuReaderParsePagePayloadTest,InvalidHeaderLength)3459 TEST_F(CpuReaderParsePagePayloadTest, InvalidHeaderLength) {
3460 const ExamplePage* test_case = &g_four_byte_commit;
3461 ProtoTranslationTable* table = GetTable(test_case->name);
3462 auto page = PageFromXxd(test_case->data);
3463
3464 FtraceDataSourceConfig ds_config = EmptyConfig();
3465
3466 const uint8_t* parse_pos = page.get();
3467 std::optional<CpuReader::PageHeader> page_header =
3468 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
3469
3470 const uint8_t* page_end = page.get() + base::GetSysPageSize();
3471 ASSERT_TRUE(page_header.has_value());
3472 EXPECT_FALSE(page_header->lost_events);
3473 EXPECT_LE(parse_pos + page_header->size, page_end);
3474
3475 FtraceParseStatus status = CpuReader::ParsePagePayload(
3476 parse_pos, &page_header.value(), table, &ds_config,
3477 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
3478
3479 EXPECT_EQ(4u, page_header->size);
3480 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_ABI_SHORT_DATA_LENGTH);
3481
3482 EXPECT_THAT(AllTracePackets(), IsEmpty());
3483 }
3484
3485 // Kernel code:
3486 // trace_f2fs_truncate_partial_nodes(... nid = {1,2,3}, depth = 4, err = 0)
3487 //
3488 // After kernel commit 0b04d4c0542e("f2fs: Fix
3489 // f2fs_truncate_partial_nodes ftrace event")
3490 static ExamplePage g_f2fs_truncate_partial_nodes_new{
3491 "b281660544_new",
3492 R"(
3493 00000000: 1555 c3e4 cb07 0000 3c00 0000 0000 0000 .U......<.......
3494 00000010: 3e33 0b87 2700 0000 0c00 0000 7d02 0000 >3..'.......}...
3495 00000020: c638 0000 3900 e00f 0000 0000 b165 0000 .8..9........e..
3496 00000030: 0000 0000 0100 0000 0200 0000 0300 0000 ................
3497 00000040: 0400 0000 0000 0000 0000 0000 0000 0000 ................
3498 )",
3499 };
3500
TEST_F(CpuReaderParsePagePayloadTest,F2fsTruncatePartialNodesNew)3501 TEST_F(CpuReaderParsePagePayloadTest, F2fsTruncatePartialNodesNew) {
3502 const ExamplePage* test_case = &g_f2fs_truncate_partial_nodes_new;
3503
3504 ProtoTranslationTable* table = GetTable(test_case->name);
3505 auto page = PageFromXxd(test_case->data);
3506
3507 FtraceDataSourceConfig ds_config = EmptyConfig();
3508 ds_config.event_filter.AddEnabledEvent(table->EventToFtraceId(
3509 GroupAndName("f2fs", "f2fs_truncate_partial_nodes")));
3510
3511 const uint8_t* parse_pos = page.get();
3512 std::optional<CpuReader::PageHeader> page_header =
3513 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
3514
3515 const uint8_t* page_end = page.get() + base::GetSysPageSize();
3516 ASSERT_TRUE(page_header.has_value());
3517 EXPECT_FALSE(page_header->lost_events);
3518 EXPECT_LE(parse_pos + page_header->size, page_end);
3519
3520 FtraceParseStatus status = CpuReader::ParsePagePayload(
3521 parse_pos, &page_header.value(), table, &ds_config,
3522 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
3523
3524 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
3525
3526 auto bundle = GetBundle();
3527 ASSERT_THAT(bundle.event(), SizeIs(1));
3528 auto& event = bundle.event()[0];
3529 EXPECT_EQ(event.f2fs_truncate_partial_nodes().dev(), 65081u);
3530 EXPECT_EQ(event.f2fs_truncate_partial_nodes().ino(), 26033u);
3531 // This field is disabled in ftrace_proto_gen.cc
3532 EXPECT_FALSE(event.f2fs_truncate_partial_nodes().has_nid());
3533 EXPECT_EQ(event.f2fs_truncate_partial_nodes().depth(), 4);
3534 EXPECT_EQ(event.f2fs_truncate_partial_nodes().err(), 0);
3535 }
3536
3537 // Kernel code:
3538 // trace_f2fs_truncate_partial_nodes(... nid = {1,2,3}, depth = 4, err = 0)
3539 //
3540 // Before kernel commit 0b04d4c0542e("f2fs: Fix
3541 // f2fs_truncate_partial_nodes ftrace event")
3542 static ExamplePage g_f2fs_truncate_partial_nodes_old{
3543 "b281660544_old",
3544 R"(
3545 00000000: 8f90 aa0d 9e00 0000 3c00 0000 0000 0000 ........<.......
3546 00000010: 3e97 0295 0e01 0000 0c00 0000 7d02 0000 >...........}...
3547 00000020: 8021 0000 3900 e00f 0000 0000 0d66 0000 .!..9........f..
3548 00000030: 0000 0000 0100 0000 0200 0000 0300 0000 ................
3549 00000040: 0400 0000 0000 0000 0000 0000 0000 0000 ................
3550 )",
3551 };
3552
TEST_F(CpuReaderParsePagePayloadTest,F2fsTruncatePartialNodesOld)3553 TEST_F(CpuReaderParsePagePayloadTest, F2fsTruncatePartialNodesOld) {
3554 const ExamplePage* test_case = &g_f2fs_truncate_partial_nodes_old;
3555
3556 ProtoTranslationTable* table = GetTable(test_case->name);
3557 auto page = PageFromXxd(test_case->data);
3558
3559 FtraceDataSourceConfig ds_config = EmptyConfig();
3560 auto id = table->EventToFtraceId(
3561 GroupAndName("f2fs", "f2fs_truncate_partial_nodes"));
3562 PERFETTO_LOG("Enabling: %zu", id);
3563 ds_config.event_filter.AddEnabledEvent(id);
3564
3565 const uint8_t* parse_pos = page.get();
3566 std::optional<CpuReader::PageHeader> page_header =
3567 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
3568
3569 const uint8_t* page_end = page.get() + base::GetSysPageSize();
3570 ASSERT_TRUE(page_header.has_value());
3571 EXPECT_FALSE(page_header->lost_events);
3572 EXPECT_LE(parse_pos + page_header->size, page_end);
3573
3574 FtraceParseStatus status = CpuReader::ParsePagePayload(
3575 parse_pos, &page_header.value(), table, &ds_config,
3576 CreateBundler(ds_config), &metadata_, &last_read_event_ts_);
3577
3578 EXPECT_EQ(status, FtraceParseStatus::FTRACE_STATUS_OK);
3579
3580 auto bundle = GetBundle();
3581 ASSERT_THAT(bundle.event(), SizeIs(1));
3582 auto& event = bundle.event()[0];
3583 EXPECT_EQ(event.f2fs_truncate_partial_nodes().dev(), 65081u);
3584 EXPECT_EQ(event.f2fs_truncate_partial_nodes().ino(), 26125u);
3585 // This field is disabled in ftrace_proto_gen.cc
3586 EXPECT_FALSE(event.f2fs_truncate_partial_nodes().has_nid());
3587 // Due to a kernel bug, nid[1] is parsed as depth.
3588 EXPECT_EQ(event.f2fs_truncate_partial_nodes().depth(), 2);
3589 // Due to a kernel bug, nid[2] is parsed as err.
3590 EXPECT_EQ(event.f2fs_truncate_partial_nodes().err(), 3);
3591 }
3592
3593 // one print
3594 char g_last_ts_test_page_0[] = R"(
3595 00000000: cd79 fb3a 2fa4 0400 2c00 0000 0000 0000 .y.:/...,.......
3596 00000010: 7eb6 e5eb 8f11 0000 0800 0000 0500 0000 ~...............
3597 00000020: 1e83 1400 42ab e0af ffff ffff 6669 7273 ....B.......firs
3598 00000030: 745f 7072 696e 740a 0000 0000 0000 0000 t_print.........
3599 )";
3600
3601 // one print
3602 char g_last_ts_test_page_1[] = R"(
3603 00000000: 3c11 d579 99a5 0400 2c00 0000 0000 0000 <..y....,.......
3604 00000010: 3ed1 6315 3701 0000 0800 0000 0500 0000 >.c.7...........
3605 00000020: 9e8c 1400 42ab e0af ffff ffff 7365 636f ....B.......seco
3606 00000030: 6e64 5f70 7269 6e74 0a00 0000 0000 0000 nd_print........
3607 )";
3608
3609 // data loss marker ("since last read") + multiple sched_switch + one print
3610 char g_last_ts_test_page_2[] = R"(
3611 00000000: 8ac6 cb70 a8a5 0400 4c02 0080 ffff ffff ...p....L.......
3612 00000010: 1000 0000 4701 0102 01b1 0f00 636f 6465 ....G.......code
3613 00000020: 0000 0000 0000 0000 0000 0000 01b1 0f00 ................
3614 00000030: 7800 0000 0100 0000 0000 0000 7377 6170 x...........swap
3615 00000040: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
3616 00000050: 7800 0000 b0e3 f602 4701 0102 0000 0000 x.......G.......
3617 00000060: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
3618 00000070: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
3619 00000080: 6b77 6f72 6b65 722f 303a 3500 0000 0000 kworker/0:5.....
3620 00000090: ac85 1400 7800 0000 1002 0300 4701 0102 ....x.......G...
3621 000000a0: ac85 1400 6b77 6f72 6b65 722f 303a 3500 ....kworker/0:5.
3622 000000b0: 0000 0000 ac85 1400 7800 0000 8000 0000 ........x.......
3623 000000c0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
3624 000000d0: 0000 0000 0000 0000 7800 0000 f086 7106 ........x.....q.
3625 000000e0: 4701 0102 0000 0000 7377 6170 7065 722f G.......swapper/
3626 000000f0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
3627 00000100: 0000 0000 0000 0000 6f62 6e6f 2d64 6573 ........obno-des
3628 00000110: 6b74 6f70 2d6e 6f00 d513 0000 7800 0000 ktop-no.....x...
3629 00000120: 3013 1000 4701 0102 d513 0000 6f62 6e6f 0...G.......obno
3630 00000130: 2d64 6573 6b74 6f70 2d6e 6f00 d513 0000 -desktop-no.....
3631 00000140: 7800 0000 0100 0000 0000 0000 7377 6170 x...........swap
3632 00000150: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
3633 00000160: 7800 0000 10b0 2703 4701 0102 0000 0000 x.....'.G.......
3634 00000170: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
3635 00000180: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
3636 00000190: 6b77 6f72 6b65 722f 303a 3500 0000 0000 kworker/0:5.....
3637 000001a0: ac85 1400 7800 0000 70e7 0200 4701 0102 ....x...p...G...
3638 000001b0: ac85 1400 6b77 6f72 6b65 722f 303a 3500 ....kworker/0:5.
3639 000001c0: 0000 0000 ac85 1400 7800 0000 8000 0000 ........x.......
3640 000001d0: 0000 0000 6b73 6f66 7469 7271 642f 3000 ....ksoftirqd/0.
3641 000001e0: 0000 0000 0f00 0000 7800 0000 10a4 0200 ........x.......
3642 000001f0: 4701 0102 0f00 0000 6b73 6f66 7469 7271 G.......ksoftirq
3643 00000200: 642f 3000 0000 0000 0f00 0000 7800 0000 d/0.........x...
3644 00000210: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
3645 00000220: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
3646 00000230: fef2 0a4d 7500 0000 0800 0000 0500 0000 ...Mu...........
3647 00000240: 1a8d 1400 42ab e0af ffff ffff 7468 6972 ....B.......thir
3648 00000250: 645f 7072 696e 740a 0000 0000 0000 0000 d_print.........
3649 )";
3650
3651 // Tests that |previous_bundle_end_timestamp| is correctly updated in cases
3652 // where a single ProcessPagesForDataSource call produces multiple ftrace bundle
3653 // packets (due to splitting on data loss markers).
TEST(CpuReaderTest,LastReadEventTimestampWithSplitBundles)3654 TEST(CpuReaderTest, LastReadEventTimestampWithSplitBundles) {
3655 // build test buffer with 3 pages
3656 ProtoTranslationTable* table = GetTable("synthetic");
3657 std::vector<std::unique_ptr<uint8_t[]>> test_pages;
3658 test_pages.emplace_back(PageFromXxd(g_last_ts_test_page_0));
3659 test_pages.emplace_back(PageFromXxd(g_last_ts_test_page_1));
3660 test_pages.emplace_back(PageFromXxd(g_last_ts_test_page_2));
3661 size_t num_pages = test_pages.size();
3662 size_t page_sz = base::GetSysPageSize();
3663 auto buf = std::make_unique<uint8_t[]>(page_sz * num_pages);
3664 for (size_t i = 0; i < num_pages; i++) {
3665 void* dest = buf.get() + (i * page_sz);
3666 memcpy(dest, static_cast<const void*>(test_pages[i].get()), page_sz);
3667 }
3668
3669 // build cfg requesting ftrace/print
3670 auto compact_sched_buf = std::make_unique<CompactSchedBuffer>();
3671 FtraceMetadata metadata{};
3672 FtraceDataSourceConfig ftrace_cfg = EmptyConfig();
3673 ftrace_cfg.event_filter.AddEnabledEvent(
3674 table->EventToFtraceId(GroupAndName("ftrace", "print")));
3675
3676 // invoke ProcessPagesForDataSource
3677 TraceWriterForTesting trace_writer;
3678 base::FlatSet<protos::pbzero::FtraceParseStatus> parse_errors;
3679 uint64_t last_read_event_ts = 0;
3680 bool success = CpuReader::ProcessPagesForDataSource(
3681 &trace_writer, &metadata, /*cpu=*/0, &ftrace_cfg, &parse_errors,
3682 &last_read_event_ts, buf.get(), num_pages, compact_sched_buf.get(), table,
3683 /*symbolizer=*/nullptr,
3684 /*ftrace_clock_snapshot=*/nullptr,
3685 protos::pbzero::FTRACE_CLOCK_UNSPECIFIED);
3686
3687 EXPECT_TRUE(success);
3688
3689 // We've read three pages, one print event on each. There is a data loss
3690 // marker on the third page, indicating that the kernel overwrote events
3691 // between 2nd and 3rd page (imagine our daemon getting cpu starved between
3692 // those reads).
3693 //
3694 // Therefore we expect two bundles, as we start a new one whenever we
3695 // encounter data loss (to set the |lost_events| field in the bundle proto).
3696 //
3697 // In terms of |previous_bundle_end_timestamp|, the first bundle will emit
3698 // zero since that's our initial input. The second bundle needs to emit the
3699 // timestamp of the last event in the first bundle.
3700 auto packets = trace_writer.GetAllTracePackets();
3701 ASSERT_EQ(2u, packets.size());
3702
3703 // 2 prints
3704 auto const& first_bundle = packets[0].ftrace_events();
3705 EXPECT_FALSE(first_bundle.lost_events());
3706 ASSERT_EQ(2u, first_bundle.event().size());
3707 EXPECT_TRUE(first_bundle.has_previous_bundle_end_timestamp());
3708 EXPECT_EQ(0u, first_bundle.previous_bundle_end_timestamp());
3709
3710 const uint64_t kSecondPrintTs = 1308020252356549ULL;
3711 EXPECT_EQ(kSecondPrintTs, first_bundle.event()[1].timestamp());
3712 EXPECT_EQ(0u, first_bundle.previous_bundle_end_timestamp());
3713
3714 // 1 print + lost_events + updated previous_bundle_end_timestamp
3715 auto const& second_bundle = packets[1].ftrace_events();
3716 EXPECT_TRUE(second_bundle.lost_events());
3717 EXPECT_EQ(1u, second_bundle.event().size());
3718 EXPECT_EQ(kSecondPrintTs, second_bundle.previous_bundle_end_timestamp());
3719 }
3720
3721 } // namespace
3722 } // namespace perfetto
3723