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 enum Flags : uint32_t { 35 kFlagsNone = 0, 36 kHandlesIncrementalState = 1 << 0, 37 }; 38 const char* const name; 39 uint32_t flags; 40 }; 41 42 ProbesDataSource(TracingSessionID, const Descriptor*); 43 virtual ~ProbesDataSource(); 44 45 virtual void Start() = 0; 46 virtual void Flush(FlushRequestID, std::function<void()> callback) = 0; 47 48 // Only data sources that opt in via DataSourceDescriptor should receive this 49 // call. ClearIncrementalState()50 virtual void ClearIncrementalState() { 51 PERFETTO_ELOG( 52 "ClearIncrementalState received by data source that doesn't provide " 53 "its own implementation."); 54 } 55 56 const TracingSessionID tracing_session_id; 57 const Descriptor* const descriptor; 58 bool started = false; // Set by probes_producer.cc. 59 60 private: 61 ProbesDataSource(const ProbesDataSource&) = delete; 62 ProbesDataSource& operator=(const ProbesDataSource&) = delete; 63 }; 64 65 } // namespace perfetto 66 67 #endif // SRC_TRACED_PROBES_PROBES_DATA_SOURCE_H_ 68