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
22 #include "perfetto/base/build_config.h"
23 #include "perfetto/ext/base/utils.h"
24 #include "perfetto/protozero/proto_utils.h"
25 #include "perfetto/protozero/scattered_heap_buffer.h"
26 #include "perfetto/protozero/scattered_stream_writer.h"
27 #include "src/traced/probes/ftrace/event_info.h"
28 #include "src/traced/probes/ftrace/ftrace_config_muxer.h"
29 #include "src/traced/probes/ftrace/ftrace_procfs.h"
30 #include "src/traced/probes/ftrace/proto_translation_table.h"
31 #include "src/traced/probes/ftrace/test/cpu_reader_support.h"
32 #include "src/tracing/core/trace_writer_for_testing.h"
33 #include "test/gtest_and_gmock.h"
34
35 #include "protos/perfetto/trace/ftrace/dpu.gen.h"
36 #include "protos/perfetto/trace/ftrace/ftrace.gen.h"
37 #include "protos/perfetto/trace/ftrace/ftrace_event.gen.h"
38 #include "protos/perfetto/trace/ftrace/ftrace_event.pbzero.h"
39 #include "protos/perfetto/trace/ftrace/ftrace_event_bundle.gen.h"
40 #include "protos/perfetto/trace/ftrace/ftrace_event_bundle.pbzero.h"
41 #include "protos/perfetto/trace/ftrace/power.gen.h"
42 #include "protos/perfetto/trace/ftrace/sched.gen.h"
43 #include "protos/perfetto/trace/ftrace/task.gen.h"
44 #include "protos/perfetto/trace/trace_packet.gen.h"
45 #include "src/traced/probes/ftrace/test/test_messages.gen.h"
46 #include "src/traced/probes/ftrace/test/test_messages.pbzero.h"
47
48 using protozero::proto_utils::ProtoSchemaType;
49 using testing::_;
50 using testing::AnyNumber;
51 using testing::Contains;
52 using testing::Each;
53 using testing::ElementsAre;
54 using testing::ElementsAreArray;
55 using testing::EndsWith;
56 using testing::Eq;
57 using testing::NiceMock;
58 using testing::Pair;
59 using testing::Return;
60 using testing::StartsWith;
61
62 namespace perfetto {
63
64 namespace {
65
EmptyConfig()66 FtraceDataSourceConfig EmptyConfig() {
67 return FtraceDataSourceConfig{EventFilter{},
68 DisabledCompactSchedConfigForTesting(),
69 {},
70 {},
71 false /*symbolize_ksyms*/};
72 }
73
74 constexpr uint64_t kNanoInSecond = 1000 * 1000 * 1000;
75 constexpr uint64_t kNanoInMicro = 1000;
76
WithinOneMicrosecond(uint64_t actual_ns,uint64_t expected_s,uint64_t expected_us)77 ::testing::AssertionResult WithinOneMicrosecond(uint64_t actual_ns,
78 uint64_t expected_s,
79 uint64_t expected_us) {
80 // Round to closest us.
81 uint64_t actual_us = (actual_ns + kNanoInMicro / 2) / kNanoInMicro;
82 uint64_t total_expected_us = expected_s * 1000 * 1000 + expected_us;
83 if (actual_us == total_expected_us)
84 return ::testing::AssertionSuccess();
85
86 return ::testing::AssertionFailure()
87 << actual_ns / kNanoInSecond << "."
88 << (actual_ns % kNanoInSecond) / kNanoInMicro << " vs. " << expected_s
89 << "." << expected_us;
90 }
91
92 class MockFtraceProcfs : public FtraceProcfs {
93 public:
MockFtraceProcfs()94 MockFtraceProcfs() : FtraceProcfs("/root/") {
95 ON_CALL(*this, NumberOfCpus()).WillByDefault(Return(1));
96 ON_CALL(*this, WriteToFile(_, _)).WillByDefault(Return(true));
97 ON_CALL(*this, ClearFile(_)).WillByDefault(Return(true));
98 EXPECT_CALL(*this, NumberOfCpus()).Times(AnyNumber());
99 }
100
101 MOCK_METHOD2(WriteToFile,
102 bool(const std::string& path, const std::string& str));
103 MOCK_METHOD1(ReadOneCharFromFile, char(const std::string& path));
104 MOCK_METHOD1(ClearFile, bool(const std::string& path));
105 MOCK_CONST_METHOD1(ReadFileIntoString, std::string(const std::string& path));
106 MOCK_CONST_METHOD0(NumberOfCpus, size_t());
107 };
108
109 class CpuReaderTableTest : public ::testing::Test {
110 protected:
111 NiceMock<MockFtraceProcfs> ftrace_;
112 };
113
114 // Single class to manage the whole protozero -> scattered stream -> chunks ->
115 // single buffer -> real proto dance. Has a method: writer() to get an
116 // protozero ftrace bundle writer and a method ParseProto() to attempt to
117 // parse whatever has been written so far into a proto message.
118 template <class ZeroT, class ProtoT>
119 class ProtoProvider {
120 public:
ProtoProvider(size_t chunk_size)121 explicit ProtoProvider(size_t chunk_size) : chunk_size_(chunk_size) {}
122 ~ProtoProvider() = default;
123
writer()124 ZeroT* writer() { return writer_.get(); }
ResetWriter()125 void ResetWriter() { writer_.Reset(); }
126
127 // Stitch together the scattered chunks into a single buffer then attempt
128 // to parse the buffer as a FtraceEventBundle. Returns the FtraceEventBundle
129 // on success and nullptr on failure.
ParseProto()130 std::unique_ptr<ProtoT> ParseProto() {
131 auto bundle = std::unique_ptr<ProtoT>(new ProtoT());
132 std::vector<uint8_t> buffer = writer_.SerializeAsArray();
133 if (!bundle->ParseFromArray(buffer.data(), buffer.size()))
134 return nullptr;
135 return bundle;
136 }
137
138 private:
139 ProtoProvider(const ProtoProvider&) = delete;
140 ProtoProvider& operator=(const ProtoProvider&) = delete;
141
142 size_t chunk_size_;
143 protozero::HeapBuffered<ZeroT> writer_;
144 };
145
146 using BundleProvider = ProtoProvider<protos::pbzero::FtraceEventBundle,
147 protos::gen::FtraceEventBundle>;
148
149 class BinaryWriter {
150 public:
BinaryWriter()151 BinaryWriter()
152 : size_(base::kPageSize), page_(new uint8_t[size_]), ptr_(page_.get()) {}
153
154 template <typename T>
Write(T t)155 void Write(T t) {
156 memcpy(ptr_, &t, sizeof(T));
157 ptr_ += sizeof(T);
158 PERFETTO_CHECK(ptr_ < ptr_ + size_);
159 }
160
WriteFixedString(size_t n,const char * s)161 void WriteFixedString(size_t n, const char* s) {
162 size_t length = strlen(s);
163 PERFETTO_CHECK(length < n);
164 char c;
165 while ((c = *s++)) {
166 Write<char>(c);
167 }
168 Write<char>('\0');
169 for (size_t i = 0; i < n - length - 1; i++) {
170 Write<char>('\xff');
171 }
172 }
173
GetCopy()174 std::unique_ptr<uint8_t[]> GetCopy() {
175 std::unique_ptr<uint8_t[]> buffer(new uint8_t[written()]);
176 memcpy(buffer.get(), page_.get(), written());
177 return buffer;
178 }
179
written()180 size_t written() { return static_cast<size_t>(ptr_ - page_.get()); }
181
182 private:
183 size_t size_;
184 std::unique_ptr<uint8_t[]> page_;
185 uint8_t* ptr_;
186 };
187
188 } // namespace
189
TEST(PageFromXxdTest,OneLine)190 TEST(PageFromXxdTest, OneLine) {
191 std::string text = R"(
192 00000000: 0000 0000 0000 0000 0000 0000 0000 0000 ................
193 00000000: 0000 0000 5600 0000 0000 0000 0000 0000 ................
194 )";
195 auto page = PageFromXxd(text);
196 EXPECT_EQ(page.get()[0x14], 0x56);
197 }
198
TEST(PageFromXxdTest,ManyLines)199 TEST(PageFromXxdTest, ManyLines) {
200 std::string text = R"(
201 00000000: 1234 0000 0000 0000 0000 0000 0000 0056 ................
202 00000010: 7800 0000 0000 0000 0000 0000 0000 009a ................
203 00000020: 0000 0000 bc00 0000 00de 0000 0000 009a ................
204 )";
205 auto page = PageFromXxd(text);
206 EXPECT_EQ(page.get()[0x00], 0x12);
207 EXPECT_EQ(page.get()[0x01], 0x34);
208 EXPECT_EQ(page.get()[0x0f], 0x56);
209 EXPECT_EQ(page.get()[0x10], 0x78);
210 EXPECT_EQ(page.get()[0x1f], 0x9a);
211 EXPECT_EQ(page.get()[0x24], 0xbc);
212 EXPECT_EQ(page.get()[0x29], 0xde);
213 }
214
TEST(CpuReaderTest,BinaryWriter)215 TEST(CpuReaderTest, BinaryWriter) {
216 BinaryWriter writer;
217 writer.Write<uint64_t>(1);
218 writer.Write<uint32_t>(2);
219 writer.Write<uint16_t>(3);
220 writer.Write<uint8_t>(4);
221 auto buffer = writer.GetCopy();
222 EXPECT_EQ(buffer.get()[0], 1);
223 EXPECT_EQ(buffer.get()[1], 0);
224 EXPECT_EQ(buffer.get()[2], 0);
225 EXPECT_EQ(buffer.get()[3], 0);
226 EXPECT_EQ(buffer.get()[4], 0);
227 EXPECT_EQ(buffer.get()[5], 0);
228 EXPECT_EQ(buffer.get()[6], 0);
229 EXPECT_EQ(buffer.get()[7], 0);
230 EXPECT_EQ(buffer.get()[8], 2);
231 }
232
TEST(ReadAndAdvanceTest,Number)233 TEST(ReadAndAdvanceTest, Number) {
234 uint64_t expected = 42;
235 uint64_t actual = 0;
236 uint8_t buffer[8] = {};
237 const uint8_t* start = buffer;
238 const uint8_t* ptr = buffer;
239 memcpy(&buffer, &expected, 8);
240 EXPECT_TRUE(CpuReader::ReadAndAdvance<uint64_t>(&ptr, ptr + 8, &actual));
241 EXPECT_EQ(ptr, start + 8);
242 EXPECT_EQ(actual, expected);
243 }
244
TEST(ReadAndAdvanceTest,PlainStruct)245 TEST(ReadAndAdvanceTest, PlainStruct) {
246 struct PlainStruct {
247 uint64_t timestamp;
248 uint64_t length;
249 };
250
251 uint64_t expected[2] = {42, 999};
252 PlainStruct actual;
253 uint8_t buffer[16] = {};
254 const uint8_t* start = buffer;
255 const uint8_t* ptr = buffer;
256 memcpy(&buffer, &expected, 16);
257 EXPECT_TRUE(CpuReader::ReadAndAdvance<PlainStruct>(&ptr, ptr + 16, &actual));
258 EXPECT_EQ(ptr, start + 16);
259 EXPECT_EQ(actual.timestamp, 42ul);
260 EXPECT_EQ(actual.length, 999ul);
261 }
262
TEST(ReadAndAdvanceTest,ComplexStruct)263 TEST(ReadAndAdvanceTest, ComplexStruct) {
264 struct ComplexStruct {
265 uint64_t timestamp;
266 uint32_t length;
267 uint32_t : 24;
268 uint32_t overwrite : 8;
269 };
270
271 uint64_t expected[2] = {42, 0xcdffffffabababab};
272 ComplexStruct actual = {};
273 uint8_t buffer[16] = {};
274 const uint8_t* start = buffer;
275 const uint8_t* ptr = buffer;
276 memcpy(&buffer, &expected, 16);
277 EXPECT_TRUE(
278 CpuReader::ReadAndAdvance<ComplexStruct>(&ptr, ptr + 16, &actual));
279 EXPECT_EQ(ptr, start + 16);
280 EXPECT_EQ(actual.timestamp, 42ul);
281 EXPECT_EQ(actual.length, 0xabababab);
282 EXPECT_EQ(actual.overwrite, 0xCDu);
283 }
284
TEST(ReadAndAdvanceTest,Overruns)285 TEST(ReadAndAdvanceTest, Overruns) {
286 uint64_t result = 42;
287 uint8_t buffer[7] = {};
288 const uint8_t* start = buffer;
289 const uint8_t* ptr = buffer;
290 EXPECT_FALSE(CpuReader::ReadAndAdvance<uint64_t>(&ptr, ptr + 7, &result));
291 EXPECT_EQ(ptr, start);
292 EXPECT_EQ(result, 42ul);
293 }
294
TEST(ReadAndAdvanceTest,AtEnd)295 TEST(ReadAndAdvanceTest, AtEnd) {
296 uint8_t result = 42;
297 uint8_t buffer[8] = {};
298 const uint8_t* start = buffer;
299 const uint8_t* ptr = buffer;
300 EXPECT_FALSE(CpuReader::ReadAndAdvance<uint8_t>(&ptr, ptr, &result));
301 EXPECT_EQ(ptr, start);
302 EXPECT_EQ(result, 42);
303 }
304
TEST(ReadAndAdvanceTest,Underruns)305 TEST(ReadAndAdvanceTest, Underruns) {
306 uint64_t expected = 42;
307 uint64_t actual = 0;
308 uint8_t buffer[9] = {};
309 const uint8_t* start = buffer;
310 const uint8_t* ptr = buffer;
311 memcpy(&buffer, &expected, 8);
312 EXPECT_TRUE(CpuReader::ReadAndAdvance<uint64_t>(&ptr, ptr + 8, &actual));
313 EXPECT_EQ(ptr, start + 8);
314 EXPECT_EQ(actual, expected);
315 }
316
TEST(ParsePageHeaderTest,WithOverrun)317 TEST(ParsePageHeaderTest, WithOverrun) {
318 std::string text = R"(
319 00000000: 3ef3 db77 67a2 0100 f00f 0080 ffff ffff
320 )";
321 auto page = PageFromXxd(text);
322
323 // parse as if we're on a 32 bit kernel (4 byte "commit" field)
324 {
325 const uint8_t* ptr = page.get();
326 auto ret = CpuReader::ParsePageHeader(&ptr, 4u);
327 ASSERT_TRUE(ret.has_value());
328 CpuReader::PageHeader parsed = ret.value();
329
330 ASSERT_EQ(parsed.timestamp, 0x0001A26777DBF33Eull); // first 8 bytes
331 ASSERT_EQ(parsed.size, 0x0ff0u); // 4080
332 ASSERT_TRUE(parsed.lost_events);
333
334 // pointer advanced past the header (8+4 bytes)
335 ASSERT_EQ(ptr, page.get() + 12);
336 }
337
338 // parse as if we're on a 64 bit kernel (8 byte "commit" field)
339 {
340 const uint8_t* ptr = page.get();
341 auto ret = CpuReader::ParsePageHeader(&ptr, 8u);
342 ASSERT_TRUE(ret.has_value());
343 CpuReader::PageHeader parsed = ret.value();
344
345 ASSERT_EQ(parsed.timestamp, 0x0001A26777DBF33Eull); // first 8 bytes
346 ASSERT_EQ(parsed.size, 0x0ff0u); // 4080
347 ASSERT_TRUE(parsed.lost_events);
348
349 // pointer advanced past the header (8+8 bytes)
350 ASSERT_EQ(ptr, page.get() + 16);
351 }
352 }
353
354 // clang-format off
355 // # tracer: nop
356 // #
357 // # entries-in-buffer/entries-written: 1/1 #P:8
358 // #
359 // # _-----=> irqs-off
360 // # / _----=> need-resched
361 // # | / _---=> hardirq/softirq
362 // # || / _--=> preempt-depth
363 // # ||| / delay
364 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
365 // # | | | |||| | |
366 // sh-28712 [000] ...1 608934.535199: tracing_mark_write: Hello, world!
367 // clang-format on
368
369 static ExamplePage g_single_print{
370 "synthetic",
371 R"(
372 00000000: ba12 6a33 c628 0200 2c00 0000 0000 0000 ..j3.(..,.......
373 00000010: def0 ec67 8d21 0000 0800 0000 0500 0001 ...g.!..........
374 00000020: 2870 0000 ac5d 1661 86ff ffff 4865 6c6c (p...].a....Hell
375 00000030: 6f2c 2077 6f72 6c64 210a 00ff 0000 0000 o, world!.......
376 )",
377 };
378
TEST(CpuReaderTest,ParseSinglePrint)379 TEST(CpuReaderTest, ParseSinglePrint) {
380 const ExamplePage* test_case = &g_single_print;
381
382 BundleProvider bundle_provider(base::kPageSize);
383 ProtoTranslationTable* table = GetTable(test_case->name);
384 auto page = PageFromXxd(test_case->data);
385
386 FtraceDataSourceConfig ds_config = EmptyConfig();
387 ds_config.event_filter.AddEnabledEvent(
388 table->EventToFtraceId(GroupAndName("ftrace", "print")));
389
390 FtraceMetadata metadata{};
391 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
392 const uint8_t* parse_pos = page.get();
393 base::Optional<CpuReader::PageHeader> page_header =
394 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
395
396 const uint8_t* page_end = page.get() + base::kPageSize;
397 ASSERT_TRUE(page_header.has_value());
398 EXPECT_EQ(44ul, page_header->size);
399 EXPECT_FALSE(page_header->lost_events);
400 EXPECT_TRUE(parse_pos < page_end);
401 EXPECT_TRUE(parse_pos + page_header->size < page_end);
402
403 size_t evt_bytes = CpuReader::ParsePagePayload(
404 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
405 bundle_provider.writer(), &metadata);
406
407 EXPECT_EQ(evt_bytes, 44ul);
408
409 auto bundle = bundle_provider.ParseProto();
410 ASSERT_TRUE(bundle);
411 ASSERT_EQ(bundle->event().size(), 1u);
412 const protos::gen::FtraceEvent& event = bundle->event()[0];
413 EXPECT_EQ(event.pid(), 28712ul);
414 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 608934, 535199));
415 EXPECT_EQ(event.print().buf(), "Hello, world!\n");
416 }
417
418 // clang-format off
419 // # tracer: nop
420 // #
421 // # entries-in-buffer/entries-written: 2/2 #P:8
422 // #
423 // # _-----=> irqs-off
424 // # / _----=> need-resched
425 // # | / _---=> hardirq/softirq
426 // # || / _--=> preempt-depth
427 // # ||| / delay
428 // # TASK-PID TGID CPU# |||| TIMESTAMP FUNCTION
429 // # | | | | |||| | |
430 // echo-6908 ( 6908) [000] ...1 282762.884473: tracing_mark_write: qwertyuiopqwrtyuiopqwertyuiopqwertyuiopqwer[...]
431 // echo-6908 ( 6908) [000] ...1 282762.884492: tracing_mark_write:
432 // clang-format on
433
434 static ExamplePage g_really_long_event{
435 "synthetic",
436 R"(
437 00000000: 6be0 48dd 2b01 0100 e403 0000 0000 0000 k.H.+...........
438 00000010: 1e00 0000 0000 0000 0000 0000 c003 0000 ................
439 00000020: 0500 0001 fc1a 0000 4096 3615 9cff ffff ........@.6.....
440 00000030: 7177 6572 7479 7569 6f70 7177 7274 7975 qwertyuiopqwrtyu
441 00000040: 696f 7071 7765 7274 7975 696f 7071 7765 iopqwertyuiopqwe
442 00000050: 7274 7975 696f 7071 7765 7274 7975 696f rtyuiopqwertyuio
443 00000060: 7071 7772 7479 7569 6f70 7177 6572 7479 pqwrtyuiopqwerty
444 00000070: 7569 6f70 7177 6572 7479 7569 6f71 7765 uiopqwertyuioqwe
445 00000080: 7274 7975 696f 7071 7772 7479 7569 6f70 rtyuiopqwrtyuiop
446 00000090: 7177 6572 7479 7569 6f70 7177 6572 7479 qwertyuiopqwerty
447 000000a0: 7569 6f71 7765 7274 7975 696f 7071 7772 uioqwertyuiopqwr
448 000000b0: 7479 7569 6f70 7177 6572 7479 7569 6f70 tyuiopqwertyuiop
449 000000c0: 7177 6572 7479 7569 6f70 7070 7177 6572 qwertyuiopppqwer
450 000000d0: 7479 7569 6f70 7177 7274 7975 696f 7071 tyuiopqwrtyuiopq
451 000000e0: 7765 7274 7975 696f 7071 7765 7274 7975 wertyuiopqwertyu
452 000000f0: 696f 7071 7765 7274 7975 696f 7071 7772 iopqwertyuiopqwr
453 00000100: 7479 7569 6f70 7177 6572 7479 7569 6f70 tyuiopqwertyuiop
454 00000110: 7177 6572 7479 7569 6f71 7765 7274 7975 qwertyuioqwertyu
455 00000120: 696f 7071 7772 7479 7569 6f70 7177 6572 iopqwrtyuiopqwer
456 00000130: 7479 7569 6f70 7177 6572 7479 7569 6f71 tyuiopqwertyuioq
457 00000140: 7765 7274 7975 696f 7071 7772 7479 7569 wertyuiopqwrtyui
458 00000150: 6f70 7177 6572 7479 7569 6f70 7177 6572 opqwertyuiopqwer
459 00000160: 7479 7569 6f70 7070 7177 6572 7479 7569 tyuiopppqwertyui
460 00000170: 6f70 7177 7274 7975 696f 7071 7765 7274 opqwrtyuiopqwert
461 00000180: 7975 696f 7071 7765 7274 7975 696f 7071 yuiopqwertyuiopq
462 00000190: 7765 7274 7975 696f 7071 7772 7479 7569 wertyuiopqwrtyui
463 000001a0: 6f70 7177 6572 7479 7569 6f70 7177 6572 opqwertyuiopqwer
464 000001b0: 7479 7569 6f71 7765 7274 7975 696f 7071 tyuioqwertyuiopq
465 000001c0: 7772 7479 7569 6f70 7177 6572 7479 7569 wrtyuiopqwertyui
466 000001d0: 6f70 7177 6572 7479 7569 6f71 7765 7274 opqwertyuioqwert
467 000001e0: 7975 696f 7071 7772 7479 7569 6f70 7177 yuiopqwrtyuiopqw
468 000001f0: 6572 7479 7569 6f70 7177 6572 7479 7569 ertyuiopqwertyui
469 00000200: 6f70 7070 7177 6572 7479 7569 6f70 7177 opppqwertyuiopqw
470 00000210: 7274 7975 696f 7071 7765 7274 7975 696f rtyuiopqwertyuio
471 00000220: 7071 7765 7274 7975 696f 7071 7765 7274 pqwertyuiopqwert
472 00000230: 7975 696f 7071 7772 7479 7569 6f70 7177 yuiopqwrtyuiopqw
473 00000240: 6572 7479 7569 6f70 7177 6572 7479 7569 ertyuiopqwertyui
474 00000250: 6f71 7765 7274 7975 696f 7071 7772 7479 oqwertyuiopqwrty
475 00000260: 7569 6f70 7177 6572 7479 7569 6f70 7177 uiopqwertyuiopqw
476 00000270: 6572 7479 7569 6f71 7765 7274 7975 696f ertyuioqwertyuio
477 00000280: 7071 7772 7479 7569 6f70 7177 6572 7479 pqwrtyuiopqwerty
478 00000290: 7569 6f70 7177 6572 7479 7569 6f70 7070 uiopqwertyuioppp
479 000002a0: 7177 6572 7479 7569 6f70 7177 7274 7975 qwertyuiopqwrtyu
480 000002b0: 696f 7071 7765 7274 7975 696f 7071 7765 iopqwertyuiopqwe
481 000002c0: 7274 7975 696f 7071 7765 7274 7975 696f rtyuiopqwertyuio
482 000002d0: 7071 7772 7479 7569 6f70 7177 6572 7479 pqwrtyuiopqwerty
483 000002e0: 7569 6f70 7177 6572 7479 7569 6f71 7765 uiopqwertyuioqwe
484 000002f0: 7274 7975 696f 7071 7772 7479 7569 6f70 rtyuiopqwrtyuiop
485 00000300: 7177 6572 7479 7569 6f70 7177 6572 7479 qwertyuiopqwerty
486 00000310: 7569 6f71 7765 7274 7975 696f 7071 7772 uioqwertyuiopqwr
487 00000320: 7479 7569 6f70 7177 6572 7479 7569 6f70 tyuiopqwertyuiop
488 00000330: 7177 6572 7479 7569 6f70 7070 7177 6572 qwertyuiopppqwer
489 00000340: 7479 7569 6f70 7177 7274 7975 696f 7071 tyuiopqwrtyuiopq
490 00000350: 7765 7274 7975 696f 7071 7765 7274 7975 wertyuiopqwertyu
491 00000360: 696f 7071 7765 7274 7975 696f 7071 7772 iopqwertyuiopqwr
492 00000370: 7479 7569 6f70 7177 6572 7479 7569 6f70 tyuiopqwertyuiop
493 00000380: 7177 6572 7479 7569 6f71 7765 7274 7975 qwertyuioqwertyu
494 00000390: 696f 7071 7772 7479 7569 6f70 7177 6572 iopqwrtyuiopqwer
495 000003a0: 7479 7569 6f70 7177 6572 7479 7569 6f71 tyuiopqwertyuioq
496 000003b0: 7765 7274 7975 696f 7071 7772 7479 7569 wertyuiopqwrtyui
497 000003c0: 6f70 7177 6572 7479 7569 6f70 7177 6572 opqwertyuiopqwer
498 000003d0: 7479 7569 6f70 7070 0a00 5115 6562 0900 tyuioppp..Q.eb..
499 000003e0: 0500 0001 fc1a 0000 4096 3615 9cff ffff ........@.6.....
500 000003f0: 0a00 0000 0000 0000 0000 0000 0000 0000 ................
501 00000400: 0000 0000 0000 0000 0000 0000 0000 0000 ................
502 00000410: 0000 0000 0000 0000 0000 0000 0000 0000 ................
503 00000420: 0000 0000 0000 0000 0000 0000 0000 0000 ................
504 )",
505 };
506
TEST(CpuReaderTest,ReallyLongEvent)507 TEST(CpuReaderTest, ReallyLongEvent) {
508 const ExamplePage* test_case = &g_really_long_event;
509
510 BundleProvider bundle_provider(base::kPageSize);
511 ProtoTranslationTable* table = GetTable(test_case->name);
512 auto page = PageFromXxd(test_case->data);
513
514 FtraceDataSourceConfig ds_config = EmptyConfig();
515 ds_config.event_filter.AddEnabledEvent(
516 table->EventToFtraceId(GroupAndName("ftrace", "print")));
517
518 FtraceMetadata metadata{};
519 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
520
521 const uint8_t* parse_pos = page.get();
522 base::Optional<CpuReader::PageHeader> page_header =
523 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
524
525 const uint8_t* page_end = page.get() + base::kPageSize;
526 ASSERT_TRUE(page_header.has_value());
527 EXPECT_FALSE(page_header->lost_events);
528 EXPECT_TRUE(parse_pos < page_end);
529 EXPECT_TRUE(parse_pos + page_header->size < page_end);
530
531 CpuReader::ParsePagePayload(parse_pos, &page_header.value(), table,
532 &ds_config, compact_buffer.get(),
533 bundle_provider.writer(), &metadata);
534
535 auto bundle = bundle_provider.ParseProto();
536 ASSERT_TRUE(bundle);
537 const protos::gen::FtraceEvent& long_print = bundle->event()[0];
538 EXPECT_THAT(long_print.print().buf(), StartsWith("qwerty"));
539 EXPECT_THAT(long_print.print().buf(), EndsWith("ppp\n"));
540 const protos::gen::FtraceEvent& newline = bundle->event()[1];
541 EXPECT_EQ(newline.print().buf(), "\n");
542 }
543
544 // This event is as the event for ParseSinglePrint above except the string
545 // is extended and not null terminated.
546 static ExamplePage g_single_print_non_null_terminated{
547 "synthetic",
548 R"(
549 00000000: ba12 6a33 c628 0200 2c00 0000 0000 0000 ..j3.(..,.......
550 00000010: def0 ec67 8d21 0000 0800 0000 0500 0001 ...g.!..........
551 00000020: 2870 0000 ac5d 1661 86ff ffff 4865 6c6c (p...].a....Hell
552 00000030: 6f2c 2077 6f72 6c64 2161 6161 6161 6161 o, world!aaaaaaa
553 00000040: 6161 6161 6161 6161 6161 6161 6161 6161 aaaaaaaaaaaaaaaa
554 )",
555 };
556
TEST(CpuReaderTest,ParseSinglePrintNonNullTerminated)557 TEST(CpuReaderTest, ParseSinglePrintNonNullTerminated) {
558 const ExamplePage* test_case = &g_single_print_non_null_terminated;
559
560 BundleProvider bundle_provider(base::kPageSize);
561 ProtoTranslationTable* table = GetTable(test_case->name);
562 auto page = PageFromXxd(test_case->data);
563
564 FtraceDataSourceConfig ds_config = EmptyConfig();
565 ds_config.event_filter.AddEnabledEvent(
566 table->EventToFtraceId(GroupAndName("ftrace", "print")));
567
568 FtraceMetadata metadata{};
569 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
570 const uint8_t* parse_pos = page.get();
571 base::Optional<CpuReader::PageHeader> page_header =
572 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
573
574 const uint8_t* page_end = page.get() + base::kPageSize;
575 ASSERT_TRUE(page_header.has_value());
576 EXPECT_FALSE(page_header->lost_events);
577 EXPECT_TRUE(parse_pos < page_end);
578 EXPECT_TRUE(parse_pos + page_header->size < page_end);
579
580 size_t evt_bytes = CpuReader::ParsePagePayload(
581 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
582 bundle_provider.writer(), &metadata);
583
584 ASSERT_EQ(44u, evt_bytes);
585
586 auto bundle = bundle_provider.ParseProto();
587 ASSERT_TRUE(bundle);
588 ASSERT_EQ(bundle->event().size(), 1u);
589 const protos::gen::FtraceEvent& event = bundle->event()[0];
590 EXPECT_EQ(event.pid(), 28712ul);
591 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 608934, 535199));
592 EXPECT_EQ(event.print().buf(), "Hello, world!aaa");
593 }
594
595 static ExamplePage g_single_print_zero_size{
596 "synthetic",
597 R"(
598 00000000: ba12 6a33 c628 0200 2c00 0000 0000 0000 ..j3.(..,.......
599 00000010: def0 ec67 8d21 0000 0800 0000 0500 0001 ...g.!..........
600 00000020: 2870 0000 ac5d 1661 86ff ffff 0000 0000 (p...].a........
601 00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
602 00000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
603 )",
604 };
605
TEST(CpuReaderTest,ParseSinglePrintZeroSize)606 TEST(CpuReaderTest, ParseSinglePrintZeroSize) {
607 const ExamplePage* test_case = &g_single_print_zero_size;
608
609 BundleProvider bundle_provider(base::kPageSize);
610 ProtoTranslationTable* table = GetTable(test_case->name);
611 auto page = PageFromXxd(test_case->data);
612
613 FtraceDataSourceConfig ds_config = EmptyConfig();
614 ds_config.event_filter.AddEnabledEvent(
615 table->EventToFtraceId(GroupAndName("ftrace", "print")));
616
617 FtraceMetadata metadata{};
618 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
619 const uint8_t* parse_pos = page.get();
620 base::Optional<CpuReader::PageHeader> page_header =
621 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
622
623 const uint8_t* page_end = page.get() + base::kPageSize;
624 ASSERT_TRUE(page_header.has_value());
625 EXPECT_FALSE(page_header->lost_events);
626 EXPECT_TRUE(parse_pos < page_end);
627 EXPECT_TRUE(parse_pos + page_header->size < page_end);
628
629 size_t evt_bytes = CpuReader::ParsePagePayload(
630 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
631 bundle_provider.writer(), &metadata);
632
633 ASSERT_EQ(44u, evt_bytes);
634
635 auto bundle = bundle_provider.ParseProto();
636 ASSERT_TRUE(bundle);
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_TRUE(event.print().has_buf());
642 EXPECT_EQ(event.print().buf(), "");
643 }
644
TEST(CpuReaderTest,FilterByEvent)645 TEST(CpuReaderTest, FilterByEvent) {
646 const ExamplePage* test_case = &g_single_print;
647
648 BundleProvider bundle_provider(base::kPageSize);
649 ProtoTranslationTable* table = GetTable(test_case->name);
650 auto page = PageFromXxd(test_case->data);
651
652 FtraceDataSourceConfig ds_config = EmptyConfig();
653
654 FtraceMetadata metadata{};
655 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
656 const uint8_t* parse_pos = page.get();
657 base::Optional<CpuReader::PageHeader> page_header =
658 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
659
660 ASSERT_TRUE(page_header.has_value());
661 EXPECT_FALSE(page_header->lost_events);
662
663 size_t evt_bytes = CpuReader::ParsePagePayload(
664 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
665 bundle_provider.writer(), &metadata);
666
667 EXPECT_LT(0u, evt_bytes);
668
669 auto bundle = bundle_provider.ParseProto();
670 ASSERT_TRUE(bundle);
671 ASSERT_EQ(bundle->event().size(), 0u);
672 }
673
674 // clang-format off
675 // # tracer: nop
676 // #
677 // # entries-in-buffer/entries-written: 3/3 #P:8
678 // #
679 // # _-----=> irqs-off
680 // # / _----=> need-resched
681 // # | / _---=> hardirq/softirq
682 // # || / _--=> preempt-depth
683 // # ||| / delay
684 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
685 // # | | | |||| | |
686 // sh-30693 [000] ...1 615436.216806: tracing_mark_write: Hello, world!
687 // sh-30693 [000] ...1 615486.377232: tracing_mark_write: Good afternoon, world!
688 // sh-30693 [000] ...1 615495.632679: tracing_mark_write: Goodbye, world!
689 // clang-format on
690
691 static ExamplePage g_three_prints{
692 "synthetic",
693 R"(
694 00000000: a3ab 1569 bc2f 0200 9400 0000 0000 0000 ...i./..........
695 00000010: 1e00 0000 0000 0000 0800 0000 0500 0001 ................
696 00000020: e577 0000 ac5d 1661 86ff ffff 4865 6c6c .w...].a....Hell
697 00000030: 6f2c 2077 6f72 6c64 210a 0000 5e32 6bb9 o, world!...^2k.
698 00000040: 7501 0000 0b00 0000 0500 0001 e577 0000 u............w..
699 00000050: ac5d 1661 86ff ffff 476f 6f64 2061 6674 .].a....Good aft
700 00000060: 6572 6e6f 6f6e 2c20 776f 726c 6421 0a00 ernoon, world!..
701 00000070: 0000 0000 9e6a 5df5 4400 0000 0900 0000 .....j].D.......
702 00000080: 0500 0001 e577 0000 ac5d 1661 86ff ffff .....w...].a....
703 00000090: 476f 6f64 6279 652c 2077 6f72 6c64 210a Goodbye, world!.
704 000000a0: 0051 0000 0000 0000 0000 0000 0000 0000 .Q..............
705 )",
706 };
707
TEST(CpuReaderTest,ParseThreePrint)708 TEST(CpuReaderTest, ParseThreePrint) {
709 const ExamplePage* test_case = &g_three_prints;
710
711 BundleProvider bundle_provider(base::kPageSize);
712 ProtoTranslationTable* table = GetTable(test_case->name);
713 auto page = PageFromXxd(test_case->data);
714
715 FtraceDataSourceConfig ds_config = EmptyConfig();
716 ds_config.event_filter.AddEnabledEvent(
717 table->EventToFtraceId(GroupAndName("ftrace", "print")));
718
719 FtraceMetadata metadata{};
720 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
721 const uint8_t* parse_pos = page.get();
722 base::Optional<CpuReader::PageHeader> page_header =
723 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
724
725 const uint8_t* page_end = page.get() + base::kPageSize;
726 ASSERT_TRUE(page_header.has_value());
727 EXPECT_FALSE(page_header->lost_events);
728 EXPECT_TRUE(parse_pos < page_end);
729 EXPECT_TRUE(parse_pos + page_header->size < page_end);
730
731 size_t evt_bytes = CpuReader::ParsePagePayload(
732 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
733 bundle_provider.writer(), &metadata);
734
735 EXPECT_LT(0u, evt_bytes);
736
737 auto bundle = bundle_provider.ParseProto();
738 ASSERT_TRUE(bundle);
739 ASSERT_EQ(bundle->event().size(), 3u);
740
741 {
742 const protos::gen::FtraceEvent& event = bundle->event()[0];
743 EXPECT_EQ(event.pid(), 30693ul);
744 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 615436, 216806));
745 EXPECT_EQ(event.print().buf(), "Hello, world!\n");
746 }
747
748 {
749 const protos::gen::FtraceEvent& event = bundle->event()[1];
750 EXPECT_EQ(event.pid(), 30693ul);
751 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 615486, 377232));
752 EXPECT_EQ(event.print().buf(), "Good afternoon, world!\n");
753 }
754
755 {
756 const protos::gen::FtraceEvent& event = bundle->event()[2];
757 EXPECT_EQ(event.pid(), 30693ul);
758 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 615495, 632679));
759 EXPECT_EQ(event.print().buf(), "Goodbye, world!\n");
760 }
761 }
762
763 // clang-format off
764 // # tracer: nop
765 // #
766 // # entries-in-buffer/entries-written: 6/6 #P:8
767 // #
768 // # _-----=> irqs-off
769 // # / _----=> need-resched
770 // # | / _---=> hardirq/softirq
771 // # || / _--=> preempt-depth
772 // # ||| / delay
773 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
774 // # | | | |||| | |
775 // 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
776 // 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
777 // 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
778 // 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
779 // 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
780 // 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
781 // clang-format on
782
783 static ExamplePage g_six_sched_switch{
784 "synthetic",
785 R"(
786 00000000: 2b16 c3be 90b6 0300 a001 0000 0000 0000 +...............
787 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ............/...
788 00000020: 0300 0000 6b73 6f66 7469 7271 642f 3000 ....ksoftirqd/0.
789 00000030: 0000 0000 0300 0000 7800 0000 0100 0000 ........x.......
790 00000040: 0000 0000 736c 6565 7000 722f 3000 0000 ....sleep.r/0...
791 00000050: 0000 0000 950e 0000 7800 0000 b072 8805 ........x....r..
792 00000060: 2f00 0103 950e 0000 736c 6565 7000 722f /.......sleep.r/
793 00000070: 3000 0000 0000 0000 950e 0000 7800 0000 0...........x...
794 00000080: 0008 0000 0000 0000 7263 756f 702f 3000 ........rcuop/0.
795 00000090: 0000 0000 0000 0000 0a00 0000 7800 0000 ............x...
796 000000a0: f0b0 4700 2f00 0103 0700 0000 7263 755f ..G./.......rcu_
797 000000b0: 7072 6565 6d70 7400 0000 0000 0700 0000 preempt.........
798 000000c0: 7800 0000 0100 0000 0000 0000 736c 6565 x...........slee
799 000000d0: 7000 722f 3000 0000 0000 0000 950e 0000 p.r/0...........
800 000000e0: 7800 0000 1001 ef00 2f00 0103 950e 0000 x......./.......
801 000000f0: 736c 6565 7000 722f 3000 0000 0000 0000 sleep.r/0.......
802 00000100: 950e 0000 7800 0000 0008 0000 0000 0000 ....x...........
803 00000110: 7368 0064 0065 722f 3000 0000 0000 0000 sh.d.er/0.......
804 00000120: b90d 0000 7800 0000 f0c7 e601 2f00 0103 ....x......./...
805 00000130: b90d 0000 7368 0064 0065 722f 3000 0000 ....sh.d.er/0...
806 00000140: 0000 0000 b90d 0000 7800 0000 0100 0000 ........x.......
807 00000150: 0000 0000 736c 6565 7000 722f 3000 0000 ....sleep.r/0...
808 00000160: 0000 0000 950e 0000 7800 0000 d030 0e00 ........x....0..
809 00000170: 2f00 0103 950e 0000 736c 6565 7000 722f /.......sleep.r/
810 00000180: 3000 0000 0000 0000 950e 0000 7800 0000 0...........x...
811 00000190: 4000 0000 0000 0000 6b77 6f72 6b65 722f @.......kworker/
812 000001a0: 7531 363a 3300 0000 610e 0000 7800 0000 u16:3...a...x...
813 000001b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
814 )",
815 };
816
TEST(CpuReaderTest,ParseSixSchedSwitch)817 TEST(CpuReaderTest, ParseSixSchedSwitch) {
818 const ExamplePage* test_case = &g_six_sched_switch;
819
820 BundleProvider bundle_provider(base::kPageSize);
821 ProtoTranslationTable* table = GetTable(test_case->name);
822 auto page = PageFromXxd(test_case->data);
823
824 FtraceDataSourceConfig ds_config = EmptyConfig();
825 ds_config.event_filter.AddEnabledEvent(
826 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
827
828 FtraceMetadata metadata{};
829 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
830 const uint8_t* parse_pos = page.get();
831 base::Optional<CpuReader::PageHeader> page_header =
832 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
833
834 const uint8_t* page_end = page.get() + base::kPageSize;
835 ASSERT_TRUE(page_header.has_value());
836 EXPECT_FALSE(page_header->lost_events);
837 EXPECT_TRUE(parse_pos < page_end);
838 EXPECT_TRUE(parse_pos + page_header->size < page_end);
839
840 size_t evt_bytes = CpuReader::ParsePagePayload(
841 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
842 bundle_provider.writer(), &metadata);
843
844 EXPECT_LT(0u, evt_bytes);
845
846 auto bundle = bundle_provider.ParseProto();
847 ASSERT_TRUE(bundle);
848 ASSERT_EQ(bundle->event().size(), 6u);
849
850 {
851 const protos::gen::FtraceEvent& event = bundle->event()[1];
852 EXPECT_EQ(event.pid(), 3733ul);
853 EXPECT_TRUE(WithinOneMicrosecond(event.timestamp(), 1045157, 725035));
854 EXPECT_EQ(event.sched_switch().prev_comm(), "sleep");
855 EXPECT_EQ(event.sched_switch().prev_pid(), 3733);
856 EXPECT_EQ(event.sched_switch().prev_prio(), 120);
857 EXPECT_EQ(event.sched_switch().next_comm(), "rcuop/0");
858 EXPECT_EQ(event.sched_switch().next_pid(), 10);
859 EXPECT_EQ(event.sched_switch().next_prio(), 120);
860 }
861 }
862
TEST(CpuReaderTest,ParseSixSchedSwitchCompactFormat)863 TEST(CpuReaderTest, ParseSixSchedSwitchCompactFormat) {
864 const ExamplePage* test_case = &g_six_sched_switch;
865
866 BundleProvider bundle_provider(base::kPageSize);
867 ProtoTranslationTable* table = GetTable(test_case->name);
868 auto page = PageFromXxd(test_case->data);
869
870 FtraceDataSourceConfig ds_config{EventFilter{},
871 EnabledCompactSchedConfigForTesting(),
872 {},
873 {},
874 false /* symbolize_ksyms*/};
875 ds_config.event_filter.AddEnabledEvent(
876 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
877
878 FtraceMetadata metadata{};
879 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
880 const uint8_t* parse_pos = page.get();
881 base::Optional<CpuReader::PageHeader> page_header =
882 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
883
884 const uint8_t* page_end = page.get() + base::kPageSize;
885 ASSERT_TRUE(page_header.has_value());
886 EXPECT_FALSE(page_header->lost_events);
887 EXPECT_TRUE(parse_pos < page_end);
888 EXPECT_TRUE(parse_pos + page_header->size < page_end);
889
890 size_t evt_bytes = CpuReader::ParsePagePayload(
891 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
892 bundle_provider.writer(), &metadata);
893
894 EXPECT_LT(0u, evt_bytes);
895
896 // Nothing written into the proto yet:
897 auto bundle = bundle_provider.ParseProto();
898 ASSERT_TRUE(bundle);
899 EXPECT_EQ(0u, bundle->event().size());
900 EXPECT_FALSE(bundle->has_compact_sched());
901 bundle_provider.ResetWriter();
902
903 // Instead, sched switch fields were buffered:
904 EXPECT_LT(0u, compact_buffer->sched_switch().size());
905 EXPECT_LT(0u, compact_buffer->interner().interned_comms_size());
906
907 // Write the buffer out & check the serialized format:
908 compact_buffer->WriteAndReset(bundle_provider.writer());
909 bundle_provider.writer()->Finalize();
910 bundle = bundle_provider.ParseProto();
911 ASSERT_TRUE(bundle);
912
913 const auto& compact_sched = bundle->compact_sched();
914
915 EXPECT_EQ(6u, compact_sched.switch_timestamp().size());
916 EXPECT_EQ(6u, compact_sched.switch_prev_state().size());
917 EXPECT_EQ(6u, compact_sched.switch_next_pid().size());
918 EXPECT_EQ(6u, compact_sched.switch_next_prio().size());
919 // 4 unique interned next_comm strings:
920 EXPECT_EQ(4u, compact_sched.intern_table().size());
921 EXPECT_EQ(6u, compact_sched.switch_next_comm_index().size());
922
923 // First event exactly as expected (absolute timestamp):
924 EXPECT_TRUE(WithinOneMicrosecond(compact_sched.switch_timestamp()[0], 1045157,
925 722134));
926 EXPECT_EQ(1, compact_sched.switch_prev_state()[0]);
927 EXPECT_EQ(3733, compact_sched.switch_next_pid()[0]);
928 EXPECT_EQ(120, compact_sched.switch_next_prio()[0]);
929 auto comm_intern_idx = compact_sched.switch_next_comm_index()[0];
930 std::string next_comm = compact_sched.intern_table()[comm_intern_idx];
931 EXPECT_EQ("sleep", next_comm);
932 }
933
TEST_F(CpuReaderTableTest,ParseAllFields)934 TEST_F(CpuReaderTableTest, ParseAllFields) {
935 using FakeEventProvider =
936 ProtoProvider<pbzero::FakeFtraceEvent, gen::FakeFtraceEvent>;
937
938 uint16_t ftrace_event_id = 102;
939
940 std::vector<Field> common_fields;
941 {
942 common_fields.emplace_back(Field{});
943 Field* field = &common_fields.back();
944 field->ftrace_offset = 0;
945 field->ftrace_size = 4;
946 field->ftrace_type = kFtraceUint32;
947 field->proto_field_id = 1;
948 field->proto_field_type = ProtoSchemaType::kUint32;
949 SetTranslationStrategy(field->ftrace_type, field->proto_field_type,
950 &field->strategy);
951 }
952
953 {
954 common_fields.emplace_back(Field{});
955 Field* field = &common_fields.back();
956 field->ftrace_offset = 4;
957 field->ftrace_size = 4;
958 field->ftrace_type = kFtraceCommonPid32;
959 field->proto_field_id = 2;
960 field->proto_field_type = ProtoSchemaType::kInt32;
961 SetTranslationStrategy(field->ftrace_type, field->proto_field_type,
962 &field->strategy);
963 }
964
965 std::vector<Event> events;
966 events.emplace_back(Event{});
967 {
968 Event* event = &events.back();
969 event->name = "";
970 event->group = "";
971 event->proto_field_id = 42;
972 event->ftrace_event_id = ftrace_event_id;
973
974 {
975 // uint32 -> uint32
976 event->fields.emplace_back(Field{});
977 Field* field = &event->fields.back();
978 field->ftrace_offset = 8;
979 field->ftrace_size = 4;
980 field->ftrace_type = kFtraceUint32;
981 field->proto_field_id = 1;
982 field->proto_field_type = ProtoSchemaType::kUint32;
983 }
984
985 {
986 // pid32 -> uint32
987 event->fields.emplace_back(Field{});
988 Field* field = &event->fields.back();
989 field->ftrace_offset = 12;
990 field->ftrace_size = 4;
991 field->ftrace_type = kFtracePid32;
992 field->proto_field_id = 2;
993 field->proto_field_type = ProtoSchemaType::kInt32;
994 }
995
996 {
997 // dev32 -> uint64
998 event->fields.emplace_back(Field{});
999 Field* field = &event->fields.back();
1000 field->ftrace_offset = 16;
1001 field->ftrace_size = 4;
1002 field->ftrace_type = kFtraceDevId32;
1003 field->proto_field_id = 3;
1004 field->proto_field_type = ProtoSchemaType::kUint64;
1005 }
1006
1007 {
1008 // ino_t (32bit) -> uint64
1009 event->fields.emplace_back(Field{});
1010 Field* field = &event->fields.back();
1011 field->ftrace_offset = 20;
1012 field->ftrace_size = 4;
1013 field->ftrace_type = kFtraceInode32;
1014 field->proto_field_id = 4;
1015 field->proto_field_type = ProtoSchemaType::kUint64;
1016 }
1017
1018 {
1019 // dev64 -> uint64
1020 event->fields.emplace_back(Field{});
1021 Field* field = &event->fields.back();
1022 field->ftrace_offset = 24;
1023 field->ftrace_size = 8;
1024 field->ftrace_type = kFtraceDevId64;
1025 field->proto_field_id = 5;
1026 field->proto_field_type = ProtoSchemaType::kUint64;
1027 }
1028
1029 {
1030 // ino_t (64bit) -> uint64
1031 event->fields.emplace_back(Field{});
1032 Field* field = &event->fields.back();
1033 field->ftrace_offset = 32;
1034 field->ftrace_size = 8;
1035 field->ftrace_type = kFtraceInode64;
1036 field->proto_field_id = 6;
1037 field->proto_field_type = ProtoSchemaType::kUint64;
1038 }
1039
1040 {
1041 // char[16] -> string
1042 event->fields.emplace_back(Field{});
1043 Field* field = &event->fields.back();
1044 field->ftrace_offset = 40;
1045 field->ftrace_size = 16;
1046 field->ftrace_type = kFtraceFixedCString;
1047 field->proto_field_id = 500;
1048 field->proto_field_type = ProtoSchemaType::kString;
1049 }
1050
1051 {
1052 // char* -> string
1053 event->fields.emplace_back(Field{});
1054 Field* field = &event->fields.back();
1055 field->ftrace_offset = 56;
1056 field->ftrace_size = 8;
1057 field->ftrace_type = kFtraceStringPtr;
1058 field->proto_field_id = 503;
1059 field->proto_field_type = ProtoSchemaType::kString;
1060 }
1061
1062 {
1063 // dataloc -> string
1064 event->fields.emplace_back(Field{});
1065 Field* field = &event->fields.back();
1066 field->ftrace_offset = 65;
1067 field->ftrace_size = 4;
1068 field->ftrace_type = kFtraceDataLoc;
1069 field->proto_field_id = 502;
1070 field->proto_field_type = ProtoSchemaType::kString;
1071 }
1072
1073 {
1074 // char -> string
1075 event->fields.emplace_back(Field{});
1076 Field* field = &event->fields.back();
1077 field->ftrace_offset = 69;
1078 field->ftrace_size = 0;
1079 field->ftrace_type = kFtraceCString;
1080 field->proto_field_id = 501;
1081 field->proto_field_type = ProtoSchemaType::kString;
1082 }
1083
1084 for (Field& field : event->fields) {
1085 SetTranslationStrategy(field.ftrace_type, field.proto_field_type,
1086 &field.strategy);
1087 }
1088 }
1089
1090 PrintkMap printk_formats;
1091 printk_formats.insert(0xffffff8504f51b23, "my_printk_format_string");
1092 ProtoTranslationTable table(
1093 &ftrace_, events, std::move(common_fields),
1094 ProtoTranslationTable::DefaultPageHeaderSpecForTesting(),
1095 InvalidCompactSchedEventFormatForTesting(), printk_formats);
1096
1097 FakeEventProvider provider(base::kPageSize);
1098
1099 BinaryWriter writer;
1100
1101 // Must use the bit masks to translate between kernel and userspace device ids
1102 // to generate the below examples
1103 const uint32_t kKernelBlockDeviceId = 271581216;
1104
1105 const BlockDeviceID kUserspaceBlockDeviceId =
1106 CpuReader::TranslateBlockDeviceIDToUserspace<BlockDeviceID>(
1107 kKernelBlockDeviceId);
1108 const uint64_t k64BitKernelBlockDeviceId = 4442450946;
1109 const BlockDeviceID k64BitUserspaceBlockDeviceId =
1110 CpuReader::TranslateBlockDeviceIDToUserspace<uint64_t>(
1111 k64BitKernelBlockDeviceId);
1112
1113 writer.Write<int32_t>(1001); // Common field.
1114 writer.Write<int32_t>(9999); // Common pid
1115 writer.Write<int32_t>(1003); // Uint32 field
1116 writer.Write<int32_t>(97); // Pid
1117 writer.Write<int32_t>(kKernelBlockDeviceId); // Dev id
1118 writer.Write<int32_t>(98); // Inode 32
1119 writer.Write<int64_t>(k64BitKernelBlockDeviceId); // Dev id 64
1120 writer.Write<int64_t>(99u); // Inode 64
1121 writer.WriteFixedString(16, "Hello");
1122 writer.Write<uint64_t>(0xffffff8504f51b23ULL); // char* (printk formats)
1123 writer.Write<uint8_t>(0); // Deliberately mis-aligning.
1124 writer.Write<uint32_t>(40 | 6 << 16);
1125 writer.WriteFixedString(300, "Goodbye");
1126
1127 auto input = writer.GetCopy();
1128 auto length = writer.written();
1129 FtraceMetadata metadata{};
1130
1131 ASSERT_TRUE(CpuReader::ParseEvent(ftrace_event_id, input.get(),
1132 input.get() + length, &table,
1133 provider.writer(), &metadata));
1134
1135 auto event = provider.ParseProto();
1136 ASSERT_TRUE(event);
1137 EXPECT_EQ(event->common_field(), 1001ul);
1138 EXPECT_EQ(event->common_pid(), 9999ul);
1139 EXPECT_TRUE(event->has_all_fields());
1140 EXPECT_EQ(event->all_fields().field_uint32(), 1003u);
1141 EXPECT_EQ(event->all_fields().field_pid(), 97);
1142 EXPECT_EQ(event->all_fields().field_dev_32(),
1143 static_cast<uint32_t>(kUserspaceBlockDeviceId));
1144 EXPECT_EQ(event->all_fields().field_inode_32(), 98u);
1145 // TODO(primiano): for some reason this fails on mac.
1146 #if !PERFETTO_BUILDFLAG(PERFETTO_OS_APPLE)
1147 EXPECT_EQ(event->all_fields().field_dev_64(), k64BitUserspaceBlockDeviceId);
1148 #endif
1149 EXPECT_EQ(event->all_fields().field_inode_64(), 99u);
1150 EXPECT_EQ(event->all_fields().field_char_16(), "Hello");
1151 EXPECT_EQ(event->all_fields().field_char(), "Goodbye");
1152 EXPECT_EQ(event->all_fields().field_data_loc(), "Hello");
1153 EXPECT_EQ(event->all_fields().field_char_star(), "my_printk_format_string");
1154 EXPECT_THAT(metadata.pids, Contains(97));
1155 EXPECT_EQ(metadata.inode_and_device.size(), 2U);
1156 EXPECT_THAT(metadata.inode_and_device,
1157 Contains(Pair(98u, kUserspaceBlockDeviceId)));
1158 EXPECT_THAT(metadata.inode_and_device,
1159 Contains(Pair(99u, k64BitUserspaceBlockDeviceId)));
1160 }
1161
TEST(CpuReaderTest,TaskRenameEvent)1162 TEST(CpuReaderTest, TaskRenameEvent) {
1163 BundleProvider bundle_provider(base::kPageSize);
1164
1165 BinaryWriter writer;
1166 ProtoTranslationTable* table = GetTable("android_seed_N2F62_3.10.49");
1167
1168 constexpr uint32_t kTaskRenameId = 19;
1169
1170 writer.Write<int32_t>(1001); // Common field.
1171 writer.Write<int32_t>(9999); // Common pid
1172 writer.Write<int32_t>(9999); // Pid
1173 writer.WriteFixedString(16, "Hello"); // Old Comm
1174 writer.WriteFixedString(16, "Goodbye"); // New Comm
1175 writer.Write<uint64_t>(10); // flags
1176 writer.Write<int16_t>(10); // oom_score_adj
1177
1178 auto input = writer.GetCopy();
1179 auto length = writer.written();
1180 FtraceMetadata metadata{};
1181
1182 ASSERT_TRUE(CpuReader::ParseEvent(kTaskRenameId, input.get(),
1183 input.get() + length, table,
1184 bundle_provider.writer(), &metadata));
1185 EXPECT_THAT(metadata.rename_pids, Contains(9999));
1186 EXPECT_THAT(metadata.pids, Contains(9999));
1187 }
1188
1189 // Regression test for b/205763418: Kernels without f0a515780393("tracing: Don't
1190 // make assumptions about length of string on task rename") can output non
1191 // zero-terminated strings in some cases. Even though it's a kernel bug, there's
1192 // no point in rejecting that.
TEST(CpuReaderTest,EventNonZeroTerminated)1193 TEST(CpuReaderTest, EventNonZeroTerminated) {
1194 BundleProvider bundle_provider(base::kPageSize);
1195
1196 BinaryWriter writer;
1197 ProtoTranslationTable* table = GetTable("android_seed_N2F62_3.10.49");
1198
1199 constexpr uint32_t kTaskRenameId = 19;
1200
1201 writer.Write<int32_t>(1001); // Common field.
1202 writer.Write<int32_t>(9999); // Common pid
1203 writer.Write<int32_t>(9999); // Pid
1204 writer.WriteFixedString(16, "Hello"); // Old Comm
1205 std::array<char, 16> newcomm;
1206 memcpy(&newcomm, "0123456789abcdef", sizeof newcomm);
1207 writer.Write(newcomm); // New Comm - not null terminated
1208 writer.Write<uint64_t>(10); // flags
1209 writer.Write<int16_t>(10); // oom_score_adj
1210
1211 auto input = writer.GetCopy();
1212 auto length = writer.written();
1213 FtraceMetadata metadata{};
1214
1215 ASSERT_TRUE(CpuReader::ParseEvent(
1216 kTaskRenameId, input.get(), input.get() + length, table,
1217 bundle_provider.writer()->add_event(), &metadata));
1218 std::unique_ptr<protos::gen::FtraceEventBundle> a =
1219 bundle_provider.ParseProto();
1220 ASSERT_NE(a, nullptr);
1221 ASSERT_EQ(a->event().size(), 1u);
1222 ASSERT_EQ(a->event()[0].task_rename().newcomm(), "0123456789abcdef");
1223 }
1224
1225 // Page with a single sched_switch, no data loss.
1226 static char g_switch_page[] =
1227 R"(
1228 00000000: 2b16 c3be 90b6 0300 4c00 0000 0000 0000 ................
1229 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ................
1230 00000020: 0300 0000 6b73 6f66 7469 7271 642f 3000 ................
1231 00000030: 0000 0000 0300 0000 7800 0000 0100 0000 ................
1232 00000040: 0000 0000 736c 6565 7000 722f 3000 0000 ................
1233 00000050: 0000 0000 950e 0000 7800 0000 0000 0000 ................
1234 )";
1235
1236 // Page with a single sched_switch, header has data loss flag set.
1237 static char g_switch_page_lost_events[] =
1238 R"(
1239 00000000: 2b16 c3be 90b6 0300 4c00 0080 ffff ffff ................
1240 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ................
1241 00000020: 0300 0000 6b73 6f66 7469 7271 642f 3000 ................
1242 00000030: 0000 0000 0300 0000 7800 0000 0100 0000 ................
1243 00000040: 0000 0000 736c 6565 7000 722f 3000 0000 ................
1244 00000050: 0000 0000 950e 0000 7800 0000 0000 0000 ................
1245 )";
1246
1247 // Page with invalid data.
1248 static char g_invalid_page[] =
1249 R"(
1250 00000000: 2b16 c3be 90b6 0300 4b00 0000 0000 0000 ................
1251 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ................
1252 00000020: 0300 0000 6b73 6f66 7469 7271 642f 3000 ................
1253 00000030: 0000 0000 0300 0000 7800 0000 0100 0000 ................
1254 00000040: 0000 0000 736c 6565 7000 722f 3000 0000 ................
1255 00000050: 0000 0000 950e 0000 7800 0000 0000 0000 ................
1256 )";
1257
TEST(CpuReaderTest,NewPacketOnLostEvents)1258 TEST(CpuReaderTest, NewPacketOnLostEvents) {
1259 auto page_ok = PageFromXxd(g_switch_page);
1260 auto page_loss = PageFromXxd(g_switch_page_lost_events);
1261
1262 std::vector<const void*> test_page_order = {
1263 page_ok.get(), page_ok.get(), page_ok.get(), page_loss.get(),
1264 page_loss.get(), page_ok.get(), page_ok.get(), page_ok.get()};
1265
1266 // Prepare a buffer with 8 contiguous pages, with the above contents.
1267 static constexpr size_t kTestPages = 8;
1268
1269 std::unique_ptr<uint8_t[]> buf(new uint8_t[base::kPageSize * kTestPages]());
1270 for (size_t i = 0; i < kTestPages; i++) {
1271 void* dest = buf.get() + (i * base::kPageSize);
1272 memcpy(dest, static_cast<const void*>(test_page_order[i]), base::kPageSize);
1273 }
1274
1275 BundleProvider bundle_provider(base::kPageSize);
1276 ProtoTranslationTable* table = GetTable("synthetic");
1277 FtraceMetadata metadata{};
1278 FtraceDataSourceConfig ds_config = EmptyConfig();
1279 ds_config.event_filter.AddEnabledEvent(
1280 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
1281
1282 TraceWriterForTesting trace_writer;
1283 size_t processed_pages = CpuReader::ProcessPagesForDataSource(
1284 &trace_writer, &metadata, /*cpu=*/1, &ds_config, buf.get(), kTestPages,
1285 table, /*symbolizer=*/nullptr, /*ftrace_clock_snapshot=*/nullptr,
1286 protos::pbzero::FTRACE_CLOCK_UNSPECIFIED);
1287
1288 ASSERT_EQ(processed_pages, kTestPages);
1289
1290 // Each packet should contain the parsed contents of a contiguous run of pages
1291 // without data loss.
1292 // So we should get three packets (each page has 1 event):
1293 // [3 events] [1 event] [4 events].
1294 auto packets = trace_writer.GetAllTracePackets();
1295
1296 ASSERT_EQ(3u, packets.size());
1297 EXPECT_FALSE(packets[0].ftrace_events().lost_events());
1298 EXPECT_EQ(3u, packets[0].ftrace_events().event().size());
1299
1300 EXPECT_TRUE(packets[1].ftrace_events().lost_events());
1301 EXPECT_EQ(1u, packets[1].ftrace_events().event().size());
1302
1303 EXPECT_TRUE(packets[2].ftrace_events().lost_events());
1304 EXPECT_EQ(4u, packets[2].ftrace_events().event().size());
1305 }
1306
TEST(CpuReaderTest,ProcessPagesForDataSourceError)1307 TEST(CpuReaderTest, ProcessPagesForDataSourceError) {
1308 auto page_ok = PageFromXxd(g_switch_page);
1309 auto page_err = PageFromXxd(g_invalid_page);
1310
1311 std::vector<const void*> test_page_order = {
1312 page_ok.get(), page_ok.get(), page_ok.get(), page_err.get(),
1313 page_ok.get(), page_ok.get(), page_err.get(), page_ok.get()};
1314
1315 // Prepare a buffer with 8 contiguous pages, with the above contents.
1316 static constexpr size_t kTestPages = 8;
1317
1318 std::unique_ptr<uint8_t[]> buf(new uint8_t[base::kPageSize * kTestPages]());
1319 for (size_t i = 0; i < kTestPages; i++) {
1320 void* dest = buf.get() + (i * base::kPageSize);
1321 memcpy(dest, static_cast<const void*>(test_page_order[i]), base::kPageSize);
1322 }
1323
1324 BundleProvider bundle_provider(base::kPageSize);
1325 ProtoTranslationTable* table = GetTable("synthetic");
1326 FtraceMetadata metadata{};
1327 FtraceDataSourceConfig ds_config = EmptyConfig();
1328 ds_config.event_filter.AddEnabledEvent(
1329 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
1330
1331 TraceWriterForTesting trace_writer;
1332 size_t processed_pages = CpuReader::ProcessPagesForDataSource(
1333 &trace_writer, &metadata, /*cpu=*/1, &ds_config, buf.get(), kTestPages,
1334 table, /*symbolizer=*/nullptr, /*ftrace_clock_snapshot=*/nullptr,
1335 protos::pbzero::FTRACE_CLOCK_UNSPECIFIED);
1336
1337 EXPECT_EQ(processed_pages, 3u);
1338 }
1339
1340 // Page containing an absolute timestamp (RINGBUF_TYPE_TIME_STAMP).
1341 static char g_abs_timestamp[] =
1342 R"(
1343 00000000: 8949 fbfb 38e4 0400 6407 0000 0000 0000 .I..8...d.......
1344 00000010: 5032 0a2d 3b01 0100 0000 0000 7377 6170 P2.-;.......swap
1345 00000020: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1346 00000030: 7800 0000 0000 0000 0000 0000 6776 6673 x...........gvfs
1347 00000040: 2d61 6663 2d76 6f6c 756d 6500 6483 0000 -afc-volume.d...
1348 00000050: 7800 0000 f0de 1700 3b01 0100 6483 0000 x.......;...d...
1349 00000060: 6776 6673 2d61 6663 2d76 6f6c 756d 6500 gvfs-afc-volume.
1350 00000070: 6483 0000 7800 0000 0100 0000 0000 0000 d...x...........
1351 00000080: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1352 00000090: 0000 0000 7800 0000 aaa1 5c08 0401 1100 ....x.....\.....
1353 000000a0: 0000 0000 88fc 31eb 029f ffff 609e d3c0 ......1.....`...
1354 000000b0: ffff ffff 0076 b4a1 029f ffff 0020 0000 .....v....... ..
1355 000000c0: ffff ffff e477 1700 0301 1100 0000 0000 .....w..........
1356 000000d0: 88fc 31eb 029f ffff aa26 0100 3e01 1100 ..1......&..>...
1357 000000e0: 0000 0000 6b77 6f72 6b65 722f 7538 3a35 ....kworker/u8:5
1358 000000f0: 0000 0000 24c0 0c00 7800 0000 0100 0000 ....$...x.......
1359 00000100: 0300 0000 90e6 e700 3b01 0100 0000 0000 ........;.......
1360 00000110: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1361 00000120: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
1362 00000130: 6b77 6f72 6b65 722f 7538 3a35 0000 0000 kworker/u8:5....
1363 00000140: 24c0 0c00 7800 0000 aa56 0300 3e01 0100 $...x....V..>...
1364 00000150: 24c0 0c00 6b77 6f72 6b65 722f 7538 3a31 $...kworker/u8:1
1365 00000160: 0000 0000 8eb5 0c00 7800 0000 0100 0000 ........x.......
1366 00000170: 0300 0000 06eb 0300 0201 0000 24c0 0c00 ............$...
1367 00000180: 6026 f22a 049f ffff f0e4 4cc0 ffff ffff `&.*......L.....
1368 00000190: ca45 0f00 3e01 0100 24c0 0c00 646d 6372 .E..>...$...dmcr
1369 000001a0: 7970 745f 7772 6974 652f 3200 2601 0000 ypt_write/2.&...
1370 000001b0: 7800 0000 0100 0000 0100 0000 c617 0200 x...............
1371 000001c0: 0101 0000 24c0 0c00 6026 f22a 049f ffff ....$...`&.*....
1372 000001d0: f0e4 4cc0 ffff ffff a47c 0000 0301 0100 ..L......|......
1373 000001e0: 24c0 0c00 6015 f22a 049f ffff 0685 0000 $...`..*........
1374 000001f0: 0201 0000 24c0 0c00 a05d f22a 049f ffff ....$....].*....
1375 00000200: f0e4 4cc0 ffff ffff c6dd 0800 0101 0000 ..L.............
1376 00000210: 24c0 0c00 a05d f22a 049f ffff f0e4 4cc0 $....].*......L.
1377 00000220: ffff ffff 8444 0000 0301 0100 24c0 0c00 .....D......$...
1378 00000230: 6059 f22a 049f ffff e672 0000 0201 0000 `Y.*.....r......
1379 00000240: 24c0 0c00 e050 f22a 049f ffff f0e4 4cc0 $....P.*......L.
1380 00000250: ffff ffff 4673 0a00 0101 0000 24c0 0c00 ....Fs......$...
1381 00000260: e050 f22a 049f ffff f0e4 4cc0 ffff ffff .P.*......L.....
1382 00000270: 04ca 0000 0301 0100 24c0 0c00 2000 f22a ........$... ..*
1383 00000280: 049f ffff 86b1 0000 0201 0000 24c0 0c00 ............$...
1384 00000290: 6015 f22a 049f ffff f0e4 4cc0 ffff ffff `..*......L.....
1385 000002a0: e640 0c00 0101 0000 24c0 0c00 6015 f22a .@......$...`..*
1386 000002b0: 049f ffff f0e4 4cc0 ffff ffff 64b4 0000 ......L.....d...
1387 000002c0: 0301 0100 24c0 0c00 2011 f22a 049f ffff ....$... ..*....
1388 000002d0: 66b9 0000 0201 0000 24c0 0c00 a06e f22a f.......$....n.*
1389 000002e0: 049f ffff f0e4 4cc0 ffff ffff 6ae1 4200 ......L.....j.B.
1390 000002f0: 3e01 1100 24c0 0c00 6a62 6432 2f64 6d2d >...$...jbd2/dm-
1391 00000300: 312d 3800 0000 0000 6a01 0000 7800 0000 1-8.....j...x...
1392 00000310: 0100 0000 0300 0000 269b 0400 0101 0000 ........&.......
1393 00000320: 24c0 0c00 a06e f22a 049f ffff f0e4 4cc0 $....n.*......L.
1394 00000330: ffff ffff ff9d 6fb6 1f87 9c00 1000 0000 ......o.........
1395 00000340: 3b01 0100 24c0 0c00 6b77 6f72 6b65 722f ;...$...kworker/
1396 00000350: 7538 3a35 0000 0000 24c0 0c00 7800 0000 u8:5....$...x...
1397 00000360: 8000 0000 0000 0000 7377 6170 7065 722f ........swapper/
1398 00000370: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1399 00000380: 6ad2 3802 0401 1100 0000 0000 c800 384b j.8...........8K
1400 00000390: 029f ffff 7018 75c0 ffff ffff 00ac edce ....p.u.........
1401 000003a0: 039f ffff 0020 0000 0000 0000 c4de 0000 ..... ..........
1402 000003b0: 0301 1100 0000 0000 c800 384b 029f ffff ..........8K....
1403 000003c0: 8a27 0100 3e01 1100 0000 0000 6b77 6f72 .'..>.......kwor
1404 000003d0: 6b65 722f 303a 3200 0000 0000 48b4 0c00 ker/0:2.....H...
1405 000003e0: 7800 0000 0100 0000 0000 0000 706d 0800 x...........pm..
1406 000003f0: 3b01 0100 0000 0000 7377 6170 7065 722f ;.......swapper/
1407 00000400: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1408 00000410: 0000 0000 0000 0000 6b77 6f72 6b65 722f ........kworker/
1409 00000420: 303a 3200 0000 0000 48b4 0c00 7800 0000 0:2.....H...x...
1410 00000430: 4636 0200 0201 0000 48b4 0c00 c800 384b F6......H.....8K
1411 00000440: 029f ffff 7018 75c0 ffff ffff ca56 0500 ....p.u......V..
1412 00000450: 0401 0100 48b4 0c00 606a ad55 029f ffff ....H...`j.U....
1413 00000460: f0e4 4cc0 ffff ffff 002c 04d0 039f ffff ..L......,......
1414 00000470: 0020 0000 ffff ffff e435 0000 0301 0100 . .......5......
1415 00000480: 48b4 0c00 606a ad55 029f ffff ca67 0000 H...`j.U.....g..
1416 00000490: 3e01 0100 48b4 0c00 6b77 6f72 6b65 722f >...H...kworker/
1417 000004a0: 7538 3a35 0000 0000 24c0 0c00 7800 0000 u8:5....$...x...
1418 000004b0: 0100 0000 0000 0000 e6fc 0200 0101 0000 ................
1419 000004c0: 48b4 0c00 c800 384b 029f ffff 7018 75c0 H.....8K....p.u.
1420 000004d0: ffff ffff 708f 0200 3b01 0100 48b4 0c00 ....p...;...H...
1421 000004e0: 6b77 6f72 6b65 722f 303a 3200 0000 0000 kworker/0:2.....
1422 000004f0: 48b4 0c00 7800 0000 8000 0000 0000 0000 H...x...........
1423 00000500: 6b77 6f72 6b65 722f 7538 3a35 0000 0000 kworker/u8:5....
1424 00000510: 24c0 0c00 7800 0000 0614 0100 0201 0000 $...x...........
1425 00000520: 24c0 0c00 606a ad55 029f ffff f0e4 4cc0 $...`j.U......L.
1426 00000530: ffff ffff ea7e 0c00 3e01 0100 24c0 0c00 .....~..>...$...
1427 00000540: 646d 6372 7970 745f 7772 6974 652f 3200 dmcrypt_write/2.
1428 00000550: 2601 0000 7800 0000 0100 0000 0100 0000 &...x...........
1429 00000560: 4645 0200 0101 0000 24c0 0c00 606a ad55 FE......$...`j.U
1430 00000570: 029f ffff f0e4 4cc0 ffff ffff b043 0900 ......L......C..
1431 00000580: 3b01 0100 24c0 0c00 6b77 6f72 6b65 722f ;...$...kworker/
1432 00000590: 7538 3a35 0000 0000 24c0 0c00 7800 0000 u8:5....$...x...
1433 000005a0: 8000 0000 0000 0000 7377 6170 7065 722f ........swapper/
1434 000005b0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1435 000005c0: ca7a 3900 0401 1100 0000 0000 48bc d5a1 .z9.........H...
1436 000005d0: 029f ffff 10e2 62bb ffff ffff 00e0 40d0 ......b.......@.
1437 000005e0: 039f ffff 0020 0000 0000 0000 c4bb 0000 ..... ..........
1438 000005f0: 0301 1100 0000 0000 48bc d5a1 029f ffff ........H.......
1439 00000600: 2aea 0000 3e01 1100 0000 0000 6b77 6f72 *...>.......kwor
1440 00000610: 6b65 722f 303a 3148 0000 0000 cfc1 0c00 ker/0:1H........
1441 00000620: 6400 0000 0100 0000 0000 0000 90bb 0600 d...............
1442 00000630: 3b01 0100 0000 0000 7377 6170 7065 722f ;.......swapper/
1443 00000640: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1444 00000650: 0000 0000 0000 0000 6b77 6f72 6b65 722f ........kworker/
1445 00000660: 303a 3148 0000 0000 cfc1 0c00 6400 0000 0:1H........d...
1446 00000670: 8617 0200 0201 0000 cfc1 0c00 48bc d5a1 ............H...
1447 00000680: 029f ffff 10e2 62bb ffff ffff c68f 0400 ......b.........
1448 00000690: 0101 0000 cfc1 0c00 48bc d5a1 029f ffff ........H.......
1449 000006a0: 10e2 62bb ffff ffff b063 0300 3b01 0100 ..b......c..;...
1450 000006b0: cfc1 0c00 6b77 6f72 6b65 722f 303a 3148 ....kworker/0:1H
1451 000006c0: 0000 0000 cfc1 0c00 6400 0000 8000 0000 ........d.......
1452 000006d0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1453 000006e0: 0000 0000 0000 0000 7800 0000 4a10 ad01 ........x...J...
1454 000006f0: 3e01 1100 0000 0000 6a62 6432 2f64 6d2d >.......jbd2/dm-
1455 00000700: 312d 3800 0000 0000 6a01 0000 7800 0000 1-8.....j...x...
1456 00000710: 0100 0000 0300 0000 ea27 b900 3e01 1100 .........'..>...
1457 00000720: 0000 0000 7263 755f 7363 6865 6400 0000 ....rcu_sched...
1458 00000730: 0000 0000 0d00 0000 7800 0000 0100 0000 ........x.......
1459 00000740: 0200 0000 3d00 0000 2c00 0000 0000 0000 ....=...,.......
1460 00000750: 0000 0000 0000 0000 0000 0000 0000 0000 ................
1461 00000760: 0000 0000 0000 0000 0000 0000 0000 0000 ................
1462 00000770: 0000 0000 0000 0000 0000 0000 0000 0000 ................
1463 )";
1464
TEST(CpuReaderTest,ParseAbsoluteTimestamp)1465 TEST(CpuReaderTest, ParseAbsoluteTimestamp) {
1466 BundleProvider bundle_provider(base::kPageSize);
1467 auto page = PageFromXxd(g_abs_timestamp);
1468
1469 // Hand-build a translation table that handles sched_switch for this test
1470 // page. We cannot reuse the test data format file, since the ftrace id for
1471 // sched_switch in this page is different.
1472 std::vector<Field> common_fields;
1473 { // common_pid
1474 common_fields.emplace_back(Field{});
1475 Field* field = &common_fields.back();
1476 field->ftrace_offset = 4;
1477 field->ftrace_size = 4;
1478 field->ftrace_type = kFtraceCommonPid32;
1479 field->proto_field_id = 2;
1480 field->proto_field_type = ProtoSchemaType::kInt32;
1481 SetTranslationStrategy(field->ftrace_type, field->proto_field_type,
1482 &field->strategy);
1483 }
1484 using Switch = protos::gen::SchedSwitchFtraceEvent;
1485 Event sched_switch_event{
1486 "sched_switch",
1487 "sched",
1488 {
1489 {8, 16, FtraceFieldType::kFtraceFixedCString, "prev_comm",
1490 Switch::kPrevCommFieldNumber, ProtoSchemaType::kString,
1491 TranslationStrategy::kInvalidTranslationStrategy},
1492 {24, 4, FtraceFieldType::kFtracePid32, "prev_pid",
1493 Switch::kPrevPidFieldNumber, ProtoSchemaType::kInt32,
1494 TranslationStrategy::kInvalidTranslationStrategy},
1495 {28, 4, FtraceFieldType::kFtraceInt32, "prev_prio",
1496 Switch::kPrevPrioFieldNumber, ProtoSchemaType::kInt32,
1497 TranslationStrategy::kInvalidTranslationStrategy},
1498 {32, 8, FtraceFieldType::kFtraceInt64, "prev_state",
1499 Switch::kPrevStateFieldNumber, ProtoSchemaType::kInt64,
1500 TranslationStrategy::kInvalidTranslationStrategy},
1501 {40, 16, FtraceFieldType::kFtraceFixedCString, "next_comm",
1502 Switch::kNextCommFieldNumber, ProtoSchemaType::kString,
1503 TranslationStrategy::kInvalidTranslationStrategy},
1504 {56, 4, FtraceFieldType::kFtracePid32, "next_pid",
1505 Switch::kNextPidFieldNumber, ProtoSchemaType::kInt32,
1506 TranslationStrategy::kInvalidTranslationStrategy},
1507 {60, 4, FtraceFieldType::kFtraceInt32, "next_prio",
1508 Switch::kNextPrioFieldNumber, ProtoSchemaType::kInt32,
1509 TranslationStrategy::kInvalidTranslationStrategy},
1510 },
1511 /*ftrace_event_id=*/315,
1512 /*proto_field_id=*/4,
1513 /*size=*/64};
1514 for (Field& field : sched_switch_event.fields) {
1515 SetTranslationStrategy(field.ftrace_type, field.proto_field_type,
1516 &field.strategy);
1517 }
1518 std::vector<Event> events;
1519 events.emplace_back(std::move(sched_switch_event));
1520
1521 NiceMock<MockFtraceProcfs> mock_ftrace;
1522 PrintkMap printk_formats;
1523 ProtoTranslationTable translation_table(
1524 &mock_ftrace, events, std::move(common_fields),
1525 ProtoTranslationTable::DefaultPageHeaderSpecForTesting(),
1526 InvalidCompactSchedEventFormatForTesting(), printk_formats);
1527 ProtoTranslationTable* table = &translation_table;
1528
1529 FtraceDataSourceConfig ds_config = EmptyConfig();
1530 ds_config.event_filter.AddEnabledEvent(
1531 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
1532
1533 FtraceMetadata metadata{};
1534 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
1535 const uint8_t* parse_pos = page.get();
1536 base::Optional<CpuReader::PageHeader> page_header =
1537 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
1538
1539 const uint8_t* page_end = page.get() + base::kPageSize;
1540 ASSERT_TRUE(page_header.has_value());
1541 EXPECT_FALSE(page_header->lost_events);
1542 EXPECT_TRUE(parse_pos < page_end);
1543 EXPECT_TRUE(parse_pos + page_header->size < page_end);
1544
1545 size_t evt_bytes = CpuReader::ParsePagePayload(
1546 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
1547 bundle_provider.writer(), &metadata);
1548
1549 ASSERT_LT(0u, evt_bytes);
1550
1551 auto bundle = bundle_provider.ParseProto();
1552 ASSERT_TRUE(bundle);
1553
1554 // There should be 9 sched_switch events within the above page.
1555 // We assert that all of their timestamps are exactly as expected.
1556 //
1557 // The key record that we're testing is an absolute timestamp
1558 // (RINGBUF_TYPE_TIME_STAMP) between the 3rd and 4th sched_switch events.
1559 //
1560 // This timestamp record starts at 0x334 bytes into the page.
1561 // The event header (first 4 bytes): 0xb66f9dff
1562 // -> type (bottom 5 bits): 31 (RINGBUF_TYPE_TIME_STAMP)
1563 // -> bottom 27 bits of ts: 0x5b37cef
1564 // Next 4 bytes have the top bits (28..59) of ts.
1565 // -> post-shift: 0x4e438f8000000
1566 // Adding the two parts of the timestamp, we get: 1376833332542703.
1567 //
1568 // The next event (sched_switch at 0x33c) after this timestamp has a
1569 // delta-timestamp of 0 in its event header, so we expect the 4th
1570 // sched_switch to have a timestamp of exactly 1376833332542703.
1571 EXPECT_EQ(bundle->event().size(), 9u);
1572
1573 std::vector<uint64_t> switch_timestamps;
1574 for (const auto& e : bundle->event())
1575 switch_timestamps.push_back(e.timestamp());
1576
1577 uint64_t expected_timestamps[] = {
1578 1376833327307547ull, 1376833327356434ull, 1376833332265799ull,
1579 1376833332542703ull, 1376833333729055ull, 1376833333757142ull,
1580 1376833333808564ull, 1376833333943445ull, 1376833333964012ull};
1581
1582 ASSERT_THAT(switch_timestamps,
1583 testing::ElementsAreArray(expected_timestamps));
1584 }
1585
TEST(CpuReaderTest,TranslateBlockDeviceIDToUserspace)1586 TEST(CpuReaderTest, TranslateBlockDeviceIDToUserspace) {
1587 const uint32_t kKernelBlockDeviceId = 271581216;
1588 const BlockDeviceID kUserspaceBlockDeviceId = 66336;
1589 const uint64_t k64BitKernelBlockDeviceId = 4442450946;
1590 const BlockDeviceID k64BitUserspaceBlockDeviceId =
1591 static_cast<BlockDeviceID>(17594983681026ULL);
1592
1593 EXPECT_EQ(CpuReader::TranslateBlockDeviceIDToUserspace<uint32_t>(
1594 kKernelBlockDeviceId),
1595 kUserspaceBlockDeviceId);
1596 EXPECT_EQ(CpuReader::TranslateBlockDeviceIDToUserspace<uint64_t>(
1597 k64BitKernelBlockDeviceId),
1598 k64BitUserspaceBlockDeviceId);
1599 }
1600
1601 // clang-format off
1602 // # tracer: nop
1603 // #
1604 // # entries-in-buffer/entries-written: 1041/238740 #P:8
1605 // #
1606 // # _-----=> irqs-off
1607 // # / _----=> need-resched
1608 // # | / _---=> hardirq/softirq
1609 // # || / _--=> preempt-depth
1610 // # ||| / delay
1611 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
1612 // # | | | |||| | |
1613 // android.bg-1668 [000] ...1 174991.234105: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1614 // android.bg-1668 [000] ...1 174991.234108: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
1615 // android.bg-1668 [000] ...1 174991.234118: ext4_da_write_begin: dev 259,32 ino 2883605 pos 20480 len 4096 flags 0
1616 // 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
1617 // android.bg-1668 [000] ...1 174991.234133: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 5
1618 // android.bg-1668 [000] ...1 174991.234135: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [5/4294967290) 576460752303423487 H0x10
1619 // 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
1620 // android.bg-1668 [000] ...1 174991.234142: ext4_es_insert_extent: dev 259,32 ino 2883605 es [5/1) mapped 576460752303423487 status D
1621 // android.bg-1668 [000] ...1 174991.234153: ext4_da_write_end: dev 259,32 ino 2883605 pos 20480 len 4096 copied 4096
1622 // android.bg-1668 [000] ...1 174991.234158: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1623 // android.bg-1668 [000] ...1 174991.234160: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
1624 // android.bg-1668 [000] ...1 174991.234170: ext4_da_write_begin: dev 259,32 ino 2883605 pos 24576 len 2968 flags 0
1625 // 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
1626 // android.bg-1668 [000] ...1 174991.234184: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 6
1627 // android.bg-1668 [000] ...1 174991.234187: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [6/4294967289) 576460752303423487 H0x10
1628 // 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
1629 // android.bg-1668 [000] ...1 174991.234193: ext4_es_insert_extent: dev 259,32 ino 2883605 es [6/1) mapped 576460752303423487 status D
1630 // android.bg-1668 [000] ...1 174991.234203: ext4_da_write_end: dev 259,32 ino 2883605 pos 24576 len 2968 copied 2968
1631 // android.bg-1668 [000] ...1 174991.234209: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1632 // android.bg-1668 [000] ...1 174991.234211: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
1633 // android.bg-1668 [000] ...1 174991.234262: ext4_sync_file_enter: dev 259,32 ino 2883605 parent 2883592 datasync 0
1634 // 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
1635 // android.bg-1668 [000] ...1 174991.234287: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_writepages+0x6a4/0x119c
1636 // 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
1637 // android.bg-1668 [000] ...1 174991.234319: ext4_da_write_pages_extent: dev 259,32 ino 2883605 lblk 0 len 7 flags 0x200
1638 // android.bg-1668 [000] ...1 174991.234322: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 0
1639 // android.bg-1668 [000] ...1 174991.234324: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [0/7) 576460752303423487 D0x10
1640 // 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
1641 // 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
1642 // 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
1643 // 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
1644 // android.bg-1668 [000] ...1 174991.234409: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller __ext4_ext_dirty+0x104/0x170
1645 // android.bg-1668 [000] ...1 174991.234420: ext4_get_reserved_cluster_alloc: dev 259,32 ino 2883605 lblk 0 len 7
1646 // 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
1647 // 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
1648 // android.bg-1668 [000] ...1 174991.234441: ext4_es_lookup_extent_enter: dev 259,32 ino 3 lblk 1
1649 // android.bg-1668 [000] ...1 174991.234445: ext4_es_lookup_extent_exit: dev 259,32 ino 3 found 1 [0/2) 9255 W0x10
1650 // 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
1651 // android.bg-1668 [000] ...1 174991.234460: ext4_es_lookup_extent_enter: dev 259,32 ino 4 lblk 1
1652 // android.bg-1668 [000] ...1 174991.234463: ext4_es_lookup_extent_exit: dev 259,32 ino 4 found 1 [0/2) 9257 W0x10
1653 // android.bg-1668 [000] ...1 174991.234471: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1654 // android.bg-1668 [000] ...1 174991.234474: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
1655 // 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
1656 // android.bg-1668 [000] ...1 174991.234484: ext4_es_insert_extent: dev 259,32 ino 2883605 es [0/7) mapped 2155471 status W
1657 // android.bg-1668 [000] ...1 174991.234547: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_writepages+0xdc0/0x119c
1658 // android.bg-1668 [000] ...1 174991.234604: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_writepages+0x6a4/0x119c
1659 // 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
1660 // 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
1661 // Profile Saver-5504 [000] ...1 175002.711928: ext4_discard_preallocations: dev 259,32 ino 1311176
1662 // Profile Saver-5504 [000] ...1 175002.714165: ext4_begin_ordered_truncate: dev 259,32 ino 1311176 new_size 0
1663 // Profile Saver-5504 [000] ...1 175002.714172: ext4_journal_start: dev 259,32 blocks, 3 rsv_blocks, 0 caller ext4_setattr+0x5b4/0x788
1664 // Profile Saver-5504 [000] ...1 175002.714218: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_setattr+0x65c/0x788
1665 // Profile Saver-5504 [000] ...1 175002.714277: ext4_invalidatepage: dev 259,32 ino 1311176 page_index 0 offset 0 length 4096
1666 // Profile Saver-5504 [000] ...1 175002.714281: ext4_releasepage: dev 259,32 ino 1311176 page_index 0
1667 // Profile Saver-5504 [000] ...1 175002.714295: ext4_invalidatepage: dev 259,32 ino 1311176 page_index 1 offset 0 length 4096
1668 // Profile Saver-5504 [000] ...1 175002.714296: ext4_releasepage: dev 259,32 ino 1311176 page_index 1
1669 // Profile Saver-5504 [000] ...1 175002.714315: ext4_truncate_enter: dev 259,32 ino 1311176 blocks 24
1670 // Profile Saver-5504 [000] ...1 175002.714318: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_truncate+0x258/0x4b8
1671 // Profile Saver-5504 [000] ...1 175002.714322: ext4_discard_preallocations: dev 259,32 ino 1311176
1672 // Profile Saver-5504 [000] ...1 175002.714324: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_ext_truncate+0x24/0xc8
1673 // Profile Saver-5504 [000] ...1 175002.714328: ext4_es_remove_extent: dev 259,32 ino 1311176 es [0/4294967295)
1674 // 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
1675 // Profile Saver-5504 [000] ...1 175002.714338: ext4_ext_remove_space: dev 259,32 ino 1311176 since 0 end 4294967294 depth 0
1676 // 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
1677 // 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
1678 // Profile Saver-5504 [000] ...1 175002.714354: ext4_free_blocks: dev 259,32 ino 1311176 mode 0100600 block 5276994 count 2 flags 1ST_CLUSTER
1679 // Profile Saver-5504 [000] ...1 175002.714365: ext4_mballoc_free: dev 259,32 inode 1311176 extent 161/1346/2
1680 // 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
1681 // Profile Saver-5504 [000] ...1 175002.714391: ext4_es_lookup_extent_enter: dev 259,32 ino 3 lblk 4
1682 // Profile Saver-5504 [000] ...1 175002.714394: ext4_es_lookup_extent_exit: dev 259,32 ino 3 found 1 [4/1) 557094 W0x10
1683 // 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
1684 // Profile Saver-5504 [000] ...1 175002.714404: ext4_es_lookup_extent_enter: dev 259,32 ino 4 lblk 8
1685 // Profile Saver-5504 [000] ...1 175002.714406: ext4_es_lookup_extent_exit: dev 259,32 ino 4 found 1 [8/3) 7376914 W0x10
1686 // Profile Saver-5504 [000] ...1 175002.714413: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1687 // Profile Saver-5504 [000] ...1 175002.714414: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1688 // Profile Saver-5504 [000] ...1 175002.714420: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller __ext4_ext_dirty+0x104/0x170
1689 // 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
1690 // Profile Saver-5504 [000] ...1 175002.714425: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller __ext4_ext_dirty+0x104/0x170
1691 // Profile Saver-5504 [000] ...1 175002.714433: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_truncate+0x3c4/0x4b8
1692 // Profile Saver-5504 [000] ...1 175002.714436: ext4_truncate_exit: dev 259,32 ino 1311176 blocks 8
1693 // Profile Saver-5504 [000] ...1 175002.714437: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1694 // Profile Saver-5504 [000] ...1 175002.714438: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1695 // Profile Saver-5504 [000] ...1 175002.714462: ext4_da_write_begin: dev 259,32 ino 1311176 pos 0 len 4 flags 0
1696 // 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
1697 // Profile Saver-5504 [000] ...1 175002.714477: ext4_es_lookup_extent_enter: dev 259,32 ino 1311176 lblk 0
1698 // Profile Saver-5504 [000] ...1 175002.714477: ext4_es_lookup_extent_exit: dev 259,32 ino 1311176 found 0 [0/0) 0
1699 // Profile Saver-5504 [000] ...1 175002.714480: ext4_ext_map_blocks_enter: dev 259,32 ino 1311176 lblk 0 len 1 flags
1700 // Profile Saver-5504 [000] ...1 175002.714485: ext4_es_find_delayed_extent_range_enter: dev 259,32 ino 1311176 lblk 0
1701 // 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
1702 // Profile Saver-5504 [000] ...1 175002.714490: ext4_es_insert_extent: dev 259,32 ino 1311176 es [0/4294967295) mapped 576460752303423487 status H
1703 // 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
1704 // 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
1705 // Profile Saver-5504 [000] ...1 175002.714505: ext4_es_insert_extent: dev 259,32 ino 1311176 es [0/1) mapped 576460752303423487 status D
1706 // Profile Saver-5504 [000] ...1 175002.714513: ext4_da_write_end: dev 259,32 ino 1311176 pos 0 len 4 copied 4
1707 // Profile Saver-5504 [000] ...1 175002.714519: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1708 // Profile Saver-5504 [000] ...1 175002.714520: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1709 // Profile Saver-5504 [000] ...1 175002.714527: ext4_da_write_begin: dev 259,32 ino 1311176 pos 4 len 4 flags 0
1710 // 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
1711 // Profile Saver-5504 [000] ...1 175002.714531: ext4_da_write_end: dev 259,32 ino 1311176 pos 4 len 4 copied 4
1712 // Profile Saver-5504 [000] ...1 175002.714532: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1713 // Profile Saver-5504 [000] ...1 175002.714532: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1714 // Profile Saver-5504 [000] ...1 175002.715313: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1715 // Profile Saver-5504 [000] ...1 175002.715322: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1716 // Profile Saver-5504 [000] ...1 175002.723849: ext4_da_write_begin: dev 259,32 ino 1311176 pos 8 len 5 flags 0
1717 // 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
1718 // Profile Saver-5504 [000] ...1 175002.723873: ext4_da_write_end: dev 259,32 ino 1311176 pos 8 len 5 copied 5
1719 // Profile Saver-5504 [000] ...1 175002.723877: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1720 // Profile Saver-5504 [000] ...1 175002.723879: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1721 // Profile Saver-5504 [000] ...1 175002.726857: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1722 // Profile Saver-5504 [000] ...1 175002.726867: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1723 // Profile Saver-5504 [000] ...1 175002.726881: ext4_da_write_begin: dev 259,32 ino 1311176 pos 13 len 4 flags 0
1724 // 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
1725 // Profile Saver-5504 [000] ...1 175002.726890: ext4_da_write_end: dev 259,32 ino 1311176 pos 13 len 4 copied 4
1726 // Profile Saver-5504 [000] ...1 175002.726892: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1727 // Profile Saver-5504 [000] ...1 175002.726892: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1728 // Profile Saver-5504 [000] ...1 175002.726900: ext4_da_write_begin: dev 259,32 ino 1311176 pos 17 len 4079 flags 0
1729 // 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
1730 // Profile Saver-5504 [000] ...1 175002.726904: ext4_da_write_end: dev 259,32 ino 1311176 pos 17 len 4079 copied 4079
1731 // Profile Saver-5504 [000] ...1 175002.726905: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1732 // Profile Saver-5504 [000] ...1 175002.726906: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1733 // Profile Saver-5504 [000] ...1 175002.726908: ext4_da_write_begin: dev 259,32 ino 1311176 pos 4096 len 2780 flags 0
1734 // 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
1735 // Profile Saver-5504 [000] ...1 175002.726921: ext4_es_lookup_extent_enter: dev 259,32 ino 1311176 lblk 1
1736 // Profile Saver-5504 [000] ...1 175002.726924: ext4_es_lookup_extent_exit: dev 259,32 ino 1311176 found 1 [1/4294967294) 576460752303423487 H0x10
1737 // 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
1738 // Profile Saver-5504 [000] ...1 175002.726933: ext4_es_insert_extent: dev 259,32 ino 1311176 es [1/1) mapped 576460752303423487 status D
1739 // Profile Saver-5504 [000] ...1 175002.726940: ext4_da_write_end: dev 259,32 ino 1311176 pos 4096 len 2780 copied 2780
1740 // Profile Saver-5504 [000] ...1 175002.726941: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
1741 // Profile Saver-5504 [000] ...1 175002.726942: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
1742 // 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
1743 // d.process.acor-27885 [000] ...1 175018.227699: ext4_mark_inode_dirty: dev 259,32 ino 3278189 caller ext4_dirty_inode+0x48/0x68
1744 // d.process.acor-27885 [000] ...1 175018.227839: ext4_sync_file_enter: dev 259,32 ino 3278183 parent 3277001 datasync 1
1745 // 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
1746 // 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
1747 // clang-format on
1748
1749 static ExamplePage g_full_page_sched_switch{
1750 "synthetic",
1751 R"(
1752 00000000: 31f2 7622 1a00 0000 b40f 0000 0000 0000 1.v"............
1753 00000010: 1e00 0000 0000 0000 1000 0000 2f00 0103 ............/...
1754 00000020: 140d 0000 4a69 7420 7468 7265 6164 2070 ....Jit thread p
1755 00000030: 6f6f 6c00 140d 0000 8100 0000 0008 0000 ool.............
1756 00000040: 0000 0000 4576 656e 7454 6872 6561 6400 ....EventThread.
1757 00000050: 6572 0000 7002 0000 6100 0000 f057 0e00 er..p...a....W..
1758 00000060: 2f00 0103 7002 0000 4576 656e 7454 6872 /...p...EventThr
1759 00000070: 6561 6400 6572 0000 7002 0000 6100 0000 ead.er..p...a...
1760 00000080: 0100 0000 0000 0000 4a69 7420 7468 7265 ........Jit thre
1761 00000090: 6164 2070 6f6f 6c00 140d 0000 8100 0000 ad pool.........
1762 000000a0: 50c2 0910 2f00 0103 140d 0000 4a69 7420 P.../.......Jit
1763 000000b0: 7468 7265 6164 2070 6f6f 6c00 140d 0000 thread pool.....
1764 000000c0: 8100 0000 0100 0000 0000 0000 7377 6170 ............swap
1765 000000d0: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1766 000000e0: 7800 0000 901a c80e 2f00 0103 0000 0000 x......./.......
1767 000000f0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1768 00000100: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
1769 00000110: 4469 7370 5379 6e63 0069 6e67 6572 0000 DispSync.inger..
1770 00000120: 6f02 0000 6100 0000 1064 1e00 2f00 0103 o...a....d../...
1771 00000130: 6f02 0000 4469 7370 5379 6e63 0069 6e67 o...DispSync.ing
1772 00000140: 6572 0000 6f02 0000 6100 0000 0100 0000 er..o...a.......
1773 00000150: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1774 00000160: 0000 0000 0000 0000 7800 0000 9074 8600 ........x....t..
1775 00000170: 2f00 0103 0000 0000 7377 6170 7065 722f /.......swapper/
1776 00000180: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1777 00000190: 0000 0000 0000 0000 4576 656e 7454 6872 ........EventThr
1778 000001a0: 6561 6400 6572 0000 7002 0000 6100 0000 ead.er..p...a...
1779 000001b0: d071 0b00 2f00 0103 7002 0000 4576 656e .q../...p...Even
1780 000001c0: 7454 6872 6561 6400 6572 0000 7002 0000 tThread.er..p...
1781 000001d0: 6100 0000 0100 0000 0000 0000 7377 6170 a...........swap
1782 000001e0: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1783 000001f0: 7800 0000 10cd 4504 2f00 0103 0000 0000 x.....E./.......
1784 00000200: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1785 00000210: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
1786 00000220: 7375 676f 763a 3000 0000 0000 0000 0000 sugov:0.........
1787 00000230: 3802 0000 3100 0000 30d6 1300 2f00 0103 8...1...0.../...
1788 00000240: 3802 0000 7375 676f 763a 3000 0000 0000 8...sugov:0.....
1789 00000250: 0000 0000 3802 0000 3100 0000 0100 0000 ....8...1.......
1790 00000260: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1791 00000270: 0000 0000 0000 0000 7800 0000 3049 a202 ........x...0I..
1792 00000280: 2f00 0103 0000 0000 7377 6170 7065 722f /.......swapper/
1793 00000290: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1794 000002a0: 0000 0000 0000 0000 4469 7370 5379 6e63 ........DispSync
1795 000002b0: 0069 6e67 6572 0000 6f02 0000 6100 0000 .inger..o...a...
1796 000002c0: d07a 1000 2f00 0103 6f02 0000 4469 7370 .z../...o...Disp
1797 000002d0: 5379 6e63 0069 6e67 6572 0000 6f02 0000 Sync.inger..o...
1798 000002e0: 6100 0000 0100 0000 0000 0000 7377 6170 a...........swap
1799 000002f0: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1800 00000300: 7800 0000 d085 1100 2f00 0103 0000 0000 x......./.......
1801 00000310: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1802 00000320: 0000 0000 7800 0000 0000 0000 0000 0000 ....x...........
1803 00000330: 7375 7266 6163 6566 6c69 6e67 6572 0000 surfaceflinger..
1804 00000340: 4b02 0000 6200 0000 907a f000 2f00 0103 K...b....z../...
1805 00000350: 4b02 0000 7375 7266 6163 6566 6c69 6e67 K...surfacefling
1806 00000360: 6572 0000 4b02 0000 6200 0000 0100 0000 er..K...b.......
1807 00000370: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1808 00000380: 0000 0000 0000 0000 7800 0000 305a 6400 ........x...0Zd.
1809 00000390: 2f00 0103 0000 0000 7377 6170 7065 722f /.......swapper/
1810 000003a0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1811 000003b0: 0000 0000 0000 0000 6d64 7373 5f66 6230 ........mdss_fb0
1812 000003c0: 0000 0000 0000 0000 5714 0000 5300 0000 ........W...S...
1813 000003d0: 10b1 9e03 2f00 0103 5714 0000 6d64 7373 ..../...W...mdss
1814 000003e0: 5f66 6230 0000 0000 0000 0000 5714 0000 _fb0........W...
1815 000003f0: 5300 0000 0200 0000 0000 0000 6b73 6f66 S...........ksof
1816 00000400: 7469 7271 642f 3000 0000 0000 0300 0000 tirqd/0.........
1817 00000410: 7800 0000 90bb 9900 2f00 0103 0300 0000 x......./.......
1818 00000420: 6b73 6f66 7469 7271 642f 3000 0000 0000 ksoftirqd/0.....
1819 00000430: 0300 0000 7800 0000 0100 0000 0000 0000 ....x...........
1820 00000440: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1821 00000450: 0000 0000 7800 0000 701e 5305 2f00 0103 ....x...p.S./...
1822 00000460: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1823 00000470: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1824 00000480: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
1825 00000490: 3600 0000 6401 0000 7800 0000 90a1 2900 6...d...x.....).
1826 000004a0: 2f00 0103 6401 0000 6b77 6f72 6b65 722f /...d...kworker/
1827 000004b0: 7531 363a 3600 0000 6401 0000 7800 0000 u16:6...d...x...
1828 000004c0: 0200 0000 0000 0000 7377 6170 7065 722f ........swapper/
1829 000004d0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1830 000004e0: b0e5 4f04 2f00 0103 0000 0000 7377 6170 ..O./.......swap
1831 000004f0: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1832 00000500: 7800 0000 0000 0000 0000 0000 4269 6e64 x...........Bind
1833 00000510: 6572 3a32 3136 385f 3135 0000 e614 0000 er:2168_15......
1834 00000520: 7800 0000 b0bd 7c00 2f00 0103 e614 0000 x.....|./.......
1835 00000530: 4269 6e64 6572 3a32 3136 385f 3135 0000 Binder:2168_15..
1836 00000540: e614 0000 7800 0000 0100 0000 0000 0000 ....x...........
1837 00000550: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1838 00000560: 0000 0000 7800 0000 d0bd 7e01 2f00 0103 ....x.....~./...
1839 00000570: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1840 00000580: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1841 00000590: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
1842 000005a0: 3900 0000 e204 0000 7800 0000 7016 0800 9.......x...p...
1843 000005b0: 2f00 0103 e204 0000 6b77 6f72 6b65 722f /.......kworker/
1844 000005c0: 7531 363a 3900 0000 e204 0000 7800 0000 u16:9.......x...
1845 000005d0: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
1846 000005e0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1847 000005f0: 1004 5200 2f00 0103 0000 0000 7377 6170 ..R./.......swap
1848 00000600: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1849 00000610: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
1850 00000620: 6b65 722f 7531 363a 3900 0000 e204 0000 ker/u16:9.......
1851 00000630: 7800 0000 d0db 0700 2f00 0103 e204 0000 x......./.......
1852 00000640: 6b77 6f72 6b65 722f 7531 363a 3900 0000 kworker/u16:9...
1853 00000650: e204 0000 7800 0000 0100 0000 0000 0000 ....x...........
1854 00000660: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1855 00000670: 0000 0000 7800 0000 b0a2 8c00 2f00 0103 ....x......./...
1856 00000680: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1857 00000690: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1858 000006a0: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
1859 000006b0: 3900 0000 e204 0000 7800 0000 d02b 0400 9.......x....+..
1860 000006c0: 2f00 0103 e204 0000 6b77 6f72 6b65 722f /.......kworker/
1861 000006d0: 7531 363a 3900 0000 e204 0000 7800 0000 u16:9.......x...
1862 000006e0: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
1863 000006f0: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1864 00000700: d064 ef05 2f00 0103 0000 0000 7377 6170 .d../.......swap
1865 00000710: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1866 00000720: 7800 0000 0000 0000 0000 0000 4469 7370 x...........Disp
1867 00000730: 5379 6e63 0069 6e67 6572 0000 6f02 0000 Sync.inger..o...
1868 00000740: 6100 0000 f07d 1b00 2f00 0103 6f02 0000 a....}../...o...
1869 00000750: 4469 7370 5379 6e63 0069 6e67 6572 0000 DispSync.inger..
1870 00000760: 6f02 0000 6100 0000 0100 0000 0000 0000 o...a...........
1871 00000770: 6b73 6f66 7469 7271 642f 3000 0000 0000 ksoftirqd/0.....
1872 00000780: 0300 0000 7800 0000 304c 2000 2f00 0103 ....x...0L ./...
1873 00000790: 0300 0000 6b73 6f66 7469 7271 642f 3000 ....ksoftirqd/0.
1874 000007a0: 0000 0000 0300 0000 7800 0000 0100 0000 ........x.......
1875 000007b0: 0000 0000 6465 7832 6f61 7400 3935 5f33 ....dex2oat.95_3
1876 000007c0: 0000 0000 341f 0000 8200 0000 700b 0700 ....4.......p...
1877 000007d0: 2f00 0103 341f 0000 6465 7832 6f61 7400 /...4...dex2oat.
1878 000007e0: 3935 5f33 0000 0000 341f 0000 8200 0000 95_3....4.......
1879 000007f0: 0000 0000 0000 0000 7375 676f 763a 3000 ........sugov:0.
1880 00000800: 0000 0000 0000 0000 3802 0000 3100 0000 ........8...1...
1881 00000810: 50b0 0600 2f00 0103 3802 0000 7375 676f P.../...8...sugo
1882 00000820: 763a 3000 0000 0000 0000 0000 3802 0000 v:0.........8...
1883 00000830: 3100 0000 0008 0000 0000 0000 6d69 6772 1...........migr
1884 00000840: 6174 696f 6e2f 3000 0000 0000 0d00 0000 ation/0.........
1885 00000850: 0000 0000 d09c 0600 2f00 0103 0d00 0000 ......../.......
1886 00000860: 6d69 6772 6174 696f 6e2f 3000 0000 0000 migration/0.....
1887 00000870: 0d00 0000 0000 0000 0100 0000 0000 0000 ................
1888 00000880: 7375 676f 763a 3000 0000 0000 0000 0000 sugov:0.........
1889 00000890: 3802 0000 3100 0000 7061 1900 2f00 0103 8...1...pa../...
1890 000008a0: 3802 0000 7375 676f 763a 3000 0000 0000 8...sugov:0.....
1891 000008b0: 0000 0000 3802 0000 3100 0000 0100 0000 ....8...1.......
1892 000008c0: 0000 0000 6465 7832 6f61 7400 3935 5f33 ....dex2oat.95_3
1893 000008d0: 0000 0000 341f 0000 8200 0000 f03c 5600 ....4........<V.
1894 000008e0: 2f00 0103 341f 0000 6465 7832 6f61 7400 /...4...dex2oat.
1895 000008f0: 3935 5f33 0000 0000 341f 0000 8200 0000 95_3....4.......
1896 00000900: 0200 0000 0000 0000 7377 6170 7065 722f ........swapper/
1897 00000910: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1898 00000920: 5013 c400 2f00 0103 0000 0000 7377 6170 P.../.......swap
1899 00000930: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1900 00000940: 7800 0000 0000 0000 0000 0000 616e 6472 x...........andr
1901 00000950: 6f69 642e 6861 7264 7761 7200 d20a 0000 oid.hardwar.....
1902 00000960: 7800 0000 30c9 1300 2f00 0103 d20a 0000 x...0.../.......
1903 00000970: 616e 6472 6f69 642e 6861 7264 7761 7200 android.hardwar.
1904 00000980: d20a 0000 7800 0000 0100 0000 0000 0000 ....x...........
1905 00000990: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1906 000009a0: 0000 0000 7800 0000 7097 c000 2f00 0103 ....x...p.../...
1907 000009b0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1908 000009c0: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1909 000009d0: 0000 0000 616e 6472 6f69 642e 6861 7264 ....android.hard
1910 000009e0: 7761 7200 d20a 0000 7800 0000 305c 0c00 war.....x...0\..
1911 000009f0: 2f00 0103 d20a 0000 616e 6472 6f69 642e /.......android.
1912 00000a00: 6861 7264 7761 7200 d20a 0000 7800 0000 hardwar.....x...
1913 00000a10: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
1914 00000a20: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1915 00000a30: d0aa 1401 2f00 0103 0000 0000 7377 6170 ..../.......swap
1916 00000a40: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1917 00000a50: 7800 0000 0000 0000 0000 0000 616e 6472 x...........andr
1918 00000a60: 6f69 642e 6861 7264 7761 7200 d20a 0000 oid.hardwar.....
1919 00000a70: 7800 0000 903b 0c00 2f00 0103 d20a 0000 x....;../.......
1920 00000a80: 616e 6472 6f69 642e 6861 7264 7761 7200 android.hardwar.
1921 00000a90: d20a 0000 7800 0000 0100 0000 0000 0000 ....x...........
1922 00000aa0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1923 00000ab0: 0000 0000 7800 0000 f024 5401 2f00 0103 ....x....$T./...
1924 00000ac0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1925 00000ad0: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1926 00000ae0: 0000 0000 616e 6472 6f69 642e 6861 7264 ....android.hard
1927 00000af0: 7761 7200 d20a 0000 7800 0000 f0f3 0b00 war.....x.......
1928 00000b00: 2f00 0103 d20a 0000 616e 6472 6f69 642e /.......android.
1929 00000b10: 6861 7264 7761 7200 d20a 0000 7800 0000 hardwar.....x...
1930 00000b20: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
1931 00000b30: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1932 00000b40: d0b5 bf02 2f00 0103 0000 0000 7377 6170 ..../.......swap
1933 00000b50: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1934 00000b60: 7800 0000 0000 0000 0000 0000 4469 7370 x...........Disp
1935 00000b70: 5379 6e63 0069 6e67 6572 0000 6f02 0000 Sync.inger..o...
1936 00000b80: 6100 0000 90cd 1400 2f00 0103 6f02 0000 a......./...o...
1937 00000b90: 4469 7370 5379 6e63 0069 6e67 6572 0000 DispSync.inger..
1938 00000ba0: 6f02 0000 6100 0000 0100 0000 0000 0000 o...a...........
1939 00000bb0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1940 00000bc0: 0000 0000 7800 0000 50a6 1100 2f00 0103 ....x...P.../...
1941 00000bd0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1942 00000be0: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1943 00000bf0: 0000 0000 7375 7266 6163 6566 6c69 6e67 ....surfacefling
1944 00000c00: 6572 0000 4b02 0000 6200 0000 b04c 4200 er..K...b....LB.
1945 00000c10: 2f00 0103 4b02 0000 7375 7266 6163 6566 /...K...surfacef
1946 00000c20: 6c69 6e67 6572 0000 4b02 0000 6200 0000 linger..K...b...
1947 00000c30: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
1948 00000c40: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1949 00000c50: b025 060a 2f00 0103 0000 0000 7377 6170 .%../.......swap
1950 00000c60: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1951 00000c70: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
1952 00000c80: 6b65 722f 7531 363a 3600 0000 6401 0000 ker/u16:6...d...
1953 00000c90: 7800 0000 d0b6 0600 2f00 0103 6401 0000 x......./...d...
1954 00000ca0: 6b77 6f72 6b65 722f 7531 363a 3600 0000 kworker/u16:6...
1955 00000cb0: 6401 0000 7800 0000 0100 0000 0000 0000 d...x...........
1956 00000cc0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1957 00000cd0: 0000 0000 7800 0000 f0a0 5800 2f00 0103 ....x.....X./...
1958 00000ce0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1959 00000cf0: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1960 00000d00: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
1961 00000d10: 3600 0000 6401 0000 7800 0000 f07a 1300 6...d...x....z..
1962 00000d20: 2f00 0103 6401 0000 6b77 6f72 6b65 722f /...d...kworker/
1963 00000d30: 7531 363a 3600 0000 6401 0000 7800 0000 u16:6...d...x...
1964 00000d40: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
1965 00000d50: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1966 00000d60: b080 b101 2f00 0103 0000 0000 7377 6170 ..../.......swap
1967 00000d70: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1968 00000d80: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
1969 00000d90: 6b65 722f 7531 363a 3600 0000 6401 0000 ker/u16:6...d...
1970 00000da0: 7800 0000 103c 1200 2f00 0103 6401 0000 x....<../...d...
1971 00000db0: 6b77 6f72 6b65 722f 7531 363a 3600 0000 kworker/u16:6...
1972 00000dc0: 6401 0000 7800 0000 0100 0000 0000 0000 d...x...........
1973 00000dd0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1974 00000de0: 0000 0000 7800 0000 50ea 3800 2f00 0103 ....x...P.8./...
1975 00000df0: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1976 00000e00: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1977 00000e10: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
1978 00000e20: 3600 0000 6401 0000 7800 0000 5032 0400 6...d...x...P2..
1979 00000e30: 2f00 0103 6401 0000 6b77 6f72 6b65 722f /...d...kworker/
1980 00000e40: 7531 363a 3600 0000 6401 0000 7800 0000 u16:6...d...x...
1981 00000e50: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
1982 00000e60: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
1983 00000e70: 70f5 9000 2f00 0103 0000 0000 7377 6170 p.../.......swap
1984 00000e80: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
1985 00000e90: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
1986 00000ea0: 6b65 722f 7531 363a 3600 0000 6401 0000 ker/u16:6...d...
1987 00000eb0: 7800 0000 10d7 0300 2f00 0103 6401 0000 x......./...d...
1988 00000ec0: 6b77 6f72 6b65 722f 7531 363a 3600 0000 kworker/u16:6...
1989 00000ed0: 6401 0000 7800 0000 0100 0000 0000 0000 d...x...........
1990 00000ee0: 7377 6170 7065 722f 3000 0000 0000 0000 swapper/0.......
1991 00000ef0: 0000 0000 7800 0000 907c 0900 2f00 0103 ....x....|../...
1992 00000f00: 0000 0000 7377 6170 7065 722f 3000 0000 ....swapper/0...
1993 00000f10: 0000 0000 0000 0000 7800 0000 0000 0000 ........x.......
1994 00000f20: 0000 0000 6b77 6f72 6b65 722f 7531 363a ....kworker/u16:
1995 00000f30: 3600 0000 6401 0000 7800 0000 7082 0300 6...d...x...p...
1996 00000f40: 2f00 0103 6401 0000 6b77 6f72 6b65 722f /...d...kworker/
1997 00000f50: 7531 363a 3600 0000 6401 0000 7800 0000 u16:6...d...x...
1998 00000f60: 0100 0000 0000 0000 7377 6170 7065 722f ........swapper/
1999 00000f70: 3000 0000 0000 0000 0000 0000 7800 0000 0...........x...
2000 00000f80: f0ec 2100 2f00 0103 0000 0000 7377 6170 ..!./.......swap
2001 00000f90: 7065 722f 3000 0000 0000 0000 0000 0000 per/0...........
2002 00000fa0: 7800 0000 0000 0000 0000 0000 6b77 6f72 x...........kwor
2003 00000fb0: 6b65 722f 7531 363a 3600 0000 6401 0000 ker/u16:6...d...
2004 00000fc0: 7800 0000 0000 0000 0000 0000 0000 0000 x...............
2005 00000fd0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2006 00000fe0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2007 00000ff0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2008 )",
2009 };
2010
TEST(CpuReaderTest,ParseFullPageSchedSwitch)2011 TEST(CpuReaderTest, ParseFullPageSchedSwitch) {
2012 const ExamplePage* test_case = &g_full_page_sched_switch;
2013
2014 BundleProvider bundle_provider(base::kPageSize);
2015 ProtoTranslationTable* table = GetTable(test_case->name);
2016 auto page = PageFromXxd(test_case->data);
2017
2018 FtraceDataSourceConfig ds_config = EmptyConfig();
2019 ds_config.event_filter.AddEnabledEvent(
2020 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
2021
2022 FtraceMetadata metadata{};
2023 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
2024 const uint8_t* parse_pos = page.get();
2025 base::Optional<CpuReader::PageHeader> page_header =
2026 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
2027
2028 const uint8_t* page_end = page.get() + base::kPageSize;
2029 ASSERT_TRUE(page_header.has_value());
2030 EXPECT_FALSE(page_header->lost_events);
2031 EXPECT_TRUE(parse_pos < page_end);
2032 EXPECT_TRUE(parse_pos + page_header->size < page_end);
2033
2034 size_t evt_bytes = CpuReader::ParsePagePayload(
2035 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
2036 bundle_provider.writer(), &metadata);
2037
2038 EXPECT_LT(0u, evt_bytes);
2039
2040 auto bundle = bundle_provider.ParseProto();
2041 ASSERT_TRUE(bundle);
2042 EXPECT_EQ(bundle->event().size(), 59u);
2043 }
2044
2045 // clang-format off
2046 // # tracer: nop
2047 // #
2048 // # entries-in-buffer/entries-written: 18/18 #P:8
2049 // #
2050 // # _-----=> irqs-off
2051 // # / _----=> need-resched
2052 // # | / _---=> hardirq/softirq
2053 // # || / _--=> preempt-depth
2054 // # ||| / delay
2055 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
2056 // # | | | |||| | |
2057 // <...>-9290 [000] .... 1352.654573: suspend_resume: sync_filesystems[0] end
2058 // <...>-9290 [000] .... 1352.665366: suspend_resume: freeze_processes[0] begin
2059 // <...>-9290 [000] .... 1352.699711: suspend_resume: freeze_processes[0] end
2060 // <...>-9290 [000] .... 1352.699718: suspend_resume: suspend_enter[1] end
2061 // <...>-9290 [000] .... 1352.699723: suspend_resume: dpm_prepare[2] begin
2062 // <...>-9290 [000] .... 1352.703470: suspend_resume: dpm_prepare[2] end
2063 // <...>-9290 [000] .... 1352.703477: suspend_resume: dpm_suspend[2] begin
2064 // <...>-9290 [000] .... 1352.720107: suspend_resume: dpm_resume[16] end
2065 // <...>-9290 [000] .... 1352.720113: suspend_resume: dpm_complete[16] begin
2066 // <...>-9290 [000] .n.. 1352.724540: suspend_resume: dpm_complete[16] end
2067 // <...>-9290 [000] .... 1352.724567: suspend_resume: resume_console[1] begin
2068 // <...>-9290 [000] .... 1352.724570: suspend_resume: resume_console[1] end
2069 // <...>-9290 [000] .... 1352.724574: suspend_resume: thaw_processes[0] begin
2070 static ExamplePage g_suspend_resume {
2071 "synthetic",
2072 R"(00000000: edba 155a 3201 0000 7401 0000 0000 0000 ...Z2...t.......
2073 00000010: 7e58 22cd 1201 0000 0600 0000 ac00 0000 ~X".............
2074 00000020: 4a24 0000 5a7a f504 85ff ffff 0000 0000 J$..Zz..........
2075 00000030: 0017 0000 c621 9614 ac00 0000 4a24 0000 .....!......J$..
2076 00000040: 1c7a f504 85ff ffff 0000 0000 0100 0000 .z..............
2077 00000050: e6f1 8141 ac00 0000 4a24 0000 1c7a f504 ...A....J$...z..
2078 00000060: 85ff ffff 0000 0000 0000 0000 8682 0300 ................
2079 00000070: ac00 0000 4a24 0000 4c7a f504 85ff ffff ....J$..Lz......
2080 00000080: 0100 0000 0063 755f 0657 0200 ac00 0000 .....cu_.W......
2081 00000090: 4a24 0000 8ad5 0105 85ff ffff 0200 0000 J$..............
2082 000000a0: 0100 0000 06b5 2507 ac00 0000 4a24 0000 ......%.....J$..
2083 000000b0: 8ad5 0105 85ff ffff 0200 0000 0000 0000 ................
2084 000000c0: 460d 0300 ac00 0000 4a24 0000 51d5 0105 F.......J$..Q...
2085 000000d0: 85ff ffff 0200 0000 0117 0000 c63e b81f .............>..
2086 000000e0: ac00 0000 4a24 0000 7fd5 0105 85ff ffff ....J$..........
2087 000000f0: 1000 0000 0010 0b00 a6f9 0200 ac00 0000 ................
2088 00000100: 4a24 0000 96d5 0105 85ff ffff 1000 0000 J$..............
2089 00000110: 01c0 1f00 a6dd 7108 ac00 0400 4a24 0000 ......q.....J$..
2090 00000120: 96d5 0105 85ff ffff 1000 0000 0000 0000 ................
2091 00000130: c6f1 0c00 ac00 0000 4a24 0000 3d7a f504 ........J$..=z..
2092 00000140: 85ff ffff 0100 0000 01ea 24d5 a66c 0100 ..........$..l..
2093 00000150: ac00 0000 4a24 0000 3d7a f504 85ff ffff ....J$..=z......
2094 00000160: 0100 0000 0000 0001 6636 0200 ac00 0000 ........f6......
2095 00000170: 4a24 0000 d178 f504 85ff ffff 0000 0000 J$...x..........
2096 00000180: 0100 0000 0000 0000 0000 0000 0000 0000 ................
2097 00000190: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2098 )"};
2099
TEST(CpuReaderTest,ParseSuspendResume)2100 TEST(CpuReaderTest, ParseSuspendResume) {
2101 const ExamplePage* test_case = &g_suspend_resume;
2102
2103 BundleProvider bundle_provider(base::kPageSize);
2104 ProtoTranslationTable* table = GetTable(test_case->name);
2105 auto page = PageFromXxd(test_case->data);
2106
2107 FtraceDataSourceConfig ds_config = EmptyConfig();
2108 ds_config.event_filter.AddEnabledEvent(
2109 table->EventToFtraceId(GroupAndName("power", "suspend_resume")));
2110
2111 FtraceMetadata metadata{};
2112 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
2113 const uint8_t* parse_pos = page.get();
2114 base::Optional<CpuReader::PageHeader> page_header =
2115 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
2116 ASSERT_TRUE(page_header.has_value());
2117
2118 CpuReader::ParsePagePayload(
2119 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
2120 bundle_provider.writer(), &metadata);
2121 auto bundle = bundle_provider.ParseProto();
2122 ASSERT_TRUE(bundle);
2123 ASSERT_EQ(bundle->event().size(), 13u);
2124 EXPECT_EQ(bundle->event()[0].suspend_resume().action(), "sync_filesystems");
2125 EXPECT_EQ(bundle->event()[1].suspend_resume().action(), "freeze_processes");
2126 EXPECT_EQ(bundle->event()[2].suspend_resume().action(), "freeze_processes");
2127 EXPECT_EQ(bundle->event()[3].suspend_resume().action(), "suspend_enter");
2128 // dpm_prepare deliberately missing from:
2129 // src/traced/probes/ftrace/test/data/synthetic/printk_formats to ensure we
2130 // handle that case correctly.
2131 EXPECT_EQ(bundle->event()[4].suspend_resume().action(), "");
2132 }
2133
2134 // clang-format off
2135 // # tracer: nop
2136 // #
2137 // # entries-in-buffer/entries-written: 1041/238740 #P:8
2138 // #
2139 // # _-----=> irqs-off
2140 // # / _----=> need-resched
2141 // # | / _---=> hardirq/softirq
2142 // # || / _--=> preempt-depth
2143 // # ||| / delay
2144 // # TASK-PID CPU# |||| TIMESTAMP FUNCTION
2145 // # | | | |||| | |
2146 // android.bg-1668 [000] ...1 174991.234105: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2147 // android.bg-1668 [000] ...1 174991.234108: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2148 // android.bg-1668 [000] ...1 174991.234118: ext4_da_write_begin: dev 259,32 ino 2883605 pos 20480 len 4096 flags 0
2149 // 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
2150 // android.bg-1668 [000] ...1 174991.234133: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 5
2151 // android.bg-1668 [000] ...1 174991.234135: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [5/4294967290) 576460752303423487 H0x10
2152 // 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
2153 // android.bg-1668 [000] ...1 174991.234142: ext4_es_insert_extent: dev 259,32 ino 2883605 es [5/1) mapped 576460752303423487 status D
2154 // android.bg-1668 [000] ...1 174991.234153: ext4_da_write_end: dev 259,32 ino 2883605 pos 20480 len 4096 copied 4096
2155 // android.bg-1668 [000] ...1 174991.234158: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2156 // android.bg-1668 [000] ...1 174991.234160: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2157 // android.bg-1668 [000] ...1 174991.234170: ext4_da_write_begin: dev 259,32 ino 2883605 pos 24576 len 2968 flags 0
2158 // 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
2159 // android.bg-1668 [000] ...1 174991.234184: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 6
2160 // android.bg-1668 [000] ...1 174991.234187: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [6/4294967289) 576460752303423487 H0x10
2161 // 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
2162 // android.bg-1668 [000] ...1 174991.234193: ext4_es_insert_extent: dev 259,32 ino 2883605 es [6/1) mapped 576460752303423487 status D
2163 // android.bg-1668 [000] ...1 174991.234203: ext4_da_write_end: dev 259,32 ino 2883605 pos 24576 len 2968 copied 2968
2164 // android.bg-1668 [000] ...1 174991.234209: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2165 // android.bg-1668 [000] ...1 174991.234211: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2166 // android.bg-1668 [000] ...1 174991.234262: ext4_sync_file_enter: dev 259,32 ino 2883605 parent 2883592 datasync 0
2167 // 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
2168 // android.bg-1668 [000] ...1 174991.234287: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_writepages+0x6a4/0x119c
2169 // 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
2170 // android.bg-1668 [000] ...1 174991.234319: ext4_da_write_pages_extent: dev 259,32 ino 2883605 lblk 0 len 7 flags 0x200
2171 // android.bg-1668 [000] ...1 174991.234322: ext4_es_lookup_extent_enter: dev 259,32 ino 2883605 lblk 0
2172 // android.bg-1668 [000] ...1 174991.234324: ext4_es_lookup_extent_exit: dev 259,32 ino 2883605 found 1 [0/7) 576460752303423487 D0x10
2173 // 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
2174 // 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
2175 // 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
2176 // 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
2177 // android.bg-1668 [000] ...1 174991.234409: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller __ext4_ext_dirty+0x104/0x170
2178 // android.bg-1668 [000] ...1 174991.234420: ext4_get_reserved_cluster_alloc: dev 259,32 ino 2883605 lblk 0 len 7
2179 // 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
2180 // 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
2181 // android.bg-1668 [000] ...1 174991.234441: ext4_es_lookup_extent_enter: dev 259,32 ino 3 lblk 1
2182 // android.bg-1668 [000] ...1 174991.234445: ext4_es_lookup_extent_exit: dev 259,32 ino 3 found 1 [0/2) 9255 W0x10
2183 // 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
2184 // android.bg-1668 [000] ...1 174991.234460: ext4_es_lookup_extent_enter: dev 259,32 ino 4 lblk 1
2185 // android.bg-1668 [000] ...1 174991.234463: ext4_es_lookup_extent_exit: dev 259,32 ino 4 found 1 [0/2) 9257 W0x10
2186 // android.bg-1668 [000] ...1 174991.234471: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2187 // android.bg-1668 [000] ...1 174991.234474: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_dirty_inode+0x48/0x68
2188 // 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
2189 // android.bg-1668 [000] ...1 174991.234484: ext4_es_insert_extent: dev 259,32 ino 2883605 es [0/7) mapped 2155471 status W
2190 // android.bg-1668 [000] ...1 174991.234547: ext4_mark_inode_dirty: dev 259,32 ino 2883605 caller ext4_writepages+0xdc0/0x119c
2191 // android.bg-1668 [000] ...1 174991.234604: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_writepages+0x6a4/0x119c
2192 // 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
2193 // 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
2194 // Profile Saver-5504 [000] ...1 175002.711928: ext4_discard_preallocations: dev 259,32 ino 1311176
2195 // Profile Saver-5504 [000] ...1 175002.714165: ext4_begin_ordered_truncate: dev 259,32 ino 1311176 new_size 0
2196 // Profile Saver-5504 [000] ...1 175002.714172: ext4_journal_start: dev 259,32 blocks, 3 rsv_blocks, 0 caller ext4_setattr+0x5b4/0x788
2197 // Profile Saver-5504 [000] ...1 175002.714218: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_setattr+0x65c/0x788
2198 // Profile Saver-5504 [000] ...1 175002.714277: ext4_invalidatepage: dev 259,32 ino 1311176 page_index 0 offset 0 length 4096
2199 // Profile Saver-5504 [000] ...1 175002.714281: ext4_releasepage: dev 259,32 ino 1311176 page_index 0
2200 // Profile Saver-5504 [000] ...1 175002.714295: ext4_invalidatepage: dev 259,32 ino 1311176 page_index 1 offset 0 length 4096
2201 // Profile Saver-5504 [000] ...1 175002.714296: ext4_releasepage: dev 259,32 ino 1311176 page_index 1
2202 // Profile Saver-5504 [000] ...1 175002.714315: ext4_truncate_enter: dev 259,32 ino 1311176 blocks 24
2203 // Profile Saver-5504 [000] ...1 175002.714318: ext4_journal_start: dev 259,32 blocks, 10 rsv_blocks, 0 caller ext4_truncate+0x258/0x4b8
2204 // Profile Saver-5504 [000] ...1 175002.714322: ext4_discard_preallocations: dev 259,32 ino 1311176
2205 // Profile Saver-5504 [000] ...1 175002.714324: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_ext_truncate+0x24/0xc8
2206 // Profile Saver-5504 [000] ...1 175002.714328: ext4_es_remove_extent: dev 259,32 ino 1311176 es [0/4294967295)
2207 // 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
2208 // Profile Saver-5504 [000] ...1 175002.714338: ext4_ext_remove_space: dev 259,32 ino 1311176 since 0 end 4294967294 depth 0
2209 // 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
2210 // 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
2211 // Profile Saver-5504 [000] ...1 175002.714354: ext4_free_blocks: dev 259,32 ino 1311176 mode 0100600 block 5276994 count 2 flags 1ST_CLUSTER
2212 // Profile Saver-5504 [000] ...1 175002.714365: ext4_mballoc_free: dev 259,32 inode 1311176 extent 161/1346/2
2213 // 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
2214 // Profile Saver-5504 [000] ...1 175002.714391: ext4_es_lookup_extent_enter: dev 259,32 ino 3 lblk 4
2215 // Profile Saver-5504 [000] ...1 175002.714394: ext4_es_lookup_extent_exit: dev 259,32 ino 3 found 1 [4/1) 557094 W0x10
2216 // 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
2217 // Profile Saver-5504 [000] ...1 175002.714404: ext4_es_lookup_extent_enter: dev 259,32 ino 4 lblk 8
2218 // Profile Saver-5504 [000] ...1 175002.714406: ext4_es_lookup_extent_exit: dev 259,32 ino 4 found 1 [8/3) 7376914 W0x10
2219 // Profile Saver-5504 [000] ...1 175002.714413: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2220 // Profile Saver-5504 [000] ...1 175002.714414: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2221 // Profile Saver-5504 [000] ...1 175002.714420: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller __ext4_ext_dirty+0x104/0x170
2222 // 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
2223 // Profile Saver-5504 [000] ...1 175002.714425: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller __ext4_ext_dirty+0x104/0x170
2224 // Profile Saver-5504 [000] ...1 175002.714433: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_truncate+0x3c4/0x4b8
2225 // Profile Saver-5504 [000] ...1 175002.714436: ext4_truncate_exit: dev 259,32 ino 1311176 blocks 8
2226 // Profile Saver-5504 [000] ...1 175002.714437: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2227 // Profile Saver-5504 [000] ...1 175002.714438: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2228 // Profile Saver-5504 [000] ...1 175002.714462: ext4_da_write_begin: dev 259,32 ino 1311176 pos 0 len 4 flags 0
2229 // 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
2230 // Profile Saver-5504 [000] ...1 175002.714477: ext4_es_lookup_extent_enter: dev 259,32 ino 1311176 lblk 0
2231 // Profile Saver-5504 [000] ...1 175002.714477: ext4_es_lookup_extent_exit: dev 259,32 ino 1311176 found 0 [0/0) 0
2232 // Profile Saver-5504 [000] ...1 175002.714480: ext4_ext_map_blocks_enter: dev 259,32 ino 1311176 lblk 0 len 1 flags
2233 // Profile Saver-5504 [000] ...1 175002.714485: ext4_es_find_delayed_extent_range_enter: dev 259,32 ino 1311176 lblk 0
2234 // 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
2235 // Profile Saver-5504 [000] ...1 175002.714490: ext4_es_insert_extent: dev 259,32 ino 1311176 es [0/4294967295) mapped 576460752303423487 status H
2236 // 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
2237 // 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
2238 // Profile Saver-5504 [000] ...1 175002.714505: ext4_es_insert_extent: dev 259,32 ino 1311176 es [0/1) mapped 576460752303423487 status D
2239 // Profile Saver-5504 [000] ...1 175002.714513: ext4_da_write_end: dev 259,32 ino 1311176 pos 0 len 4 copied 4
2240 // Profile Saver-5504 [000] ...1 175002.714519: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2241 // Profile Saver-5504 [000] ...1 175002.714520: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2242 // Profile Saver-5504 [000] ...1 175002.714527: ext4_da_write_begin: dev 259,32 ino 1311176 pos 4 len 4 flags 0
2243 // 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
2244 // Profile Saver-5504 [000] ...1 175002.714531: ext4_da_write_end: dev 259,32 ino 1311176 pos 4 len 4 copied 4
2245 // Profile Saver-5504 [000] ...1 175002.714532: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2246 // Profile Saver-5504 [000] ...1 175002.714532: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2247 // Profile Saver-5504 [000] ...1 175002.715313: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2248 // Profile Saver-5504 [000] ...1 175002.715322: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2249 // Profile Saver-5504 [000] ...1 175002.723849: ext4_da_write_begin: dev 259,32 ino 1311176 pos 8 len 5 flags 0
2250 // 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
2251 // Profile Saver-5504 [000] ...1 175002.723873: ext4_da_write_end: dev 259,32 ino 1311176 pos 8 len 5 copied 5
2252 // Profile Saver-5504 [000] ...1 175002.723877: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2253 // Profile Saver-5504 [000] ...1 175002.723879: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2254 // Profile Saver-5504 [000] ...1 175002.726857: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2255 // Profile Saver-5504 [000] ...1 175002.726867: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2256 // Profile Saver-5504 [000] ...1 175002.726881: ext4_da_write_begin: dev 259,32 ino 1311176 pos 13 len 4 flags 0
2257 // 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
2258 // Profile Saver-5504 [000] ...1 175002.726890: ext4_da_write_end: dev 259,32 ino 1311176 pos 13 len 4 copied 4
2259 // Profile Saver-5504 [000] ...1 175002.726892: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2260 // Profile Saver-5504 [000] ...1 175002.726892: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2261 // Profile Saver-5504 [000] ...1 175002.726900: ext4_da_write_begin: dev 259,32 ino 1311176 pos 17 len 4079 flags 0
2262 // 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
2263 // Profile Saver-5504 [000] ...1 175002.726904: ext4_da_write_end: dev 259,32 ino 1311176 pos 17 len 4079 copied 4079
2264 // Profile Saver-5504 [000] ...1 175002.726905: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2265 // Profile Saver-5504 [000] ...1 175002.726906: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2266 // Profile Saver-5504 [000] ...1 175002.726908: ext4_da_write_begin: dev 259,32 ino 1311176 pos 4096 len 2780 flags 0
2267 // 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
2268 // Profile Saver-5504 [000] ...1 175002.726921: ext4_es_lookup_extent_enter: dev 259,32 ino 1311176 lblk 1
2269 // Profile Saver-5504 [000] ...1 175002.726924: ext4_es_lookup_extent_exit: dev 259,32 ino 1311176 found 1 [1/4294967294) 576460752303423487 H0x10
2270 // 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
2271 // Profile Saver-5504 [000] ...1 175002.726933: ext4_es_insert_extent: dev 259,32 ino 1311176 es [1/1) mapped 576460752303423487 status D
2272 // Profile Saver-5504 [000] ...1 175002.726940: ext4_da_write_end: dev 259,32 ino 1311176 pos 4096 len 2780 copied 2780
2273 // Profile Saver-5504 [000] ...1 175002.726941: ext4_journal_start: dev 259,32 blocks, 2 rsv_blocks, 0 caller ext4_dirty_inode+0x30/0x68
2274 // Profile Saver-5504 [000] ...1 175002.726942: ext4_mark_inode_dirty: dev 259,32 ino 1311176 caller ext4_dirty_inode+0x48/0x68
2275 // 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
2276 // d.process.acor-27885 [000] ...1 175018.227699: ext4_mark_inode_dirty: dev 259,32 ino 3278189 caller ext4_dirty_inode+0x48/0x68
2277 // d.process.acor-27885 [000] ...1 175018.227839: ext4_sync_file_enter: dev 259,32 ino 3278183 parent 3277001 datasync 1
2278 // 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
2279 // 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
2280 // clang-format on
2281
2282 static ExamplePage g_full_page_ext4{
2283 "synthetic",
2284 R"(
2285 00000000: 50fe 5852 279f 0000 c80f 00c0 ffff ffff P.XR'...........
2286 00000010: 0800 0000 5701 0001 8406 0000 2000 3010 ....W....... .0.
2287 00000020: 566b 0000 8829 e86a 91ff ffff 0200 0000 Vk...).j........
2288 00000030: 0000 0000 2873 0100 1b01 0001 8406 0000 ....(s..........
2289 00000040: 2000 3010 9200 0000 1500 2c00 0000 0000 .0.......,.....
2290 00000050: a029 e86a 91ff ffff 0ac8 0400 1e01 0001 .).j............
2291 00000060: 8406 0000 2000 3010 2866 0100 1500 2c00 .... .0.(f....,.
2292 00000070: 0000 0000 0050 0000 0000 0000 0010 0000 .....P..........
2293 00000080: 0000 0000 a804 0400 5701 0001 8406 0000 ........W.......
2294 00000090: 2000 3010 91ff ffff 586f e86a 91ff ffff .0.....Xo.j....
2295 000000a0: 0100 0000 0000 0000 c83a 0300 6c01 0001 .........:..l...
2296 000000b0: 8406 0000 2000 3010 0000 0000 1500 2c00 .... .0.......,.
2297 000000c0: 0000 0000 0500 0000 5701 0001 ac6c 0100 ........W....l..
2298 000000d0: 6d01 0001 8406 0000 2000 3010 91ff ffff m....... .0.....
2299 000000e0: 1500 2c00 0000 0000 0500 0000 faff ffff ..,.............
2300 000000f0: ffff ffff ffff ff07 184e 0000 0100 0000 .........N......
2301 00000100: ec08 0200 3f01 0002 8406 0000 2000 3010 ....?....... .0.
2302 00000110: 0000 0000 1500 2c00 0000 0000 0800 0000 ......,.........
2303 00000120: 0000 0000 0600 0000 0000 0000 8081 0000 ................
2304 00000130: 0000 0000 ec24 0100 6701 0001 8406 0000 .....$..g.......
2305 00000140: 2000 3010 0000 0000 1500 2c00 0000 0000 .0.......,.....
2306 00000150: 0500 0000 0100 0000 ffff ffff ffff ff07 ................
2307 00000160: 0400 0000 7b04 3200 2a30 0500 2101 0001 ....{.2.*0..!...
2308 00000170: 8406 0000 2000 3010 0000 0000 1500 2c00 .... .0.......,.
2309 00000180: 0000 0000 0050 0000 0000 0000 0010 0000 .....P..........
2310 00000190: 0010 0000 288b 0200 5701 0001 8406 0000 ....(...W.......
2311 000001a0: 2000 3010 0000 0000 8829 e86a 91ff ffff .0......).j....
2312 000001b0: 0200 0000 0000 0000 0832 0100 1b01 0001 .........2......
2313 000001c0: 8406 0000 2000 3010 566b 0000 1500 2c00 .... .0.Vk....,.
2314 000001d0: 0000 0000 a029 e86a 91ff ffff eaa0 0400 .....).j........
2315 000001e0: 1e01 0001 8406 0000 2000 3010 280b 0400 ........ .0.(...
2316 000001f0: 1500 2c00 0000 0000 0060 0000 0000 0000 ..,......`......
2317 00000200: 980b 0000 0000 0000 88d0 0300 5701 0001 ............W...
2318 00000210: 8406 0000 2000 3010 566b 0000 586f e86a .... .0.Vk..Xo.j
2319 00000220: 91ff ffff 0100 0000 0000 0000 c813 0300 ................
2320 00000230: 6c01 0001 8406 0000 2000 3010 566b 0000 l....... .0.Vk..
2321 00000240: 1500 2c00 0000 0000 0600 0000 0000 0000 ..,.............
2322 00000250: ac5f 0100 6d01 0001 8406 0000 2000 3010 ._..m....... .0.
2323 00000260: 1100 3010 1500 2c00 0000 0000 0600 0000 ..0...,.........
2324 00000270: f9ff ffff ffff ffff ffff ff07 185a ea6a .............Z.j
2325 00000280: 0100 0000 4c02 0200 3f01 0002 8406 0000 ....L...?.......
2326 00000290: 2000 3010 566b 0000 1500 2c00 0000 0000 .0.Vk....,.....
2327 000002a0: 0800 0000 0000 0000 0700 0000 0000 0000 ................
2328 000002b0: 8081 0000 6d01 0001 0c0b 0100 6701 0001 ....m.......g...
2329 000002c0: 8406 0000 2000 3010 0000 0000 1500 2c00 .... .0.......,.
2330 000002d0: 0000 0000 0600 0000 0100 0000 ffff ffff ................
2331 000002e0: ffff ff07 049a 0100 5701 0001 aa1c 0500 ........W.......
2332 000002f0: 2101 0001 8406 0000 2000 3010 91ff ffff !....... .0.....
2333 00000300: 1500 2c00 0000 0000 0060 0000 0000 0000 ..,......`......
2334 00000310: 980b 0000 980b 0000 889e 0200 5701 0001 ............W...
2335 00000320: 8406 0000 2000 3010 91ff ffff 8829 e86a .... .0......).j
2336 00000330: 91ff ffff 0200 0000 0000 0000 8838 0100 .............8..
2337 00000340: 1b01 0001 8406 0000 2000 3010 91ff ffff ........ .0.....
2338 00000350: 1500 2c00 0000 0000 a029 e86a 91ff ffff ..,......).j....
2339 00000360: 2ab8 1800 3501 0001 8406 0000 2000 3010 *...5....... .0.
2340 00000370: feff ffff 1500 2c00 0000 0000 0800 2c00 ......,.......,.
2341 00000380: 0000 0000 0000 0000 2000 3010 32fe 0300 ........ .0.2...
2342 00000390: 2201 0001 8406 0000 2000 3010 0000 0000 "....... .0.....
2343 000003a0: 1500 2c00 0000 0000 ffff ffff ffff ff7f ..,.............
2344 000003b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2345 000003c0: ffff ffff ffff ff7f 0000 0000 0000 0000 ................
2346 000003d0: 0100 0000 0000 0000 887e 0800 5701 0001 .........~..W...
2347 000003e0: 8406 0000 2000 3010 7b04 3200 7c3f e86a .... .0.{.2.|?.j
2348 000003f0: 91ff ffff 0a00 0000 0000 0000 ec2d 0300 .............-..
2349 00000400: 2301 0001 8406 0000 2000 3010 7b04 3200 #....... .0.{.2.
2350 00000410: 1500 2c00 0000 0000 0000 0000 0000 0000 ..,.............
2351 00000420: ffff ffff ffff ff7f 0100 0000 3c01 0001 ............<...
2352 00000430: 0a42 0c00 2401 0001 8406 0000 2000 3010 .B..$....... .0.
2353 00000440: 0800 0000 1500 2c00 0000 0000 0000 0000 ......,.........
2354 00000450: 0000 0000 0700 0000 0002 0000 885f 0100 ............._..
2355 00000460: 6c01 0001 8406 0000 2000 3010 0100 0000 l....... .0.....
2356 00000470: 1500 2c00 0000 0000 0000 0000 566b 0000 ..,.........Vk..
2357 00000480: 0c25 0100 6d01 0001 8406 0000 2000 3010 .%..m....... .0.
2358 00000490: 0400 0000 1500 2c00 0000 0000 0000 0000 ......,.........
2359 000004a0: 0700 0000 ffff ffff ffff ff07 1400 0000 ................
2360 000004b0: 0100 0000 caee 0100 5101 0001 8406 0000 ........Q.......
2361 000004c0: 2000 3010 1100 0000 1500 2c00 0000 0000 .0.......,.....
2362 000004d0: 0000 0000 0700 0000 2500 0000 2000 3010 ........%... .0.
2363 000004e0: 323b 0600 3201 0001 8406 0000 2000 3010 2;..2....... .0.
2364 000004f0: c86e 0000 1500 2c00 0000 0000 0700 0000 .n....,.........
2365 00000500: 0000 0000 0000 0000 0000 0000 0080 b000 ................
2366 00000510: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2367 00000520: 0000 0000 2024 0000 0400 0000 ae0a 1a00 .... $..........
2368 00000530: 3a01 0001 8406 0000 2000 3010 0000 0000 :....... .0.....
2369 00000540: 1500 2c00 0000 0000 0000 0000 0000 0000 ..,.............
2370 00000550: 6101 0000 0700 0000 0000 0000 cf63 0000 a............c..
2371 00000560: 4100 0000 0700 0000 b4c5 0200 3301 0001 A...........3...
2372 00000570: 8406 0000 2000 3010 2000 3010 1500 2c00 .... .0. .0...,.
2373 00000580: 0000 0000 cfe3 2000 0000 0000 0700 0000 ...... .........
2374 00000590: 0000 0000 0000 0000 0000 0000 0080 b000 ................
2375 000005a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2376 000005b0: 0000 0000 2024 0000 6c01 0001 4859 0400 .... $..l...HY..
2377 000005c0: 1b01 0001 8406 0000 2000 3010 0000 0000 ........ .0.....
2378 000005d0: 1500 2c00 0000 0000 9c99 ea6a 91ff ffff ..,........j....
2379 000005e0: c850 0500 6001 0001 8406 0000 2000 3010 .P..`....... .0.
2380 000005f0: 0000 0000 1500 2c00 0000 0000 0000 0000 ......,.........
2381 00000600: 0700 0000 2ee6 0200 3e01 0002 8406 0000 ........>.......
2382 00000610: 2000 3010 566b 0000 1500 2c00 0000 0000 .0.Vk....,.....
2383 00000620: 0800 0000 0000 0000 0700 0000 0700 0000 ................
2384 00000630: 0000 0000 0000 0000 0100 0000 8081 3010 ..............0.
2385 00000640: a804 0400 5701 0001 8406 0000 2000 3010 ....W....... .0.
2386 00000650: cb07 3200 885a ea6a 91ff ffff 0100 0000 ..2..Z.j........
2387 00000660: 0000 0000 8875 0300 6c01 0001 8406 0000 .....u..l.......
2388 00000670: 2000 3010 0300 0000 0300 0000 0000 0000 .0.............
2389 00000680: 0100 0000 0100 0000 ccd4 0100 6d01 0001 ............m...
2390 00000690: 8406 0000 2000 3010 cb07 3200 0300 0000 .... .0...2.....
2391 000006a0: 0000 0000 0000 0000 0200 0000 2724 0000 ............'$..
2392 000006b0: 0000 0000 1100 3010 0100 0000 a850 0500 ......0......P..
2393 000006c0: 5701 0001 8406 0000 2000 3010 0000 0000 W....... .0.....
2394 000006d0: 885a ea6a 91ff ffff 0100 0000 0000 0000 .Z.j............
2395 000006e0: 680f 0200 6c01 0001 8406 0000 2000 3010 h...l....... .0.
2396 000006f0: 0000 0000 0400 0000 0000 0000 0100 0000 ................
2397 00000700: 6d01 0001 ac79 0100 6d01 0001 8406 0000 m....y..m.......
2398 00000710: 2000 3010 0000 0000 0400 0000 0000 0000 .0.............
2399 00000720: 0000 0000 0200 0000 2924 0000 0000 0000 ........)$......
2400 00000730: 1143 0200 0100 0000 2818 0400 5701 0001 .C......(...W...
2401 00000740: 8406 0000 2000 3010 0000 0000 8829 e86a .... .0......).j
2402 00000750: 91ff ffff 0200 0000 0000 0000 8838 0100 .............8..
2403 00000760: 1b01 0001 8406 0000 2000 3010 0400 0000 ........ .0.....
2404 00000770: 1500 2c00 0000 0000 a029 e86a 91ff ffff ..,......).j....
2405 00000780: 0e89 0300 5301 0001 8406 0000 2000 3010 ....S....... .0.
2406 00000790: e128 0000 1500 2c00 0000 0000 2500 0000 .(....,.....%...
2407 000007a0: 0000 0000 cfe3 2000 0000 0000 0000 0000 ...... .........
2408 000007b0: 0700 0000 6000 0000 0700 0000 aca0 0100 ....`...........
2409 000007c0: 6701 0001 8406 0000 2000 3010 e128 0000 g....... .0..(..
2410 000007d0: 1500 2c00 0000 0000 0000 0000 0700 0000 ..,.............
2411 000007e0: cfe3 2000 0000 0000 01a2 0800 0000 0000 .. .............
2412 000007f0: 28b2 1e00 1b01 0001 8406 0000 2000 3010 (........... .0.
2413 00000800: e128 0000 1500 2c00 0000 0000 9846 e86a .(....,......F.j
2414 00000810: 91ff ffff 68d2 1b00 5701 0001 8406 0000 ....h...W.......
2415 00000820: 2000 3010 e128 0000 7c3f e86a 91ff ffff .0..(..|?.j....
2416 00000830: 0a00 0000 0000 0000 0c57 0200 2301 0001 .........W..#...
2417 00000840: 8406 0000 2000 3010 006c 0000 1500 2c00 .... .0..l....,.
2418 00000850: 0000 0000 0700 0000 0000 0000 f8ff ffff ................
2419 00000860: ffff ff7f 0100 0000 0000 0000 6e69 8200 ............ni..
2420 00000870: 2501 0001 8406 0000 2000 3010 ca6e 0000 %....... .0..n..
2421 00000880: 1500 2c00 0000 0000 0000 0000 0700 0000 ..,.............
2422 00000890: 0000 0000 0000 0000 0700 0000 0000 0000 ................
2423 000008a0: 0100 0000 0200 3010 3e13 bd82 5500 0000 ......0.>...U...
2424 000008b0: 0600 0000 3001 0001 8015 0000 2000 3010 ....0....... .0.
2425 000008c0: 0000 0000 c801 1400 0000 0000 8860 4404 .............`D.
2426 000008d0: 1c01 0001 8015 0000 2000 3010 2000 0000 ........ .0. ...
2427 000008e0: c801 1400 0000 0000 0000 0000 0000 0000 ................
2428 000008f0: 88a9 0300 5701 0001 8015 0000 2000 3010 ....W....... .0.
2429 00000900: 0400 0000 1c1e e86a 91ff ffff 0300 0000 .......j........
2430 00000910: 0000 0000 a85a 1600 1b01 0001 8015 0000 .....Z..........
2431 00000920: 2000 3010 2000 3010 c801 1400 0000 0000 .0. .0.........
2432 00000930: c41e e86a 91ff ffff ca95 1c00 2901 0001 ...j........)...
2433 00000940: 8015 0000 2000 3010 2000 3010 c801 1400 .... .0. .0.....
2434 00000950: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2435 00000960: 0010 0000 c8fb 0100 2801 0001 8015 0000 ........(.......
2436 00000970: 2000 3010 5101 0001 c801 1400 0000 0000 .0.Q...........
2437 00000980: 0000 0000 0000 0000 6af1 0600 2901 0001 ........j...)...
2438 00000990: 8015 0000 2000 3010 0000 0000 c801 1400 .... .0.........
2439 000009a0: 0000 0000 0100 0000 0000 0000 0000 0000 ................
2440 000009b0: 0010 0000 488f 0000 2801 0001 8015 0000 ....H...(.......
2441 000009c0: 2000 3010 0200 ffff c801 1400 0000 0000 .0.............
2442 000009d0: 0100 0000 0000 0000 483b 0900 4d01 0001 ........H;..M...
2443 000009e0: 8015 0000 2000 3010 0000 0000 c801 1400 .... .0.........
2444 000009f0: 0000 0000 1800 0000 0000 0000 8852 0100 .............R..
2445 00000a00: 5701 0001 8015 0000 2000 3010 e128 0000 W....... .0..(..
2446 00000a10: 9ce9 e76a 91ff ffff 0a00 0000 0000 0000 ...j............
2447 00000a20: e615 0200 3001 0001 8015 0000 2000 3010 ....0....... .0.
2448 00000a30: 0155 0000 c801 1400 0000 0000 68d0 0000 .U..........h...
2449 00000a40: 1b01 0001 8015 0000 2000 3010 6606 3200 ........ .0.f.2.
2450 00000a50: c801 1400 0000 0000 acfa ea6a 91ff ffff ...........j....
2451 00000a60: 6a0f 0200 6901 0001 8015 0000 2000 3010 j...i....... .0.
2452 00000a70: 7106 3200 c801 1400 0000 0000 0000 0000 q.2.............
2453 00000a80: 0000 0000 ffff ffff 0000 0000 e895 0300 ................
2454 00000a90: 5701 0001 8015 0000 2000 3010 0300 0000 W....... .0.....
2455 00000aa0: acbe ea6a 91ff ffff 0100 0000 0000 0000 ...j............
2456 00000ab0: 8a38 0100 6501 0001 8015 0000 2000 3010 .8..e....... .0.
2457 00000ac0: c41e e86a c801 1400 0000 0000 0000 0000 ...j............
2458 00000ad0: feff ffff 0000 0000 0000 0000 ee86 0400 ................
2459 00000ae0: 6301 0001 8015 0000 2000 3010 0000 0000 c....... .0.....
2460 00000af0: c801 1400 0000 0000 0000 0000 0000 0000 ................
2461 00000b00: 0000 0000 0000 0000 4285 5000 0000 0000 ........B.P.....
2462 00000b10: 0200 0000 0000 0000 8e36 0200 6201 0001 .........6..b...
2463 00000b20: 8015 0000 2000 3010 7d55 0000 c801 1400 .... .0.}U......
2464 00000b30: 0000 0000 0000 0000 0100 0000 0000 0000 ................
2465 00000b40: 0000 0000 4285 5000 0000 0000 0000 0000 ....B.P.........
2466 00000b50: 0200 3010 8c5f 0100 3401 0001 8015 0000 ..0.._..4.......
2467 00000b60: 2000 3010 0000 0000 c801 1400 0000 0000 .0.............
2468 00000b70: 4285 5000 0000 0000 0200 0000 0000 0000 B.P.............
2469 00000b80: 1000 0000 8081 0000 aa43 0500 3c01 0001 .........C..<...
2470 00000b90: 8015 0000 2000 3010 2801 0001 c801 1400 .... .0.(.......
2471 00000ba0: 0000 0000 4205 0000 a100 0000 0200 0000 ....B...........
2472 00000bb0: 0200 0000 8871 0800 5701 0001 8015 0000 .....q..W.......
2473 00000bc0: 2000 3010 2000 3010 885a ea6a 91ff ffff .0. .0..Z.j....
2474 00000bd0: 0100 0000 0000 0000 4825 0400 6c01 0001 ........H%..l...
2475 00000be0: 8015 0000 2000 3010 2801 0001 0300 0000 .... .0.(.......
2476 00000bf0: 0000 0000 0400 0000 7106 3200 0c73 0100 ........q.2..s..
2477 00000c00: 6d01 0001 8015 0000 2000 3010 2901 0001 m....... .0.)...
2478 00000c10: 0300 0000 0000 0000 0400 0000 0100 0000 ................
2479 00000c20: 2680 0800 0000 0000 1100 0000 0100 0000 &...............
2480 00000c30: c845 0400 5701 0001 8015 0000 2000 3010 .E..W....... .0.
2481 00000c40: 2000 3010 885a ea6a 91ff ffff 0100 0000 .0..Z.j........
2482 00000c50: 0000 0000 e8c9 0000 6c01 0001 8015 0000 ........l.......
2483 00000c60: 2000 3010 2000 3010 0400 0000 0000 0000 .0. .0.........
2484 00000c70: 0800 0000 0500 0000 6cdd 0000 6d01 0001 ........l...m...
2485 00000c80: 8015 0000 2000 3010 2801 0001 0400 0000 .... .0.(.......
2486 00000c90: 0000 0000 0800 0000 0300 0000 1290 7000 ..............p.
2487 00000ca0: 0000 0000 1100 0000 0100 0000 6875 0300 ............hu..
2488 00000cb0: 5701 0001 8015 0000 2000 3010 7106 3200 W....... .0.q.2.
2489 00000cc0: 8829 e86a 91ff ffff 0200 0000 0000 0000 .).j............
2490 00000cd0: a847 0000 1b01 0001 8015 0000 2000 3010 .G.......... .0.
2491 00000ce0: 9ce9 e76a c801 1400 0000 0000 a029 e86a ...j.........).j
2492 00000cf0: 91ff ffff e83a 0300 1b01 0001 8015 0000 .....:..........
2493 00000d00: 2000 3010 7106 3200 c801 1400 0000 0000 .0.q.2.........
2494 00000d10: 9c99 ea6a 91ff ffff ae93 0100 6601 0001 ...j........f...
2495 00000d20: 8015 0000 2000 3010 acfa ea6a c801 1400 .... .0....j....
2496 00000d30: 0000 0000 0000 0000 feff ffff 0000 0000 ................
2497 00000d40: 2000 3010 0000 0000 0000 0000 0000 0000 .0.............
2498 00000d50: 0000 0000 48b6 0000 1b01 0001 8015 0000 ....H...........
2499 00000d60: 2000 3010 e128 0000 c801 1400 0000 0000 .0..(..........
2500 00000d70: 9c99 ea6a 91ff ffff a8ea 0300 1b01 0001 ...j............
2501 00000d80: 8015 0000 2000 3010 e128 0000 c801 1400 .... .0..(......
2502 00000d90: 0000 0000 08eb e76a 91ff ffff 885f 0100 .......j....._..
2503 00000da0: 4e01 0001 8015 0000 2000 3010 2efe 0300 N....... .0.....
2504 00000db0: c801 1400 0000 0000 0800 0000 0000 0000 ................
2505 00000dc0: e8bc 0000 5701 0001 8015 0000 2000 3010 ....W....... .0.
2506 00000dd0: 0000 0000 8829 e86a 91ff ffff 0200 0000 .....).j........
2507 00000de0: 0000 0000 c895 0000 1b01 0001 8015 0000 ................
2508 00000df0: 2000 3010 2000 3010 c801 1400 0000 0000 .0. .0.........
2509 00000e00: a029 e86a 91ff ffff cab2 0b00 1e01 0001 .).j............
2510 00000e10: 8015 0000 2000 3010 0000 0000 c801 1400 .... .0.........
2511 00000e20: 0000 0000 0000 0000 0000 0000 0400 0000 ................
2512 00000e30: 0000 0000 689a 0400 5701 0001 8015 0000 ....h...W.......
2513 00000e40: 2000 3010 0000 0000 586f e86a 91ff ffff .0.....Xo.j....
2514 00000e50: 0100 0000 0000 0000 8884 0200 6c01 0001 ............l...
2515 00000e60: 8015 0000 2000 3010 8829 e86a c801 1400 .... .0..).j....
2516 00000e70: 0000 0000 0000 0000 4100 0000 ac47 0000 ........A....G..
2517 00000e80: 6d01 0001 8015 0000 2000 3010 e128 0000 m....... .0..(..
2518 00000e90: c801 1400 0000 0000 0000 0000 0000 0000 ................
2519 00000ea0: 0000 0000 0000 0000 001c 0200 0000 0000 ................
2520 00000eb0: 2a66 0100 5101 0001 8015 0000 2000 3010 *f..Q....... .0.
2521 00000ec0: 0000 0000 c801 1400 0000 0000 0000 0000 ................
2522 00000ed0: 0100 0000 0000 0000 2000 3010 087e 0200 ........ .0..~..
2523 00000ee0: 6a01 0001 8015 0000 2000 3010 0100 0000 j....... .0.....
2524 00000ef0: c801 1400 0000 0000 0000 0000 0100 0000 ................
2525 00000f00: 8c11 0100 6b01 0001 8015 0000 2000 3010 ....k....... .0.
2526 00000f10: 1b01 0001 c801 1400 0000 0000 0000 0000 ................
2527 00000f20: 0000 0000 0000 0000 0000 0000 0028 0000 .............(..
2528 00000f30: 2000 3010 8c5f 0100 6701 0001 8015 0000 .0.._..g.......
2529 00000f40: 2000 3010 0000 0000 c801 1400 0000 0000 .0.............
2530 00000f50: 0000 0000 ffff ffff ffff ffff ffff ff07 ................
2531 00000f60: 0800 0000 0700 0000 6e02 0200 5301 0001 ........n...S...
2532 00000f70: 8015 0000 2000 3010 0100 0000 c801 1400 .... .0.........
2533 00000f80: 0000 0000 0000 0000 2000 3010 0000 0000 ........ .0.....
2534 00000f90: 0100 0000 0000 0000 0100 0000 0000 0000 ................
2535 00000fa0: 0000 0000 cc3a 0300 3f01 0002 8015 0000 .....:..?.......
2536 00000fb0: 2000 3010 7106 3200 c801 1400 0000 0000 .0.q.2.........
2537 00000fc0: 0800 0000 0000 0000 0100 0000 0000 0000 ................
2538 00000fd0: 8081 3010 3d00 0000 f542 0000 0000 0000 ..0.=....B......
2539 00000fe0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2540 00000ff0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2541 )",
2542 };
2543
TEST(CpuReaderTest,ParseExt4WithOverwrite)2544 TEST(CpuReaderTest, ParseExt4WithOverwrite) {
2545 const ExamplePage* test_case = &g_full_page_ext4;
2546
2547 BundleProvider bundle_provider(base::kPageSize);
2548 ProtoTranslationTable* table = GetTable(test_case->name);
2549 auto page = PageFromXxd(test_case->data);
2550
2551 FtraceDataSourceConfig ds_config = EmptyConfig();
2552 ds_config.event_filter.AddEnabledEvent(
2553 table->EventToFtraceId(GroupAndName("sched", "sched_switch")));
2554
2555 FtraceMetadata metadata{};
2556 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
2557 const uint8_t* parse_pos = page.get();
2558 base::Optional<CpuReader::PageHeader> page_header =
2559 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
2560
2561 const uint8_t* page_end = page.get() + base::kPageSize;
2562 ASSERT_TRUE(page_header.has_value());
2563 EXPECT_TRUE(page_header->lost_events); // data loss
2564 EXPECT_TRUE(parse_pos < page_end);
2565 EXPECT_TRUE(parse_pos + page_header->size < page_end);
2566
2567 size_t evt_bytes = CpuReader::ParsePagePayload(
2568 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
2569 bundle_provider.writer(), &metadata);
2570
2571 EXPECT_LT(0u, evt_bytes);
2572
2573 auto bundle = bundle_provider.ParseProto();
2574 ASSERT_TRUE(bundle);
2575 }
2576
2577 // Page with a single event containing a __data_loc entry with value 0x0000
2578 //
2579 // [timestamp ] [32 byte payload next ]
2580 // 00000000: D7 B3 0A 57 CF 02 00 00 20 00 00 00 00 00 00 00 ...W.... .......
2581 // [evt hdr ] [id ]
2582 // 00000010: 67 A6 13 00 0F 06 00 00 3D 01 00 00 45 00 00 00 g.......=...E...
2583 // 00000020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
2584 //
2585 // name: tracing_mark_write
2586 // ID: 1551
2587 // format:
2588 // field:unsigned short common_type; offset:0; size:2; signed:0;
2589 // field:unsigned char common_flags; offset:2; size:1; signed:0;
2590 // field:unsigned char common_preempt_count; offset:3; size:1;
2591 // signed:0; field:int common_pid; offset:4; size:4; signed:1;
2592 //
2593 // field:char type; offset:8; size:1; signed:0;
2594 // field:int pid; offset:12; size:4; signed:1;
2595 // field:__data_loc char[] name; offset:16; size:4; signed:0;
2596 // field:int value; offset:20; size:4; signed:1;
2597 //
2598 static char g_zero_data_loc[] =
2599 R"(
2600 00000000: D7B3 0A57 CF02 0000 2000 0000 0000 0000 ...W.... .......
2601 00000010: 67A6 1300 0F06 0000 3D01 0000 4500 0000 g.......=...E...
2602 00000020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2603 00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
2604 )";
2605
2606 TEST(CpuReaderTest, ZeroLengthDataLoc) {
2607 BundleProvider bundle_provider(base::kPageSize);
2608 auto page = PageFromXxd(g_zero_data_loc);
2609
2610 // Hand-build a translation table that handles dpu/tracing_mark_write for this
2611 // test page.
2612 // TODO(rsavitski): look into making these tests less verbose by feeding a
2613 // format string through proto_translation_table to get the format.
2614 std::vector<Field> common_fields;
2615 { // common_pid
2616 common_fields.emplace_back(Field{});
2617 Field* field = &common_fields.back();
2618 field->ftrace_offset = 4;
2619 field->ftrace_size = 4;
2620 field->ftrace_type = kFtraceCommonPid32;
2621 field->proto_field_id = 2;
2622 field->proto_field_type = ProtoSchemaType::kInt32;
2623 SetTranslationStrategy(field->ftrace_type, field->proto_field_type,
2624 &field->strategy);
2625 }
2626 using Dpu = protos::gen::DpuTracingMarkWriteFtraceEvent;
2627 Event evt{"tracing_mark_write",
2628 "dpu",
2629 {
2630 {8, 1, FtraceFieldType::kFtraceUint8, "type",
2631 Dpu::kTypeFieldNumber, ProtoSchemaType::kUint32,
2632 TranslationStrategy::kInvalidTranslationStrategy},
2633 {12, 4, FtraceFieldType::kFtraceInt32, "pid",
2634 Dpu::kPidFieldNumber, ProtoSchemaType::kInt32,
2635 TranslationStrategy::kInvalidTranslationStrategy},
2636 {16, 4, FtraceFieldType::kFtraceDataLoc, "name",
2637 Dpu::kNameFieldNumber, ProtoSchemaType::kString,
2638 TranslationStrategy::kInvalidTranslationStrategy},
2639 {20, 4, FtraceFieldType::kFtraceInt32, "value",
2640 Dpu::kValueFieldNumber, ProtoSchemaType::kInt32,
2641 TranslationStrategy::kInvalidTranslationStrategy},
2642 },
2643 /*ftrace_event_id=*/1551,
2644 /*proto_field_id=*/348,
2645 /*size=*/24};
2646 for (Field& field : evt.fields) {
2647 SetTranslationStrategy(field.ftrace_type, field.proto_field_type,
2648 &field.strategy);
2649 }
2650 std::vector<Event> events;
2651 events.emplace_back(std::move(evt));
2652
2653 NiceMock<MockFtraceProcfs> mock_ftrace;
2654 PrintkMap printk_formats;
2655 ProtoTranslationTable translation_table(
2656 &mock_ftrace, events, std::move(common_fields),
2657 ProtoTranslationTable::DefaultPageHeaderSpecForTesting(),
2658 InvalidCompactSchedEventFormatForTesting(), printk_formats);
2659 ProtoTranslationTable* table = &translation_table;
2660
2661 FtraceDataSourceConfig ds_config = EmptyConfig();
2662 ds_config.event_filter.AddEnabledEvent(
2663 table->EventToFtraceId(GroupAndName("dpu", "tracing_mark_write")));
2664
2665 FtraceMetadata metadata{};
2666 std::unique_ptr<CompactSchedBuffer> compact_buffer(new CompactSchedBuffer());
2667 const uint8_t* parse_pos = page.get();
2668 base::Optional<CpuReader::PageHeader> page_header =
2669 CpuReader::ParsePageHeader(&parse_pos, table->page_header_size_len());
2670
2671 const uint8_t* page_end = page.get() + base::kPageSize;
2672 ASSERT_TRUE(page_header.has_value());
2673 EXPECT_FALSE(page_header->lost_events);
2674 EXPECT_TRUE(parse_pos < page_end);
2675 EXPECT_TRUE(parse_pos + page_header->size < page_end);
2676
2677 size_t evt_bytes = CpuReader::ParsePagePayload(
2678 parse_pos, &page_header.value(), table, &ds_config, compact_buffer.get(),
2679 bundle_provider.writer(), &metadata);
2680
2681 // successfully parsed the whole 32 byte event
2682 ASSERT_EQ(32u, page_header->size);
2683 ASSERT_EQ(32u, evt_bytes);
2684
2685 auto bundle = bundle_provider.ParseProto();
2686 ASSERT_TRUE(bundle);
2687 EXPECT_EQ(bundle->event().size(), 1u);
2688 const protos::gen::FtraceEvent& event = bundle->event()[0];
2689 EXPECT_EQ(event.pid(), 317u);
2690 EXPECT_EQ(event.dpu_tracing_mark_write().type(), 69u);
2691 EXPECT_EQ(event.dpu_tracing_mark_write().pid(), 0);
2692 EXPECT_EQ(event.dpu_tracing_mark_write().value(), 0);
2693 EXPECT_EQ(event.dpu_tracing_mark_write().name(), "");
2694 }
2695
2696 } // namespace perfetto
2697