1/* 2 * Copyright (C) 2018 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 INCLUDE_PERFETTO_TRACING_CORE_SHARED_MEMORY_ARBITER_H_ 18#define INCLUDE_PERFETTO_TRACING_CORE_SHARED_MEMORY_ARBITER_H_ 19 20#include <stddef.h> 21 22#include <functional> 23#include <memory> 24#include <vector> 25 26#include "perfetto/base/export.h" 27#include "perfetto/tracing/core/basic_types.h" 28#include "perfetto/tracing/core/service.h" 29 30namespace perfetto { 31 32namespace base { 33class TaskRunner; 34} 35 36class CommitDataRequest; 37class SharedMemory; 38class TraceWriter; 39 40// Used by the Producer-side of the transport layer to vend TraceWriters 41// from the SharedMemory it receives from the Service-side. 42class PERFETTO_EXPORT SharedMemoryArbiter { 43 public: 44 virtual ~SharedMemoryArbiter(); 45 46 // Creates a new TraceWriter and assigns it a new WriterID. The WriterID is 47 // written in each chunk header owned by a given TraceWriter and is used by 48 // the Service to reconstruct TracePackets written by the same TraceWriter. 49 // Returns null impl of TraceWriter if all WriterID slots are exhausted. 50 virtual std::unique_ptr<TraceWriter> CreateTraceWriter( 51 BufferID target_buffer) = 0; 52 53 // Notifies the service that all data for the given FlushRequestID has been 54 // committed in the shared memory buffer. 55 virtual void NotifyFlushComplete(FlushRequestID) = 0; 56 57 // Implemented in src/core/shared_memory_arbiter_impl.cc . 58 static std::unique_ptr<SharedMemoryArbiter> CreateInstance( 59 SharedMemory*, 60 size_t page_size, 61 Service::ProducerEndpoint*, 62 base::TaskRunner*); 63}; 64 65} // namespace perfetto 66 67#endif // INCLUDE_PERFETTO_TRACING_CORE_SHARED_MEMORY_ARBITER_H_ 68