Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #55 from elvin-nnov/master
Browse files Browse the repository at this point in the history
XDK heap profiler collector
  • Loading branch information
Raphael Kubo da Costa committed Oct 29, 2014
2 parents 390bd33 + 66b6f26 commit 03d8b6c
Show file tree
Hide file tree
Showing 13 changed files with 2,135 additions and 48 deletions.
34 changes: 34 additions & 0 deletions include/v8-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,19 @@ class V8_EXPORT CpuProfile {
};


/**
* HeapEventXDK contains the latest chunk of heap info
*/
class V8_EXPORT HeapEventXDK {
public:
const char* getSymbols();
const char* getFrames();
const char* getTypes();
const char* getChunks();
const char* getRetentions();
unsigned int getDuration();
};

/**
* Interface for controlling CPU profiling. Instance of the
* profiler can be retrieved using v8::Isolate::GetCpuProfiler.
Expand Down Expand Up @@ -314,6 +327,19 @@ class V8_EXPORT OutputStream { // NOLINT
virtual WriteResult WriteHeapStatsChunk(HeapStatsUpdate* data, int count) {
return kAbort;
}


/**
* Writes XDK object
*/
virtual WriteResult WriteHeapXDKChunk(const char* symbols, int symbolsSize,
const char* frames, int framesSize,
const char* types, int typesSize,
const char* chunks, int chunksSize,
const char* retentions,
int retentionSize) {
return kAbort;
}
};


Expand Down Expand Up @@ -530,6 +556,14 @@ class V8_EXPORT HeapProfiler {
*/
void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);

void StartTrackingHeapObjectsXDK(int stackDepth, bool retentions,
bool strict_collection = false);
/**
* @author amalyshe
*/
void GetHeapXDKStats(OutputStream* stream);
HeapEventXDK* StopTrackingHeapObjectsXDK();

private:
HeapProfiler();
~HeapProfiler();
Expand Down
61 changes: 60 additions & 1 deletion src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "src/v8threads.h"
#include "src/version.h"
#include "src/vm-state-inl.h"

#include "src/xdk-allocation.h"

#define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))

Expand Down Expand Up @@ -7316,6 +7316,47 @@ Handle<String> HeapSnapshot::GetTitle() const {
}


const char* HeapEventXDK::getSymbols() {
const i::HeapEventXDK* eventXDK =
reinterpret_cast<const i::HeapEventXDK*>(this);
return eventXDK->symbols();
}


const char* HeapEventXDK::getFrames() {
const i::HeapEventXDK* eventXDK =
reinterpret_cast<const i::HeapEventXDK*>(this);
return eventXDK->frames();
}


const char* HeapEventXDK::getTypes() {
const i::HeapEventXDK* eventXDK =
reinterpret_cast<const i::HeapEventXDK*>(this);
return eventXDK->types();
}


const char* HeapEventXDK::getChunks() {
const i::HeapEventXDK* eventXDK =
reinterpret_cast<const i::HeapEventXDK*>(this);
return eventXDK->chunks();
}


const char* HeapEventXDK::getRetentions() {
const i::HeapEventXDK* eventXDK =
reinterpret_cast<const i::HeapEventXDK*>(this);
return eventXDK->retentions();
}


unsigned int HeapEventXDK::getDuration() {
const i::HeapEventXDK* eventXDK =
reinterpret_cast<const i::HeapEventXDK*>(this);
return eventXDK->duration();
}

const HeapGraphNode* HeapSnapshot::GetRoot() const {
return reinterpret_cast<const HeapGraphNode*>(ToInternal(this)->root());
}
Expand Down Expand Up @@ -7412,6 +7453,24 @@ SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream) {
}


void HeapProfiler::GetHeapXDKStats(OutputStream* stream) {
reinterpret_cast<i::HeapProfiler*>(this)->PushHeapObjectsXDKStats(stream);
}


void HeapProfiler::StartTrackingHeapObjectsXDK(int stackDepth,
bool retentions, bool strict_collection) {
reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTrackingXDK(
stackDepth, retentions, strict_collection);
}


HeapEventXDK* HeapProfiler::StopTrackingHeapObjectsXDK() {
return reinterpret_cast<HeapEventXDK*>(
reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTrackingXDK());
}


void HeapProfiler::DeleteAllHeapSnapshots() {
reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots();
}
Expand Down
56 changes: 52 additions & 4 deletions src/heap-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "src/allocation-tracker.h"
#include "src/heap-snapshot-generator-inl.h"
#include "src/xdk-allocation.h"

namespace v8 {
namespace internal {
Expand Down Expand Up @@ -68,7 +69,7 @@ HeapSnapshot* HeapProfiler::TakeSnapshot(
v8::HeapProfiler::ObjectNameResolver* resolver) {
HeapSnapshot* result = new HeapSnapshot(this, name, next_snapshot_uid_++);
{
HeapSnapshotGenerator generator(result, control, resolver, heap());
HeapSnapshotGenerator generator(this, result, control, resolver, heap());
if (!generator.GenerateSnapshot()) {
delete result;
result = NULL;
Expand Down Expand Up @@ -115,6 +116,46 @@ void HeapProfiler::StopHeapObjectsTracking() {
}


void HeapProfiler::StartHeapObjectsTrackingXDK(int stackDepth,
bool retentions, bool strict_collection) {
ids_->UpdateHeapObjectsMap();
is_tracking_object_moves_ = true;
DCHECK(!is_tracking_allocations());
allocation_tracker_xdk_.Reset(new XDKAllocationTracker(this, ids_.get(),
names_.get(), stackDepth, retentions,
strict_collection));
heap()->DisableInlineAllocation();
// init pre collected objects
allocation_tracker_xdk_->CollectFreedObjects(false, true);
}


void HeapProfiler::PushHeapObjectsXDKStats(OutputStream* stream) {
// get the garbage here
if (!allocation_tracker_xdk_.is_empty()) {
allocation_tracker_xdk_->CollectFreedObjects();
OutputStream::WriteResult result =
allocation_tracker_xdk_->SendChunk(stream);
// TODO(amalyshe): it's interesting why CDT can return kAbort. Need to
// investigate if we need add better error generation in the
// allocation_tracker_xdk_->SendChunk
if (result == OutputStream::kAbort) return;
stream->EndOfStream();
}
}


v8::internal::HeapEventXDK* HeapProfiler::StopHeapObjectsTrackingXDK() {
HeapEventXDK* event = NULL;
if (!allocation_tracker_xdk_.is_empty()) {
event = allocation_tracker_xdk_->stopTracking();
allocation_tracker_xdk_.Reset(NULL);
heap()->EnableInlineAllocation();
}
return event;
}


size_t HeapProfiler::GetMemorySizeUsedByProfiler() {
size_t size = sizeof(*this);
size += names_->GetUsedMemorySize();
Expand Down Expand Up @@ -145,9 +186,13 @@ SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) {


void HeapProfiler::ObjectMoveEvent(Address from, Address to, int size) {
bool known_object = ids_->MoveObject(from, to, size);
if (!known_object && !allocation_tracker_.is_empty()) {
allocation_tracker_->address_to_trace()->MoveObject(from, to, size);
if (allocation_tracker_xdk_.is_empty()) {
bool known_object = ids_->MoveObject(from, to, size);
if (!known_object && !allocation_tracker_.is_empty()) {
allocation_tracker_->address_to_trace()->MoveObject(from, to, size);
}
} else {
allocation_tracker_xdk_->OnMove(from, to, size);
}
}

Expand All @@ -157,6 +202,9 @@ void HeapProfiler::AllocationEvent(Address addr, int size) {
if (!allocation_tracker_.is_empty()) {
allocation_tracker_->AllocationEvent(addr, size);
}
if (!allocation_tracker_xdk_.is_empty()) {
allocation_tracker_xdk_->OnAlloc(addr, size);
}
}


Expand Down
10 changes: 9 additions & 1 deletion src/heap-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace v8 {
namespace internal {

class HeapSnapshot;
class HeapEventXDK;

class HeapProfiler {
public:
Expand All @@ -39,6 +40,11 @@ class HeapProfiler {
StringsStorage* names() const { return names_.get(); }

SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
void PushHeapObjectsXDKStats(OutputStream* stream);
void StartHeapObjectsTrackingXDK(int stackDepth, bool retentions,
bool strict_collection = false);
v8::internal::HeapEventXDK* StopHeapObjectsTrackingXDK();

int GetSnapshotsCount();
HeapSnapshot* GetSnapshot(int index);
SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
Expand All @@ -60,7 +66,8 @@ class HeapProfiler {

bool is_tracking_object_moves() const { return is_tracking_object_moves_; }
bool is_tracking_allocations() const {
return !allocation_tracker_.is_empty();
return (!allocation_tracker_.is_empty() ||
!allocation_tracker_xdk_.is_empty());
}

Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id);
Expand All @@ -76,6 +83,7 @@ class HeapProfiler {
unsigned next_snapshot_uid_;
List<v8::HeapProfiler::WrapperInfoCallback> wrapper_callbacks_;
SmartPointer<AllocationTracker> allocation_tracker_;
SmartPointer<XDKAllocationTracker> allocation_tracker_xdk_;
bool is_tracking_object_moves_;
};

Expand Down
2 changes: 1 addition & 1 deletion src/heap-snapshot-generator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ HeapSnapshot* HeapGraphEdge::snapshot() const {


int HeapEntry::index() const {
return static_cast<int>(this - &snapshot_->entries().first());
return static_cast<int>(this - &entries_->first());
}


Expand Down
Loading

0 comments on commit 03d8b6c

Please sign in to comment.