Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 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_TRACING_CORE_SERVICE_IMPL_H_ |
| 18 | #define SRC_TRACING_CORE_SERVICE_IMPL_H_ |
| 19 | |
| 20 | #include <functional> |
| 21 | #include <map> |
| 22 | #include <memory> |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 23 | #include <set> |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 24 | |
Sami Kyostila | 32e0b54 | 2018-02-14 08:55:43 +0000 | [diff] [blame] | 25 | #include "gtest/gtest_prod.h" |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 26 | #include "perfetto/base/logging.h" |
Primiano Tucci | bbaa58c | 2017-12-20 13:48:20 +0100 | [diff] [blame] | 27 | #include "perfetto/base/page_allocator.h" |
Sami Kyostila | fbccb3c | 2018-03-21 14:00:47 +0000 | [diff] [blame] | 28 | #include "perfetto/base/time.h" |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 29 | #include "perfetto/base/weak_ptr.h" |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 30 | #include "perfetto/tracing/core/basic_types.h" |
Primiano Tucci | ecf9e4a | 2018-03-14 14:51:58 +0000 | [diff] [blame] | 31 | #include "perfetto/tracing/core/commit_data_request.h" |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 32 | #include "perfetto/tracing/core/data_source_descriptor.h" |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 33 | #include "perfetto/tracing/core/service.h" |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 34 | #include "perfetto/tracing/core/shared_memory_abi.h" |
Oystein Eftevaag | 1269b4a | 2018-01-10 16:29:38 -0800 | [diff] [blame] | 35 | #include "perfetto/tracing/core/trace_config.h" |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 36 | #include "src/tracing/core/id_allocator.h" |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 37 | |
| 38 | namespace perfetto { |
| 39 | |
| 40 | namespace base { |
| 41 | class TaskRunner; |
| 42 | } // namespace base |
| 43 | |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 44 | class Consumer; |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 45 | class DataSourceConfig; |
| 46 | class Producer; |
| 47 | class SharedMemory; |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 48 | class SharedMemoryArbiterImpl; |
Hector Dearman | 6214c8f | 2018-03-27 16:16:22 +0100 | [diff] [blame] | 49 | class TraceBuffer; |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 50 | class TraceConfig; |
Sami Kyostila | fbccb3c | 2018-03-21 14:00:47 +0000 | [diff] [blame] | 51 | class TracePacket; |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 52 | |
| 53 | // The tracing service business logic. |
| 54 | class ServiceImpl : public Service { |
| 55 | public: |
| 56 | // The implementation behind the service endpoint exposed to each producer. |
| 57 | class ProducerEndpointImpl : public Service::ProducerEndpoint { |
| 58 | public: |
| 59 | ProducerEndpointImpl(ProducerID, |
Sami Kyostila | 32e0b54 | 2018-02-14 08:55:43 +0000 | [diff] [blame] | 60 | uid_t uid, |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 61 | ServiceImpl*, |
| 62 | base::TaskRunner*, |
Isabelle Taylor | 86262cb | 2018-03-27 16:00:54 +0100 | [diff] [blame] | 63 | Producer*, |
| 64 | const std::string& producer_name); |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 65 | ~ProducerEndpointImpl() override; |
| 66 | |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 67 | // Service::ProducerEndpoint implementation. |
Primiano Tucci | 9daa483 | 2018-03-28 23:28:17 +0100 | [diff] [blame] | 68 | void RegisterDataSource(const DataSourceDescriptor&) override; |
| 69 | void UnregisterDataSource(const std::string& name) override; |
Primiano Tucci | 3e69ed9 | 2018-03-14 14:52:29 +0000 | [diff] [blame] | 70 | void CommitData(const CommitDataRequest&, CommitDataCallback) override; |
Isabelle Taylor | 69faa90 | 2018-03-21 15:42:03 +0000 | [diff] [blame] | 71 | void SetSharedMemory(std::unique_ptr<SharedMemory>); |
| 72 | |
Primiano Tucci | af429f9 | 2017-12-19 01:51:50 +0100 | [diff] [blame] | 73 | std::unique_ptr<TraceWriter> CreateTraceWriter(BufferID) override; |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 74 | SharedMemory* shared_memory() const override; |
Isabelle Taylor | 69faa90 | 2018-03-21 15:42:03 +0000 | [diff] [blame] | 75 | size_t shared_buffer_page_size_kb() const override; |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 76 | |
| 77 | private: |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 78 | friend class ServiceImpl; |
Sami Kyostila | 32e0b54 | 2018-02-14 08:55:43 +0000 | [diff] [blame] | 79 | FRIEND_TEST(ServiceImplTest, RegisterAndUnregister); |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 80 | ProducerEndpointImpl(const ProducerEndpointImpl&) = delete; |
| 81 | ProducerEndpointImpl& operator=(const ProducerEndpointImpl&) = delete; |
| 82 | |
| 83 | ProducerID const id_; |
Sami Kyostila | 32e0b54 | 2018-02-14 08:55:43 +0000 | [diff] [blame] | 84 | const uid_t uid_; |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 85 | ServiceImpl* const service_; |
| 86 | base::TaskRunner* const task_runner_; |
| 87 | Producer* producer_; |
| 88 | std::unique_ptr<SharedMemory> shared_memory_; |
Isabelle Taylor | 69faa90 | 2018-03-21 15:42:03 +0000 | [diff] [blame] | 89 | size_t shared_buffer_page_size_kb_ = 0; |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 90 | SharedMemoryABI shmem_abi_; |
Isabelle Taylor | 69faa90 | 2018-03-21 15:42:03 +0000 | [diff] [blame] | 91 | size_t shared_memory_size_hint_bytes_ = 0; |
Isabelle Taylor | 86262cb | 2018-03-27 16:00:54 +0100 | [diff] [blame] | 92 | const std::string name_; |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 93 | |
| 94 | // This is used only in in-process configurations (mostly tests). |
| 95 | std::unique_ptr<SharedMemoryArbiterImpl> inproc_shmem_arbiter_; |
Florian Mayer | cd08ec6 | 2018-01-31 17:49:25 +0000 | [diff] [blame] | 96 | PERFETTO_THREAD_CHECKER(thread_checker_) |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 99 | // The implementation behind the service endpoint exposed to each consumer. |
| 100 | class ConsumerEndpointImpl : public Service::ConsumerEndpoint { |
| 101 | public: |
| 102 | ConsumerEndpointImpl(ServiceImpl*, base::TaskRunner*, Consumer*); |
| 103 | ~ConsumerEndpointImpl() override; |
| 104 | |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 105 | void NotifyOnTracingStop(); |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 106 | base::WeakPtr<ConsumerEndpointImpl> GetWeakPtr(); |
| 107 | |
| 108 | // Service::ConsumerEndpoint implementation. |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 109 | void EnableTracing(const TraceConfig&, base::ScopedFile) override; |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 110 | void DisableTracing() override; |
| 111 | void ReadBuffers() override; |
| 112 | void FreeBuffers() override; |
| 113 | |
| 114 | private: |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 115 | friend class ServiceImpl; |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 116 | ConsumerEndpointImpl(const ConsumerEndpointImpl&) = delete; |
| 117 | ConsumerEndpointImpl& operator=(const ConsumerEndpointImpl&) = delete; |
| 118 | |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 119 | base::TaskRunner* const task_runner_; |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 120 | ServiceImpl* const service_; |
| 121 | Consumer* const consumer_; |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 122 | TracingSessionID tracing_session_id_ = 0; |
Florian Mayer | cd08ec6 | 2018-01-31 17:49:25 +0000 | [diff] [blame] | 123 | |
| 124 | PERFETTO_THREAD_CHECKER(thread_checker_) |
| 125 | |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 126 | base::WeakPtrFactory<ConsumerEndpointImpl> weak_ptr_factory_; |
| 127 | }; |
| 128 | |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 129 | explicit ServiceImpl(std::unique_ptr<SharedMemory::Factory>, |
| 130 | base::TaskRunner*); |
| 131 | ~ServiceImpl() override; |
| 132 | |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 133 | // Called by ProducerEndpointImpl. |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 134 | void DisconnectProducer(ProducerID); |
Primiano Tucci | 9daa483 | 2018-03-28 23:28:17 +0100 | [diff] [blame] | 135 | void RegisterDataSource(ProducerID, const DataSourceDescriptor&); |
| 136 | void UnregisterDataSource(ProducerID, const std::string& name); |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 137 | void CopyProducerPageIntoLogBuffer(ProducerID, |
Primiano Tucci | ecf9e4a | 2018-03-14 14:51:58 +0000 | [diff] [blame] | 138 | uid_t, |
| 139 | WriterID, |
| 140 | ChunkID, |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 141 | BufferID, |
Primiano Tucci | ecf9e4a | 2018-03-14 14:51:58 +0000 | [diff] [blame] | 142 | uint16_t num_fragments, |
| 143 | uint8_t chunk_flags, |
| 144 | const uint8_t* src, |
| 145 | size_t size); |
| 146 | void ApplyChunkPatches(ProducerID, |
| 147 | const std::vector<CommitDataRequest::ChunkToPatch>&); |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 148 | |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 149 | // Called by ConsumerEndpointImpl. |
| 150 | void DisconnectConsumer(ConsumerEndpointImpl*); |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 151 | bool EnableTracing(ConsumerEndpointImpl*, |
| 152 | const TraceConfig&, |
| 153 | base::ScopedFile); |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 154 | void DisableTracing(TracingSessionID); |
| 155 | void ReadBuffers(TracingSessionID, ConsumerEndpointImpl*); |
| 156 | void FreeBuffers(TracingSessionID); |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 157 | |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 158 | // Service implementation. |
| 159 | std::unique_ptr<Service::ProducerEndpoint> ConnectProducer( |
| 160 | Producer*, |
Sami Kyostila | 32e0b54 | 2018-02-14 08:55:43 +0000 | [diff] [blame] | 161 | uid_t uid, |
Isabelle Taylor | 86262cb | 2018-03-27 16:00:54 +0100 | [diff] [blame] | 162 | const std::string& producer_name, |
Isabelle Taylor | 69faa90 | 2018-03-21 15:42:03 +0000 | [diff] [blame] | 163 | size_t shared_memory_size_hint_bytes = 0) override; |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 164 | |
| 165 | std::unique_ptr<Service::ConsumerEndpoint> ConnectConsumer( |
| 166 | Consumer*) override; |
| 167 | |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 168 | // Exposed mainly for testing. |
| 169 | size_t num_producers() const { return producers_.size(); } |
| 170 | ProducerEndpointImpl* GetProducer(ProducerID) const; |
| 171 | |
| 172 | private: |
Primiano Tucci | 081d46a | 2018-02-28 11:09:43 +0000 | [diff] [blame] | 173 | FRIEND_TEST(ServiceImplTest, ProducerIDWrapping); |
| 174 | |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 175 | struct RegisteredDataSource { |
| 176 | ProducerID producer_id; |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 177 | DataSourceDescriptor descriptor; |
| 178 | }; |
| 179 | |
Sami Kyostila | 06487a2 | 2018-02-27 13:48:38 +0000 | [diff] [blame] | 180 | // Represents an active data source for a tracing session. |
| 181 | struct DataSourceInstance { |
| 182 | DataSourceInstanceID instance_id; |
Primiano Tucci | 9daa483 | 2018-03-28 23:28:17 +0100 | [diff] [blame] | 183 | std::string data_source_name; |
Sami Kyostila | 06487a2 | 2018-02-27 13:48:38 +0000 | [diff] [blame] | 184 | }; |
| 185 | |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 186 | // Holds the state of a tracing session. A tracing session is uniquely bound |
| 187 | // a specific Consumer. Each Consumer can own one or more sessions. |
| 188 | struct TracingSession { |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 189 | TracingSession(ConsumerEndpointImpl*, const TraceConfig&); |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 190 | |
| 191 | size_t num_buffers() const { return buffers_index.size(); } |
| 192 | |
Sami Kyostila | 01c45f0 | 2018-03-29 15:43:10 +0100 | [diff] [blame] | 193 | int delay_to_next_write_period_ms() const { |
| 194 | PERFETTO_DCHECK(write_period_ms > 0); |
| 195 | return write_period_ms - |
| 196 | (base::GetWallTimeMs().count() % write_period_ms); |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | // The consumer that started the session. |
| 200 | ConsumerEndpointImpl* const consumer; |
| 201 | |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 202 | // The original trace config provided by the Consumer when calling |
| 203 | // EnableTracing(). |
| 204 | const TraceConfig config; |
Oystein Eftevaag | 1269b4a | 2018-01-10 16:29:38 -0800 | [diff] [blame] | 205 | |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 206 | // List of data source instances that have been enabled on the various |
| 207 | // producers for this tracing session. |
Sami Kyostila | 06487a2 | 2018-02-27 13:48:38 +0000 | [diff] [blame] | 208 | std::multimap<ProducerID, DataSourceInstance> data_source_instances; |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 209 | |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 210 | // Maps a per-trace-session buffer index into the corresponding global |
| 211 | // BufferID (shared namespace amongst all consumers). This vector has as |
| 212 | // many entries as |config.buffers_size()|. |
| 213 | std::vector<BufferID> buffers_index; |
Sami Kyostila | fbccb3c | 2018-03-21 14:00:47 +0000 | [diff] [blame] | 214 | |
| 215 | // When the last clock snapshot was emitted into the output stream. |
| 216 | base::TimeMillis last_clock_snapshot = {}; |
Sami Kyostila | 200bd2e | 2018-03-26 12:24:10 +0100 | [diff] [blame] | 217 | |
| 218 | // Whether we mirrored the trace config back to the trace output yet. |
| 219 | bool did_emit_config = false; |
Primiano Tucci | 2ffd1a5 | 2018-03-27 01:01:30 +0100 | [diff] [blame] | 220 | |
| 221 | bool tracing_enabled = false; |
| 222 | |
| 223 | // This is set when the Consumer calls sets |write_into_file| == true in the |
| 224 | // TraceConfig. In this case this represents the file we should stream the |
| 225 | // trace packets into, rather than returning it to the consumer via |
| 226 | // OnTraceData(). |
| 227 | base::ScopedFile write_into_file; |
| 228 | int write_period_ms = 0; |
| 229 | size_t max_file_size_bytes = 0; |
| 230 | size_t bytes_written_into_file = 0; |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 231 | }; |
| 232 | |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 233 | ServiceImpl(const ServiceImpl&) = delete; |
| 234 | ServiceImpl& operator=(const ServiceImpl&) = delete; |
| 235 | |
Sami Kyostila | 06487a2 | 2018-02-27 13:48:38 +0000 | [diff] [blame] | 236 | void CreateDataSourceInstance(const TraceConfig::DataSource&, |
Isabelle Taylor | 86262cb | 2018-03-27 16:00:54 +0100 | [diff] [blame] | 237 | const TraceConfig::ProducerConfig&, |
Sami Kyostila | 06487a2 | 2018-02-27 13:48:38 +0000 | [diff] [blame] | 238 | const RegisteredDataSource&, |
| 239 | TracingSession*); |
Oystein Eftevaag | 1269b4a | 2018-01-10 16:29:38 -0800 | [diff] [blame] | 240 | |
Primiano Tucci | 081d46a | 2018-02-28 11:09:43 +0000 | [diff] [blame] | 241 | // Returns the next available ProducerID that is not in |producers_|. |
| 242 | ProducerID GetNextProducerID(); |
| 243 | |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 244 | // Returns a pointer to the |tracing_sessions_| entry or nullptr if the |
| 245 | // session doesn't exists. |
| 246 | TracingSession* GetTracingSession(TracingSessionID); |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 247 | |
Lalit Maganti | 485faff | 2018-03-06 11:51:35 +0000 | [diff] [blame] | 248 | // Update the memory guard rail by using the latest information from the |
| 249 | // shared memory and trace buffers. |
| 250 | void UpdateMemoryGuardrail(); |
| 251 | |
Sami Kyostila | fbccb3c | 2018-03-21 14:00:47 +0000 | [diff] [blame] | 252 | void MaybeSnapshotClocks(TracingSession*, std::vector<TracePacket>*); |
Sami Kyostila | 200bd2e | 2018-03-26 12:24:10 +0100 | [diff] [blame] | 253 | void MaybeEmitTraceConfig(TracingSession*, std::vector<TracePacket>*); |
Sami Kyostila | fbccb3c | 2018-03-21 14:00:47 +0000 | [diff] [blame] | 254 | |
Hector Dearman | 6214c8f | 2018-03-27 16:16:22 +0100 | [diff] [blame] | 255 | TraceBuffer* GetBufferByID(BufferID); |
Primiano Tucci | ecf9e4a | 2018-03-14 14:51:58 +0000 | [diff] [blame] | 256 | |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 257 | base::TaskRunner* const task_runner_; |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 258 | std::unique_ptr<SharedMemory::Factory> shm_factory_; |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 259 | ProducerID last_producer_id_ = 0; |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 260 | DataSourceInstanceID last_data_source_instance_id_ = 0; |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 261 | TracingSessionID last_tracing_session_id_ = 0; |
Isabelle Taylor | 69faa90 | 2018-03-21 15:42:03 +0000 | [diff] [blame] | 262 | size_t shared_memory_size_hint_bytes_ = 0; |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 263 | |
| 264 | // Buffer IDs are global across all consumers (because a Producer can produce |
| 265 | // data for more than one trace session, hence more than one consumer). |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 266 | IdAllocator<BufferID> buffer_ids_; |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 267 | |
| 268 | std::multimap<std::string /*name*/, RegisteredDataSource> data_sources_; |
| 269 | |
| 270 | // TODO(primiano): There doesn't seem to be any good reason why |producers_| |
| 271 | // is a map indexed by ID and not just a set<ProducerEndpointImpl*>. |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 272 | std::map<ProducerID, ProducerEndpointImpl*> producers_; |
Primiano Tucci | 5358933 | 2017-12-19 11:31:13 +0100 | [diff] [blame] | 273 | |
Primiano Tucci | 42e2de1 | 2017-12-07 16:46:04 +0000 | [diff] [blame] | 274 | std::set<ConsumerEndpointImpl*> consumers_; |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 275 | std::map<TracingSessionID, TracingSession> tracing_sessions_; |
Hector Dearman | 6214c8f | 2018-03-27 16:16:22 +0100 | [diff] [blame] | 276 | std::map<BufferID, std::unique_ptr<TraceBuffer>> buffers_; |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 277 | |
Florian Mayer | 61c5548 | 2018-03-06 14:43:54 +0000 | [diff] [blame] | 278 | bool lockdown_mode_ = false; |
| 279 | |
Florian Mayer | cd08ec6 | 2018-01-31 17:49:25 +0000 | [diff] [blame] | 280 | PERFETTO_THREAD_CHECKER(thread_checker_) |
| 281 | |
Primiano Tucci | 20d441d | 2018-01-16 09:25:51 +0000 | [diff] [blame] | 282 | base::WeakPtrFactory<ServiceImpl> weak_ptr_factory_; // Keep at the end. |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | } // namespace perfetto |
| 286 | |
| 287 | #endif // SRC_TRACING_CORE_SERVICE_IMPL_H_ |