Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Unified Diff: src/tracing/trace-event.h

Issue 1704253002: Reland: Add Scoped Context Info (Isolate) to V8 Traces (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/libplatform/default-platform.cc ('k') | test/cctest/heap/test-incremental-marking.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/tracing/trace-event.h
diff --git a/src/tracing/trace-event.h b/src/tracing/trace-event.h
index d17f78589ff07de789280be6d612ee2fcb72ed0b..2b3bf9bf92cca8fc5524ee1e644057d43795a0f1 100644
--- a/src/tracing/trace-event.h
+++ b/src/tracing/trace-event.h
@@ -10,6 +10,7 @@
#include "base/trace_event/common/trace_event_common.h"
#include "include/v8-platform.h"
#include "src/base/atomicops.h"
+#include "src/base/macros.h"
// This header file defines implementation details of how the trace macros in
// trace_event_common.h collect and store trace events. Anything not
@@ -42,6 +43,11 @@ enum CategoryGroupEnabledFlags {
// macros. Use this macro to prevent Process ID mangling.
#define TRACE_ID_DONT_MANGLE(id) v8::internal::tracing::TraceID::DontMangle(id)
+// By default, trace IDs are eventually converted to a single 64-bit number. Use
+// this macro to add a scope string.
+#define TRACE_ID_WITH_SCOPE(scope, id) \
+ trace_event_internal::TraceID::WithScope(scope, id)
+
// Sets the current sample state to the given category and name (both must be
// constant strings). These states are intended for a sampling profiler.
// Implementation note: we store category and name together because we don't
@@ -106,6 +112,7 @@ enum CategoryGroupEnabledFlags {
// char phase,
// const uint8_t* category_group_enabled,
// const char* name,
+// const char* scope,
// uint64_t id,
// uint64_t bind_id,
// int num_args,
@@ -181,26 +188,26 @@ extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3];
if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
v8::internal::tracing::AddTraceEvent( \
phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
- v8::internal::tracing::kNoId, v8::internal::tracing::kNoId, flags, \
- ##__VA_ARGS__); \
+ v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, \
+ v8::internal::tracing::kNoId, flags, ##__VA_ARGS__); \
} \
} while (0)
// Implementation detail: internal macro to create static category and add begin
// event if the category is enabled. Also adds the end event when the scope
// ends.
-#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
- INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
- v8::internal::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
- if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
- uint64_t h = v8::internal::tracing::AddTraceEvent( \
- TRACE_EVENT_PHASE_COMPLETE, \
- INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
- v8::internal::tracing::kNoId, v8::internal::tracing::kNoId, \
- TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
- INTERNAL_TRACE_EVENT_UID(tracer) \
- .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
- h); \
+#define INTERNAL_TRACE_EVENT_ADD_SCOPED(category_group, name, ...) \
+ INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(category_group); \
+ v8::internal::tracing::ScopedTracer INTERNAL_TRACE_EVENT_UID(tracer); \
+ if (INTERNAL_TRACE_EVENT_CATEGORY_GROUP_ENABLED_FOR_RECORDING_MODE()) { \
+ uint64_t h = v8::internal::tracing::AddTraceEvent( \
+ TRACE_EVENT_PHASE_COMPLETE, \
+ INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
+ v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, \
+ v8::internal::tracing::kNoId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__); \
+ INTERNAL_TRACE_EVENT_UID(tracer) \
+ .Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
+ h); \
}
#define INTERNAL_TRACE_EVENT_ADD_SCOPED_WITH_FLOW(category_group, name, \
@@ -214,8 +221,8 @@ extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3];
uint64_t h = v8::internal::tracing::AddTraceEvent( \
TRACE_EVENT_PHASE_COMPLETE, \
INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
- v8::internal::tracing::kNoId, trace_event_bind_id.data(), \
- trace_event_flags, ##__VA_ARGS__); \
+ v8::internal::tracing::kGlobalScope, v8::internal::tracing::kNoId, \
+ trace_event_bind_id.raw_id(), trace_event_flags, ##__VA_ARGS__); \
INTERNAL_TRACE_EVENT_UID(tracer) \
.Initialize(INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
h); \
@@ -233,8 +240,8 @@ extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3];
&trace_event_flags); \
v8::internal::tracing::AddTraceEvent( \
phase, INTERNAL_TRACE_EVENT_UID(category_group_enabled), name, \
- trace_event_trace_id.data(), v8::internal::tracing::kNoId, \
- trace_event_flags, ##__VA_ARGS__); \
+ trace_event_trace_id.scope(), trace_event_trace_id.raw_id(), \
+ v8::internal::tracing::kNoId, trace_event_flags, ##__VA_ARGS__); \
} \
} while (0)
@@ -254,6 +261,27 @@ extern TRACE_EVENT_API_ATOMIC_WORD g_trace_state[3];
phase, category_group, name, id, thread_id, timestamp, flags, ...) \
UNIMPLEMENTED()
+// Enter and leave a context based on the current scope.
+#define INTERNAL_TRACE_EVENT_SCOPED_CONTEXT(category_group, name, context) \
+ struct INTERNAL_TRACE_EVENT_UID(ScopedContext) { \
+ public: \
+ INTERNAL_TRACE_EVENT_UID(ScopedContext)(uint64_t cid) : cid_(cid) { \
+ TRACE_EVENT_ENTER_CONTEXT(category_group, name, cid_); \
+ } \
+ ~INTERNAL_TRACE_EVENT_UID(ScopedContext)() { \
+ TRACE_EVENT_LEAVE_CONTEXT(category_group, name, cid_); \
+ } \
+ \
+ private: \
+ /* Local class friendly DISALLOW_COPY_AND_ASSIGN */ \
+ INTERNAL_TRACE_EVENT_UID(ScopedContext) \
+ (const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {} \
+ void operator=(const INTERNAL_TRACE_EVENT_UID(ScopedContext)&) {} \
+ uint64_t cid_; \
+ }; \
+ INTERNAL_TRACE_EVENT_UID(ScopedContext) \
+ INTERNAL_TRACE_EVENT_UID(scoped_context)(context.raw_id());
+
namespace v8 {
namespace internal {
namespace tracing {
@@ -261,6 +289,7 @@ namespace tracing {
// Specify these values when the corresponding argument of AddTraceEvent is not
// used.
const int kZeroNumArgs = 0;
+const decltype(nullptr) kGlobalScope = nullptr;
const uint64_t kNoId = 0;
class TraceEventHelper {
@@ -273,70 +302,108 @@ class TraceEventHelper {
// collide when the same pointer is used on different processes.
class TraceID {
public:
+ class WithScope {
+ public:
+ WithScope(const char* scope, uint64_t raw_id)
+ : scope_(scope), raw_id_(raw_id) {}
+ uint64_t raw_id() const { return raw_id_; }
+ const char* scope() const { return scope_; }
+
+ private:
+ const char* scope_ = nullptr;
+ uint64_t raw_id_;
+ };
+
class DontMangle {
public:
- explicit DontMangle(const void* id)
- : data_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(id))) {}
- explicit DontMangle(uint64_t id) : data_(id) {}
- explicit DontMangle(unsigned int id) : data_(id) {}
- explicit DontMangle(uint16_t id) : data_(id) {}
- explicit DontMangle(unsigned char id) : data_(id) {}
- explicit DontMangle(int64_t id) : data_(static_cast<uint64_t>(id)) {}
- explicit DontMangle(int id) : data_(static_cast<uint64_t>(id)) {}
- explicit DontMangle(int16_t id) : data_(static_cast<uint64_t>(id)) {}
- explicit DontMangle(signed char id) : data_(static_cast<uint64_t>(id)) {}
- uint64_t data() const { return data_; }
+ explicit DontMangle(const void* raw_id)
+ : raw_id_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(raw_id))) {}
+ explicit DontMangle(uint64_t raw_id) : raw_id_(raw_id) {}
+ explicit DontMangle(unsigned int raw_id) : raw_id_(raw_id) {}
+ explicit DontMangle(uint16_t raw_id) : raw_id_(raw_id) {}
+ explicit DontMangle(unsigned char raw_id) : raw_id_(raw_id) {}
+ explicit DontMangle(int64_t raw_id)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {}
+ explicit DontMangle(int raw_id) : raw_id_(static_cast<uint64_t>(raw_id)) {}
+ explicit DontMangle(int16_t raw_id)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {}
+ explicit DontMangle(signed char raw_id)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {}
+ explicit DontMangle(WithScope scoped_id)
+ : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {}
+ const char* scope() const { return scope_; }
+ uint64_t raw_id() const { return raw_id_; }
private:
- uint64_t data_;
+ const char* scope_ = nullptr;
+ uint64_t raw_id_;
};
class ForceMangle {
public:
- explicit ForceMangle(uint64_t id) : data_(id) {}
- explicit ForceMangle(unsigned int id) : data_(id) {}
- explicit ForceMangle(uint16_t id) : data_(id) {}
- explicit ForceMangle(unsigned char id) : data_(id) {}
- explicit ForceMangle(int64_t id) : data_(static_cast<uint64_t>(id)) {}
- explicit ForceMangle(int id) : data_(static_cast<uint64_t>(id)) {}
- explicit ForceMangle(int16_t id) : data_(static_cast<uint64_t>(id)) {}
- explicit ForceMangle(signed char id) : data_(static_cast<uint64_t>(id)) {}
- uint64_t data() const { return data_; }
+ explicit ForceMangle(uint64_t raw_id) : raw_id_(raw_id) {}
+ explicit ForceMangle(unsigned int raw_id) : raw_id_(raw_id) {}
+ explicit ForceMangle(uint16_t raw_id) : raw_id_(raw_id) {}
+ explicit ForceMangle(unsigned char raw_id) : raw_id_(raw_id) {}
+ explicit ForceMangle(int64_t raw_id)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {}
+ explicit ForceMangle(int raw_id) : raw_id_(static_cast<uint64_t>(raw_id)) {}
+ explicit ForceMangle(int16_t raw_id)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {}
+ explicit ForceMangle(signed char raw_id)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {}
+ uint64_t raw_id() const { return raw_id_; }
private:
- uint64_t data_;
+ uint64_t raw_id_;
};
- TraceID(const void* id, unsigned int* flags)
- : data_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(id))) {
+ TraceID(const void* raw_id, unsigned int* flags)
+ : raw_id_(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(raw_id))) {
*flags |= TRACE_EVENT_FLAG_MANGLE_ID;
}
- TraceID(ForceMangle id, unsigned int* flags) : data_(id.data()) {
+ TraceID(ForceMangle raw_id, unsigned int* flags) : raw_id_(raw_id.raw_id()) {
*flags |= TRACE_EVENT_FLAG_MANGLE_ID;
}
- TraceID(DontMangle id, unsigned int* flags) : data_(id.data()) {}
- TraceID(uint64_t id, unsigned int* flags) : data_(id) { (void)flags; }
- TraceID(unsigned int id, unsigned int* flags) : data_(id) { (void)flags; }
- TraceID(uint16_t id, unsigned int* flags) : data_(id) { (void)flags; }
- TraceID(unsigned char id, unsigned int* flags) : data_(id) { (void)flags; }
- TraceID(int64_t id, unsigned int* flags) : data_(static_cast<uint64_t>(id)) {
+ TraceID(DontMangle maybe_scoped_id, unsigned int* flags)
+ : scope_(maybe_scoped_id.scope()), raw_id_(maybe_scoped_id.raw_id()) {}
+ TraceID(uint64_t raw_id, unsigned int* flags) : raw_id_(raw_id) {
+ (void)flags;
+ }
+ TraceID(unsigned int raw_id, unsigned int* flags) : raw_id_(raw_id) {
+ (void)flags;
+ }
+ TraceID(uint16_t raw_id, unsigned int* flags) : raw_id_(raw_id) {
+ (void)flags;
+ }
+ TraceID(unsigned char raw_id, unsigned int* flags) : raw_id_(raw_id) {
(void)flags;
}
- TraceID(int id, unsigned int* flags) : data_(static_cast<uint64_t>(id)) {
+ TraceID(int64_t raw_id, unsigned int* flags)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {
(void)flags;
}
- TraceID(int16_t id, unsigned int* flags) : data_(static_cast<uint64_t>(id)) {
+ TraceID(int raw_id, unsigned int* flags)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {
(void)flags;
}
- TraceID(signed char id, unsigned int* flags)
- : data_(static_cast<uint64_t>(id)) {
+ TraceID(int16_t raw_id, unsigned int* flags)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {
(void)flags;
}
+ TraceID(signed char raw_id, unsigned int* flags)
+ : raw_id_(static_cast<uint64_t>(raw_id)) {
+ (void)flags;
+ }
+ TraceID(WithScope scoped_id, unsigned int* flags)
+ : scope_(scoped_id.scope()), raw_id_(scoped_id.raw_id()) {}
- uint64_t data() const { return data_; }
+ uint64_t raw_id() const { return raw_id_; }
+ const char* scope() const { return scope_; }
private:
- uint64_t data_;
+ const char* scope_ = nullptr;
+ uint64_t raw_id_;
};
// Simple union to store various types as uint64_t.
@@ -407,34 +474,33 @@ INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&, as_string,
static V8_INLINE uint64_t AddTraceEvent(char phase,
const uint8_t* category_group_enabled,
- const char* name, uint64_t id,
- uint64_t bind_id, unsigned int flags) {
+ const char* name, const char* scope,
+ uint64_t id, uint64_t bind_id,
+ unsigned int flags) {
return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name,
- id, bind_id, kZeroNumArgs, NULL, NULL,
- NULL, flags);
+ scope, id, bind_id, kZeroNumArgs, NULL,
+ NULL, NULL, flags);
}
template <class ARG1_TYPE>
-static V8_INLINE uint64_t AddTraceEvent(char phase,
- const uint8_t* category_group_enabled,
- const char* name, uint64_t id,
- uint64_t bind_id, unsigned int flags,
- const char* arg1_name,
- const ARG1_TYPE& arg1_val) {
+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,
+ const char* arg1_name, const ARG1_TYPE& arg1_val) {
const int num_args = 1;
uint8_t arg_types[1];
uint64_t arg_values[1];
SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
- return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name,
- id, bind_id, num_args, &arg1_name,
- arg_types, arg_values, flags);
+ return TRACE_EVENT_API_ADD_TRACE_EVENT(
+ phase, category_group_enabled, name, scope, id, bind_id, num_args,
+ &arg1_name, arg_types, arg_values, flags);
}
template <class ARG1_TYPE, class ARG2_TYPE>
static V8_INLINE uint64_t AddTraceEvent(
char phase, const uint8_t* category_group_enabled, const char* name,
- uint64_t id, uint64_t bind_id, unsigned int flags, const char* arg1_name,
- const ARG1_TYPE& arg1_val, const char* arg2_name,
+ const char* scope, uint64_t id, uint64_t bind_id, unsigned int flags,
+ const char* arg1_name, const ARG1_TYPE& arg1_val, const char* arg2_name,
const ARG2_TYPE& arg2_val) {
const int num_args = 2;
const char* arg_names[2] = {arg1_name, arg2_name};
@@ -442,9 +508,9 @@ static V8_INLINE uint64_t AddTraceEvent(
uint64_t arg_values[2];
SetTraceValue(arg1_val, &arg_types[0], &arg_values[0]);
SetTraceValue(arg2_val, &arg_types[1], &arg_values[1]);
- return TRACE_EVENT_API_ADD_TRACE_EVENT(phase, category_group_enabled, name,
- id, bind_id, num_args, arg_names,
- arg_types, arg_values, flags);
+ 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);
}
// Used by TRACE_EVENTx macros. Do not use directly.
« no previous file with comments | « src/libplatform/default-platform.cc ('k') | test/cctest/heap/test-incremental-marking.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698