1 /* 2 * Copyright (C) 2019 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_PERFETTO_CMD_TRIGGER_PRODUCER_H_ 18 #define SRC_PERFETTO_CMD_TRIGGER_PRODUCER_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include "perfetto/base/task_runner.h" 24 #include "perfetto/base/weak_ptr.h" 25 #include "perfetto/tracing/core/producer.h" 26 #include "perfetto/tracing/core/tracing_service.h" 27 28 namespace perfetto { 29 30 class DataSourceConfig; 31 32 // This is a producer that only sends the provided |triggers| to the service. It 33 // will never register any data sources. 34 class TriggerProducer : public Producer { 35 public: 36 TriggerProducer(base::TaskRunner* task_runner, 37 std::function<void(bool)> callback, 38 const std::vector<std::string>* const triggers); 39 ~TriggerProducer() override; 40 41 // We will call Trigger() on the |producer_endpoint_| and then 42 // immediately call |callback_|. 43 void OnConnect() override; 44 // We have no clean up to do OnDisconnect. 45 void OnDisconnect() override; 46 47 // Unimplemented methods are below this. 48 void OnTracingSetup() override; 49 void SetupDataSource(DataSourceInstanceID, const DataSourceConfig&) override; 50 void StartDataSource(DataSourceInstanceID, const DataSourceConfig&) override; 51 void StopDataSource(DataSourceInstanceID) override; 52 void Flush(FlushRequestID, const DataSourceInstanceID*, size_t) override; 53 void ClearIncrementalState(const DataSourceInstanceID* data_source_ids, 54 size_t num_data_sources) override; 55 56 private: 57 bool issued_callback_ = false; 58 base::TaskRunner* const task_runner_; 59 const std::function<void(bool)> callback_; 60 const std::vector<std::string>* const triggers_; 61 std::unique_ptr<TracingService::ProducerEndpoint> producer_endpoint_; 62 base::WeakPtrFactory<TriggerProducer> weak_factory_; 63 }; 64 65 } // namespace perfetto 66 67 #endif // SRC_PERFETTO_CMD_TRIGGER_PRODUCER_H_ 68