1 /* 2 * Copyright (C) 2015 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 #ifndef SIMPLE_PERF_RECORD_H_ 18 #define SIMPLE_PERF_RECORD_H_ 19 20 #include <stdio.h> 21 #include <sys/types.h> 22 23 #include <memory> 24 #include <queue> 25 #include <string> 26 #include <vector> 27 28 #include <android-base/logging.h> 29 30 #include "CallChainJoiner.h" 31 #include "OfflineUnwinder.h" 32 #include "build_id.h" 33 #include "perf_event.h" 34 35 namespace simpleperf { 36 37 enum user_record_type { 38 PERF_RECORD_USER_DEFINED_TYPE_START = 64, 39 PERF_RECORD_ATTR = 64, 40 PERF_RECORD_EVENT_TYPE, 41 PERF_RECORD_TRACING_DATA, 42 PERF_RECORD_BUILD_ID, 43 PERF_RECORD_FINISHED_ROUND, 44 45 PERF_RECORD_AUXTRACE_INFO = 70, 46 PERF_RECORD_AUXTRACE = 71, 47 48 SIMPLE_PERF_RECORD_TYPE_START = 32768, 49 SIMPLE_PERF_RECORD_KERNEL_SYMBOL, 50 // TODO: remove DsoRecord and SymbolRecord. 51 SIMPLE_PERF_RECORD_DSO, 52 SIMPLE_PERF_RECORD_SYMBOL, 53 SIMPLE_PERF_RECORD_SPLIT, 54 SIMPLE_PERF_RECORD_SPLIT_END, 55 SIMPLE_PERF_RECORD_EVENT_ID, 56 SIMPLE_PERF_RECORD_CALLCHAIN, 57 SIMPLE_PERF_RECORD_UNWINDING_RESULT, 58 SIMPLE_PERF_RECORD_TRACING_DATA, 59 }; 60 61 // perf_event_header uses u16 to store record size. However, that is not 62 // enough for storing records like KERNEL_SYMBOL or TRACING_DATA. So define 63 // a simpleperf_record_header struct to store record header for simpleperf 64 // defined records (type > SIMPLE_PERF_RECORD_TYPE_START). 65 struct simpleperf_record_header { 66 uint32_t type; 67 uint16_t size1; 68 uint16_t size0; 69 }; 70 71 static_assert(sizeof(simpleperf_record_header) == sizeof(perf_event_header), 72 "simpleperf_record_header should have the same size as perf_event_header"); 73 74 struct PerfSampleIpType { 75 uint64_t ip; 76 }; 77 78 struct PerfSampleTidType { 79 uint32_t pid, tid; 80 }; 81 82 struct PerfSampleTimeType { 83 uint64_t time; 84 }; 85 86 struct PerfSampleAddrType { 87 uint64_t addr; 88 }; 89 90 struct PerfSampleIdType { 91 uint64_t id; 92 }; 93 94 struct PerfSampleStreamIdType { 95 uint64_t stream_id; 96 }; 97 98 struct PerfSampleCpuType { 99 uint32_t cpu, res; 100 }; 101 102 struct PerfSamplePeriodType { 103 uint64_t period; 104 }; 105 106 struct PerfSampleReadType { 107 uint64_t time_enabled = 0; 108 uint64_t time_running = 0; 109 std::vector<uint64_t> counts; 110 std::vector<uint64_t> ids; 111 }; 112 113 struct PerfSampleCallChainType { 114 uint64_t ip_nr; 115 uint64_t* ips; 116 }; 117 118 struct PerfSampleRawType { 119 uint32_t size; 120 const char* data; 121 }; 122 123 struct BranchStackItemType { 124 uint64_t from; 125 uint64_t to; 126 uint64_t flags; 127 }; 128 129 struct PerfSampleBranchStackType { 130 uint64_t stack_nr; 131 const BranchStackItemType* stack; 132 }; 133 134 struct PerfSampleRegsUserType { 135 uint64_t abi; 136 uint64_t reg_mask; 137 uint64_t reg_nr; 138 const uint64_t* regs; 139 }; 140 141 struct PerfSampleStackUserType { 142 uint64_t size; 143 char* data; 144 uint64_t dyn_size; 145 }; 146 147 struct RecordHeader { 148 public: 149 uint32_t type; 150 uint16_t misc; 151 uint32_t size; 152 RecordHeaderRecordHeader153 RecordHeader() : type(0), misc(0), size(0) {} 154 ParseRecordHeader155 bool Parse(const char* p) { 156 auto pheader = reinterpret_cast<const perf_event_header*>(p); 157 if (pheader->type < SIMPLE_PERF_RECORD_TYPE_START) { 158 type = pheader->type; 159 misc = pheader->misc; 160 size = pheader->size; 161 } else { 162 auto sheader = reinterpret_cast<const simpleperf_record_header*>(p); 163 type = sheader->type; 164 misc = 0; 165 size = (sheader->size1 << 16) | sheader->size0; 166 } 167 if (size < sizeof(perf_event_header)) { 168 LOG(ERROR) << "invalid record"; 169 return false; 170 } 171 return true; 172 } 173 MoveToBinaryFormatRecordHeader174 void MoveToBinaryFormat(char*& p) const { 175 if (type < SIMPLE_PERF_RECORD_TYPE_START) { 176 auto pheader = reinterpret_cast<perf_event_header*>(p); 177 pheader->type = type; 178 pheader->misc = misc; 179 CHECK_LT(size, 1u << 16); 180 pheader->size = static_cast<uint16_t>(size); 181 } else { 182 auto sheader = reinterpret_cast<simpleperf_record_header*>(p); 183 sheader->type = type; 184 CHECK_EQ(misc, 0u); 185 sheader->size1 = size >> 16; 186 sheader->size0 = size & 0xffff; 187 } 188 p += sizeof(perf_event_header); 189 } 190 }; 191 192 // SampleId is optional at the end of a record in binary format. Its content is 193 // determined by sample_id_all and sample_type in perf_event_attr. To avoid the 194 // complexity of referring to perf_event_attr each time, we copy sample_id_all 195 // and sample_type inside the SampleId structure. 196 struct SampleId { 197 bool sample_id_all; 198 uint64_t sample_type; 199 200 PerfSampleTidType tid_data; // Valid if sample_id_all && PERF_SAMPLE_TID. 201 PerfSampleTimeType time_data; // Valid if sample_id_all && PERF_SAMPLE_TIME. 202 PerfSampleIdType id_data; // Valid if sample_id_all && PERF_SAMPLE_ID. 203 PerfSampleStreamIdType stream_id_data; // Valid if sample_id_all && PERF_SAMPLE_STREAM_ID. 204 PerfSampleCpuType cpu_data; // Valid if sample_id_all && PERF_SAMPLE_CPU. 205 206 SampleId(); 207 208 // Create the content of sample_id. It depends on the attr we use. 209 size_t CreateContent(const perf_event_attr& attr, uint64_t event_id); 210 211 // Parse sample_id from binary format in the buffer pointed by p. 212 bool ReadFromBinaryFormat(const perf_event_attr& attr, const char* p, const char* end); 213 214 // Write the binary format of sample_id to the buffer pointed by p. 215 void WriteToBinaryFormat(char*& p) const; 216 void Dump(size_t indent) const; 217 size_t Size() const; 218 }; 219 220 // Usually one record contains the following three parts in order in binary 221 // format: 222 // RecordHeader (at the head of a record, containing type and size info) 223 // data depends on the record type 224 // SampleId (optional part at the end of a record) 225 // We hold the common parts (RecordHeader and SampleId) in the base class 226 // Record, and hold the type specific data part in classes derived from Record. 227 struct Record { 228 RecordHeader header; 229 SampleId sample_id; 230 RecordRecord231 Record() : binary_(nullptr), own_binary_(false) {} 232 Record(Record&& other) noexcept; 233 ~RecordRecord234 virtual ~Record() { 235 if (own_binary_) { 236 delete[] binary_; 237 } 238 } 239 240 virtual bool Parse(const perf_event_attr& attr, char* p, char* end) = 0; 241 OwnBinaryRecord242 void OwnBinary() { own_binary_ = true; } 243 typeRecord244 uint32_t type() const { return header.type; } 245 miscRecord246 uint16_t misc() const { return header.misc; } 247 sizeRecord248 uint32_t size() const { return header.size; } 249 header_sizeRecord250 static uint32_t header_size() { return sizeof(perf_event_header); } 251 InKernelRecord252 bool InKernel() const { 253 uint16_t cpumode = header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 254 return cpumode == PERF_RECORD_MISC_KERNEL || cpumode == PERF_RECORD_MISC_GUEST_KERNEL; 255 } 256 SetTypeAndMiscRecord257 void SetTypeAndMisc(uint32_t type, uint16_t misc) { 258 header.type = type; 259 header.misc = misc; 260 } 261 SetSizeRecord262 void SetSize(uint32_t size) { header.size = size; } 263 264 void Dump(size_t indent = 0) const; 265 BinaryRecord266 const char* Binary() const { return binary_; } BinaryForTestingOnlyRecord267 char* BinaryForTestingOnly() { return binary_; } 268 269 virtual uint64_t Timestamp() const; 270 virtual uint32_t Cpu() const; 271 virtual uint64_t Id() const; 272 273 protected: 274 bool ParseHeader(char*& p, char*& end); 275 void UpdateBinary(char* new_binary); 276 virtual void DumpData(size_t) const = 0; 277 278 char* binary_; 279 bool own_binary_; 280 281 DISALLOW_COPY_AND_ASSIGN(Record); 282 }; 283 284 struct MmapRecord : public Record { 285 struct MmapRecordDataType { 286 uint32_t pid, tid; 287 uint64_t addr; 288 uint64_t len; 289 uint64_t pgoff; 290 }; 291 const MmapRecordDataType* data; 292 const char* filename; 293 MmapRecordMmapRecord294 MmapRecord() {} 295 MmapRecord(const perf_event_attr& attr, bool in_kernel, uint32_t pid, uint32_t tid, uint64_t addr, 296 uint64_t len, uint64_t pgoff, const std::string& filename, uint64_t event_id, 297 uint64_t time = 0); 298 299 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 300 void SetDataAndFilename(const MmapRecordDataType& data, const std::string& filename); 301 302 protected: 303 void DumpData(size_t indent) const override; 304 }; 305 306 struct Mmap2Record : public Record { 307 struct Mmap2RecordDataType { 308 uint32_t pid, tid; 309 uint64_t addr; 310 uint64_t len; 311 uint64_t pgoff; 312 uint32_t maj; 313 uint32_t min; 314 uint64_t ino; 315 uint64_t ino_generation; 316 uint32_t prot, flags; 317 }; 318 const Mmap2RecordDataType* data; 319 const char* filename; 320 Mmap2RecordMmap2Record321 Mmap2Record() {} 322 Mmap2Record(const perf_event_attr& attr, bool in_kernel, uint32_t pid, uint32_t tid, 323 uint64_t addr, uint64_t len, uint64_t pgoff, uint32_t prot, 324 const std::string& filename, uint64_t event_id, uint64_t time = 0); 325 326 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 327 void SetDataAndFilename(const Mmap2RecordDataType& data, const std::string& filename); 328 329 protected: 330 void DumpData(size_t indent) const override; 331 }; 332 333 struct CommRecord : public Record { 334 struct CommRecordDataType { 335 uint32_t pid, tid; 336 }; 337 const CommRecordDataType* data; 338 const char* comm; 339 CommRecordCommRecord340 CommRecord() {} 341 CommRecord(const perf_event_attr& attr, uint32_t pid, uint32_t tid, const std::string& comm, 342 uint64_t event_id, uint64_t time); 343 344 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 345 void SetCommandName(const std::string& name); 346 347 protected: 348 void DumpData(size_t indent) const override; 349 }; 350 351 struct ExitOrForkRecord : public Record { 352 struct ExitOrForkRecordDataType { 353 uint32_t pid, ppid; 354 uint32_t tid, ptid; 355 uint64_t time; 356 }; 357 const ExitOrForkRecordDataType* data; 358 ExitOrForkRecordExitOrForkRecord359 ExitOrForkRecord() : data(nullptr) {} 360 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 361 362 protected: 363 void DumpData(size_t indent) const override; 364 }; 365 366 struct ExitRecord : public ExitOrForkRecord {}; 367 368 struct ForkRecord : public ExitOrForkRecord { ForkRecordForkRecord369 ForkRecord() {} 370 ForkRecord(const perf_event_attr& attr, uint32_t pid, uint32_t tid, uint32_t ppid, uint32_t ptid, 371 uint64_t event_id); 372 }; 373 374 struct LostRecord : public Record { 375 uint64_t id; 376 uint64_t lost; 377 378 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 379 380 protected: 381 void DumpData(size_t indent) const override; 382 }; 383 384 struct SampleRecord : public Record { 385 uint64_t sample_type; // sample_type is a bit mask determining which fields 386 // below are valid. 387 uint64_t read_format; 388 389 PerfSampleIpType ip_data; // Valid if PERF_SAMPLE_IP. 390 PerfSampleTidType tid_data; // Valid if PERF_SAMPLE_TID. 391 PerfSampleTimeType time_data; // Valid if PERF_SAMPLE_TIME. 392 PerfSampleAddrType addr_data; // Valid if PERF_SAMPLE_ADDR. 393 PerfSampleIdType id_data; // Valid if PERF_SAMPLE_ID. 394 PerfSampleStreamIdType stream_id_data; // Valid if PERF_SAMPLE_STREAM_ID. 395 PerfSampleCpuType cpu_data; // Valid if PERF_SAMPLE_CPU. 396 PerfSamplePeriodType period_data; // Valid if PERF_SAMPLE_PERIOD. 397 PerfSampleReadType read_data; // Valid if PERF_SAMPLE_READ. 398 399 PerfSampleCallChainType callchain_data; // Valid if PERF_SAMPLE_CALLCHAIN. 400 PerfSampleRawType raw_data; // Valid if PERF_SAMPLE_RAW. 401 PerfSampleBranchStackType branch_stack_data; // Valid if PERF_SAMPLE_BRANCH_STACK. 402 PerfSampleRegsUserType regs_user_data; // Valid if PERF_SAMPLE_REGS_USER. 403 PerfSampleStackUserType stack_user_data; // Valid if PERF_SAMPLE_STACK_USER. 404 SampleRecordSampleRecord405 SampleRecord() {} 406 SampleRecord(const perf_event_attr& attr, uint64_t id, uint64_t ip, uint32_t pid, uint32_t tid, 407 uint64_t time, uint32_t cpu, uint64_t period, const PerfSampleReadType& read_data, 408 const std::vector<uint64_t>& ips, const std::vector<char>& stack, 409 uint64_t dyn_stack_size); 410 411 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 412 void ReplaceRegAndStackWithCallChain(const std::vector<uint64_t>& ips); 413 // Remove kernel callchain, return true if there is a user space callchain left, otherwise 414 // return false. 415 bool ExcludeKernelCallChain(); 416 bool HasUserCallChain() const; 417 void UpdateUserCallChain(const std::vector<uint64_t>& user_ips); 418 419 uint64_t Timestamp() const override; 420 uint32_t Cpu() const override; 421 uint64_t Id() const override; 422 GetValidStackSizeSampleRecord423 uint64_t GetValidStackSize() const { 424 // Invaid stack data has been removed by RecordReadThread::PushRecordToRecordBuffer(). 425 return stack_user_data.size; 426 } 427 428 void AdjustCallChainGeneratedByKernel(); 429 std::vector<uint64_t> GetCallChain(size_t* kernel_ip_count) const; 430 431 protected: 432 void BuildBinaryWithNewCallChain(uint32_t new_size, const std::vector<uint64_t>& ips); 433 void DumpData(size_t indent) const override; 434 }; 435 436 struct AuxRecord : public Record { 437 struct DataType { 438 uint64_t aux_offset; 439 uint64_t aux_size; 440 uint64_t flags; 441 }* data; 442 443 bool Parse(const perf_event_attr& attr, char* p, char* end) override; UnformattedAuxRecord444 bool Unformatted() const { return data->flags & PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW; } 445 446 protected: 447 void DumpData(size_t indent) const override; 448 }; 449 450 struct SwitchRecord : public Record { 451 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 452 453 protected: DumpDataSwitchRecord454 void DumpData(size_t) const override {} 455 }; 456 457 struct SwitchCpuWideRecord : public Record { 458 PerfSampleTidType tid_data; 459 460 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 461 462 protected: 463 void DumpData(size_t indent) const override; 464 }; 465 466 // BuildIdRecord is defined in user-space, stored in BuildId feature section in 467 // record file. 468 struct BuildIdRecord : public Record { 469 uint32_t pid; 470 BuildId build_id; 471 const char* filename; 472 BuildIdRecordBuildIdRecord473 BuildIdRecord() {} 474 BuildIdRecord(bool in_kernel, uint32_t pid, const BuildId& build_id, const std::string& filename); 475 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 476 477 protected: 478 void DumpData(size_t indent) const override; 479 }; 480 481 struct AuxTraceInfoRecord : public Record { 482 // magic values to be compatible with linux perf 483 static constexpr uint32_t AUX_TYPE_ETM = 3; 484 static constexpr uint64_t MAGIC_ETM4 = 0x4040404040404040ULL; 485 static constexpr uint64_t MAGIC_ETE = 0x5050505050505050ULL; 486 487 struct ETM4Info { 488 uint64_t magic; 489 uint64_t cpu; 490 uint64_t nrtrcparams; 491 uint64_t trcconfigr; 492 uint64_t trctraceidr; 493 uint64_t trcidr0; 494 uint64_t trcidr1; 495 uint64_t trcidr2; 496 uint64_t trcidr8; 497 uint64_t trcauthstatus; 498 }; 499 500 struct ETEInfo { 501 uint64_t magic; 502 uint64_t cpu; 503 uint64_t nrtrcparams; 504 uint64_t trcconfigr; 505 uint64_t trctraceidr; 506 uint64_t trcidr0; 507 uint64_t trcidr1; 508 uint64_t trcidr2; 509 uint64_t trcidr8; 510 uint64_t trcauthstatus; 511 uint64_t trcdevarch; 512 }; 513 514 struct DataType { 515 uint32_t aux_type; 516 uint32_t reserved; 517 uint64_t version; 518 uint32_t nr_cpu; 519 uint32_t pmu_type; 520 uint64_t snapshot; 521 uint64_t info[0]; 522 }* data; 523 AuxTraceInfoRecordAuxTraceInfoRecord524 AuxTraceInfoRecord() {} 525 AuxTraceInfoRecord(const DataType& data, const std::vector<ETEInfo>& ete_info); 526 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 527 528 protected: 529 void DumpData(size_t indent) const override; 530 }; 531 532 struct AuxTraceRecord : public Record { 533 struct DataType { 534 uint64_t aux_size; 535 uint64_t offset; 536 uint64_t reserved0; // reference 537 uint32_t idx; 538 uint32_t tid; 539 uint32_t cpu; 540 uint32_t reserved1; 541 }* data; 542 // AuxTraceRecord is followed by aux tracing data with size data->aux_size. 543 // The location of aux tracing data in memory or file is kept in location. 544 struct AuxDataLocation { 545 const char* addr = nullptr; 546 uint64_t file_offset = 0; 547 } location; 548 AuxTraceRecordAuxTraceRecord549 AuxTraceRecord() {} 550 AuxTraceRecord(uint64_t aux_size, uint64_t offset, uint32_t idx, uint32_t tid, uint32_t cpu); 551 552 bool Parse(const perf_event_attr& attr, char* p, char* end) override; CpuAuxTraceRecord553 uint32_t Cpu() const override { return data->cpu; } SizeAuxTraceRecord554 static size_t Size() { return sizeof(perf_event_header) + sizeof(DataType); } 555 556 protected: 557 void DumpData(size_t indent) const override; 558 }; 559 560 struct KernelSymbolRecord : public Record { 561 uint32_t kallsyms_size; 562 const char* kallsyms; 563 KernelSymbolRecordKernelSymbolRecord564 KernelSymbolRecord() {} 565 explicit KernelSymbolRecord(const std::string& kallsyms); 566 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 567 568 protected: 569 void DumpData(size_t indent) const override; 570 }; 571 572 struct DsoRecord : public Record { 573 uint64_t dso_type; 574 uint64_t dso_id; 575 uint64_t min_vaddr; 576 const char* dso_name; 577 DsoRecordDsoRecord578 DsoRecord() {} 579 DsoRecord(uint64_t dso_type, uint64_t dso_id, const std::string& dso_name, uint64_t min_vaddr); 580 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 581 582 protected: 583 void DumpData(size_t indent) const override; 584 }; 585 586 struct SymbolRecord : public Record { 587 uint64_t addr; 588 uint64_t len; 589 uint64_t dso_id; 590 const char* name; 591 SymbolRecordSymbolRecord592 SymbolRecord() {} 593 SymbolRecord(uint64_t addr, uint64_t len, const std::string& name, uint64_t dso_id); 594 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 595 596 protected: 597 void DumpData(size_t indent) const override; 598 }; 599 600 struct TracingDataRecord : public Record { 601 uint32_t data_size; 602 const char* data; 603 TracingDataRecordTracingDataRecord604 TracingDataRecord() {} 605 explicit TracingDataRecord(const std::vector<char>& tracing_data); 606 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 607 608 protected: 609 void DumpData(size_t indent) const override; 610 }; 611 612 struct EventIdRecord : public Record { 613 uint64_t count; 614 struct EventIdData { 615 uint64_t attr_id; 616 uint64_t event_id; 617 } const* data; 618 EventIdRecordEventIdRecord619 EventIdRecord() {} 620 explicit EventIdRecord(const std::vector<uint64_t>& data); 621 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 622 623 protected: 624 void DumpData(size_t indent) const override; 625 }; 626 627 struct CallChainRecord : public Record { 628 uint32_t pid; 629 uint32_t tid; 630 uint64_t chain_type; 631 uint64_t time; 632 uint64_t ip_nr; 633 uint64_t* ips; 634 uint64_t* sps; 635 CallChainRecordCallChainRecord636 CallChainRecord() {} 637 638 CallChainRecord(pid_t pid, pid_t tid, simpleperf::CallChainJoiner::ChainType type, uint64_t time, 639 const std::vector<uint64_t>& ips, const std::vector<uint64_t>& sps); 640 641 bool Parse(const perf_event_attr& attr, char* p, char* end) override; TimestampCallChainRecord642 uint64_t Timestamp() const override { return time; } 643 644 protected: 645 void DumpData(size_t indent) const override; 646 }; 647 648 struct UnwindingResultRecord : public Record { 649 uint64_t time; 650 UnwindingResult unwinding_result; 651 PerfSampleRegsUserType regs_user_data; 652 PerfSampleStackUserType stack_user_data; 653 654 struct CallChain { 655 uint64_t length = 0; 656 uint64_t* ips = nullptr; 657 uint64_t* sps = nullptr; 658 } callchain; 659 UnwindingResultRecordUnwindingResultRecord660 UnwindingResultRecord() {} 661 662 UnwindingResultRecord(uint64_t time, const simpleperf::UnwindingResult& unwinding_result, 663 const PerfSampleRegsUserType& regs_user_data, 664 const PerfSampleStackUserType& stack_user_data, 665 const std::vector<uint64_t>& ips, const std::vector<uint64_t>& sps); 666 667 bool Parse(const perf_event_attr& attr, char* p, char* end) override; TimestampUnwindingResultRecord668 uint64_t Timestamp() const override { return time; } 669 670 protected: 671 void DumpData(size_t indent) const override; 672 }; 673 674 // UnknownRecord is used for unknown record types, it makes sure all unknown 675 // records are not changed when modifying perf.data. 676 struct UnknownRecord : public Record { 677 const char* data; 678 679 bool Parse(const perf_event_attr& attr, char* p, char* end) override; 680 681 protected: 682 void DumpData(size_t indent) const override; 683 }; 684 685 // Read record from the buffer pointed by [p]. But the record doesn't own 686 // the buffer. 687 std::unique_ptr<Record> ReadRecordFromBuffer(const perf_event_attr& attr, uint32_t type, char* p, 688 char* end); 689 690 // Read records from the buffer pointed by [buf]. None of the records own 691 // the buffer. 692 std::vector<std::unique_ptr<Record>> ReadRecordsFromBuffer(const perf_event_attr& attr, char* buf, 693 size_t buf_size); 694 695 // Read one record from the buffer pointed by [p]. But the record doesn't 696 // own the buffer. 697 std::unique_ptr<Record> ReadRecordFromBuffer(const perf_event_attr& attr, char* p, char* end); 698 699 } // namespace simpleperf 700 701 #endif // SIMPLE_PERF_RECORD_H_ 702