heap-snapshot-generator-inl.h 2.2 KB
Newer Older
1
// Copyright 2013 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4

5 6
#ifndef V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_INL_H_
#define V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_INL_H_
7

8
#include "src/profiler/heap-snapshot-generator.h"
9

10 11 12
#include "src/profiler/heap-profiler.h"
#include "src/string-hasher-inl.h"

13 14 15 16
namespace v8 {
namespace internal {

HeapEntry* HeapGraphEdge::from() const {
17
  return &snapshot()->entries()[from_index()];
18 19
}

20
Isolate* HeapGraphEdge::isolate() const { return to_entry_->isolate(); }
21

22 23 24 25 26
HeapSnapshot* HeapGraphEdge::snapshot() const {
  return to_entry_->snapshot();
}

int HeapEntry::set_children_index(int index) {
27
  // Note: children_count_ and children_end_index_ are parts of a union.
28
  int next_index = index + children_count_;
29
  children_end_index_ = index;
30 31 32
  return next_index;
}

33
void HeapEntry::add_child(HeapGraphEdge* edge) {
34
  snapshot_->children()[children_end_index_++] = edge;
35 36
}

37 38 39 40 41 42
HeapGraphEdge* HeapEntry::child(int i) { return children_begin()[i]; }

std::vector<HeapGraphEdge*>::iterator HeapEntry::children_begin() const {
  return index_ == 0 ? snapshot_->children().begin()
                     : snapshot_->entries()[index_ - 1].children_end();
}
43

44 45 46
std::vector<HeapGraphEdge*>::iterator HeapEntry::children_end() const {
  DCHECK_GE(children_end_index_, 0);
  return snapshot_->children().begin() + children_end_index_;
47 48
}

49 50
int HeapEntry::children_count() const {
  return static_cast<int>(children_end() - children_begin());
51 52
}

53 54
Isolate* HeapEntry::isolate() const { return snapshot_->profiler()->isolate(); }

55 56 57 58 59 60 61
uint32_t HeapSnapshotJSONSerializer::StringHash(const void* string) {
  const char* s = reinterpret_cast<const char*>(string);
  int len = static_cast<int>(strlen(s));
  return StringHasher::HashSequentialString(s, len,
                                            v8::internal::kZeroHashSeed);
}

62 63 64 65 66 67
int HeapSnapshotJSONSerializer::to_node_index(const HeapEntry* e) {
  return to_node_index(e->index());
}

int HeapSnapshotJSONSerializer::to_node_index(int entry_index) {
  return entry_index * kNodeFieldsCount;
68 69
}

70 71
}  // namespace internal
}  // namespace v8
72

73
#endif  // V8_PROFILER_HEAP_SNAPSHOT_GENERATOR_INL_H_