v8  3.25.30(node0.11.13)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
statistics-extension.cc
Go to the documentation of this file.
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #include "statistics-extension.h"
29 
30 namespace v8 {
31 namespace internal {
32 
33 const char* const StatisticsExtension::kSource =
34  "native function getV8Statistics();";
35 
36 
38  v8::Isolate* isolate,
40  ASSERT(strcmp(*v8::String::Utf8Value(str), "getV8Statistics") == 0);
42 }
43 
44 
45 static void AddCounter(v8::Isolate* isolate,
46  v8::Local<v8::Object> object,
47  StatsCounter* counter,
48  const char* name) {
49  if (counter->Enabled()) {
50  object->Set(v8::String::NewFromUtf8(isolate, name),
51  v8::Number::New(isolate, *counter->GetInternalPointer()));
52  }
53 }
54 
55 static void AddNumber(v8::Isolate* isolate,
56  v8::Local<v8::Object> object,
57  intptr_t value,
58  const char* name) {
59  object->Set(v8::String::NewFromUtf8(isolate, name),
60  v8::Number::New(isolate, static_cast<double>(value)));
61 }
62 
63 
64 static void AddNumber64(v8::Isolate* isolate,
65  v8::Local<v8::Object> object,
66  int64_t value,
67  const char* name) {
68  object->Set(v8::String::NewFromUtf8(isolate, name),
69  v8::Number::New(isolate, static_cast<double>(value)));
70 }
71 
72 
75  Isolate* isolate = reinterpret_cast<Isolate*>(args.GetIsolate());
76  Heap* heap = isolate->heap();
77 
78  if (args.Length() > 0) { // GC if first argument evaluates to true.
79  if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) {
80  heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension");
81  }
82  }
83 
84  Counters* counters = isolate->counters();
86 
87 #define ADD_COUNTER(name, caption) \
88  AddCounter(args.GetIsolate(), result, counters->name(), #name);
89 
92 #undef ADD_COUNTER
93 #define ADD_COUNTER(name) \
94  AddCounter(args.GetIsolate(), result, counters->count_of_##name(), \
95  "count_of_" #name); \
96  AddCounter(args.GetIsolate(), result, counters->size_of_##name(), \
97  "size_of_" #name);
98 
100 #undef ADD_COUNTER
101 #define ADD_COUNTER(name) \
102  AddCounter(args.GetIsolate(), result, counters->count_of_CODE_TYPE_##name(), \
103  "count_of_CODE_TYPE_" #name); \
104  AddCounter(args.GetIsolate(), result, counters->size_of_CODE_TYPE_##name(), \
105  "size_of_CODE_TYPE_" #name);
106 
108 #undef ADD_COUNTER
109 #define ADD_COUNTER(name) \
110  AddCounter(args.GetIsolate(), result, \
111  counters->count_of_FIXED_ARRAY_##name(), \
112  "count_of_FIXED_ARRAY_" #name); \
113  AddCounter(args.GetIsolate(), result, \
114  counters->size_of_FIXED_ARRAY_##name(), \
115  "size_of_FIXED_ARRAY_" #name);
116 
118 #undef ADD_COUNTER
119 
120  AddNumber(args.GetIsolate(), result, isolate->memory_allocator()->Size(),
121  "total_committed_bytes");
122  AddNumber(args.GetIsolate(), result, heap->new_space()->Size(),
123  "new_space_live_bytes");
124  AddNumber(args.GetIsolate(), result, heap->new_space()->Available(),
125  "new_space_available_bytes");
126  AddNumber(args.GetIsolate(), result, heap->new_space()->CommittedMemory(),
127  "new_space_commited_bytes");
128  AddNumber(args.GetIsolate(), result, heap->old_pointer_space()->Size(),
129  "old_pointer_space_live_bytes");
130  AddNumber(args.GetIsolate(), result, heap->old_pointer_space()->Available(),
131  "old_pointer_space_available_bytes");
132  AddNumber(args.GetIsolate(), result,
134  "old_pointer_space_commited_bytes");
135  AddNumber(args.GetIsolate(), result, heap->old_data_space()->Size(),
136  "old_data_space_live_bytes");
137  AddNumber(args.GetIsolate(), result, heap->old_data_space()->Available(),
138  "old_data_space_available_bytes");
139  AddNumber(args.GetIsolate(), result,
140  heap->old_data_space()->CommittedMemory(),
141  "old_data_space_commited_bytes");
142  AddNumber(args.GetIsolate(), result, heap->code_space()->Size(),
143  "code_space_live_bytes");
144  AddNumber(args.GetIsolate(), result, heap->code_space()->Available(),
145  "code_space_available_bytes");
146  AddNumber(args.GetIsolate(), result, heap->code_space()->CommittedMemory(),
147  "code_space_commited_bytes");
148  AddNumber(args.GetIsolate(), result, heap->cell_space()->Size(),
149  "cell_space_live_bytes");
150  AddNumber(args.GetIsolate(), result, heap->cell_space()->Available(),
151  "cell_space_available_bytes");
152  AddNumber(args.GetIsolate(), result, heap->cell_space()->CommittedMemory(),
153  "cell_space_commited_bytes");
154  AddNumber(args.GetIsolate(), result, heap->property_cell_space()->Size(),
155  "property_cell_space_live_bytes");
156  AddNumber(args.GetIsolate(), result, heap->property_cell_space()->Available(),
157  "property_cell_space_available_bytes");
158  AddNumber(args.GetIsolate(), result,
160  "property_cell_space_commited_bytes");
161  AddNumber(args.GetIsolate(), result, heap->lo_space()->Size(),
162  "lo_space_live_bytes");
163  AddNumber(args.GetIsolate(), result, heap->lo_space()->Available(),
164  "lo_space_available_bytes");
165  AddNumber(args.GetIsolate(), result, heap->lo_space()->CommittedMemory(),
166  "lo_space_commited_bytes");
167  AddNumber64(args.GetIsolate(), result,
169  "amount_of_external_allocated_memory");
170  args.GetReturnValue().Set(result);
171 }
172 
173 } } // namespace v8::internal
virtual intptr_t Size()
Definition: spaces.h:2821
intptr_t Available()
Definition: spaces.h:1783
#define INSTANCE_TYPE_LIST(V)
Definition: objects.h:342
void CollectAllGarbage(int flags, const char *gc_reason=NULL, const GCCallbackFlags gc_callback_flags=kNoGCCallbackFlags)
Definition: heap.cc:731
V8_INLINE Isolate * GetIsolate() const
Definition: v8.h:6061
V8_INLINE ReturnValue< T > GetReturnValue() const
Definition: v8.h:6067
V8_INLINE int Length() const
Definition: v8.h:6079
#define ASSERT(condition)
Definition: checks.h:329
#define STATS_COUNTER_LIST_2(SC)
Definition: v8-counters.h:165
intptr_t CommittedMemory()
Definition: spaces.h:1742
intptr_t CommittedMemory()
Definition: spaces.h:2461
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunctionTemplate(v8::Isolate *isolate, v8::Handle< v8::String > name)
static const int kNoGCFlags
Definition: heap.h:1257
PropertyCellSpace * property_cell_space()
Definition: heap.h:643
virtual intptr_t Size()
Definition: spaces.h:2438
MemoryAllocator * memory_allocator()
Definition: isolate.h:884
static Local< FunctionTemplate > New(Isolate *isolate, FunctionCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >(), int length=0)
Definition: api.cc:942
intptr_t Available()
Definition: spaces.h:2476
OldSpace * old_pointer_space()
Definition: heap.h:638
OldSpace * code_space()
Definition: heap.h:640
Definition: v8.h:123
static Local< Number > New(Isolate *isolate, double value)
Definition: api.cc:6220
LargeObjectSpace * lo_space()
Definition: heap.h:646
CellSpace * cell_space()
Definition: heap.h:642
static Local< Object > New(Isolate *isolate)
Definition: api.cc:5589
#define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V)
Definition: objects.h:863
#define CODE_KIND_LIST(V)
Definition: objects.h:5204
static void GetCounters(const v8::FunctionCallbackInfo< v8::Value > &args)
virtual intptr_t Size()
Definition: spaces.h:1788
Counters * counters()
Definition: isolate.h:859
int64_t amount_of_external_allocated_memory()
Definition: heap.h:1872
#define ADD_COUNTER(name, caption)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV 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 expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
Definition: flags.cc:505
NewSpace * new_space()
Definition: heap.h:637
Definition: v8.h:124
#define STATS_COUNTER_LIST_1(SC)
Definition: v8-counters.h:113
OldSpace * old_data_space()
Definition: heap.h:639
static Local< String > NewFromUtf8(Isolate *isolate, const char *data, NewStringType type=kNormalString, int length=-1)
Definition: api.cc:5417