/* * Copyright (C) 2019 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 INCLUDE_PERFETTO_TRACING_INTERNAL_TRACK_EVENT_MACROS_H_ #define INCLUDE_PERFETTO_TRACING_INTERNAL_TRACK_EVENT_MACROS_H_ // This file contains underlying macros for the trace point track event // implementation. Perfetto API users typically don't need to use anything here // directly. #include "perfetto/base/compiler.h" #include "perfetto/tracing/internal/track_event_data_source.h" #include "perfetto/tracing/string_helpers.h" #include "perfetto/tracing/track_event_category_registry.h" // Ignore GCC warning about a missing argument for a variadic macro parameter. #if defined(__GNUC__) || defined(__clang__) #pragma GCC system_header #endif // Defines data structures for backing a category registry. // // Each category has one enabled/disabled bit per possible data source instance. // The bits are packed, i.e., each byte holds the state for instances. To // improve cache locality, the bits for each instance are stored separately from // the names of the categories: // // byte 0 byte 1 // (inst0, inst1, ..., inst7), (inst0, inst1, ..., inst7) // #define PERFETTO_INTERNAL_DECLARE_CATEGORIES(attrs, ...) … // In a .cc file, declares storage for each category's runtime state. #define PERFETTO_INTERNAL_CATEGORY_STORAGE(attrs) … // Defines the TrackEvent data source for the current track event namespace. // `virtual ~TrackEvent` is added to avoid `-Wweak-vtables` warning. // Learn more : aosp/2019906 #define PERFETTO_INTERNAL_DECLARE_TRACK_EVENT_DATA_SOURCE(attrs) … #define PERFETTO_INTERNAL_DEFINE_TRACK_EVENT_DATA_SOURCE() … // At compile time, turns a category name represented by a static string into an // index into the current category registry. A build error will be generated if // the category hasn't been registered or added to the list of allowed dynamic // categories. See PERFETTO_DEFINE_CATEGORIES. #define PERFETTO_GET_CATEGORY_INDEX(category) … // Generate a unique variable name with a given prefix. #define PERFETTO_INTERNAL_CONCAT2(a, b) … #define PERFETTO_INTERNAL_CONCAT(a, b) … #define PERFETTO_UID(prefix) … // Efficiently determines whether tracing is enabled for the given category, and // if so, emits one trace event with the given arguments. #define PERFETTO_INTERNAL_TRACK_EVENT_WITH_METHOD(method, category, name, ...) … // This internal macro is unused from the repo now, but some improper usage // remain outside of the repo. // TODO(b/294800182): Remove this. #define PERFETTO_INTERNAL_TRACK_EVENT(...) … // C++17 doesn't like a move constructor being defined for the EventFinalizer // class but C++11 and MSVC doesn't compile without it being defined so support // both. #if !PERFETTO_BUILDFLAG(PERFETTO_COMPILER_MSVC) #define PERFETTO_INTERNAL_EVENT_FINALIZER_KEYWORD … #else #define PERFETTO_INTERNAL_EVENT_FINALIZER_KEYWORD … #endif #define PERFETTO_INTERNAL_SCOPED_EVENT_FINALIZER(category) … #define PERFETTO_INTERNAL_SCOPED_TRACK_EVENT(category, name, ...) … #if PERFETTO_ENABLE_LEGACY_TRACE_EVENTS // Required for TRACE_EVENT_WITH_FLOW legacy macros, which pass the bind_id as // id. #define PERFETTO_INTERNAL_SCOPED_LEGACY_TRACK_EVENT_WITH_ID( \ category, name, track, flags, thread_id, id, ...) … #endif // PERFETTO_ENABLE_LEGACY_TRACE_EVENTS #if PERFETTO_BUILDFLAG(PERFETTO_COMPILER_GCC) || \ PERFETTO_BUILDFLAG(PERFETTO_COMPILER_MSVC) // On GCC versions <9 there's a bug that prevents using captured constant // variables in constexpr evaluation inside a lambda: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82643 // TODO(khokhlov): Remove this fallback after Perfetto moves to a more recent // GCC version. #define PERFETTO_INTERNAL_CATEGORY_ENABLED … #else // !PERFETTO_BUILDFLAG(PERFETTO_COMPILER_GCC) #define PERFETTO_INTERNAL_CATEGORY_ENABLED(category) … #endif // !PERFETTO_BUILDFLAG(PERFETTO_COMPILER_GCC) // Emits an empty trace packet into the trace to ensure that the service can // safely read the last event from the trace buffer. This can be used to // periodically "flush" the last event on threads that don't support explicit // flushing of the shared memory buffer chunk when the tracing session stops // (e.g. thread pool workers in Chromium). // // This workaround is only required because the tracing service cannot safely // read the last trace packet from an incomplete SMB chunk (crbug.com/1021571 // and b/162206162) when scraping the SMB. Adding an empty trace packet ensures // that all prior events can be scraped by the service. #define PERFETTO_INTERNAL_ADD_EMPTY_EVENT() … #endif // INCLUDE_PERFETTO_TRACING_INTERNAL_TRACK_EVENT_MACROS_H_