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

Unified Diff: include/v8.h

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 | « no previous file | src/api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index 73384946ba7d93594fd5c3d78753dfe01c2726f6..11994ee024105c568e6387b4f0f516ca1269b880 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -15,6 +15,8 @@
#ifndef V8_H_
#define V8_H_
+#include <string>
+
#include "v8stdint.h"
// We reserve the V8_* prefix for macros defined in V8 public API and
@@ -1297,6 +1299,85 @@ class V8_EXPORT StackFrame {
};
+// --- Sampler API ---
+
+
+/* TODO(gholap): This should go away and struct Sample should
+ just use const void* instead of Address.
+ Currently we need it because of implementation details. */
+typedef unsigned char* Address;
+
+
+/**
+ * Isolate::Getsample collects the current JS execution state as a sample.
+ * A collected sample contains,
+ * - stack : An array of addresses.
+ * One address per stack frame.
+ * The address is the instruction pointer,
+ * pointing to the instruction which led to the
+ * creation of the stack frame.
+ * (for example, a function call)
+ * - frames_count: Number of stack frames that were captured.
+ * That is, stack[frames_count+i] might contain meaningless
+ * addresses for any i >= 0.
+ */
+struct V8_EXPORT Sample {
+ Sample()
+ : frames_count(0) {}
+ static const unsigned kMaxFramesCount = 255;
+
+ Address stack[kMaxFramesCount]; // Call stack.
+ unsigned frames_count; // Number of captured frames.
+};
+
+
+/**
+ * To make sense of the PC values gotten from each sample,
+ * information like the location of compiled code for functions,
+ * whether the code ever moved from that address etc is required.
+ *
+ * Whenever v8 creates/moves/deletes code, or links a shared library,
+ * this handler will be called to notify of the code event.
+ */
+class V8_EXPORT CodeEventHandler {
+ public:
+ virtual ~CodeEventHandler() {}
+
+ /**
+ * Called when code is created.
+ * @from: The address where this newly created code begins.
+ * @size: Size of the code.
+ * @name: String representing the name of the code.
+ */
+ virtual void Create(const void* from,
+ const int size,
+ const std::string& name) = 0;
+
+ /**
+ * Called when code is deleted.
+ * @from: The address from where the code was deleted.
+ */
+ virtual void Delete(const void* from) = 0;
+
+ /**
+ * Called when code is moved.
+ * @from: The initial address where code was.
+ * @to: New address where the code currently resides.
+ */
+ virtual void Move(const void* from, const void* to) = 0;
+
+ /**
+ * Called when v8 loads a shared library.
+ * @library_path: Path to the shared library as a string.
+ * @start: The shared library is loaded into memory starting at this address.
+ * @end: Code beyond this address doesn't belong to the shared library.
+ */
+ virtual void SharedLibrary(const std::string& library_path,
+ const void* start,
+ const void* end) = 0;
+};
+
+
/**
* A JSON Parser.
*/
@@ -4217,6 +4298,17 @@ class V8_EXPORT Isolate {
void GetHeapStatistics(HeapStatistics* heap_statistics);
/**
+ * Get a sample from the isolate.
+ */
+ void GetSample(Sample* sample);
+
+ /**
+ * Install the handler which listens to code creation/move/delete events
+ * which are needed to eventually make sense of PC values inside a sample.
+ */
+ void InstallCodeEventHandler(CodeEventHandler* handler);
+
+ /**
* Adjusts the amount of registered external memory. Used to give V8 an
* indication of the amount of externally allocated memory that is kept alive
* by JavaScript objects. V8 uses this to decide when to perform global
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698