Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
652 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--TEST-- | ||
GC Stats: No memleak, return empty runs | ||
--INI-- | ||
zend.enable_gc=1 | ||
xdebug.gc_stats_enable=1 | ||
--FILE-- | ||
<?php | ||
echo file_get_contents(xdebug_get_gcstats_filename()); | ||
xdebug_stop_gcstats(); | ||
unlink(xdebug_get_gcstats_filename()); | ||
?> | ||
--EXPECTF-- | ||
Garbage Collection Report | ||
version: 1 | ||
creator: xdebug %d.%s (PHP %s) | ||
|
||
Collected | Efficiency% | Duration | Memory Before | Memory After | Reduction% | Function | ||
----------+-------------+----------+---------------+--------------+------------+--------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--TEST-- | ||
GC Stats: Run gc_collect_cyles(); and collect stats | ||
--INI-- | ||
zend.enable_gc=1 | ||
xdebug.gc_stats_enable=1 | ||
--FILE-- | ||
<?php | ||
var_dump(ini_get("xdebug.gc_stats_enable")); | ||
|
||
for ($i = 0; $i < 100; $i++) { | ||
$a = new stdClass(); | ||
$b = new stdClass(); | ||
$b->a = $a; | ||
$a->b = $b; | ||
unset($a, $b); | ||
} | ||
gc_collect_cycles(); | ||
|
||
echo file_get_contents(xdebug_get_gcstats_filename()); | ||
xdebug_stop_gcstats(); | ||
unlink(xdebug_get_gcstats_filename()); | ||
?> | ||
--EXPECTF-- | ||
string(1) "1" | ||
Garbage Collection Report | ||
version: 1 | ||
creator: xdebug %d.%s (PHP %s) | ||
|
||
Collected | Efficiency% | Duration | Memory Before | Memory After | Reduction% | Function | ||
----------+-------------+----------+---------------+--------------+------------+--------- | ||
200 | 2.00 % | %s ms | %d | %d | %s % | gc_collect_cycles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--TEST-- | ||
GC Stats: Stats about trigger garbage collection automatically | ||
--INI-- | ||
zend.enable_gc=1 | ||
xdebug.gc_stats_enable=1 | ||
--FILE-- | ||
<?php | ||
|
||
gc_enable(); | ||
|
||
function foo() | ||
{ | ||
bar(); | ||
} | ||
|
||
function bar() | ||
{ | ||
for ($i = 0; $i < 20000; $i++) { | ||
$a = new stdClass(); | ||
$b = new stdClass(); | ||
$b->a = $a; | ||
$a->b = $b; | ||
unset($a, $b); | ||
} | ||
} | ||
|
||
foo(); | ||
|
||
$lines = file(xdebug_get_gcstats_filename()); | ||
xdebug_stop_gcstats(); | ||
unlink(xdebug_get_gcstats_filename()); | ||
|
||
var_dump(count($lines) >= 6); | ||
?> | ||
--EXPECTF-- | ||
bool(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--TEST-- | ||
GC Stats: Class with garbage | ||
--INI-- | ||
zend.enable_gc=1 | ||
xdebug.gc_stats_enable=1 | ||
--FILE-- | ||
<?php | ||
|
||
function foo() | ||
{ | ||
bar(); | ||
} | ||
|
||
function bar() | ||
{ | ||
for ($i = 0; $i < 20000; $i++) | ||
{ | ||
$a = new stdClass(); | ||
$b = new stdClass(); | ||
$b->a = $a; | ||
$a->b = $b; | ||
unset($a, $b); | ||
} | ||
} | ||
|
||
class Garbage | ||
{ | ||
public function produce() | ||
{ | ||
$foo = new stdClass(); | ||
|
||
for ($i = 0; $i < 20000; $i++) | ||
{ | ||
$a = new stdClass(); | ||
$b = new stdClass(); | ||
$b->foo = $foo; | ||
$b->a = $a; | ||
$a->b = $b; | ||
unset($a, $b); | ||
} | ||
|
||
unset($foo); | ||
gc_collect_cycles(); | ||
} | ||
} | ||
|
||
foo(); | ||
(new Garbage())->produce(); | ||
|
||
$data = file_get_contents(xdebug_get_gcstats_filename()); | ||
xdebug_stop_gcstats(); | ||
unlink(xdebug_get_gcstats_filename()); | ||
|
||
var_dump(substr_count($data, "bar") >= 3); | ||
var_dump(substr_count($data, "Garbage::produce") >= 4); | ||
var_dump(substr_count($data, "gc_collect_cycles") == 1); | ||
?> | ||
--EXPECTF-- | ||
bool(true) | ||
bool(true) | ||
bool(true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--TEST-- | ||
GC Stats: Start with xdebug_start_gcstats() | ||
--INI-- | ||
zend.enable_gc=1 | ||
xdebug.gc_stats_enable=0 | ||
--FILE-- | ||
<?php | ||
|
||
var_dump(ini_get("xdebug.gc_stats_enable")); | ||
|
||
for ($i = 0; $i < 100; $i++) | ||
{ | ||
$a = new stdClass(); | ||
$b = new stdClass(); | ||
$b->a = $a; | ||
$a->b = $b; | ||
unset($a, $b); | ||
} | ||
gc_collect_cycles(); | ||
|
||
xdebug_start_gcstats(); | ||
|
||
for ($i = 0; $i < 100; $i++) | ||
{ | ||
$a = new stdClass(); | ||
$b = new stdClass(); | ||
$b->a = $a; | ||
$a->b = $b; | ||
unset($a, $b); | ||
} | ||
gc_collect_cycles(); | ||
|
||
echo file_get_contents(xdebug_get_gcstats_filename()); | ||
xdebug_stop_gcstats(); | ||
unlink(xdebug_get_gcstats_filename()); | ||
?> | ||
--EXPECTF-- | ||
string(1) "0" | ||
Garbage Collection Report | ||
version: 1 | ||
creator: xdebug %d.%s (PHP %s) | ||
|
||
Collected | Efficiency% | Duration | Memory Before | Memory After | Reduction% | Function | ||
----------+-------------+----------+---------------+--------------+------------+--------- | ||
200 | 2.00 % | %s ms | %d | %d | %s % | gc_collect_cycles | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--TEST-- | ||
GC Stats: Start with xdebug_start_gcstats() and filename | ||
--INI-- | ||
zend.enable_gc=1 | ||
xdebug.gc_stats_enable=0 | ||
--FILE-- | ||
<?php | ||
var_dump(xdebug_get_gcstats_filename()); | ||
|
||
$filename = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'gcstats.txt'; | ||
$actual = xdebug_start_gcstats($filename); | ||
|
||
var_dump($actual === $filename); | ||
var_dump(xdebug_get_gcstats_filename()); | ||
xdebug_stop_gcstats(); | ||
unlink(xdebug_get_gcstats_filename()); | ||
?> | ||
--EXPECTF-- | ||
bool(false) | ||
bool(true) | ||
string(%d) "%sgcstats.txt" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--TEST-- | ||
GC Stats: userland statistic functions | ||
--INI-- | ||
zend.enable_gc=1 | ||
--FILE-- | ||
<?php | ||
|
||
for ($i = 0; $i < 100; $i++) { | ||
$a = new stdClass(); | ||
$b = new stdClass(); | ||
$b->a = $a; | ||
$a->b = $b; | ||
unset($a, $b); | ||
} | ||
gc_collect_cycles(); | ||
|
||
printf("runs: %d\n", xdebug_get_gc_run_count()); | ||
printf("collected: %d\n", xdebug_get_gc_total_collected_roots()); | ||
?> | ||
--EXPECTF-- | ||
runs: 1 | ||
collected: 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--TEST-- | ||
GC Stats: Closure with garbage | ||
--INI-- | ||
zend.enable_gc=1 | ||
xdebug.gc_stats_enable=1 | ||
--FILE-- | ||
<?php | ||
|
||
function foo() | ||
{ | ||
bar(); | ||
} | ||
|
||
function bar() | ||
{ | ||
for ($i = 0; $i < 20000; $i++) | ||
{ | ||
$a = new stdClass(); | ||
$b = new stdClass(); | ||
$b->a = $a; | ||
$a->b = $b; | ||
unset($a, $b); | ||
} | ||
} | ||
|
||
$closure = function() { | ||
$foo = new stdClass(); | ||
|
||
for ($i = 0; $i < 20000; $i++) | ||
{ | ||
$a = new stdClass(); | ||
$b = new stdClass(); | ||
$b->foo = $foo; | ||
$b->a = $a; | ||
$a->b = $b; | ||
unset($a, $b); | ||
} | ||
|
||
unset($foo); | ||
gc_collect_cycles(); | ||
}; | ||
|
||
foo(); | ||
$closure(); | ||
|
||
$data = file_get_contents(xdebug_get_gcstats_filename()); | ||
xdebug_stop_gcstats(); | ||
unlink(xdebug_get_gcstats_filename()); | ||
|
||
var_dump(substr_count($data, "bar") >= 3); | ||
var_dump(substr_count($data, "{closure:") >= 4); | ||
var_dump(substr_count($data, "xdebug_gc_stats8.php:20-35}") >= 4); | ||
var_dump(substr_count($data, "gc_collect_cycles") == 1); | ||
?> | ||
--EXPECTF-- | ||
bool(true) | ||
bool(true) | ||
bool(true) | ||
bool(true) |
Oops, something went wrong.