Home | History | Annotate | Download | only in profiler
      1 // Copyright 2013 the V8 project authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_INL_H_
      6 #define V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_INL_H_
      7 
      8 #include "src/profiler/heap-snapshot-generator.h"
      9 
     10 #include "src/profiler/heap-profiler.h"
     11 #include "src/string-hasher-inl.h"
     12 
     13 namespace v8 {
     14 namespace internal {
     15 
     16 
     17 HeapEntry* HeapGraphEdge::from() const {
     18   return &snapshot()->entries()[from_index()];
     19 }
     20 
     21 
     22 Isolate* HeapGraphEdge::isolate() const {
     23   return snapshot()->profiler()->isolate();
     24 }
     25 
     26 
     27 HeapSnapshot* HeapGraphEdge::snapshot() const {
     28   return to_entry_->snapshot();
     29 }
     30 
     31 
     32 int HeapEntry::index() const {
     33   return static_cast<int>(this - &snapshot_->entries().front());
     34 }
     35 
     36 
     37 int HeapEntry::set_children_index(int index) {
     38   children_index_ = index;
     39   int next_index = index + children_count_;
     40   children_count_ = 0;
     41   return next_index;
     42 }
     43 
     44 void HeapEntry::add_child(HeapGraphEdge* edge) {
     45   *(children_begin() + children_count_++) = edge;
     46 }
     47 
     48 HeapGraphEdge* HeapEntry::child(int i) { return *(children_begin() + i); }
     49 
     50 std::deque<HeapGraphEdge*>::iterator HeapEntry::children_begin() {
     51   DCHECK_GE(children_index_, 0);
     52   SLOW_DCHECK(
     53       children_index_ < static_cast<int>(snapshot_->children().size()) ||
     54       (children_index_ == static_cast<int>(snapshot_->children().size()) &&
     55        children_count_ == 0));
     56   return snapshot_->children().begin() + children_index_;
     57 }
     58 
     59 std::deque<HeapGraphEdge*>::iterator HeapEntry::children_end() {
     60   return children_begin() + children_count_;
     61 }
     62 
     63 Isolate* HeapEntry::isolate() const { return snapshot_->profiler()->isolate(); }
     64 
     65 uint32_t HeapSnapshotJSONSerializer::StringHash(const void* string) {
     66   const char* s = reinterpret_cast<const char*>(string);
     67   int len = static_cast<int>(strlen(s));
     68   return StringHasher::HashSequentialString(s, len,
     69                                             v8::internal::kZeroHashSeed);
     70 }
     71 
     72 int HeapSnapshotJSONSerializer::to_node_index(const HeapEntry* e) {
     73   return to_node_index(e->index());
     74 }
     75 
     76 int HeapSnapshotJSONSerializer::to_node_index(int entry_index) {
     77   return entry_index * kNodeFieldsCount;
     78 }
     79 
     80 }  // namespace internal
     81 }  // namespace v8
     82 
     83 #endif  // V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_INL_H_
     84