Skip to content
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit d7b6b86

Browse files
committed
Add malloced_memory to V8\HeapStatistics
V8 commit: v8/v8@cb7aa79
1 parent 260773e commit d7b6b86

File tree

5 files changed

+73
-32
lines changed

5 files changed

+73
-32
lines changed

src/php_v8_heap_statistics.cc

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void php_v8_heap_statistics_create_from_heap_statistics(zval *return_value, v8::
3535
zend_update_property_double(this_ce, return_value, ZEND_STRL("total_available_size"), hs->total_available_size());
3636
zend_update_property_double(this_ce, return_value, ZEND_STRL("used_heap_size"), hs->used_heap_size());
3737
zend_update_property_double(this_ce, return_value, ZEND_STRL("heap_size_limit"), hs->heap_size_limit());
38+
zend_update_property_double(this_ce, return_value, ZEND_STRL("malloced_memory"), hs->malloced_memory());
3839

3940
zend_update_property_bool(this_ce, return_value, ZEND_STRL("does_zap_garbage"), static_cast<zend_long>(hs->does_zap_garbage()));
4041

@@ -47,12 +48,13 @@ static PHP_METHOD(V8HeapStatistics, __construct) {
4748
double total_available_size = 0;
4849
double used_heap_size = 0;
4950
double heap_size_limit = 0;
51+
double malloced_memory = 0;
5052

5153
zend_bool does_zap_garbage = '\0';
5254

53-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|ddddddb",
55+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|dddddddb",
5456
&total_heap_size, &total_heap_size_executable, &total_physical_size, &total_available_size,
55-
&used_heap_size, &heap_size_limit, &does_zap_garbage) == FAILURE) {
57+
&used_heap_size, &heap_size_limit, &malloced_memory, &does_zap_garbage) == FAILURE) {
5658
return;
5759
}
5860

@@ -62,6 +64,7 @@ static PHP_METHOD(V8HeapStatistics, __construct) {
6264
zend_update_property_double(this_ce, getThis(), ZEND_STRL("total_available_size"), total_available_size);
6365
zend_update_property_double(this_ce, getThis(), ZEND_STRL("used_heap_size"), used_heap_size);
6466
zend_update_property_double(this_ce, getThis(), ZEND_STRL("heap_size_limit"), heap_size_limit);
67+
zend_update_property_double(this_ce, getThis(), ZEND_STRL("malloced_memory"), malloced_memory);
6568

6669
zend_update_property_bool(this_ce, getThis(), ZEND_STRL("does_zap_garbage"), does_zap_garbage);
6770
}
@@ -126,6 +129,16 @@ static PHP_METHOD(V8HeapStatistics, heap_size_limit) {
126129
RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("heap_size_limit"), 0, &rv), 1, 0);
127130
}
128131

132+
static PHP_METHOD(V8HeapStatistics, malloced_memory) {
133+
zval rv;
134+
135+
if (zend_parse_parameters_none() == FAILURE) {
136+
return;
137+
}
138+
139+
RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("malloced_memory"), 0, &rv), 1, 0);
140+
}
141+
129142
static PHP_METHOD(V8HeapStatistics, does_zap_garbage) {
130143
zval rv;
131144

@@ -144,6 +157,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_heap_statistics___construct, ZEND_SEND_BY_VAL,
144157
ZEND_ARG_TYPE_INFO(0, total_available_size, IS_DOUBLE, 0)
145158
ZEND_ARG_TYPE_INFO(0, used_heap_size, IS_DOUBLE, 0)
146159
ZEND_ARG_TYPE_INFO(0, heap_size_limit, IS_DOUBLE, 0)
160+
ZEND_ARG_TYPE_INFO(0, malloced_memory, IS_DOUBLE, 0)
161+
ZEND_ARG_TYPE_INFO(0, peak_malloced_memory, IS_DOUBLE, 0)
162+
147163
ZEND_ARG_TYPE_INFO(0, does_zap_garbage, _IS_BOOL, 0)
148164
ZEND_END_ARG_INFO()
149165

@@ -165,6 +181,9 @@ ZEND_END_ARG_INFO()
165181
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_heap_statistics__heap_size_limit, ZEND_RETURN_VALUE, 0, IS_DOUBLE, NULL, 0)
166182
ZEND_END_ARG_INFO()
167183

184+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_heap_statistics__malloced_memory, ZEND_RETURN_VALUE, 0, IS_DOUBLE, NULL, 0)
185+
ZEND_END_ARG_INFO()
186+
168187
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_heap_statistics__does_zap_garbage, ZEND_RETURN_VALUE, 0, _IS_BOOL, NULL, 0)
169188
ZEND_END_ARG_INFO()
170189

@@ -178,6 +197,7 @@ static const zend_function_entry php_v8_heap_statistics_methods[] = {
178197
PHP_ME(V8HeapStatistics, total_available_size, arginfo_v8_heap_statistics__total_available_size, ZEND_ACC_PUBLIC)
179198
PHP_ME(V8HeapStatistics, used_heap_size, arginfo_v8_heap_statistics__used_heap_size, ZEND_ACC_PUBLIC)
180199
PHP_ME(V8HeapStatistics, heap_size_limit, arginfo_v8_heap_statistics__heap_size_limit, ZEND_ACC_PUBLIC)
200+
PHP_ME(V8HeapStatistics, malloced_memory, arginfo_v8_heap_statistics__malloced_memory, ZEND_ACC_PUBLIC)
181201
PHP_ME(V8HeapStatistics, does_zap_garbage, arginfo_v8_heap_statistics__does_zap_garbage, ZEND_ACC_PUBLIC)
182202

183203
PHP_FE_END
@@ -195,6 +215,7 @@ PHP_MINIT_FUNCTION (php_v8_heap_statistics) {
195215
zend_declare_property_double(this_ce, ZEND_STRL("total_available_size"), 0, ZEND_ACC_PRIVATE);
196216
zend_declare_property_double(this_ce, ZEND_STRL("used_heap_size"), 0, ZEND_ACC_PRIVATE);
197217
zend_declare_property_double(this_ce, ZEND_STRL("heap_size_limit"), 0, ZEND_ACC_PRIVATE);
218+
zend_declare_property_double(this_ce, ZEND_STRL("malloced_memory"), 0, ZEND_ACC_PRIVATE);
198219

199220
zend_declare_property_bool(this_ce, ZEND_STRL("does_zap_garbage"), false, ZEND_ACC_PRIVATE);
200221

stubs/src/HeapStatistics.php

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,50 +27,56 @@
2727
class HeapStatistics
2828
{
2929
/**
30-
* @var int
30+
* @var float
3131
*/
3232
private $total_heap_size;
3333
/**
34-
* @var int
34+
* @var float
3535
*/
3636
private $total_heap_size_executable;
3737
/**
38-
* @var int
38+
* @var float
3939
*/
4040
private $total_physical_size;
4141
/**
42-
* @var int
42+
* @var float
4343
*/
4444
private $total_available_size;
4545
/**
46-
* @var int
46+
* @var float
4747
*/
4848
private $used_heap_size;
4949
/**
50-
* @var int
50+
* @var float
5151
*/
5252
private $heap_size_limit;
53+
/**
54+
* @var float
55+
*/
56+
private $malloced_memory;
5357
/**
5458
* @var bool
5559
*/
5660
private $does_zap_garbage;
5761

5862
/**
59-
* @param int $total_heap_size
60-
* @param int $total_heap_size_executable
61-
* @param int $total_physical_size
62-
* @param int $total_available_size
63-
* @param int $used_heap_size
64-
* @param int $heap_size_limit
65-
* @param bool $does_zap_garbage
63+
* @param float $total_heap_size
64+
* @param float $total_heap_size_executable
65+
* @param float $total_physical_size
66+
* @param float $total_available_size
67+
* @param float $used_heap_size
68+
* @param float $heap_size_limit
69+
* @param float $malloced_memory
70+
* @param bool $does_zap_garbage
6671
*/
6772
public function __construct(
68-
int $total_heap_size,
69-
int $total_heap_size_executable,
70-
int $total_physical_size,
71-
int $total_available_size,
72-
int $used_heap_size,
73-
int $heap_size_limit,
73+
float $total_heap_size,
74+
float $total_heap_size_executable,
75+
float $total_physical_size,
76+
float $total_available_size,
77+
float $used_heap_size,
78+
float $heap_size_limit,
79+
float $malloced_memory,
7480
bool $does_zap_garbage
7581
) {
7682
$this->total_heap_size = $total_heap_size;
@@ -79,40 +85,46 @@ public function __construct(
7985
$this->total_available_size = $total_available_size;
8086
$this->used_heap_size = $used_heap_size;
8187
$this->heap_size_limit = $heap_size_limit;
88+
$this->malloced_memory = $malloced_memory;
8289
$this->does_zap_garbage = $does_zap_garbage;
8390
}
8491

85-
public function total_heap_size()
92+
public function total_heap_size() : float
8693
{
8794
return $this->total_heap_size;
8895
}
8996

90-
public function total_heap_size_executable()
97+
public function total_heap_size_executable() : float
9198
{
9299
return $this->total_heap_size_executable;
93100
}
94101

95-
public function total_physical_size()
102+
public function total_physical_size() : float
96103
{
97104
return $this->total_physical_size;
98105
}
99106

100-
public function total_available_size()
107+
public function total_available_size() : float
101108
{
102109
return $this->total_available_size;
103110
}
104111

105-
public function used_heap_size()
112+
public function used_heap_size() : float
106113
{
107114
return $this->used_heap_size;
108115
}
109116

110-
public function heap_size_limit()
117+
public function heap_size_limit() : float
111118
{
112119
return $this->heap_size_limit;
113120
}
114121

115-
public function does_zap_garbage()
122+
public function malloced_memory() : float
123+
{
124+
return $this->malloced_memory;
125+
}
126+
127+
public function does_zap_garbage() : bool
116128
{
117129
return $this->does_zap_garbage;
118130
}

tests/V8HeapStatistics.phpt

Lines changed: 6 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, true);
11+
$hs = new \V8\HeapStatistics(1, 2, 3, 4, 5, 6, 7, true);
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 (7) {
23+
object(V8\HeapStatistics)#2 (8) {
2424
["total_heap_size":"V8\HeapStatistics":private]=>
2525
float(1)
2626
["total_heap_size_executable":"V8\HeapStatistics":private]=>
@@ -33,6 +33,8 @@ object(V8\HeapStatistics)#2 (7) {
3333
float(5)
3434
["heap_size_limit":"V8\HeapStatistics":private]=>
3535
float(6)
36+
["malloced_memory":"V8\HeapStatistics":private]=>
37+
float(7)
3638
["does_zap_garbage":"V8\HeapStatistics":private]=>
3739
bool(true)
3840
}
@@ -43,4 +45,6 @@ V8\HeapStatistics->total_physical_size(): float(3)
4345
V8\HeapStatistics->total_available_size(): float(4)
4446
V8\HeapStatistics->used_heap_size(): float(5)
4547
V8\HeapStatistics->heap_size_limit(): float(6)
48+
V8\HeapStatistics->malloced_memory(): float(7)
49+
V8\HeapStatistics->peak_malloced_memory(): float(8)
4650
V8\HeapStatistics->does_zap_garbage(): bool(true)

tests/V8Isolate.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object(V8\Isolate)#2 (5) {
4646
V8\Exceptions\GenericException: Not in context!
4747

4848
V8\Isolate->GetHeapStatistics():
49-
object(V8\HeapStatistics)#28 (7) {
49+
object(V8\HeapStatistics)#28 (8) {
5050
["total_heap_size":"V8\HeapStatistics":private]=>
5151
float(%d)
5252
["total_heap_size_executable":"V8\HeapStatistics":private]=>
@@ -59,6 +59,8 @@ V8\Isolate->GetHeapStatistics():
5959
float(%d)
6060
["heap_size_limit":"V8\HeapStatistics":private]=>
6161
float(%d)
62+
["malloced_memory":"V8\HeapStatistics":private]=>
63+
float(%d)
6264
["does_zap_garbage":"V8\HeapStatistics":private]=>
6365
bool(false)
6466
}

tests/V8Isolate_limit_memory.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ object(V8\Isolate)#3 (5) {
9191
["memory_limit_hit":"V8\Isolate":private]=>
9292
bool(true)
9393
}
94-
object(V8\HeapStatistics)#14 (7) {
94+
object(V8\HeapStatistics)#14 (8) {
9595
["total_heap_size":"V8\HeapStatistics":private]=>
9696
float(%d)
9797
["total_heap_size_executable":"V8\HeapStatistics":private]=>
@@ -104,6 +104,8 @@ object(V8\HeapStatistics)#14 (7) {
104104
float(%d)
105105
["heap_size_limit":"V8\HeapStatistics":private]=>
106106
float(%d)
107+
["malloced_memory":"V8\HeapStatistics":private]=>
108+
float(%d)
107109
["does_zap_garbage":"V8\HeapStatistics":private]=>
108110
bool(false)
109111
}

0 commit comments

Comments
 (0)