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