• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/base/uuid.h"
24 #include "perfetto/ext/tracing/core/basic_types.h"
25 #include "perfetto/ext/tracing/core/observable_events.h"
26 #include "perfetto/tracing/core/forward_decls.h"
27 namespace perfetto {
28 
29 class TracePacket;
30 
31 class PERFETTO_EXPORT_COMPONENT Consumer {
32  public:
33   virtual ~Consumer();
34 
35   // Called by Service (or more typically by the transport layer, on behalf of
36   // the remote Service), once the Consumer <> Service connection has been
37   // established.
38   virtual void OnConnect() = 0;
39 
40   // Called by the Service or by the transport layer if the connection with the
41   // service drops, either voluntarily (e.g., by destroying the ConsumerEndpoint
42   // obtained through Service::ConnectConsumer()) or involuntarily (e.g., if the
43   // Service process crashes).
44   virtual void OnDisconnect() = 0;
45 
46   // Called by the Service after the tracing session has ended. This can happen
47   // for a variety of reasons:
48   // - The consumer explicitly called DisableTracing()
49   // - The TraceConfig's |duration_ms| has been reached.
50   // - The TraceConfig's |max_file_size_bytes| has been reached.
51   // - An error occurred while trying to enable tracing. In this case |error|
52   //   is non-empty.
53   virtual void OnTracingDisabled(const std::string& error) = 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   // Called back by the Service (or transport layer) after invoking
83   // TracingService::ConsumerEndpoint::CloneSession().
84   // TODO(primiano): make pure virtual after various 3way patches.
85   struct OnSessionClonedArgs {
86     bool success;
87     std::string error;
88     base::Uuid uuid;  // UUID of the cloned session.
89   };
90   virtual void OnSessionCloned(const OnSessionClonedArgs&);
91 };
92 
93 }  // namespace perfetto
94 
95 #endif  // INCLUDE_PERFETTO_EXT_TRACING_CORE_CONSUMER_H_
96