Chromium Code Reviews

Unified Diff: src/api.cc

Issue 499483002: [WIP] A sampler thread in d8 for consuming the new API. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 7c484de53ee1e537a8abeefdce1e0cab69e4952e..bea1ab13ca886f38172203edb89ab02a1a3fb27d 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -11,6 +11,7 @@
#include <cmath> // For isnan.
#include "include/v8-debug.h"
#include "include/v8-profiler.h"
+#include "include/v8-sampler.h"
#include "include/v8-testing.h"
#include "src/assert-scope.h"
#include "src/base/platform/platform.h"
@@ -30,6 +31,7 @@
#include "src/heap-snapshot-generator-inl.h"
#include "src/icu_util.h"
#include "src/json-parser.h"
+#include "src/log.h"
#include "src/messages.h"
#include "src/natives.h"
#include "src/parser.h"
@@ -7425,6 +7427,33 @@ void HeapProfiler::SetRetainedObjectInfo(UniqueId id,
reinterpret_cast<i::HeapProfiler*>(this)->SetRetainedObjectInfo(id, info);
}
+void Sampler::Install(Isolate* isolate,
+ CodeEventHandler* codeEventHandler) {
+ i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
+
+ i::Logger* logger = internal_isolate->logger();
+ if (logger == NULL) return;
+
+ logger->SetCodeEventHandler(codeEventHandler);
+}
+
+Sample* Sampler::GetSample(Isolate* isolate,
+ Sample* sample) {
+ i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
+
+ i::Logger* logger = internal_isolate->logger();
+ if (logger == NULL) return NULL;
+
+ i::Sampler* sampler = logger->sampler();
+ if (sampler == NULL) return NULL;
+
+ // TODO(gohlap): These checks and getters above are just transitory.
+ // Get rid of those as we make the API mature.
+ // We have these right now because we want the new API
+ // to play well with the current cpu-profiler thread inside v8.
+
+ return sampler->GetSample(sample);
+}
v8::Testing::StressType internal::Testing::stress_type_ =
v8::Testing::kStressTypeOpt;

Powered by Google App Engine