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