xref: /aosp_15_r20/external/perfetto/src/traced/probes/probes_data_source.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2018 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 SRC_TRACED_PROBES_PROBES_DATA_SOURCE_H_
18 #define SRC_TRACED_PROBES_PROBES_DATA_SOURCE_H_
19 
20 #include <functional>
21 
22 #include "perfetto/base/logging.h"
23 #include "perfetto/ext/tracing/core/basic_types.h"
24 #include "perfetto/tracing/core/forward_decls.h"
25 
26 namespace perfetto {
27 
28 // Base class for all data sources in traced_probes.
29 class ProbesDataSource {
30  public:
31   // Static properties for a data source. Needs to be available before
32   // instantiating each data source. It must have static lifetime.
33   struct Descriptor {
34     using FillDescriptorFunc = void (*)(DataSourceDescriptor*);
35     enum Flags : uint32_t {
36       kFlagsNone = 0,
37       kHandlesIncrementalState = 1 << 0,
38     };
39     const char* const name;
40     uint32_t flags;
41     // If not nullptr, called to fill data source specific fields in
42     // DataSourceDescriptor.
43     FillDescriptorFunc fill_descriptor_func;
44   };
45 
46   ProbesDataSource(TracingSessionID, const Descriptor*);
47   virtual ~ProbesDataSource();
48 
49   virtual void Start() = 0;
50   virtual void Flush(FlushRequestID, std::function<void()> callback) = 0;
51 
52   // Only data sources that opt in via DataSourceDescriptor should receive this
53   // call.
ClearIncrementalState()54   virtual void ClearIncrementalState() {
55     PERFETTO_ELOG(
56         "ClearIncrementalState received by data source that doesn't provide "
57         "its own implementation.");
58   }
59 
60   const TracingSessionID tracing_session_id;
61   const Descriptor* const descriptor;
62   bool started = false;  // Set by probes_producer.cc.
63 
64  private:
65   ProbesDataSource(const ProbesDataSource&) = delete;
66   ProbesDataSource& operator=(const ProbesDataSource&) = delete;
67 };
68 
69 }  // namespace perfetto
70 
71 #endif  // SRC_TRACED_PROBES_PROBES_DATA_SOURCE_H_
72