Add a use counter API
authorjochen@chromium.org <jochen@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 23 Jun 2014 09:46:58 +0000 (09:46 +0000)
committerjochen@chromium.org <jochen@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 23 Jun 2014 09:46:58 +0000 (09:46 +0000)
This lets embedders track certain features of v8 and the number of times
they are used

BUG=none
R=svenpanne@chromium.org, marja@chromium.org
LOG=y

Review URL: https://codereview.chromium.org/346233002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21925 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

include/v8.h
src/api.cc
src/isolate.cc
src/isolate.h

index f6c6ac3..bc2ea0b 100644 (file)
@@ -4129,6 +4129,19 @@ class V8_EXPORT Isolate {
   };
 
   /**
+   * Features reported via the SetUseCounterCallback callback. Do not chang
+   * assigned numbers of existing items; add new features to the end of this
+   * list.
+   */
+  enum UseCounterFeature {
+    kUseAsm = 0
+  };
+
+  typedef void (*UseCounterCallback)(Isolate* isolate,
+                                     UseCounterFeature feature);
+
+
+  /**
    * Creates a new isolate.  Does not change the currently entered
    * isolate.
    *
@@ -4397,6 +4410,11 @@ class V8_EXPORT Isolate {
    */
   bool WillAutorunMicrotasks() const;
 
+  /**
+   * Sets a callback for counting the number of times a feature of V8 is used.
+   */
+  void SetUseCounterCallback(UseCounterCallback callback);
+
  private:
   template<class K, class V, class Traits> friend class PersistentValueMap;
 
index 9397c40..f076bdb 100644 (file)
@@ -6718,6 +6718,11 @@ bool Isolate::WillAutorunMicrotasks() const {
 }
 
 
+void Isolate::SetUseCounterCallback(UseCounterCallback callback) {
+  reinterpret_cast<i::Isolate*>(this)->SetUseCounterCallback(callback);
+}
+
+
 String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
     : str_(NULL), length_(0) {
   i::Isolate* isolate = i::Isolate::Current();
index a4b311f..d4368da 100644 (file)
@@ -2343,6 +2343,19 @@ void Isolate::RunMicrotasks() {
 }
 
 
+void Isolate::SetUseCounterCallback(v8::Isolate::UseCounterCallback callback) {
+  ASSERT(!use_counter_callback_);
+  use_counter_callback_ = callback;
+}
+
+
+void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) {
+  if (use_counter_callback_) {
+    use_counter_callback_(reinterpret_cast<v8::Isolate*>(this), feature);
+  }
+}
+
+
 bool StackLimitCheck::JsHasOverflowed() const {
   StackGuard* stack_guard = isolate_->stack_guard();
 #ifdef USE_SIMULATOR
index 3cabea9..2a11873 100644 (file)
@@ -1081,6 +1081,9 @@ class Isolate {
   void EnqueueMicrotask(Handle<Object> microtask);
   void RunMicrotasks();
 
+  void SetUseCounterCallback(v8::Isolate::UseCounterCallback callback);
+  void CountUsage(v8::Isolate::UseCounterFeature feature);
+
  private:
   Isolate();
 
@@ -1300,6 +1303,8 @@ class Isolate {
   // List of callbacks when a Call completes.
   List<CallCompletedCallback> call_completed_callbacks_;
 
+  v8::Isolate::UseCounterCallback use_counter_callback_;
+
   friend class ExecutionAccess;
   friend class HandleScopeImplementer;
   friend class IsolateInitializer;