• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_CLOUD_TRACE_PROCESSOR_WORKER_H_
18 #define INCLUDE_PERFETTO_EXT_CLOUD_TRACE_PROCESSOR_WORKER_H_
19 
20 #include <memory>
21 #include <vector>
22 
23 #include "perfetto/ext/base/threading/future.h"
24 #include "perfetto/ext/base/threading/stream.h"
25 
26 namespace perfetto {
27 
28 namespace base {
29 class ThreadPool;
30 }
31 
32 namespace protos {
33 class TracePoolShardCreateArgs;
34 class TracePoolShardCreateResponse;
35 
36 class TracePoolShardSetTracesArgs;
37 class TracePoolShardSetTracesResponse;
38 
39 class TracePoolShardQueryArgs;
40 class TracePoolShardQueryResponse;
41 
42 class TracePoolShardDestroyArgs;
43 class TracePoolShardDestroyResponse;
44 }  // namespace protos
45 
46 namespace cloud_trace_processor {
47 
48 class CtpEnvironment;
49 
50 // Interface for a CloudTraceProcessor "Worker".
51 //
52 // See CloudTraceProcessorWorker RPC service for high-level documentation.
53 class Worker {
54  public:
55   virtual ~Worker();
56 
57   // Returns an in-process implementation of the Worker given an instance of
58   // |CtpEnvironment| and a |ThreadPool|. The |CtpEnvironment| will be used to
59   // perform any interaction with the OS (e.g. opening and reading files) and
60   // the |ThreadPool| will be used to dispatch requests to TraceProcessor.
61   static std::unique_ptr<Worker> CreateInProcesss(CtpEnvironment*,
62                                                   base::ThreadPool*);
63 
64   // Creates a TracePoolShard which will be owned by this worker.
65   virtual base::StatusOrFuture<protos::TracePoolShardCreateResponse>
66   TracePoolShardCreate(const protos::TracePoolShardCreateArgs&) = 0;
67 
68   // Associates the provided list of traces to this TracePoolShard.
69   virtual base::StatusOrStream<protos::TracePoolShardSetTracesResponse>
70   TracePoolShardSetTraces(const protos::TracePoolShardSetTracesArgs&) = 0;
71 
72   // Executes a SQL query on the specified TracePoolShard.
73   virtual base::StatusOrStream<protos::TracePoolShardQueryResponse>
74   TracePoolShardQuery(const protos::TracePoolShardQueryArgs&) = 0;
75 
76   // Destroys the TracePoolShard with the specified id.
77   virtual base::StatusOrFuture<protos::TracePoolShardDestroyResponse>
78   TracePoolShardDestroy(const protos::TracePoolShardDestroyArgs&) = 0;
79 };
80 
81 }  // namespace cloud_trace_processor
82 }  // namespace perfetto
83 
84 #endif  // INCLUDE_PERFETTO_EXT_CLOUD_TRACE_PROCESSOR_WORKER_H_
85