Reviewers: Yang,
Message:
To enhance the embedder profiling information, I have created a callback
that
reports most of what was reported by "--log-timer-events" except for the
External events.
PTAL.
Description:
Add support for allowing an embedder to get the V8 profile timer event logs.
BUG=
Please review this at https://codereview.chromium.org/186163002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+55, -3 lines):
M include/v8.h
src/api.cc
M src/counters.cc
M src/isolate.h
M src/log.h
M src/log.cc
M test/cctest/test-api.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
dd8f2685bc37115638f5332ddbefd42a79c16cea..e6e7ccfe06c9eb13280dd7d8d826cd44df2667d0
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -3805,6 +3805,9 @@ typedef void (*FatalErrorCallback)(const char*
location, const char* message);
typedef void (*MessageCallback)(Handle<Message> message, Handle<Value>
error);
+// --- Tracing ---
+
+typedef void (*LogEventCallback)(const char* name, int event);
/**
* Create new error objects by calling the corresponding error object
@@ -4395,6 +4398,9 @@ class V8_EXPORT V8 {
/** Set the callback to invoke in case of fatal errors. */
static void SetFatalErrorHandler(FatalErrorCallback that);
+ /** Set the callback to invoke in case of a timer tracing event. */
+ static void SetEventLogger(LogEventCallback that);
+
/**
* Set the callback to invoke to check if code generation from
* strings should be allowed.
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
2c7db3be1656f10d475dd8e1de71a89ed374cdd6..ebaac1e9942f0bc2ebbea53ce4428cba6fe20ee9
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -401,6 +401,12 @@ void V8::SetFatalErrorHandler(FatalErrorCallback that)
{
}
+void V8::SetEventLogger(LogEventCallback that) {
+ i::Isolate* isolate = EnterIsolateIfNeeded();
+ isolate->set_event_logger(that);
+}
+
+
void V8::SetAllowCodeGenerationFromStringsCallback(
AllowCodeGenerationFromStringsCallback callback) {
i::Isolate* isolate = EnterIsolateIfNeeded();
Index: src/counters.cc
diff --git a/src/counters.cc b/src/counters.cc
index
e0a6a60a0a4086eb9478afe491d42593026c2cc2..12811f6f361319b5803b90cabec85e27874706ff
100644
--- a/src/counters.cc
+++ b/src/counters.cc
@@ -62,6 +62,7 @@ void HistogramTimer::Start() {
if (Enabled()) {
timer_.Start();
}
+ LOG_EVENT_BEGIN(isolate(), name());
if (FLAG_log_internal_timer_events) {
LOG(isolate(), TimerEvent(Logger::START, name()));
}
@@ -75,6 +76,7 @@ void HistogramTimer::Stop() {
AddSample(static_cast<int>(timer_.Elapsed().InMilliseconds()));
timer_.Stop();
}
+ LOG_EVENT_END(isolate(), name());
if (FLAG_log_internal_timer_events) {
LOG(isolate(), TimerEvent(Logger::END, name()));
}
Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index
897197bc75eb240474bbb6c110bb625245fda0be..b35ca716991c7c8de53dee9eb0a66735d0f2e3fb
100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -340,6 +340,7 @@ typedef List<HeapObject*> DebugObjectCache;
/* A previously allocated buffer of kMinimalBufferSize bytes, or NULL.
*/ \
V(byte*, assembler_spare_buffer,
NULL) \
V(FatalErrorCallback, exception_behavior,
NULL) \
+ V(LogEventCallback, event_logger,
NULL) \
V(AllowCodeGenerationFromStringsCallback, allow_code_gen_callback,
NULL) \
/* To distinguish the function templates, so that we can find them in
the */ \
/* function cache of the native context.
*/ \
Index: src/log.cc
diff --git a/src/log.cc b/src/log.cc
index
1c332d1736318fdccd8f8a313545019df7e6469a..d4431dcd233944a848a15ad70d0f861cd17699df
100644
--- a/src/log.cc
+++ b/src/log.cc
@@ -1125,7 +1125,13 @@ void Logger::LeaveExternal(Isolate* isolate) {
void Logger::TimerEventScope::LogTimerEvent(StartEnd se) {
- LOG(isolate_, TimerEvent(se, name_));
+ if (FLAG_log_internal_timer_events)
+ LOG(isolate_, TimerEvent(se, name_));
+ if (se == START) {
+ LOG_EVENT_BEGIN(isolate_, name_);
+ } else {
+ LOG_EVENT_END(isolate_, name_);
+ }
}
Index: src/log.h
diff --git a/src/log.h b/src/log.h
index
d4dc76a21cc5222139e209646505caf90534d16a..e5ba111de64bca624eafd9a348120b48532ee7b4
100644
--- a/src/log.h
+++ b/src/log.h
@@ -99,6 +99,13 @@ struct TickSample;
logger->Call; \
} while (false)
+#define LOG_EVENT_BEGIN(isolate, name) \
+ if ((isolate)->event_logger()) \
+ (isolate)->event_logger()(name, 0)
+
+#define LOG_EVENT_END(isolate, name) \
+ if ((isolate)->event_logger()) \
+ (isolate)->event_logger()(name, 1)
#define LOG_EVENTS_AND_TAGS_LIST(V) \
V(CODE_CREATION_EVENT, "code-creation") \
@@ -320,11 +327,11 @@ class Logger {
public:
TimerEventScope(Isolate* isolate, const char* name)
: isolate_(isolate), name_(name) {
- if (FLAG_log_internal_timer_events) LogTimerEvent(START);
+ LogTimerEvent(START);
}
~TimerEventScope() {
- if (FLAG_log_internal_timer_events) LogTimerEvent(END);
+ LogTimerEvent(END);
}
void LogTimerEvent(StartEnd se);
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
c5c932b7516cc70738ad918a9311dabe1e985427..9942838eb7f7b37ef6056e21c3b99edae1ad9733
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -22116,3 +22116,27 @@ TEST(TestFunctionCallOptimization) {
ApiCallOptimizationChecker checker;
checker.RunAll();
}
+
+
+static const char* last_event_message;
+static int last_event_status;
+void StoringEventLoggerCallback(const char* message, int status) {
+ last_event_message = message;
+ last_event_status = status;
+}
+
+
+TEST(EventLogging) {
+ LocalContext env;
+ v8::V8::SetEventLogger(StoringEventLoggerCallback);
+ v8::internal::HistogramTimer* histogramTimer =
+ new v8::internal::HistogramTimer(
+ "V8.Test", 0, 10000, 50,
+ reinterpret_cast<v8::internal::Isolate*>(env->GetIsolate()));
+ histogramTimer->Start();
+ CHECK_EQ("V8.Test", last_event_message);
+ CHECK_EQ(0, last_event_status);
+ histogramTimer->Stop();
+ CHECK_EQ("V8.Test", last_event_message);
+ CHECK_EQ(1, last_event_status);
+}
--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.