V8 Project
statistics-extension.cc
Go to the documentation of this file.
1 // Copyright 2012 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 
6 
7 namespace v8 {
8 namespace internal {
9 
10 const char* const StatisticsExtension::kSource =
11  "native function getV8Statistics();";
12 
13 
15  v8::Isolate* isolate,
17  DCHECK(strcmp(*v8::String::Utf8Value(str), "getV8Statistics") == 0);
19 }
20 
21 
22 static void AddCounter(v8::Isolate* isolate,
23  v8::Local<v8::Object> object,
24  StatsCounter* counter,
25  const char* name) {
26  if (counter->Enabled()) {
27  object->Set(v8::String::NewFromUtf8(isolate, name),
28  v8::Number::New(isolate, *counter->GetInternalPointer()));
29  }
30 }
31 
32 static void AddNumber(v8::Isolate* isolate,
33  v8::Local<v8::Object> object,
34  intptr_t value,
35  const char* name) {
36  object->Set(v8::String::NewFromUtf8(isolate, name),
37  v8::Number::New(isolate, static_cast<double>(value)));
38 }
39 
40 
41 static void AddNumber64(v8::Isolate* isolate,
42  v8::Local<v8::Object> object,
43  int64_t value,
44  const char* name) {
45  object->Set(v8::String::NewFromUtf8(isolate, name),
46  v8::Number::New(isolate, static_cast<double>(value)));
47 }
48 
49 
52  Isolate* isolate = reinterpret_cast<Isolate*>(args.GetIsolate());
53  Heap* heap = isolate->heap();
54 
55  if (args.Length() > 0) { // GC if first argument evaluates to true.
56  if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) {
57  heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension");
58  }
59  }
60 
61  Counters* counters = isolate->counters();
63 
64 #define ADD_COUNTER(name, caption) \
65  AddCounter(args.GetIsolate(), result, counters->name(), #name);
66 
69 #undef ADD_COUNTER
70 #define ADD_COUNTER(name) \
71  AddCounter(args.GetIsolate(), result, counters->count_of_##name(), \
72  "count_of_" #name); \
73  AddCounter(args.GetIsolate(), result, counters->size_of_##name(), \
74  "size_of_" #name);
75 
77 #undef ADD_COUNTER
78 #define ADD_COUNTER(name) \
79  AddCounter(args.GetIsolate(), result, counters->count_of_CODE_TYPE_##name(), \
80  "count_of_CODE_TYPE_" #name); \
81  AddCounter(args.GetIsolate(), result, counters->size_of_CODE_TYPE_##name(), \
82  "size_of_CODE_TYPE_" #name);
83 
85 #undef ADD_COUNTER
86 #define ADD_COUNTER(name) \
87  AddCounter(args.GetIsolate(), result, \
88  counters->count_of_FIXED_ARRAY_##name(), \
89  "count_of_FIXED_ARRAY_" #name); \
90  AddCounter(args.GetIsolate(), result, \
91  counters->size_of_FIXED_ARRAY_##name(), \
92  "size_of_FIXED_ARRAY_" #name);
93 
95 #undef ADD_COUNTER
96 
97  AddNumber(args.GetIsolate(), result, isolate->memory_allocator()->Size(),
98  "total_committed_bytes");
99  AddNumber(args.GetIsolate(), result, heap->new_space()->Size(),
100  "new_space_live_bytes");
101  AddNumber(args.GetIsolate(), result, heap->new_space()->Available(),
102  "new_space_available_bytes");
103  AddNumber(args.GetIsolate(), result, heap->new_space()->CommittedMemory(),
104  "new_space_commited_bytes");
105  AddNumber(args.GetIsolate(), result, heap->old_pointer_space()->Size(),
106  "old_pointer_space_live_bytes");
107  AddNumber(args.GetIsolate(), result, heap->old_pointer_space()->Available(),
108  "old_pointer_space_available_bytes");
109  AddNumber(args.GetIsolate(), result,
111  "old_pointer_space_commited_bytes");
112  AddNumber(args.GetIsolate(), result, heap->old_data_space()->Size(),
113  "old_data_space_live_bytes");
114  AddNumber(args.GetIsolate(), result, heap->old_data_space()->Available(),
115  "old_data_space_available_bytes");
116  AddNumber(args.GetIsolate(), result,
117  heap->old_data_space()->CommittedMemory(),
118  "old_data_space_commited_bytes");
119  AddNumber(args.GetIsolate(), result, heap->code_space()->Size(),
120  "code_space_live_bytes");
121  AddNumber(args.GetIsolate(), result, heap->code_space()->Available(),
122  "code_space_available_bytes");
123  AddNumber(args.GetIsolate(), result, heap->code_space()->CommittedMemory(),
124  "code_space_commited_bytes");
125  AddNumber(args.GetIsolate(), result, heap->cell_space()->Size(),
126  "cell_space_live_bytes");
127  AddNumber(args.GetIsolate(), result, heap->cell_space()->Available(),
128  "cell_space_available_bytes");
129  AddNumber(args.GetIsolate(), result, heap->cell_space()->CommittedMemory(),
130  "cell_space_commited_bytes");
131  AddNumber(args.GetIsolate(), result, heap->property_cell_space()->Size(),
132  "property_cell_space_live_bytes");
133  AddNumber(args.GetIsolate(), result, heap->property_cell_space()->Available(),
134  "property_cell_space_available_bytes");
135  AddNumber(args.GetIsolate(), result,
137  "property_cell_space_commited_bytes");
138  AddNumber(args.GetIsolate(), result, heap->lo_space()->Size(),
139  "lo_space_live_bytes");
140  AddNumber(args.GetIsolate(), result, heap->lo_space()->Available(),
141  "lo_space_available_bytes");
142  AddNumber(args.GetIsolate(), result, heap->lo_space()->CommittedMemory(),
143  "lo_space_commited_bytes");
144  AddNumber64(args.GetIsolate(), result,
146  "amount_of_external_allocated_memory");
147  args.GetReturnValue().Set(result);
148 }
149 
150 } } // namespace v8::internal
The argument information given to function call callbacks.
Definition: v8.h:2650
ReturnValue< T > GetReturnValue() const
Definition: v8.h:6348
Isolate * GetIsolate() const
Definition: v8.h:6342
int Length() const
Definition: v8.h:6360
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0)
Creates a function template.
Definition: api.cc:904
An object reference managed by the v8 garbage collector.
Definition: v8.h:198
Isolate represents an isolated instance of the V8 engine.
Definition: v8.h:4356
A light-weight stack-allocated object handle.
Definition: v8.h:334
static Local< Number > New(Isolate *isolate, double value)
Definition: api.cc:6268
static Local< Object > New(Isolate *isolate)
Definition: api.cc:5610
Converts an object to a UTF-8-encoded character array.
Definition: v8.h:2048
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)
Allocates a new string from UTF-8 data.
Definition: api.cc:5447
OldSpace * old_pointer_space()
Definition: heap.h:594
PropertyCellSpace * property_cell_space()
Definition: heap.h:599
int64_t amount_of_external_allocated_memory()
Definition: heap.h:1276
OldSpace * code_space()
Definition: heap.h:596
LargeObjectSpace * lo_space()
Definition: heap.h:600
CellSpace * cell_space()
Definition: heap.h:598
static const int kNoGCFlags
Definition: heap.h:716
OldSpace * old_data_space()
Definition: heap.h:595
NewSpace * new_space()
Definition: heap.h:593
void CollectAllGarbage(int flags, const char *gc_reason=NULL, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
Definition: heap.cc:724
MemoryAllocator * memory_allocator()
Definition: isolate.h:883
Counters * counters()
Definition: isolate.h:857
virtual intptr_t Size()
Definition: spaces.h:2740
intptr_t Available()
Definition: spaces.h:2400
intptr_t CommittedMemory()
Definition: spaces.h:2385
virtual intptr_t Size()
Definition: spaces.h:2360
intptr_t CommittedMemory()
Definition: spaces.h:1692
intptr_t Available()
Definition: spaces.h:1733
virtual intptr_t Size()
Definition: spaces.h:1739
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunctionTemplate(v8::Isolate *isolate, v8::Handle< v8::String > name)
static void GetCounters(const v8::FunctionCallbackInfo< v8::Value > &args)
#define STATS_COUNTER_LIST_1(SC)
Definition: counters.h:380
#define STATS_COUNTER_LIST_2(SC)
Definition: counters.h:433
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 name
#define DCHECK(condition)
Definition: logging.h:205
static void AddCounter(v8::Isolate *isolate, v8::Local< v8::Object > object, StatsCounter *counter, const char *name)
static void AddNumber64(v8::Isolate *isolate, v8::Local< v8::Object > object, int64_t value, const char *name)
static void AddNumber(v8::Isolate *isolate, v8::Local< v8::Object > object, intptr_t value, const char *name)
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
#define INSTANCE_TYPE_LIST(V)
Definition: objects.h:339
#define CODE_KIND_LIST(V)
Definition: objects.h:4950
#define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V)
Definition: objects.h:800
#define ADD_COUNTER(name, caption)