/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef INCLUDE_PERFETTO_PROTOZERO_SCATTERED_STREAM_WRITER_H_ #define INCLUDE_PERFETTO_PROTOZERO_SCATTERED_STREAM_WRITER_H_ #include <assert.h> #include <stddef.h> #include <stdint.h> #include <string.h> #include <algorithm> #include "perfetto/base/compiler.h" #include "perfetto/base/export.h" #include "perfetto/base/logging.h" #include "perfetto/protozero/contiguous_memory_range.h" namespace protozero { // This class deals with the following problem: append-only proto messages want // to write a stream of bytes, without caring about the implementation of the // underlying buffer (which concretely will be either the trace ring buffer // or a heap-allocated buffer). The main deal is: proto messages don't know in // advance what their size will be. // Due to the tracing buffer being split into fixed-size chunks, on some // occasions, these writes need to be spread over two (or more) non-contiguous // chunks of memory. Similarly, when the buffer is backed by the heap, we want // to avoid realloc() calls, as they might cause a full copy of the contents // of the buffer. // The purpose of this class is to abstract away the non-contiguous write logic. // This class knows how to deal with writes as long as they fall in the same // ContiguousMemoryRange and defers the chunk-chaining logic to the Delegate. class PERFETTO_EXPORT_COMPONENT ScatteredStreamWriter { … }; } // namespace protozero #endif // INCLUDE_PERFETTO_PROTOZERO_SCATTERED_STREAM_WRITER_H_