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. 51 virtual void OnTracingDisabled() = 0; 52 53 // Called back by the Service (or transport layer) after invoking 54 // TracingService::ConsumerEndpoint::ReadBuffers(). This function can be 55 // called more than once. Each invocation can carry one or more 56 // TracePacket(s). Upon the last call, |has_more| is set to true (i.e. 57 // |has_more| is a !EOF). 58 virtual void OnTraceData(std::vector<TracePacket>, bool has_more) = 0; 59 60 // Called back by the Service (or transport layer) after invoking 61 // TracingService::ConsumerEndpoint::Detach(). 62 // The consumer can disconnect at this point and the trace session will keep 63 // on going. A new consumer can later re-attach passing back the same |key| 64 // passed to Detach(), but only if the two requests come from the same uid. 65 virtual void OnDetach(bool success) = 0; 66 67 // Called back by the Service (or transport layer) after invoking 68 // TracingService::ConsumerEndpoint::Attach(). 69 virtual void OnAttach(bool success, const TraceConfig&) = 0; 70 71 // Called back by the Service (or transport layer) after invoking 72 // TracingService::ConsumerEndpoint::GetTraceStats(). 73 virtual void OnTraceStats(bool success, const TraceStats&) = 0; 74 75 // Called back by the Service (or transport layer) after invoking 76 // TracingService::ConsumerEndpoint::ObserveEvents() whenever one or more 77 // ObservableEvents of enabled event types occur. 78 virtual void OnObservableEvents(const ObservableEvents&) = 0; 79 }; 80 81 } // namespace perfetto 82 83 #endif // INCLUDE_PERFETTO_EXT_TRACING_CORE_CONSUMER_H_ 84