Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit 0826d3f

Browse files
committed
Add number of native and detached ctxt to HeapStatistics, closes #84
1 parent e1941ec commit 0826d3f

File tree

6 files changed

+108
-16
lines changed

6 files changed

+108
-16
lines changed

‎src/php_v8_heap_statistics.cc

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ void php_v8_heap_statistics_create_from_heap_statistics(zval *return_value, v8::
3737
zend_update_property_double(this_ce, return_value, ZEND_STRL("peak_malloced_memory"), hs->peak_malloced_memory());
3838

3939
zend_update_property_bool(this_ce, return_value, ZEND_STRL("does_zap_garbage"), static_cast<zend_long>(hs->does_zap_garbage()));
40+
41+
zend_update_property_double(this_ce, return_value, ZEND_STRL("number_of_native_contexts"), hs->number_of_native_contexts());
42+
zend_update_property_double(this_ce, return_value, ZEND_STRL("number_of_detached_contexts"), hs->number_of_detached_contexts());
4043
}
4144

4245
static PHP_METHOD(HeapStatistics, __construct) {
@@ -51,10 +54,14 @@ static PHP_METHOD(HeapStatistics, __construct) {
5154

5255
zend_bool does_zap_garbage = '0円';
5356

54-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|" "dddd" "dddd" "b",
57+
double number_of_native_contexts = 0;
58+
double number_of_detached_contexts = 0;
59+
60+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|" "dddd" "dddd" "b" "dd",
5561
&total_heap_size, &total_heap_size_executable, &total_physical_size, &total_available_size,
5662
&used_heap_size, &heap_size_limit, &malloced_memory, &peak_malloced_memory,
57-
&does_zap_garbage) == FAILURE) {
63+
&does_zap_garbage,
64+
&number_of_native_contexts, &number_of_detached_contexts) == FAILURE) {
5865
return;
5966
}
6067

@@ -68,6 +75,9 @@ static PHP_METHOD(HeapStatistics, __construct) {
6875
zend_update_property_double(this_ce, getThis(), ZEND_STRL("peak_malloced_memory"), peak_malloced_memory);
6976

7077
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("does_zap_garbage"), does_zap_garbage);
78+
79+
zend_update_property_double(this_ce, getThis(), ZEND_STRL("number_of_native_contexts"), number_of_native_contexts);
80+
zend_update_property_double(this_ce, getThis(), ZEND_STRL("number_of_detached_contexts"), number_of_detached_contexts);
7181
}
7282

7383
static PHP_METHOD(HeapStatistics, getTotalHeapSize) {
@@ -160,6 +170,26 @@ static PHP_METHOD(HeapStatistics, doesZapGarbage) {
160170
RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("does_zap_garbage"), 0, &rv), 1, 0);
161171
}
162172

173+
static PHP_METHOD(HeapStatistics, getNumberOfNativeContexts) {
174+
zval rv;
175+
176+
if (zend_parse_parameters_none() == FAILURE) {
177+
return;
178+
}
179+
180+
RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("number_of_native_contexts"), 0, &rv), 1, 0);
181+
}
182+
183+
static PHP_METHOD(HeapStatistics, getNumberOfDetachedContexts) {
184+
zval rv;
185+
186+
if (zend_parse_parameters_none() == FAILURE) {
187+
return;
188+
}
189+
190+
RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("number_of_detached_contexts"), 0, &rv), 1, 0);
191+
}
192+
163193

164194
PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 0)
165195
ZEND_ARG_TYPE_INFO(0, total_heap_size, IS_DOUBLE, 0)
@@ -202,6 +232,12 @@ ZEND_END_ARG_INFO()
202232
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_doesZapGarbage, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0)
203233
ZEND_END_ARG_INFO()
204234

235+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getNumberOfNativeContexts, ZEND_RETURN_VALUE, 0, IS_DOUBLE, 0)
236+
ZEND_END_ARG_INFO()
237+
238+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getNumberOfDetachedContexts, ZEND_RETURN_VALUE, 0, IS_DOUBLE, 0)
239+
ZEND_END_ARG_INFO()
240+
205241

206242
static const zend_function_entry php_v8_heap_statistics_methods[] = {
207243
PHP_V8_ME(HeapStatistics, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
@@ -215,6 +251,8 @@ static const zend_function_entry php_v8_heap_statistics_methods[] = {
215251
PHP_V8_ME(HeapStatistics, getMallocedMemory, ZEND_ACC_PUBLIC)
216252
PHP_V8_ME(HeapStatistics, getPeakMallocedMemory, ZEND_ACC_PUBLIC)
217253
PHP_V8_ME(HeapStatistics, doesZapGarbage, ZEND_ACC_PUBLIC)
254+
PHP_V8_ME(HeapStatistics, getNumberOfNativeContexts, ZEND_ACC_PUBLIC)
255+
PHP_V8_ME(HeapStatistics, getNumberOfDetachedContexts, ZEND_ACC_PUBLIC)
218256

219257
PHP_FE_END
220258
};
@@ -236,5 +274,8 @@ PHP_MINIT_FUNCTION (php_v8_heap_statistics) {
236274

237275
zend_declare_property_bool(this_ce, ZEND_STRL("does_zap_garbage"), false, ZEND_ACC_PRIVATE);
238276

277+
zend_declare_property_double(this_ce, ZEND_STRL("number_of_native_contexts"), 0, ZEND_ACC_PRIVATE);
278+
zend_declare_property_double(this_ce, ZEND_STRL("number_of_detached_contexts"), 0, ZEND_ACC_PRIVATE);
279+
239280
return SUCCESS;
240281
}

‎stubs/src/HeapStatistics.php

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ class HeapStatistics
6060
* @var bool
6161
*/
6262
private $does_zap_garbage;
63+
/**
64+
* @var float
65+
*/
66+
private $number_of_native_contexts;
67+
/**
68+
* @var float
69+
*/
70+
private $number_of_detached_contexts;
6371

6472
/**
6573
* @param float $total_heap_size
@@ -69,7 +77,10 @@ class HeapStatistics
6977
* @param float $used_heap_size
7078
* @param float $heap_size_limit
7179
* @param float $malloced_memory
80+
* @param float $peak_malloced_memory
7281
* @param bool $does_zap_garbage
82+
* @param float $number_of_native_contexts
83+
* @param float $number_of_detached_contexts
7384
*/
7485
public function __construct(
7586
float $total_heap_size,
@@ -80,17 +91,21 @@ public function __construct(
8091
float $heap_size_limit,
8192
float $malloced_memory,
8293
float $peak_malloced_memory,
83-
bool $does_zap_garbage
94+
bool $does_zap_garbage,
95+
float $number_of_native_contexts,
96+
float $number_of_detached_contexts
8497
) {
85-
$this->total_heap_size = $total_heap_size;
86-
$this->total_heap_size_executable = $total_heap_size_executable;
87-
$this->total_physical_size = $total_physical_size;
88-
$this->total_available_size = $total_available_size;
89-
$this->used_heap_size = $used_heap_size;
90-
$this->heap_size_limit = $heap_size_limit;
91-
$this->malloced_memory = $malloced_memory;
92-
$this->peak_malloced_memory = $peak_malloced_memory;
93-
$this->does_zap_garbage = $does_zap_garbage;
98+
$this->total_heap_size = $total_heap_size;
99+
$this->total_heap_size_executable = $total_heap_size_executable;
100+
$this->total_physical_size = $total_physical_size;
101+
$this->total_available_size = $total_available_size;
102+
$this->used_heap_size = $used_heap_size;
103+
$this->heap_size_limit = $heap_size_limit;
104+
$this->malloced_memory = $malloced_memory;
105+
$this->peak_malloced_memory = $peak_malloced_memory;
106+
$this->does_zap_garbage = $does_zap_garbage;
107+
$this->number_of_native_contexts = $number_of_native_contexts;
108+
$this->number_of_detached_contexts = $number_of_detached_contexts;
94109
}
95110

96111
/**
@@ -166,4 +181,22 @@ public function doesZapGarbage(): bool
166181
{
167182
return $this->does_zap_garbage;
168183
}
184+
185+
/**
186+
* The total number of native contexts object on the heap
187+
* @return float
188+
*/
189+
public function getNumberOfNativeContexts(): float
190+
{
191+
return $this->number_of_native_contexts;
192+
}
193+
194+
/**
195+
* The total number of native contexts that were detached but were not garbage collected yet
196+
* @return float
197+
*/
198+
public function getNumberOfDetachedContexts(): float
199+
{
200+
return $this->number_of_detached_contexts;
201+
}
169202
}

‎tests/001-verify_extension_entities.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ class V8\HeapStatistics
307307
private $malloced_memory
308308
private $peak_malloced_memory
309309
private $does_zap_garbage
310+
private $number_of_native_contexts
311+
private $number_of_detached_contexts
310312
public function __construct(float $total_heap_size, float $total_heap_size_executable, float $total_physical_size, float $total_available_size, float $used_heap_size, float $heap_size_limit, float $malloced_memory, float $peak_malloced_memory, bool $does_zap_garbage)
311313
public function getTotalHeapSize(): float
312314
public function getTotalHeapSizeExecutable(): float
@@ -317,6 +319,8 @@ class V8\HeapStatistics
317319
public function getMallocedMemory(): float
318320
public function getPeakMallocedMemory(): float
319321
public function doesZapGarbage(): bool
322+
public function getNumberOfNativeContexts(): float
323+
public function getNumberOfDetachedContexts(): float
320324

321325
class V8\StartupData
322326
public function __construct(string $blob)

‎tests/HeapStatistics.phpt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ V8\HeapStatistics
88
/** @var \Phpv8Testsuite $helper */
99
$helper = require '.testsuite.php';
1010

11-
$hs = new \V8\HeapStatistics(1, 2, 3, 4, 5, 6, 7, 8, true);
11+
$hs = new \V8\HeapStatistics(1, 2, 3, 4, 5, 6, 7, 8, true, 9, 10);
1212

1313
$helper->header('Object representation');
1414
$helper->dump($hs);
@@ -20,7 +20,7 @@ $helper->dump_object_methods($hs);
2020
--EXPECT--
2121
Object representation:
2222
----------------------
23-
object(V8\HeapStatistics)#2 (9) {
23+
object(V8\HeapStatistics)#2 (11) {
2424
["total_heap_size":"V8\HeapStatistics":private]=>
2525
float(1)
2626
["total_heap_size_executable":"V8\HeapStatistics":private]=>
@@ -39,6 +39,10 @@ object(V8\HeapStatistics)#2 (9) {
3939
float(8)
4040
["does_zap_garbage":"V8\HeapStatistics":private]=>
4141
bool(true)
42+
["number_of_native_contexts":"V8\HeapStatistics":private]=>
43+
float(9)
44+
["number_of_detached_contexts":"V8\HeapStatistics":private]=>
45+
float(10)
4246
}
4347

4448
V8\HeapStatistics->getTotalHeapSize(): float(1)
@@ -50,3 +54,5 @@ V8\HeapStatistics->getHeapSizeLimit(): float(6)
5054
V8\HeapStatistics->getMallocedMemory(): float(7)
5155
V8\HeapStatistics->getPeakMallocedMemory(): float(8)
5256
V8\HeapStatistics->doesZapGarbage(): bool(true)
57+
V8\HeapStatistics->getNumberOfNativeContexts(): float(9)
58+
V8\HeapStatistics->getNumberOfDetachedContexts(): float(10)

‎tests/Isolate.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ V8\Isolate::MEMORY_PRESSURE_LEVEL_MODERATE = 1
7777
V8\Isolate::MEMORY_PRESSURE_LEVEL_CRITICAL = 2
7878

7979
V8\Isolate->getHeapStatistics():
80-
object(V8\HeapStatistics)#29 (9) {
80+
object(V8\HeapStatistics)#29 (11) {
8181
["total_heap_size":"V8\HeapStatistics":private]=>
8282
float(%f)
8383
["total_heap_size_executable":"V8\HeapStatistics":private]=>
@@ -96,6 +96,10 @@ V8\Isolate->getHeapStatistics():
9696
float(%f)
9797
["does_zap_garbage":"V8\HeapStatistics":private]=>
9898
bool(false)
99+
["number_of_native_contexts":"V8\HeapStatistics":private]=>
100+
float(%f)
101+
["number_of_detached_contexts":"V8\HeapStatistics":private]=>
102+
float(%f)
99103
}
100104

101105
V8\Exceptions\ValueException: Invalid memory pressure level given. See V8\Isolate MEMORY_PRESSURE_LEVEL_* class constants for available levels.

‎tests/Isolate_limit_memory.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Memory limit accessor report hit: ok
7070

7171
object(V8\Isolate)#3 (0) {
7272
}
73-
object(V8\HeapStatistics)#10 (9) {
73+
object(V8\HeapStatistics)#10 (11) {
7474
["total_heap_size":"V8\HeapStatistics":private]=>
7575
float(%f)
7676
["total_heap_size_executable":"V8\HeapStatistics":private]=>
@@ -89,4 +89,8 @@ object(V8\HeapStatistics)#10 (9) {
8989
float(%f)
9090
["does_zap_garbage":"V8\HeapStatistics":private]=>
9191
bool(false)
92+
["number_of_native_contexts":"V8\HeapStatistics":private]=>
93+
float(%f)
94+
["number_of_detached_contexts":"V8\HeapStatistics":private]=>
95+
float(%f)
9296
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /