/* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SRC_TRACE_PROCESSOR_TP_METATRACE_H_ #define SRC_TRACE_PROCESSOR_TP_METATRACE_H_ #include <array> #include <functional> #include <vector> #include "perfetto/base/time.h" #include "perfetto/ext/base/metatrace_events.h" #include "perfetto/ext/base/string_view.h" #include "perfetto/ext/base/thread_checker.h" #include "perfetto/trace_processor/metatrace_config.h" #include "protos/perfetto/trace_processor/metatrace_categories.pbzero.h" // Trace processor maintains its own base implementation to avoid the // threading and task runners which are required by base's metatracing. // Moreover, this metatrace also adds support for args which is missing // from base's metatracing. // On the other hand, this implementation is not (currently) thread-safe // and is likely less performant than base's implementation. namespace perfetto { namespace trace_processor { namespace metatrace { Category; // Stores whether meta-tracing is enabled. extern Category g_enabled_categories; inline uint64_t TraceTimeNowNs() { … } struct Record { … }; // Implementation of fixed-size ring buffer. The implementation of this // class is modelled on the RingBuffer in metatrace.h of base but is different // in a couple of ways: // 1. This class is *not* thread safe. // 2. The Record type stored in this class has the capability of storing // extra, event-specific context. For example, when tracing SQL query // execution, we store the query string. // 3. The buffer is designed to be written continuously while meta-tracing // is enabled and read one-shot at the end of execution. class RingBuffer { … }; class ScopedEvent { … }; // Enables meta-tracing of trace-processor. void Enable(MetatraceConfig config = {}); // Disables meta-tracing of trace-processor and reads all records. void DisableAndReadBuffer(std::function<void(Record*)>); // Boilerplate to derive a unique variable name for the event. #define PERFETTO_TP_METATRACE_UID2(a, b) … #define PERFETTO_TP_METATRACE_UID(x) … #define PERFETTO_TP_TRACE(...) … } // namespace metatrace } // namespace trace_processor } // namespace perfetto #endif // SRC_TRACE_PROCESSOR_TP_METATRACE_H_