• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stddef.h>
21 #include <stdint.h>
22 
23 #include "perfetto/ext/base/sys_types.h"
24 
25 namespace perfetto {
26 
27 // Unique within the scope of the tracing service.
28 using TracingSessionID = uint64_t;
29 
30 // Unique within the scope of the tracing service.
31 using ProducerID = uint16_t;
32 
33 // Unique within the scope of the tracing service.
34 using DataSourceInstanceID = uint64_t;
35 
36 // Unique within the scope of a Producer.
37 using WriterID = uint16_t;
38 
39 // Unique within the scope of the tracing service.
40 using FlushRequestID = uint64_t;
41 
42 // Combines Producer and Writer ID in one word which can be used as key for
43 // hashtables and other data structures.
44 using ProducerAndWriterID = uint32_t;
45 
MkProducerAndWriterID(ProducerID p,WriterID w)46 inline ProducerAndWriterID MkProducerAndWriterID(ProducerID p, WriterID w) {
47   static_assert(
48       sizeof(ProducerID) + sizeof(WriterID) == sizeof(ProducerAndWriterID),
49       "MkProducerAndWriterID() and GetProducerAndWriterID() need updating");
50   return (static_cast<ProducerAndWriterID>(p) << (sizeof(WriterID) * 8)) | w;
51 }
52 
GetProducerAndWriterID(ProducerAndWriterID x,ProducerID * p,WriterID * w)53 inline void GetProducerAndWriterID(ProducerAndWriterID x,
54                                    ProducerID* p,
55                                    WriterID* w) {
56   static constexpr auto mask = (1ull << (sizeof(WriterID) * 8)) - 1;
57   *w = static_cast<WriterID>(x & mask);
58   *p = static_cast<ProducerID>(x >> (sizeof(WriterID) * 8));
59 }
60 
61 // We need one FD per producer and we are not going to be able to keep > 64k FDs
62 // open in the service.
63 static constexpr ProducerID kMaxProducerID = static_cast<ProducerID>(-1);
64 
65 // 1024 Writers per producer seems a resonable bound. This reduces the ability
66 // to memory-DoS the service by having to keep track of too many writer IDs.
67 static constexpr WriterID kMaxWriterID = static_cast<WriterID>((1 << 10) - 1);
68 
69 // Unique within the scope of a {ProducerID, WriterID} tuple.
70 using ChunkID = uint32_t;
71 static constexpr ChunkID kMaxChunkID = static_cast<ChunkID>(-1);
72 
73 // Unique within the scope of the tracing service.
74 using BufferID = uint16_t;
75 
76 // Target buffer ID for SharedMemoryArbiter. Values up to max uint16_t are
77 // equivalent to a bound BufferID. Values above max uint16_t are reservation IDs
78 // for the target buffer of a startup trace writer. Reservation IDs will be
79 // translated to actual BufferIDs after they are bound by
80 // SharedMemoryArbiter::BindStartupTargetBuffer().
81 // TODO(mohitms): Delete this type and use `struct {uint16 ; uint16;}` instead.
82 using MaybeUnboundBufferID = uint32_t;
83 
84 // Keep this in sync with SharedMemoryABI::PageHeader::target_buffer.
85 static constexpr BufferID kMaxTraceBufferID = static_cast<BufferID>(-1);
86 
87 // Unique within the scope of a tracing session.
88 using PacketSequenceID = uint32_t;
89 // Used for extra packets emitted by the service, such as statistics.
90 static constexpr PacketSequenceID kServicePacketSequenceID = 1;
91 static constexpr PacketSequenceID kMaxPacketSequenceID =
92     static_cast<PacketSequenceID>(-1);
93 
94 constexpr uid_t kInvalidUid = ::perfetto::base::kInvalidUid;
95 
96 constexpr uint32_t kDefaultFlushTimeoutMs = 5000;
97 
98 // The special id 0xffff..ffff represents the tracing session with the highest
99 // bugreport score. This is used for CloneSession(kBugreportSessionId).
100 constexpr TracingSessionID kBugreportSessionId =
101     static_cast<TracingSessionID>(-1);
102 
103 }  // namespace perfetto
104 
105 #endif  // INCLUDE_PERFETTO_EXT_TRACING_CORE_BASIC_TYPES_H_
106