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

Unified Diff: src/isolate.cc

Issue 519543002: [WIP] Added CodeEventListener to the sampler API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CallbackEvent also logs as code-creation, added coverage for that. Created 6 years, 4 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/isolate.h ('k') | src/log.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index 8f2fa4aa098ff373b19e013d29c8c9147d98afb9..d09a7462dbd38030d7c551c4acb283ffbbd56c0d 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -4,6 +4,9 @@
#include <stdlib.h>
+#include <sstream>
+#include <string>
+
#include "src/v8.h"
#include "src/ast.h"
@@ -2346,6 +2349,127 @@ void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) {
}
+void Isolate::CodeCreateEvent(Code* code,
+ const char* comment) {
+ if (code_event_handler() == NULL) return;
+ code_event_handler()->Create(code->address(),
+ code->ExecutableSize(),
+ comment);
+}
+
+
+namespace {
+ void AppendVA(char* buf, int buf_size, const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ Vector<char> v(buf, buf_size);
+ v8::internal::VSNPrintF(v, format, args);
+ }
+
+ void AppendStringToStdString(String* str, std::string* std_str) {
+ if (str == NULL) return;
+ DisallowHeapAllocation no_gc; // Ensure string stay valid.
+
+ int len = str->length();
+ if (len > 0x1000)
+ len = 0x1000;
+ for (int i = 0; i < len; i++) {
+ uc32 c = str->Get(i);
+ if (c > 0xff) {
+ char buf[8];
+ AppendVA(buf, 8, "\\u%04x", c);
+ std_str->append(buf);
+ } else if (c < 32 || c > 126) {
+ char buf[6];
+ snprintf(buf, sizeof(buf), "\\x%02x", c);
+ std_str->append(buf);
+ } else if (c == ',') {
+ std_str->append("\\,");
+ } else if (c == '\\') {
+ std_str->append("\\\\");
+ } else if (c == '\"') {
+ std_str->append("\"\"");
+ } else {
+ char buf[3];
+ AppendVA(buf, 3, "%lc", c);
+ std_str->append(buf);
+ }
+ }
+ }
+
+ void AppendNameToStdString(Name* name, std::string* str) {
+ if (name->IsString()) {
+ AppendStringToStdString(String::cast(name), str);
+ } else {
+ Symbol* symbol = Symbol::cast(name);
+ str->append("symbol(");
+ if (!symbol->name()->IsUndefined()) {
+ str->append("\"");
+ AppendStringToStdString(String::cast(symbol->name()), str);
+ str->append("\" ");
+ }
+ char buf[20];
+ AppendVA(buf, 20, "hash %x)", symbol->Hash());
+ str->append(buf);
+ }
+ }
+}
+
+
+void Isolate::CodeCreateEvent(Code* code,
+ Name* name) {
+ if (code_event_handler() == NULL) return;
+ std::string code_name;
+ AppendNameToStdString(name, &code_name);
+ code_event_handler()->Create(code->address(),
+ code->ExecutableSize(),
+ code_name);
+}
+
+
+void Isolate::CodeCreateEvent(Code* code,
+ String* regexp_source) {
+ if (code_event_handler() == NULL) return;
+ std::string code_name;
+ AppendStringToStdString(regexp_source, &code_name);
+ code_event_handler()->Create(code->address(),
+ code->ExecutableSize(),
+ code_name);
+}
+
+
+void Isolate::CodeCreateEvent(Code* code,
+ SharedFunctionInfo* shared,
+ Name* source, int line, int column) {
+ if (code_event_handler() == NULL) return;
+ std::string code_name;
+ SmartArrayPointer<char> name =
+ shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
+ code_name.append(name.get());
+ code_name.append(" ");
+ AppendNameToStdString(source, &code_name);
+ std::ostringstream os;
+ os << ":" << line << ":" << column;
+ code_name += os.str();
+ code_event_handler()->Create(code->address(),
+ code->ExecutableSize(),
+ code_name);
+}
+
+
+void Isolate::CodeCreateEvent(Address from,
+ const char* name_prefix,
+ Name* name) {
+ if (code_event_handler() == NULL) return;
+ std::string code_name;
+ code_name.append(name_prefix);
+ AppendNameToStdString(name, &code_name);
+ code_event_handler()->Create(from,
+ 1,
+ code_name);
+}
+
+
bool StackLimitCheck::JsHasOverflowed() const {
StackGuard* stack_guard = isolate_->stack_guard();
#ifdef USE_SIMULATOR
« no previous file with comments | « src/isolate.h ('k') | src/log.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698