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_CONSUMER_H_ 18 #define INCLUDE_PERFETTO_EXT_TRACING_CORE_CONSUMER_H_ 19 20 #include <vector> 21 22 #include "perfetto/base/export.h" 23 #include "perfetto/ext/tracing/core/basic_types.h" 24 #include "perfetto/ext/tracing/core/observable_events.h" 25 #include "perfetto/tracing/core/forward_decls.h" 26 namespace perfetto { 27 28 class TracePacket; 29 30 class PERFETTO_EXPORT Consumer { 31 public: 32 virtual ~Consumer(); 33 34 // Called by Service (or more typically by the transport layer, on behalf of 35 // the remote Service), once the Consumer <> Service connection has been 36 // established. 37 virtual void OnConnect() = 0; 38 39 // Called by the Service or by the transport layer if the connection with the 40 // service drops, either voluntarily (e.g., by destroying the ConsumerEndpoint 41 // obtained through Service::ConnectConsumer()) or involuntarily (e.g., if the 42 // Service process crashes). 43 virtual void OnDisconnect() = 0; 44 45 // Called by the Service after the tracing session has ended. This can happen 46 // for a variety of reasons: 47 // - The consumer explicitly called DisableTracing() 48 // - The TraceConfig's |duration_ms| has been reached. 49 // - The TraceConfig's |max_file_size_bytes| has been reached. 50 // - An error occurred while trying to enable tracing. In this case |error| 51 // is non-empty. 52 virtual void OnTracingDisabled(const std::string& error) = 0; 53 54 // Called back by the Service (or transport layer) after invoking 55 // TracingService::ConsumerEndpoint::ReadBuffers(). This function can be 56 // called more than once. Each invocation can carry one or more 57 // TracePacket(s). Upon the last call, |has_more| is set to true (i.e. 58 // |has_more| is a !EOF). 59 virtual void OnTraceData(std::vector<TracePacket>, bool has_more) = 0; 60 61 // Called back by the Service (or transport layer) after invoking 62 // TracingService::ConsumerEndpoint::Detach(). 63 // The consumer can disconnect at this point and the trace session will keep 64 // on going. A new consumer can later re-attach passing back the same |key| 65 // passed to Detach(), but only if the two requests come from the same uid. 66 virtual void OnDetach(bool success) = 0; 67 68 // Called back by the Service (or transport layer) after invoking 69 // TracingService::ConsumerEndpoint::Attach(). 70 virtual void OnAttach(bool success, const TraceConfig&) = 0; 71 72 // Called back by the Service (or transport layer) after invoking 73 // TracingService::ConsumerEndpoint::GetTraceStats(). 74 virtual void OnTraceStats(bool success, const TraceStats&) = 0; 75 76 // Called back by the Service (or transport layer) after invoking 77 // TracingService::ConsumerEndpoint::ObserveEvents() whenever one or more 78 // ObservableEvents of enabled event types occur. 79 virtual void OnObservableEvents(const ObservableEvents&) = 0; 80 }; 81 82 } // namespace perfetto 83 84 #endif // INCLUDE_PERFETTO_EXT_TRACING_CORE_CONSUMER_H_ 85