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 #ifndef SRC_FTRACE_READER_TEST_SCATTERED_STREAM_DELEGATE_FOR_TESTING_H_ 18 #define SRC_FTRACE_READER_TEST_SCATTERED_STREAM_DELEGATE_FOR_TESTING_H_ 19 20 #include <memory> 21 #include <vector> 22 23 #include "perfetto/base/logging.h" 24 #include "perfetto/protozero/scattered_stream_writer.h" 25 26 namespace perfetto { 27 28 class ScatteredStreamDelegateForTesting 29 : public protozero::ScatteredStreamWriter::Delegate { 30 public: 31 explicit ScatteredStreamDelegateForTesting(size_t chunk_size); 32 ~ScatteredStreamDelegateForTesting() override; 33 34 // protozero::ScatteredStreamWriter::Delegate implementation. 35 protozero::ContiguousMemoryRange GetNewBuffer() override; 36 37 // Stitch all the chunks into a single contiguous buffer. 38 std::unique_ptr<uint8_t[]> StitchChunks(size_t size); 39 40 const std::vector<std::unique_ptr<uint8_t[]>>& chunks() const { 41 return chunks_; 42 } 43 44 void set_writer(protozero::ScatteredStreamWriter* writer) { 45 writer_ = writer; 46 } 47 48 private: 49 const size_t chunk_size_; 50 protozero::ScatteredStreamWriter* writer_ = nullptr; 51 std::vector<size_t> chunks_used_size_; 52 std::vector<std::unique_ptr<uint8_t[]>> chunks_; 53 }; 54 55 } // namespace perfetto 56 57 #endif // SRC_FTRACE_READER_TEST_SCATTERED_STREAM_DELEGATE_FOR_TESTING_H_ 58