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 INCLUDE_PERFETTO_EXT_TRACING_CORE_BASIC_TYPES_H_ 18 #define INCLUDE_PERFETTO_EXT_TRACING_CORE_BASIC_TYPES_H_ 19 20 #include "perfetto/base/build_config.h" 21 22 #include <stddef.h> 23 #include <stdint.h> 24 #include <sys/types.h> 25 26 #if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) 27 using uid_t = unsigned int; 28 #endif 29 30 namespace perfetto { 31 32 // Unique within the scope of the tracing service. 33 using TracingSessionID = uint64_t; 34 35 // Unique within the scope of the tracing service. 36 using ProducerID = uint16_t; 37 38 // Unique within the scope of the tracing service. 39 using DataSourceInstanceID = uint64_t; 40 41 // Unique within the scope of a Producer. 42 using WriterID = uint16_t; 43 44 // Unique within the scope of the tracing service. 45 using FlushRequestID = uint64_t; 46 47 // We need one FD per producer and we are not going to be able to keep > 64k FDs 48 // open in the service. 49 static constexpr ProducerID kMaxProducerID = static_cast<ProducerID>(-1); 50 51 // 1024 Writers per producer seems a resonable bound. This reduces the ability 52 // to memory-DoS the service by having to keep track of too many writer IDs. 53 static constexpr WriterID kMaxWriterID = static_cast<WriterID>((1 << 10) - 1); 54 55 // Unique within the scope of a {ProducerID, WriterID} tuple. 56 using ChunkID = uint32_t; 57 static constexpr ChunkID kMaxChunkID = static_cast<ChunkID>(-1); 58 59 // Unique within the scope of the tracing service. 60 using BufferID = uint16_t; 61 62 // Target buffer ID for SharedMemoryArbiter. Values up to max uint16_t are 63 // equivalent to a bound BufferID. Values above max uint16_t are reservation IDs 64 // for the target buffer of a startup trace writer. Reservation IDs will be 65 // translated to actual BufferIDs after they are bound by 66 // SharedMemoryArbiter::BindStartupTargetBuffer(). 67 using MaybeUnboundBufferID = uint32_t; 68 69 // Keep this in sync with SharedMemoryABI::PageHeader::target_buffer. 70 static constexpr BufferID kMaxTraceBufferID = static_cast<BufferID>(-1); 71 72 // Unique within the scope of a tracing session. 73 using PacketSequenceID = uint32_t; 74 // Used for extra packets emitted by the service, such as statistics. 75 static constexpr PacketSequenceID kServicePacketSequenceID = 1; 76 static constexpr PacketSequenceID kMaxPacketSequenceID = 77 static_cast<PacketSequenceID>(-1); 78 79 constexpr uid_t kInvalidUid = static_cast<uid_t>(-1); 80 81 constexpr uint32_t kDefaultFlushTimeoutMs = 5000; 82 83 } // namespace perfetto 84 85 #endif // INCLUDE_PERFETTO_EXT_TRACING_CORE_BASIC_TYPES_H_ 86