chromium/third_party/perfetto/include/perfetto/tracing/internal/track_event_legacy.h

/*
 * Copyright (C) 2023 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_LEGACY_H_
#define INCLUDE_PERFETTO_TRACING_INTERNAL_TRACK_EVENT_LEGACY_H_

#include "perfetto/base/build_config.h"
#include "perfetto/tracing/event_context.h"
#include "perfetto/tracing/track.h"
#include "protos/perfetto/trace/track_event/track_event.pbzero.h"

#ifndef PERFETTO_ENABLE_LEGACY_TRACE_EVENTS
#define PERFETTO_ENABLE_LEGACY_TRACE_EVENTS
#endif

// ----------------------------------------------------------------------------
// Constants.
// ----------------------------------------------------------------------------

namespace perfetto {
namespace legacy {

enum TraceEventFlag {};

enum PerfettoLegacyCurrentThreadId {};

// The following user-provided adaptors are used to serialize user-defined
// thread id and time types into track events. For full compatibility, the user
// should also define the following macros appropriately:
//
//   #define TRACE_TIME_TICKS_NOW() ...
//   #define TRACE_TIME_NOW() ...

// User-provided function to convert an abstract thread id into a thread track.
template <typename T>
ThreadTrack ConvertThreadId(const T&);

// Built-in implementation for events referring to the current thread.
template <>
ThreadTrack PERFETTO_EXPORT_COMPONENT
ConvertThreadId(const PerfettoLegacyCurrentThreadId&);

}  // namespace legacy
}  // namespace perfetto

#if PERFETTO_ENABLE_LEGACY_TRACE_EVENTS
// The following constants are defined in the global namespace, since they were
// originally implemented as macros.

// Event phases.
static constexpr char TRACE_EVENT_PHASE_BEGIN =;
static constexpr char TRACE_EVENT_PHASE_END =;
static constexpr char TRACE_EVENT_PHASE_COMPLETE =;
static constexpr char TRACE_EVENT_PHASE_INSTANT =;
static constexpr char TRACE_EVENT_PHASE_ASYNC_BEGIN =;
static constexpr char TRACE_EVENT_PHASE_ASYNC_STEP_INTO =;
static constexpr char TRACE_EVENT_PHASE_ASYNC_STEP_PAST =;
static constexpr char TRACE_EVENT_PHASE_ASYNC_END =;
static constexpr char TRACE_EVENT_PHASE_NESTABLE_ASYNC_BEGIN =;
static constexpr char TRACE_EVENT_PHASE_NESTABLE_ASYNC_END =;
static constexpr char TRACE_EVENT_PHASE_NESTABLE_ASYNC_INSTANT =;
static constexpr char TRACE_EVENT_PHASE_FLOW_BEGIN =;
static constexpr char TRACE_EVENT_PHASE_FLOW_STEP =;
static constexpr char TRACE_EVENT_PHASE_FLOW_END =;
static constexpr char TRACE_EVENT_PHASE_METADATA =;
static constexpr char TRACE_EVENT_PHASE_COUNTER =;
static constexpr char TRACE_EVENT_PHASE_SAMPLE =;
static constexpr char TRACE_EVENT_PHASE_CREATE_OBJECT =;
static constexpr char TRACE_EVENT_PHASE_SNAPSHOT_OBJECT =;
static constexpr char TRACE_EVENT_PHASE_DELETE_OBJECT =;
static constexpr char TRACE_EVENT_PHASE_MEMORY_DUMP =;
static constexpr char TRACE_EVENT_PHASE_MARK =;
static constexpr char TRACE_EVENT_PHASE_CLOCK_SYNC =;

// Flags for changing the behavior of TRACE_EVENT_API_ADD_TRACE_EVENT.
static constexpr uint32_t TRACE_EVENT_FLAG_NONE =;
static constexpr uint32_t TRACE_EVENT_FLAG_COPY =;
static constexpr uint32_t TRACE_EVENT_FLAG_HAS_ID =;
static constexpr uint32_t TRACE_EVENT_FLAG_SCOPE_OFFSET =;
static constexpr uint32_t TRACE_EVENT_FLAG_SCOPE_EXTRA =;
static constexpr uint32_t TRACE_EVENT_FLAG_EXPLICIT_TIMESTAMP =;
static constexpr uint32_t TRACE_EVENT_FLAG_ASYNC_TTS =;
static constexpr uint32_t TRACE_EVENT_FLAG_BIND_TO_ENCLOSING =;
static constexpr uint32_t TRACE_EVENT_FLAG_FLOW_IN =;
static constexpr uint32_t TRACE_EVENT_FLAG_FLOW_OUT =;
static constexpr uint32_t TRACE_EVENT_FLAG_HAS_CONTEXT_ID =;
static constexpr uint32_t TRACE_EVENT_FLAG_HAS_PROCESS_ID =;
static constexpr uint32_t TRACE_EVENT_FLAG_HAS_LOCAL_ID =;
static constexpr uint32_t TRACE_EVENT_FLAG_HAS_GLOBAL_ID =;
static constexpr uint32_t TRACE_EVENT_FLAG_TYPED_PROTO_ARGS =;
static constexpr uint32_t TRACE_EVENT_FLAG_JAVA_STRING_LITERALS =;

static constexpr uint32_t TRACE_EVENT_FLAG_SCOPE_MASK =;

// Type values for identifying types in the TraceValue union.
static constexpr uint8_t TRACE_VALUE_TYPE_BOOL =;
static constexpr uint8_t TRACE_VALUE_TYPE_UINT =;
static constexpr uint8_t TRACE_VALUE_TYPE_INT =;
static constexpr uint8_t TRACE_VALUE_TYPE_DOUBLE =;
static constexpr uint8_t TRACE_VALUE_TYPE_POINTER =;
static constexpr uint8_t TRACE_VALUE_TYPE_STRING =;
static constexpr uint8_t TRACE_VALUE_TYPE_COPY_STRING =;
static constexpr uint8_t TRACE_VALUE_TYPE_CONVERTABLE =;
static constexpr uint8_t TRACE_VALUE_TYPE_PROTO =;

// Enum reflecting the scope of an INSTANT event. Must fit within
// TRACE_EVENT_FLAG_SCOPE_MASK.
static constexpr uint8_t TRACE_EVENT_SCOPE_GLOBAL =;
static constexpr uint8_t TRACE_EVENT_SCOPE_PROCESS =;
static constexpr uint8_t TRACE_EVENT_SCOPE_THREAD =;

static constexpr char TRACE_EVENT_SCOPE_NAME_GLOBAL =;
static constexpr char TRACE_EVENT_SCOPE_NAME_PROCESS =;
static constexpr char TRACE_EVENT_SCOPE_NAME_THREAD =;

#define TRACE_EVENT_API_CURRENT_THREAD_ID

#endif  // PERFETTO_ENABLE_LEGACY_TRACE_EVENTS

namespace perfetto {
namespace internal {

// LegacyTraceId encapsulates an ID that can either be an integer or pointer.
class PERFETTO_EXPORT_COMPONENT LegacyTraceId {};

#if PERFETTO_ENABLE_LEGACY_TRACE_EVENTS
template <typename T>
bool IsEqual(T x, T y) {}

template <typename T, typename U>
bool IsEqual(T, U) {}

class PERFETTO_EXPORT_COMPONENT TrackEventLegacy {};
#endif  // PERFETTO_ENABLE_LEGACY_TRACE_EVENTS

// Legacy macros allow argument values to be nullptr and convert them to the
// "NULL" string. The following function helps mimic this behavior: it forwards
// all types of arguments apart from a nullptr string as is, and in case of a
// nullptr returns "NULL".
template <typename T>
inline T PossiblyNull(T&& value) {}

inline const char* PossiblyNull(const char* name) {}

inline const char* PossiblyNull(char* name) {}

}  // namespace internal
}  // namespace perfetto

#endif  // INCLUDE_PERFETTO_TRACING_INTERNAL_TRACK_EVENT_LEGACY_H_