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

Unified Diff: include/v8.h

Issue 8055029: Add experimental support for tracing the state of the VM heap to a file Base URL: http://v8.googlecode.com/svn/branches/experimental/heap-visualization/
Patch Set: Created 9 years, 3 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') | src/spaces.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
===================================================================
--- include/v8.h (revision 9457)
+++ include/v8.h (working copy)
@@ -115,6 +115,7 @@
class Heap;
class HeapObject;
class Isolate;
+class HeapVisualizerImplementation;
}
@@ -682,6 +683,170 @@
/**
+ * A heap visualization listener.
+ */
+// The linter thinks V8EXPORT is the class name.
+class V8EXPORT HeapVisualizer { // NOLINT
+ public:
+ HeapVisualizer()
+ : next_(NULL),
+ pixel_size_log_2_(8),
+ buffer_fullness_(0),
+ secs_zero_(0) { }
+ virtual ~HeapVisualizer() { }
+ virtual void Write(const char* buf, int count) = 0;
+ virtual void Flush() {
+ Write(buffer_, buffer_fullness_);
+ buffer_fullness_ = 0;
+ }
+
+ static const int kHeapOverheadPseudoSpaceIdentity = 10;
+ static const int kSurvivingNewSpacePseudoSpaceIdentity = 11;
+
+ typedef enum {
+ kAllocated, // start_w len_w transparency-byte transparency-byte ...
+ kConstantAllocation, // start_w len_w transparency-byte
+ kChangeAllocation, // start_w, change-byte
+ kNameArea, // space-code-byte start_w len_w
+ kFreeArea, // start_w len_w
+ kWritten, // " "
+ kRead, // " "
+ kSwept, // " "
+ kMarked, // " "
+ kTimeStamp // s_w us_w
+ } MessageId;
+
+ typedef enum {
+ kRunning,
+ kCrankshafting,
+ kScavenging,
+ kMarking,
+ kCompacting,
+ kSweeping
+ } ProfileState;
+
+ intptr_t pixel_size_log_2() { return pixel_size_log_2_; }
+ virtual void set_pixel_size_log_2(uintptr_t pixel_size_log_2) {
+ pixel_size_log_2_ = pixel_size_log_2;
+ }
+
+ uint32_t secs_zero() { return secs_zero_; }
+ uint32_t usecs_zero() { return usecs_zero_; }
+ void set_time_zero(uint32_t secs, uint32_t usecs) {
+ secs_zero_ = secs;
+ usecs_zero_ = usecs;
+ }
+
+ // These methods don't necessarily have to be here, but they server
+ // as a sort of documentation of the protocol.
+
+ // The protocol describes the state of the heap at a (currently implicit)
+ // granularity of 'pixels'. A pixel is some power-of-2 number of bytes.
+
+ // A graymap that indicates how full a set of |size| consecutive pixels of
+ // memory are. 0 indicates that all bytes in a pixel are allocated. 255
+ // indicates that all bytes in a pixel are free.
+ void Allocate(uintptr_t address, uintptr_t size, unsigned char* freeness) {
+ Write8(kAllocated);
+ Write32(address >> pixel_size_log_2_);
+ Write32(size);
+ WriteX(freeness, size);
+ }
+
+ // A way to quickly set the allocatedness of a set of pixels to the same
+ // value. Normally the freeness will be 0 (all bytes allocated) or 255 (all
+ // bytes free).
+ void ConstantAllocation(
+ uintptr_t address, uintptr_t size, unsigned char freeness) {
+ Write8(kConstantAllocation);
+ Write32(address >> pixel_size_log_2_);
+ Write32(size >> pixel_size_log_2_);
+ Write8(freeness);
+ }
+
+ // A way to indicate that a number of bytes have been allocated within a
+ // pixel. The resolution is limited unless a pixel is smaller than 256
+ // bytes, since there are only 8 bits of precision in the final byte which
+ // indicates how many bytes have been allocated from 0 to 255 (representing
+ // all the bytes in the pixel).
+ void ChangeAllocation(uintptr_t address, uintptr_t change) {
+ Write8(kChangeAllocation);
+ Write32(address >> pixel_size_log_2_);
+ uintptr_t change_byte = change >> pixel_size_log_2_;
+ Write8(change_byte == 256 ? 255 : change_byte);
+ }
+
+ // Indicates for a range of memory that it has been allocated from the OS and
+ // dedicated to a particular use in the heap. The |space| argument is a
+ // space id from spaces.h or one of the pseudo-space-identities defined in
+ // this class.
+ void Name(int space, uintptr_t address, uintptr_t size) {
+ Write8(kNameArea);
+ Write8(space);
+ Write32(address >> pixel_size_log_2_);
+ Write32(size >> pixel_size_log_2_);
+ }
+
+ // Currently unused way of indicating that something has happened in a region
+ // of memory.
+ void Event(MessageId id, uintptr_t address, uintptr_t size) {
+ Write8(id);
+ Write32(address >> pixel_size_log_2_);
+ Write32(size >> pixel_size_log_2_);
+ }
+
+ // Transmit the time since the VM started in seconds and microseconds. Also
+ // transmits a VM state. The VM is assumed to transition into the given
+ // state at the time indicated, so the time up to the indicated time is
+ // assumed to have been spent in the previous state.
+ void TimeStamp(int state, uintptr_t s, uintptr_t us) {
+ Write8(kTimeStamp);
+ Write8(state);
+ Write32(s);
+ Write32(us);
+ }
+
+ HeapVisualizer* next() { return next_; }
+
+ private:
+ static const int kBufferSize = 4096;
+
+ HeapVisualizer* next_;
+ uintptr_t pixel_size_log_2_;
+ int buffer_fullness_;
+ uint32_t secs_zero_;
+ uint32_t usecs_zero_;
+ char buffer_[kBufferSize];
+
+ void set_next(HeapVisualizer* next) { next_ = next; }
+
+ // Little endian 32 bit value.
+ inline void Write32(intptr_t x) {
+ if (kBufferSize - buffer_fullness_ < 4) {
+ Flush();
+ }
+ buffer_[buffer_fullness_] = x >> 24;
+ buffer_[buffer_fullness_ + 1] = x >> 16;
+ buffer_[buffer_fullness_ + 2] = x >> 8;
+ buffer_[buffer_fullness_ + 3] = x;
+ buffer_fullness_ += 4;
+ }
+
+ inline void Write8(int x) {
+ if (kBufferSize == buffer_fullness_) Flush();
+ buffer_[buffer_fullness_++] = x;
+ }
+
+ void WriteX(unsigned char* bytes, int len);
+
+ friend class v8::internal::HeapVisualizerImplementation;
+};
+
+
+void V8EXPORT RegisterHeapVisualizer(HeapVisualizer* visualizer);
+
+
+/**
* An error message.
*/
class V8EXPORT Message {
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/spaces.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698