Revision: 19745
Author: [email protected]
Date: Mon Mar 10 08:56:48 2014 UTC
Log: Add support for allowing an embedder to get the V8 profile timer
event logs.
Contributed by [email protected]
[email protected]
Review URL: https://codereview.chromium.org/186163002
http://code.google.com/p/v8/source/detail?r=19745
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/counters.cc
/branches/bleeding_edge/src/isolate.cc
/branches/bleeding_edge/src/isolate.h
/branches/bleeding_edge/src/log.cc
/branches/bleeding_edge/src/log.h
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Mon Mar 10 08:20:56 2014 UTC
+++ /branches/bleeding_edge/include/v8.h Mon Mar 10 08:56:48 2014 UTC
@@ -3799,6 +3799,9 @@
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
@@ -4185,6 +4188,11 @@
*/
void RequestGarbageCollectionForTesting(GarbageCollectionType type);
+ /**
+ * Set the callback to invoke for logging event.
+ */
+ void SetEventLogger(LogEventCallback that);
+
private:
Isolate();
Isolate(const Isolate&);
=======================================
--- /branches/bleeding_edge/src/api.cc Mon Mar 10 08:20:56 2014 UTC
+++ /branches/bleeding_edge/src/api.cc Mon Mar 10 08:56:48 2014 UTC
@@ -6381,6 +6381,11 @@
}
+void Isolate::SetEventLogger(LogEventCallback that) {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+ isolate->set_event_logger(that);
+}
+
String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
: str_(NULL), length_(0) {
i::Isolate* isolate = i::Isolate::Current();
=======================================
--- /branches/bleeding_edge/src/counters.cc Tue Sep 3 06:57:16 2013 UTC
+++ /branches/bleeding_edge/src/counters.cc Mon Mar 10 08:56:48 2014 UTC
@@ -62,9 +62,7 @@
if (Enabled()) {
timer_.Start();
}
- if (FLAG_log_internal_timer_events) {
- LOG(isolate(), TimerEvent(Logger::START, name()));
- }
+ isolate()->event_logger()(name(), Logger::START);
}
@@ -75,9 +73,7 @@
AddSample(static_cast<int>(timer_.Elapsed().InMilliseconds()));
timer_.Stop();
}
- if (FLAG_log_internal_timer_events) {
- LOG(isolate(), TimerEvent(Logger::END, name()));
- }
+ isolate()->event_logger()(name(), Logger::END);
}
} } // namespace v8::internal
=======================================
--- /branches/bleeding_edge/src/isolate.cc Fri Feb 28 10:55:47 2014 UTC
+++ /branches/bleeding_edge/src/isolate.cc Mon Mar 10 08:56:48 2014 UTC
@@ -2016,6 +2016,12 @@
bootstrapper_->Initialize(create_heap_objects);
builtins_.SetUp(this, create_heap_objects);
+ if (FLAG_log_internal_timer_events) {
+ set_event_logger(Logger::LogInternalEvents);
+ } else {
+ set_event_logger(Logger::EmptyLogInternalEvents);
+ }
+
// Set default value if not yet set.
// TODO(yangguo): move this to ResourceConstraints::ConfigureDefaults
// once ResourceConstraints becomes an argument to the Isolate
constructor.
=======================================
--- /branches/bleeding_edge/src/isolate.h Mon Mar 10 08:28:59 2014 UTC
+++ /branches/bleeding_edge/src/isolate.h Mon Mar 10 08:56:48 2014 UTC
@@ -340,6 +340,7 @@
/* 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.
*/ \
=======================================
--- /branches/bleeding_edge/src/log.cc Fri Jan 31 16:52:17 2014 UTC
+++ /branches/bleeding_edge/src/log.cc Mon Mar 10 08:56:48 2014 UTC
@@ -1122,10 +1122,16 @@
ASSERT(isolate->current_vm_state() == EXTERNAL);
isolate->set_current_vm_state(JS);
}
+
+
+void Logger::LogInternalEvents(const char* name, int se) {
+ Isolate* isolate = Isolate::Current();
+ LOG(isolate, TimerEvent(static_cast<StartEnd>(se), name));
+}
void Logger::TimerEventScope::LogTimerEvent(StartEnd se) {
- LOG(isolate_, TimerEvent(se, name_));
+ isolate_->event_logger()(name_, se);
}
=======================================
--- /branches/bleeding_edge/src/log.h Fri Jan 31 16:52:17 2014 UTC
+++ /branches/bleeding_edge/src/log.h Mon Mar 10 08:56:48 2014 UTC
@@ -316,15 +316,18 @@
static void EnterExternal(Isolate* isolate);
static void LeaveExternal(Isolate* isolate);
+ static void EmptyLogInternalEvents(const char* name, int se) { }
+ static void LogInternalEvents(const char* name, int se);
+
class TimerEventScope {
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);
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Mon Mar 10 08:20:56
2014 UTC
+++ /branches/bleeding_edge/test/cctest/test-api.cc Mon Mar 10 08:56:48
2014 UTC
@@ -22116,3 +22116,27 @@
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) {
+ v8::Isolate* isolate = CcTest::isolate();
+ isolate->SetEventLogger(StoringEventLoggerCallback);
+ v8::internal::HistogramTimer* histogramTimer =
+ new v8::internal::HistogramTimer(
+ "V8.Test", 0, 10000, 50,
+ reinterpret_cast<v8::internal::Isolate*>(isolate));
+ 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
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.