#ifndef V8_HEAP_CPPGC_TRACE_EVENT_H_
#define V8_HEAP_CPPGC_TRACE_EVENT_H_
#if !CPPGC_IS_STANDALONE
#include "src/tracing/trace-event.h"
ConvertableToTraceFormat;
#else
#include "include/cppgc/platform.h"
#include "src/base/atomicops.h"
#include "src/base/macros.h"
#include "src/tracing/trace-event-no-perfetto.h"
enum CategoryGroupEnabledFlags {
kEnabledForRecording_CategoryGroupEnabledFlags = 1 << 0,
kEnabledForEventCallback_CategoryGroupEnabledFlags = 1 << 2,
};
#define INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE …
#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED …
#define TRACE_EVENT_API_ADD_TRACE_EVENT …
#define TRACE_EVENT_API_ATOMIC_WORD …
#define TRACE_EVENT_API_ATOMIC_LOAD …
#define TRACE_EVENT_API_ATOMIC_STORE …
#define TRACE_EVENT_API_LOAD_CATEGORY_GROUP_ENABLED …
#define INTERNAL_TRACE_EVENT_UID3 …
#define INTERNAL_TRACE_EVENT_UID2 …
#define INTERNAL_TRACE_EVENT_UID …
#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES …
#define INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO …
#define INTERNAL_TRACE_EVENT_ADD …
namespace cppgc {
namespace internal {
using ConvertableToTraceFormat = v8::ConvertableToTraceFormat;
class TraceEventHelper {
public:
V8_EXPORT_PRIVATE static TracingController* GetTracingController();
};
static V8_INLINE uint64_t AddTraceEventImpl(
char phase, const uint8_t* category_group_enabled, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
const char** arg_names, const uint8_t* arg_types,
const uint64_t* arg_values, unsigned int flags, Platform* platform) {
std::unique_ptr<ConvertableToTraceFormat> arg_convertables[2];
if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) {
arg_convertables[0].reset(reinterpret_cast<ConvertableToTraceFormat*>(
static_cast<intptr_t>(arg_values[0])));
}
if (num_args > 1 && arg_types[1] == TRACE_VALUE_TYPE_CONVERTABLE) {
arg_convertables[1].reset(reinterpret_cast<ConvertableToTraceFormat*>(
static_cast<intptr_t>(arg_values[1])));
}
DCHECK_LE(num_args, 2);
TracingController* controller = platform->GetTracingController();
return controller->AddTraceEvent(phase, category_group_enabled, name, scope,
id, bind_id, num_args, arg_names, arg_types,
arg_values, arg_convertables, flags);
}
template <typename T>
static V8_INLINE typename std::enable_if<
std::is_integral<T>::value || std::is_enum<T>::value, void>::type
SetTraceValue(T arg, unsigned char* type, uint64_t* value) {
*type = std::is_same<T, bool>::value
? TRACE_VALUE_TYPE_BOOL
: std::is_signed<T>::value ? TRACE_VALUE_TYPE_INT
: TRACE_VALUE_TYPE_UINT;
*value = static_cast<uint64_t>(arg);
}
#define INTERNAL_DECLARE_SET_TRACE_VALUE …
INTERNAL_DECLARE_SET_TRACE_VALUE(double, TRACE_VALUE_TYPE_DOUBLE)
INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, TRACE_VALUE_TYPE_STRING)
#undef INTERNAL_DECLARE_SET_TRACE_VALUE
static V8_INLINE uint64_t AddTraceEvent(char phase,
const uint8_t* category_group_enabled,
const char* name, const char* scope,
uint64_t id, uint64_t bind_id,
unsigned int flags,
Platform* platform) {
return TRACE_EVENT_API_ADD_TRACE_EVENT(
phase, category_group_enabled, name, scope, id, bind_id, 0 ,
nullptr, nullptr, nullptr, flags, platform);
}
template <class ARG1_TYPE>
static V8_INLINE uint64_t AddTraceEvent(
char phase, const uint8_t* category_group_enabled, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
Platform* platform, const char* arg1_name, ARG1_TYPE&& arg1_val) {
const int num_args = 1;
uint8_t arg_type;
uint64_t arg_value;
SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_type, &arg_value);
return TRACE_EVENT_API_ADD_TRACE_EVENT(
phase, category_group_enabled, name, scope, id, bind_id, num_args,
&arg1_name, &arg_type, &arg_value, flags, platform);
}
template <class ARG1_TYPE, class ARG2_TYPE>
static V8_INLINE uint64_t AddTraceEvent(
char phase, const uint8_t* category_group_enabled, const char* name,
const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
Platform* platform, const char* arg1_name, ARG1_TYPE&& arg1_val,
const char* arg2_name, ARG2_TYPE&& arg2_val) {
const int num_args = 2;
const char* arg_names[2] = {arg1_name, arg2_name};
unsigned char arg_types[2];
uint64_t arg_values[2];
SetTraceValue(std::forward<ARG1_TYPE>(arg1_val), &arg_types[0],
&arg_values[0]);
SetTraceValue(std::forward<ARG2_TYPE>(arg2_val), &arg_types[1],
&arg_values[1]);
return TRACE_EVENT_API_ADD_TRACE_EVENT(
phase, category_group_enabled, name, scope, id, bind_id, num_args,
arg_names, arg_types, arg_values, flags, platform);
}
}
}
#endif
#endif