V8 Project
v8::internal::HeapSnapshotJSONSerializer Class Reference

#include <heap-snapshot-generator.h>

+ Collaboration diagram for v8::internal::HeapSnapshotJSONSerializer:

Public Member Functions

 HeapSnapshotJSONSerializer (HeapSnapshot *snapshot)
 
void Serialize (v8::OutputStream *stream)
 

Private Member Functions

 INLINE (static bool StringsMatch(void *key1, void *key2))
 
 INLINE (static uint32_t StringHash(const void *string))
 
int GetStringId (const char *s)
 
int entry_index (HeapEntry *e)
 
void SerializeEdge (HeapGraphEdge *edge, bool first_edge)
 
void SerializeEdges ()
 
void SerializeImpl ()
 
void SerializeNode (HeapEntry *entry)
 
void SerializeNodes ()
 
void SerializeSnapshot ()
 
void SerializeTraceTree ()
 
void SerializeTraceNode (AllocationTraceNode *node)
 
void SerializeTraceNodeInfos ()
 
void SerializeString (const unsigned char *s)
 
void SerializeStrings ()
 
 DISALLOW_COPY_AND_ASSIGN (HeapSnapshotJSONSerializer)
 

Private Attributes

HeapSnapshotsnapshot_
 
HashMap strings_
 
int next_node_id_
 
int next_string_id_
 
OutputStreamWriterwriter_
 

Static Private Attributes

static const int kEdgeFieldsCount = 3
 
static const int kNodeFieldsCount = 6
 

Friends

class HeapSnapshotJSONSerializerEnumerator
 
class HeapSnapshotJSONSerializerIterator
 

Detailed Description

Definition at line 558 of file heap-snapshot-generator.h.

Constructor & Destructor Documentation

◆ HeapSnapshotJSONSerializer()

v8::internal::HeapSnapshotJSONSerializer::HeapSnapshotJSONSerializer ( HeapSnapshot snapshot)
inlineexplicit

Definition at line 560 of file heap-snapshot-generator.h.

561  : snapshot_(snapshot),
562  strings_(StringsMatch),
563  next_node_id_(1),
564  next_string_id_(1),
565  writer_(NULL) {
566  }
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the snapshot(mksnapshot only)") DEFINE_STRING(raw_file
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL

Member Function Documentation

◆ DISALLOW_COPY_AND_ASSIGN()

v8::internal::HeapSnapshotJSONSerializer::DISALLOW_COPY_AND_ASSIGN ( HeapSnapshotJSONSerializer  )
private

◆ entry_index()

int v8::internal::HeapSnapshotJSONSerializer::entry_index ( HeapEntry *  e)
inlineprivate

Definition at line 583 of file heap-snapshot-generator.h.

583 { return e->index() * kNodeFieldsCount; }

References kNodeFieldsCount.

Referenced by SerializeEdge(), and SerializeNode().

+ Here is the caller graph for this function:

◆ GetStringId()

int v8::internal::HeapSnapshotJSONSerializer::GetStringId ( const char *  s)
private

Definition at line 2768 of file heap-snapshot-generator.cc.

2768  {
2769  HashMap::Entry* cache_entry = strings_.Lookup(
2770  const_cast<char*>(s), StringHash(s), true);
2771  if (cache_entry->value == NULL) {
2772  cache_entry->value = reinterpret_cast<void*>(next_string_id_++);
2773  }
2774  return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value));
2775 }
Entry * Lookup(void *key, uint32_t hash, bool insert, AllocationPolicy allocator=AllocationPolicy())
Definition: hashmap.h:114

References v8::internal::TemplateHashMapImpl< AllocationPolicy >::Lookup(), next_string_id_, NULL, and strings_.

Referenced by SerializeEdge(), SerializeNode(), and SerializeTraceNodeInfos().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ INLINE() [1/2]

v8::internal::HeapSnapshotJSONSerializer::INLINE ( static bool   StringsMatchvoid *key1, void *key2)
inlineprivate

Definition at line 570 of file heap-snapshot-generator.h.

570  {
571  return strcmp(reinterpret_cast<char*>(key1),
572  reinterpret_cast<char*>(key2)) == 0;
573  }

◆ INLINE() [2/2]

v8::internal::HeapSnapshotJSONSerializer::INLINE ( static uint32_t   StringHashconst void *string)
inlineprivate

Definition at line 575 of file heap-snapshot-generator.h.

575  {
576  const char* s = reinterpret_cast<const char*>(string);
577  int len = static_cast<int>(strlen(s));
580  }
static uint32_t HashSequentialString(const schar *chars, int length, uint32_t seed)
Definition: objects-inl.h:6563
static const uint32_t kZeroHashSeed
Definition: utils.h:245

References v8::internal::StringHasher::HashSequentialString(), and v8::internal::kZeroHashSeed.

+ Here is the call graph for this function:

◆ Serialize()

void v8::internal::HeapSnapshotJSONSerializer::Serialize ( v8::OutputStream stream)

Definition at line 2721 of file heap-snapshot-generator.cc.

2721  {
2722  if (AllocationTracker* allocation_tracker =
2724  allocation_tracker->PrepareForSerialization();
2725  }
2726  DCHECK(writer_ == NULL);
2727  writer_ = new OutputStreamWriter(stream);
2728  SerializeImpl();
2729  delete writer_;
2730  writer_ = NULL;
2731 }
AllocationTracker * allocation_tracker() const
Definition: heap-profiler.h:35
#define DCHECK(condition)
Definition: logging.h:205

References v8::internal::HeapProfiler::allocation_tracker(), DCHECK, NULL, v8::internal::HeapSnapshot::profiler(), SerializeImpl(), snapshot_, and writer_.

Referenced by v8::HeapSnapshot::Serialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeEdge()

void v8::internal::HeapSnapshotJSONSerializer::SerializeEdge ( HeapGraphEdge edge,
bool  first_edge 
)
private

Definition at line 2821 of file heap-snapshot-generator.cc.

2822  {
2823  // The buffer needs space for 3 unsigned ints, 3 commas, \n and \0
2824  static const int kBufferSize =
2825  MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned * 3 + 3 + 2; // NOLINT
2826  EmbeddedVector<char, kBufferSize> buffer;
2827  int edge_name_or_index = edge->type() == HeapGraphEdge::kElement
2828  || edge->type() == HeapGraphEdge::kHidden
2829  ? edge->index() : GetStringId(edge->name());
2830  int buffer_pos = 0;
2831  if (!first_edge) {
2832  buffer[buffer_pos++] = ',';
2833  }
2834  buffer_pos = utoa(edge->type(), buffer, buffer_pos);
2835  buffer[buffer_pos++] = ',';
2836  buffer_pos = utoa(edge_name_or_index, buffer, buffer_pos);
2837  buffer[buffer_pos++] = ',';
2838  buffer_pos = utoa(entry_index(edge->to()), buffer, buffer_pos);
2839  buffer[buffer_pos++] = '\n';
2840  buffer[buffer_pos++] = '\0';
2841  writer_->AddString(buffer.start());
2842 }
static int utoa(T value, const Vector< char > &buffer, int buffer_pos)

References v8::internal::OutputStreamWriter::AddString(), entry_index(), GetStringId(), v8::base::anonymous_namespace{semaphore-unittest.cc}::kBufferSize, v8::HeapGraphEdge::kElement, v8::HeapGraphEdge::kHidden, v8::internal::kUnsigned, v8::internal::utoa(), and writer_.

Referenced by SerializeEdges().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeEdges()

void v8::internal::HeapSnapshotJSONSerializer::SerializeEdges ( )
private

Definition at line 2845 of file heap-snapshot-generator.cc.

2845  {
2846  List<HeapGraphEdge*>& edges = snapshot_->children();
2847  for (int i = 0; i < edges.length(); ++i) {
2848  DCHECK(i == 0 ||
2849  edges[i - 1]->from()->index() <= edges[i]->from()->index());
2850  SerializeEdge(edges[i], i == 0);
2851  if (writer_->aborted()) return;
2852  }
2853 }
void SerializeEdge(HeapGraphEdge *edge, bool first_edge)
List< HeapGraphEdge * > & children()

References v8::internal::OutputStreamWriter::aborted(), v8::internal::HeapSnapshot::children(), DCHECK, SerializeEdge(), snapshot_, and writer_.

Referenced by SerializeImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeImpl()

void v8::internal::HeapSnapshotJSONSerializer::SerializeImpl ( )
private

Definition at line 2734 of file heap-snapshot-generator.cc.

2734  {
2735  DCHECK(0 == snapshot_->root()->index());
2736  writer_->AddCharacter('{');
2737  writer_->AddString("\"snapshot\":{");
2739  if (writer_->aborted()) return;
2740  writer_->AddString("},\n");
2741  writer_->AddString("\"nodes\":[");
2742  SerializeNodes();
2743  if (writer_->aborted()) return;
2744  writer_->AddString("],\n");
2745  writer_->AddString("\"edges\":[");
2746  SerializeEdges();
2747  if (writer_->aborted()) return;
2748  writer_->AddString("],\n");
2749 
2750  writer_->AddString("\"trace_function_infos\":[");
2752  if (writer_->aborted()) return;
2753  writer_->AddString("],\n");
2754  writer_->AddString("\"trace_tree\":[");
2756  if (writer_->aborted()) return;
2757  writer_->AddString("],\n");
2758 
2759  writer_->AddString("\"strings\":[");
2760  SerializeStrings();
2761  if (writer_->aborted()) return;
2762  writer_->AddCharacter(']');
2763  writer_->AddCharacter('}');
2764  writer_->Finalize();
2765 }

References v8::internal::OutputStreamWriter::aborted(), v8::internal::OutputStreamWriter::AddCharacter(), v8::internal::OutputStreamWriter::AddString(), DCHECK, v8::internal::OutputStreamWriter::Finalize(), v8::internal::HeapSnapshot::root(), SerializeEdges(), SerializeNodes(), SerializeSnapshot(), SerializeStrings(), SerializeTraceNodeInfos(), SerializeTraceTree(), snapshot_, and writer_.

Referenced by Serialize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeNode()

void v8::internal::HeapSnapshotJSONSerializer::SerializeNode ( HeapEntry *  entry)
private

Definition at line 2856 of file heap-snapshot-generator.cc.

2856  {
2857  // The buffer needs space for 4 unsigned ints, 1 size_t, 5 commas, \n and \0
2858  static const int kBufferSize =
2859  5 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT
2860  + MaxDecimalDigitsIn<sizeof(size_t)>::kUnsigned // NOLINT
2861  + 6 + 1 + 1;
2862  EmbeddedVector<char, kBufferSize> buffer;
2863  int buffer_pos = 0;
2864  if (entry_index(entry) != 0) {
2865  buffer[buffer_pos++] = ',';
2866  }
2867  buffer_pos = utoa(entry->type(), buffer, buffer_pos);
2868  buffer[buffer_pos++] = ',';
2869  buffer_pos = utoa(GetStringId(entry->name()), buffer, buffer_pos);
2870  buffer[buffer_pos++] = ',';
2871  buffer_pos = utoa(entry->id(), buffer, buffer_pos);
2872  buffer[buffer_pos++] = ',';
2873  buffer_pos = utoa(entry->self_size(), buffer, buffer_pos);
2874  buffer[buffer_pos++] = ',';
2875  buffer_pos = utoa(entry->children_count(), buffer, buffer_pos);
2876  buffer[buffer_pos++] = ',';
2877  buffer_pos = utoa(entry->trace_node_id(), buffer, buffer_pos);
2878  buffer[buffer_pos++] = '\n';
2879  buffer[buffer_pos++] = '\0';
2880  writer_->AddString(buffer.start());
2881 }

References v8::internal::OutputStreamWriter::AddString(), entry_index(), GetStringId(), v8::base::anonymous_namespace{semaphore-unittest.cc}::kBufferSize, v8::internal::kUnsigned, v8::internal::Vector< T >::start(), v8::internal::utoa(), and writer_.

Referenced by SerializeNodes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeNodes()

void v8::internal::HeapSnapshotJSONSerializer::SerializeNodes ( )
private

Definition at line 2884 of file heap-snapshot-generator.cc.

2884  {
2885  List<HeapEntry>& entries = snapshot_->entries();
2886  for (int i = 0; i < entries.length(); ++i) {
2887  SerializeNode(&entries[i]);
2888  if (writer_->aborted()) return;
2889  }
2890 }

References v8::internal::OutputStreamWriter::aborted(), v8::internal::HeapSnapshot::entries(), SerializeNode(), snapshot_, and writer_.

Referenced by SerializeImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeSnapshot()

void v8::internal::HeapSnapshotJSONSerializer::SerializeSnapshot ( )
private

Definition at line 2893 of file heap-snapshot-generator.cc.

2893  {
2894  writer_->AddString("\"title\":\"");
2896  writer_->AddString("\"");
2897  writer_->AddString(",\"uid\":");
2899  writer_->AddString(",\"meta\":");
2900  // The object describing node serialization layout.
2901  // We use a set of macros to improve readability.
2902 #define JSON_A(s) "[" s "]"
2903 #define JSON_O(s) "{" s "}"
2904 #define JSON_S(s) "\"" s "\""
2906  JSON_S("node_fields") ":" JSON_A(
2907  JSON_S("type") ","
2908  JSON_S("name") ","
2909  JSON_S("id") ","
2910  JSON_S("self_size") ","
2911  JSON_S("edge_count") ","
2912  JSON_S("trace_node_id")) ","
2913  JSON_S("node_types") ":" JSON_A(
2914  JSON_A(
2915  JSON_S("hidden") ","
2916  JSON_S("array") ","
2917  JSON_S("string") ","
2918  JSON_S("object") ","
2919  JSON_S("code") ","
2920  JSON_S("closure") ","
2921  JSON_S("regexp") ","
2922  JSON_S("number") ","
2923  JSON_S("native") ","
2924  JSON_S("synthetic") ","
2925  JSON_S("concatenated string") ","
2926  JSON_S("sliced string")) ","
2927  JSON_S("string") ","
2928  JSON_S("number") ","
2929  JSON_S("number") ","
2930  JSON_S("number") ","
2931  JSON_S("number") ","
2932  JSON_S("number")) ","
2933  JSON_S("edge_fields") ":" JSON_A(
2934  JSON_S("type") ","
2935  JSON_S("name_or_index") ","
2936  JSON_S("to_node")) ","
2937  JSON_S("edge_types") ":" JSON_A(
2938  JSON_A(
2939  JSON_S("context") ","
2940  JSON_S("element") ","
2941  JSON_S("property") ","
2942  JSON_S("internal") ","
2943  JSON_S("hidden") ","
2944  JSON_S("shortcut") ","
2945  JSON_S("weak")) ","
2946  JSON_S("string_or_number") ","
2947  JSON_S("node")) ","
2948  JSON_S("trace_function_info_fields") ":" JSON_A(
2949  JSON_S("function_id") ","
2950  JSON_S("name") ","
2951  JSON_S("script_name") ","
2952  JSON_S("script_id") ","
2953  JSON_S("line") ","
2954  JSON_S("column")) ","
2955  JSON_S("trace_node_fields") ":" JSON_A(
2956  JSON_S("id") ","
2957  JSON_S("function_info_index") ","
2958  JSON_S("count") ","
2959  JSON_S("size") ","
2960  JSON_S("children"))));
2961 #undef JSON_S
2962 #undef JSON_O
2963 #undef JSON_A
2964  writer_->AddString(",\"node_count\":");
2965  writer_->AddNumber(snapshot_->entries().length());
2966  writer_->AddString(",\"edge_count\":");
2967  writer_->AddNumber(snapshot_->edges().length());
2968  writer_->AddString(",\"trace_function_count\":");
2969  uint32_t count = 0;
2970  AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker();
2971  if (tracker) {
2972  count = tracker->function_info_list().length();
2973  }
2974  writer_->AddNumber(count);
2975 }
List< HeapGraphEdge > & edges()
#define JSON_S(s)
#define JSON_A(s)
#define JSON_O(s)

References v8::internal::OutputStreamWriter::AddNumber(), v8::internal::OutputStreamWriter::AddString(), v8::internal::HeapProfiler::allocation_tracker(), v8::internal::HeapSnapshot::edges(), v8::internal::HeapSnapshot::entries(), v8::internal::AllocationTracker::function_info_list(), JSON_A, JSON_O, JSON_S, v8::internal::HeapSnapshot::profiler(), snapshot_, v8::internal::HeapSnapshot::title(), v8::internal::HeapSnapshot::uid(), and writer_.

Referenced by SerializeImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeString()

void v8::internal::HeapSnapshotJSONSerializer::SerializeString ( const unsigned char *  s)
private

Definition at line 3078 of file heap-snapshot-generator.cc.

3078  {
3079  writer_->AddCharacter('\n');
3080  writer_->AddCharacter('\"');
3081  for ( ; *s != '\0'; ++s) {
3082  switch (*s) {
3083  case '\b':
3084  writer_->AddString("\\b");
3085  continue;
3086  case '\f':
3087  writer_->AddString("\\f");
3088  continue;
3089  case '\n':
3090  writer_->AddString("\\n");
3091  continue;
3092  case '\r':
3093  writer_->AddString("\\r");
3094  continue;
3095  case '\t':
3096  writer_->AddString("\\t");
3097  continue;
3098  case '\"':
3099  case '\\':
3100  writer_->AddCharacter('\\');
3101  writer_->AddCharacter(*s);
3102  continue;
3103  default:
3104  if (*s > 31 && *s < 128) {
3105  writer_->AddCharacter(*s);
3106  } else if (*s <= 31) {
3107  // Special character with no dedicated literal.
3108  WriteUChar(writer_, *s);
3109  } else {
3110  // Convert UTF-8 into \u UTF-16 literal.
3111  unsigned length = 1, cursor = 0;
3112  for ( ; length <= 4 && *(s + length) != '\0'; ++length) { }
3113  unibrow::uchar c = unibrow::Utf8::CalculateValue(s, length, &cursor);
3114  if (c != unibrow::Utf8::kBadChar) {
3115  WriteUChar(writer_, c);
3116  DCHECK(cursor != 0);
3117  s += cursor - 1;
3118  } else {
3119  writer_->AddCharacter('?');
3120  }
3121  }
3122  }
3123  }
3124  writer_->AddCharacter('\"');
3125 }
static const uchar kBadChar
Definition: unicode.h:139
static uchar CalculateValue(const byte *str, unsigned length, unsigned *cursor)
Definition: unicode.cc:191
unsigned int uchar
Definition: unicode.h:17
static void WriteUChar(OutputStreamWriter *w, unibrow::uchar u)

References v8::internal::OutputStreamWriter::AddCharacter(), v8::internal::OutputStreamWriter::AddString(), unibrow::Utf8::CalculateValue(), DCHECK, unibrow::Utf8::kBadChar, writer_, and v8::internal::WriteUChar().

Referenced by SerializeStrings().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeStrings()

void v8::internal::HeapSnapshotJSONSerializer::SerializeStrings ( )
private

Definition at line 3128 of file heap-snapshot-generator.cc.

3128  {
3129  ScopedVector<const unsigned char*> sorted_strings(
3130  strings_.occupancy() + 1);
3131  for (HashMap::Entry* entry = strings_.Start();
3132  entry != NULL;
3133  entry = strings_.Next(entry)) {
3134  int index = static_cast<int>(reinterpret_cast<uintptr_t>(entry->value));
3135  sorted_strings[index] = reinterpret_cast<const unsigned char*>(entry->key);
3136  }
3137  writer_->AddString("\"<dummy>\"");
3138  for (int i = 1; i < sorted_strings.length(); ++i) {
3139  writer_->AddCharacter(',');
3140  SerializeString(sorted_strings[i]);
3141  if (writer_->aborted()) return;
3142  }
3143 }
Entry * Next(Entry *p) const
Definition: hashmap.h:226
uint32_t occupancy() const
Definition: hashmap.h:61

References v8::internal::OutputStreamWriter::aborted(), v8::internal::OutputStreamWriter::AddCharacter(), v8::internal::OutputStreamWriter::AddString(), v8::internal::Vector< T >::length(), v8::internal::TemplateHashMapImpl< AllocationPolicy >::Next(), NULL, v8::internal::TemplateHashMapImpl< AllocationPolicy >::occupancy(), SerializeString(), v8::internal::TemplateHashMapImpl< AllocationPolicy >::Start(), strings_, and writer_.

Referenced by SerializeImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeTraceNode()

void v8::internal::HeapSnapshotJSONSerializer::SerializeTraceNode ( AllocationTraceNode node)
private

Definition at line 2996 of file heap-snapshot-generator.cc.

2996  {
2997  // The buffer needs space for 4 unsigned ints, 4 commas, [ and \0
2998  const int kBufferSize =
2999  4 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT
3000  + 4 + 1 + 1;
3001  EmbeddedVector<char, kBufferSize> buffer;
3002  int buffer_pos = 0;
3003  buffer_pos = utoa(node->id(), buffer, buffer_pos);
3004  buffer[buffer_pos++] = ',';
3005  buffer_pos = utoa(node->function_info_index(), buffer, buffer_pos);
3006  buffer[buffer_pos++] = ',';
3007  buffer_pos = utoa(node->allocation_count(), buffer, buffer_pos);
3008  buffer[buffer_pos++] = ',';
3009  buffer_pos = utoa(node->allocation_size(), buffer, buffer_pos);
3010  buffer[buffer_pos++] = ',';
3011  buffer[buffer_pos++] = '[';
3012  buffer[buffer_pos++] = '\0';
3013  writer_->AddString(buffer.start());
3014 
3015  Vector<AllocationTraceNode*> children = node->children();
3016  for (int i = 0; i < children.length(); i++) {
3017  if (i > 0) {
3018  writer_->AddCharacter(',');
3019  }
3020  SerializeTraceNode(children[i]);
3021  }
3022  writer_->AddCharacter(']');
3023 }
void SerializeTraceNode(AllocationTraceNode *node)

References v8::internal::OutputStreamWriter::AddCharacter(), v8::internal::OutputStreamWriter::AddString(), v8::internal::AllocationTraceNode::allocation_count(), v8::internal::AllocationTraceNode::allocation_size(), v8::internal::AllocationTraceNode::children(), v8::internal::AllocationTraceNode::function_info_index(), v8::internal::AllocationTraceNode::id(), v8::base::anonymous_namespace{semaphore-unittest.cc}::kBufferSize, v8::internal::kUnsigned, v8::internal::Vector< T >::length(), v8::internal::utoa(), and writer_.

Referenced by SerializeTraceTree().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeTraceNodeInfos()

void v8::internal::HeapSnapshotJSONSerializer::SerializeTraceNodeInfos ( )
private

Definition at line 3039 of file heap-snapshot-generator.cc.

3039  {
3040  AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker();
3041  if (!tracker) return;
3042  // The buffer needs space for 6 unsigned ints, 6 commas, \n and \0
3043  const int kBufferSize =
3044  6 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT
3045  + 6 + 1 + 1;
3046  EmbeddedVector<char, kBufferSize> buffer;
3047  const List<AllocationTracker::FunctionInfo*>& list =
3048  tracker->function_info_list();
3049  bool first_entry = true;
3050  for (int i = 0; i < list.length(); i++) {
3051  AllocationTracker::FunctionInfo* info = list[i];
3052  int buffer_pos = 0;
3053  if (first_entry) {
3054  first_entry = false;
3055  } else {
3056  buffer[buffer_pos++] = ',';
3057  }
3058  buffer_pos = utoa(info->function_id, buffer, buffer_pos);
3059  buffer[buffer_pos++] = ',';
3060  buffer_pos = utoa(GetStringId(info->name), buffer, buffer_pos);
3061  buffer[buffer_pos++] = ',';
3062  buffer_pos = utoa(GetStringId(info->script_name), buffer, buffer_pos);
3063  buffer[buffer_pos++] = ',';
3064  // The cast is safe because script id is a non-negative Smi.
3065  buffer_pos = utoa(static_cast<unsigned>(info->script_id), buffer,
3066  buffer_pos);
3067  buffer[buffer_pos++] = ',';
3068  buffer_pos = SerializePosition(info->line, buffer, buffer_pos);
3069  buffer[buffer_pos++] = ',';
3070  buffer_pos = SerializePosition(info->column, buffer, buffer_pos);
3071  buffer[buffer_pos++] = '\n';
3072  buffer[buffer_pos++] = '\0';
3073  writer_->AddString(buffer.start());
3074  }
3075 }
static int SerializePosition(int position, const Vector< char > &buffer, int buffer_pos)

References v8::internal::OutputStreamWriter::AddString(), v8::internal::HeapProfiler::allocation_tracker(), v8::internal::AllocationTracker::FunctionInfo::column, v8::internal::AllocationTracker::FunctionInfo::function_id, v8::internal::AllocationTracker::function_info_list(), GetStringId(), v8::base::anonymous_namespace{semaphore-unittest.cc}::kBufferSize, v8::internal::kUnsigned, v8::internal::AllocationTracker::FunctionInfo::line, v8::internal::AllocationTracker::FunctionInfo::name, v8::internal::HeapSnapshot::profiler(), v8::internal::AllocationTracker::FunctionInfo::script_id, v8::internal::AllocationTracker::FunctionInfo::script_name, v8::internal::SerializePosition(), snapshot_, v8::internal::utoa(), and writer_.

Referenced by SerializeImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SerializeTraceTree()

void v8::internal::HeapSnapshotJSONSerializer::SerializeTraceTree ( )
private

Definition at line 2988 of file heap-snapshot-generator.cc.

2988  {
2989  AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker();
2990  if (!tracker) return;
2991  AllocationTraceTree* traces = tracker->trace_tree();
2992  SerializeTraceNode(traces->root());
2993 }
AllocationTraceTree * trace_tree()

References v8::internal::HeapProfiler::allocation_tracker(), v8::internal::HeapSnapshot::profiler(), v8::internal::AllocationTraceTree::root(), SerializeTraceNode(), snapshot_, and v8::internal::AllocationTracker::trace_tree().

Referenced by SerializeImpl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ HeapSnapshotJSONSerializerEnumerator

friend class HeapSnapshotJSONSerializerEnumerator
friend

Definition at line 605 of file heap-snapshot-generator.h.

◆ HeapSnapshotJSONSerializerIterator

friend class HeapSnapshotJSONSerializerIterator
friend

Definition at line 606 of file heap-snapshot-generator.h.

Member Data Documentation

◆ kEdgeFieldsCount

const int v8::internal::HeapSnapshotJSONSerializer::kEdgeFieldsCount = 3
staticprivate

Definition at line 596 of file heap-snapshot-generator.h.

◆ kNodeFieldsCount

const int v8::internal::HeapSnapshotJSONSerializer::kNodeFieldsCount = 6
staticprivate

Definition at line 597 of file heap-snapshot-generator.h.

Referenced by entry_index().

◆ next_node_id_

int v8::internal::HeapSnapshotJSONSerializer::next_node_id_
private

Definition at line 601 of file heap-snapshot-generator.h.

◆ next_string_id_

int v8::internal::HeapSnapshotJSONSerializer::next_string_id_
private

Definition at line 602 of file heap-snapshot-generator.h.

Referenced by GetStringId().

◆ snapshot_

HeapSnapshot* v8::internal::HeapSnapshotJSONSerializer::snapshot_
private

◆ strings_

HashMap v8::internal::HeapSnapshotJSONSerializer::strings_
private

Definition at line 600 of file heap-snapshot-generator.h.

Referenced by GetStringId(), and SerializeStrings().

◆ writer_


The documentation for this class was generated from the following files: