v8  3.14.5(node0.10.28)
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 
39  ASSERT(strcmp(*v8::String::AsciiValue(str), "getV8Statistics") == 0);
41 }
42 
43 
44 static void AddCounter(v8::Local<v8::Object> object,
45  StatsCounter* counter,
46  const char* name) {
47  if (counter->Enabled()) {
48  object->Set(v8::String::New(name),
49  v8::Number::New(*counter->GetInternalPointer()));
50  }
51 }
52 
53 static void AddNumber(v8::Local<v8::Object> object,
54  intptr_t value,
55  const char* name) {
56  object->Set(v8::String::New(name),
57  v8::Number::New(static_cast<double>(value)));
58 }
59 
60 
62  const v8::Arguments& args) {
63  Isolate* isolate = Isolate::Current();
64  Heap* heap = isolate->heap();
65 
66  if (args.Length() > 0) { // GC if first argument evaluates to true.
67  if (args[0]->IsBoolean() && args[0]->ToBoolean()->Value()) {
68  heap->CollectAllGarbage(Heap::kNoGCFlags, "counters extension");
69  }
70  }
71 
72  Counters* counters = isolate->counters();
74 
75 #define ADD_COUNTER(name, caption) \
76  AddCounter(result, counters->name(), #name);
77 
80 #undef ADD_COUNTER
81 #define ADD_COUNTER(name) \
82  AddCounter(result, counters->count_of_##name(), "count_of_" #name); \
83  AddCounter(result, counters->size_of_##name(), "size_of_" #name);
84 
86 #undef ADD_COUNTER
87 #define ADD_COUNTER(name) \
88  AddCounter(result, counters->count_of_CODE_TYPE_##name(), \
89  "count_of_CODE_TYPE_" #name); \
90  AddCounter(result, counters->size_of_CODE_TYPE_##name(), \
91  "size_of_CODE_TYPE_" #name);
92 
94 #undef ADD_COUNTER
95 #define ADD_COUNTER(name) \
96  AddCounter(result, counters->count_of_FIXED_ARRAY_##name(), \
97  "count_of_FIXED_ARRAY_" #name); \
98  AddCounter(result, counters->size_of_FIXED_ARRAY_##name(), \
99  "size_of_FIXED_ARRAY_" #name);
100 
102 #undef ADD_COUNTER
103 
104  AddNumber(result, isolate->memory_allocator()->Size(),
105  "total_committed_bytes");
106  AddNumber(result, heap->new_space()->Size(),
107  "new_space_live_bytes");
108  AddNumber(result, heap->new_space()->Available(),
109  "new_space_available_bytes");
110  AddNumber(result, heap->new_space()->CommittedMemory(),
111  "new_space_commited_bytes");
112  AddNumber(result, heap->old_pointer_space()->Size(),
113  "old_pointer_space_live_bytes");
114  AddNumber(result, heap->old_pointer_space()->Available(),
115  "old_pointer_space_available_bytes");
116  AddNumber(result, heap->old_pointer_space()->CommittedMemory(),
117  "old_pointer_space_commited_bytes");
118  AddNumber(result, heap->old_data_space()->Size(),
119  "old_data_space_live_bytes");
120  AddNumber(result, heap->old_data_space()->Available(),
121  "old_data_space_available_bytes");
122  AddNumber(result, heap->old_data_space()->CommittedMemory(),
123  "old_data_space_commited_bytes");
124  AddNumber(result, heap->code_space()->Size(),
125  "code_space_live_bytes");
126  AddNumber(result, heap->code_space()->Available(),
127  "code_space_available_bytes");
128  AddNumber(result, heap->code_space()->CommittedMemory(),
129  "code_space_commited_bytes");
130  AddNumber(result, heap->cell_space()->Size(),
131  "cell_space_live_bytes");
132  AddNumber(result, heap->cell_space()->Available(),
133  "cell_space_available_bytes");
134  AddNumber(result, heap->cell_space()->CommittedMemory(),
135  "cell_space_commited_bytes");
136  AddNumber(result, heap->lo_space()->Size(),
137  "lo_space_live_bytes");
138  AddNumber(result, heap->lo_space()->Available(),
139  "lo_space_available_bytes");
140  AddNumber(result, heap->lo_space()->CommittedMemory(),
141  "lo_space_commited_bytes");
142  AddNumber(result, heap->amount_of_external_allocated_memory(),
143  "amount_of_external_allocated_memory");
144  return result;
145 }
146 
147 
149  static StatisticsExtension statistics_extension;
150  static v8::DeclareExtension declaration(&statistics_extension);
151 }
152 
153 } } // namespace v8::internal
virtual intptr_t Size()
Definition: spaces.h:2515
static Local< FunctionTemplate > New(InvocationCallback callback=0, Handle< Value > data=Handle< Value >(), Handle< Signature > signature=Handle< Signature >())
Definition: api.cc:951
intptr_t Available()
Definition: spaces.h:1506
#define INSTANCE_TYPE_LIST(V)
Definition: objects.h:318
void CollectAllGarbage(int flags, const char *gc_reason=NULL)
Definition: heap.cc:538
static V8EXPORT Local< String > New(const char *data, int length=-1)
Definition: api.cc:4779
#define ASSERT(condition)
Definition: checks.h:270
#define STATS_COUNTER_LIST_2(SC)
Definition: v8-counters.h:147
intptr_t CommittedMemory()
Definition: spaces.h:1491
intptr_t CommittedMemory()
Definition: spaces.h:2156
static const int kNoGCFlags
Definition: heap.h:1081
virtual intptr_t Size()
Definition: spaces.h:2133
MemoryAllocator * memory_allocator()
Definition: isolate.h:845
int Length() const
Definition: v8.h:4318
intptr_t Available()
Definition: spaces.h:2162
OldSpace * old_pointer_space()
Definition: heap.h:506
OldSpace * code_space()
Definition: heap.h:508
Definition: v8.h:105
LargeObjectSpace * lo_space()
Definition: heap.h:511
CellSpace * cell_space()
Definition: heap.h:510
#define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V)
Definition: objects.h:675
#define CODE_KIND_LIST(V)
Definition: objects.h:4187
virtual intptr_t Size()
Definition: spaces.h:1511
Counters * counters()
Definition: isolate.h:819
static v8::Handle< v8::Value > GetCounters(const v8::Arguments &args)
static V8EXPORT Local< Number > New(double value)
Definition: api.cc:5215
#define ADD_COUNTER(name, caption)
virtual v8::Handle< v8::FunctionTemplate > GetNativeFunction(v8::Handle< v8::String > name)
intptr_t amount_of_external_allocated_memory()
Definition: heap.h:1644
NewSpace * new_space()
Definition: heap.h:505
Definition: v8.h:106
#define STATS_COUNTER_LIST_1(SC)
Definition: v8-counters.h:89
OldSpace * old_data_space()
Definition: heap.h:507
static V8EXPORT Local< Object > New()
Definition: api.cc:4957