1 /* 2 * Copyright (C) 2024 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 SRC_TRACE_PROCESSOR_IMPORTERS_PERF_ATTRS_SECTION_READER_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PERF_ATTRS_SECTION_READER_H_ 19 20 #include <cstddef> 21 #include <utility> 22 23 #include "perfetto/base/status.h" 24 #include "perfetto/ext/base/status_or.h" 25 #include "perfetto/trace_processor/trace_blob_view.h" 26 #include "src/trace_processor/importers/perf/perf_file.h" 27 #include "src/trace_processor/importers/perf/reader.h" 28 29 namespace perfetto::trace_processor::perf_importer { 30 31 // Helper to read the attrs section of a perf file. Provides an iterator like 32 // interface over the perf_event_attr entries. 33 class AttrsSectionReader { 34 public: 35 // Creates a new iterator. 36 // `attrs_section` data contained in the attrs section of the perf file. 37 static base::StatusOr<AttrsSectionReader> Create( 38 const PerfFile::Header& header, 39 TraceBlobView attrs_section); 40 41 // Returns true while there are available entries to read via `ReadNext`. CanReadNext()42 bool CanReadNext() const { return num_attr_ != 0; } 43 44 // Reads the next entry. Can onlybe called if `HasMore` returns true. 45 base::Status ReadNext(PerfFile::AttrsEntry& entry); 46 47 private: AttrsSectionReader(TraceBlobView section,size_t num_attr,size_t attr_size)48 AttrsSectionReader(TraceBlobView section, size_t num_attr, size_t attr_size) 49 : reader_(std::move(section)), 50 num_attr_(num_attr), 51 attr_size_(attr_size) {} 52 53 Reader reader_; 54 size_t num_attr_; 55 const size_t attr_size_; 56 }; 57 58 } // namespace perfetto::trace_processor::perf_importer 59 60 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PERF_ATTRS_SECTION_READER_H_ 61