Add four extra fields to gc_status() (#9336)

- running: true if garbage collection is currently running
- protected: true if the garbage collector is protected and root
  additions are forbidden
- full: true if the garbage collector buffer size exceeds GC_MAX_BUF_SIZE
- buffer_size: current garbage collector buffer size

Documentation for existing fields:

- runs: the number of times the garbage collector has been run
- collected: the number of objects collected
- threshold: the number of roots in the buffer which will trigger
  garbage collection
- roots: the current number of roots in the buffer

Updated manual example output:

array(8) {
  ["running"]=>
  bool(false)
  ["protected"]=>
  bool(false)
  ["full"]=>
  bool(false)
  ["runs"]=>
  int(5)
  ["collected"]=>
  int(100002)
  ["threshold"]=>
  int(50001)
  ["buffer_size"]=>
  int(131072)
  ["roots"]=>
  int(0)
}
This commit is contained in:
Tim Starling 2022-10-04 23:56:02 +11:00 committed by GitHub
parent db012a8ba7
commit b8811d4ff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 6 deletions

View File

@ -18,7 +18,7 @@ static const func_info_t func_infos[] = {
F1("get_defined_constants", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_ANY),
F1("debug_backtrace", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_ARRAY),
F1("get_extension_funcs", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_LONG|MAY_BE_ARRAY_OF_STRING|MAY_BE_FALSE),
F1("gc_status", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG),
F1("gc_status", MAY_BE_ARRAY|MAY_BE_ARRAY_KEY_STRING|MAY_BE_ARRAY_OF_LONG|MAY_BE_ARRAY_OF_FALSE|MAY_BE_ARRAY_OF_TRUE),
F1("bcadd", MAY_BE_STRING),
F1("bcsub", MAY_BE_STRING),
F1("bcmul", MAY_BE_STRING),

View File

@ -13,23 +13,39 @@ gc_collect_cycles();
var_dump(gc_status());
?>
--EXPECT--
array(4) {
array(8) {
["running"]=>
bool(false)
["protected"]=>
bool(false)
["full"]=>
bool(false)
["runs"]=>
int(0)
["collected"]=>
int(0)
["threshold"]=>
int(10001)
["buffer_size"]=>
int(16384)
["roots"]=>
int(1)
}
array(4) {
array(8) {
["running"]=>
bool(false)
["protected"]=>
bool(false)
["full"]=>
bool(false)
["runs"]=>
int(1)
["collected"]=>
int(1)
["threshold"]=>
int(10001)
["buffer_size"]=>
int(16384)
["roots"]=>
int(0)
}

View File

@ -46,13 +46,21 @@ for ($j = 0; $j < 10; $j++) {
var_dump(gc_status());
?>
--EXPECT--
array(4) {
array(8) {
["running"]=>
bool(false)
["protected"]=>
bool(false)
["full"]=>
bool(false)
["runs"]=>
int(10)
["collected"]=>
int(25000)
["threshold"]=>
int(10001)
["buffer_size"]=>
int(16384)
["roots"]=>
int(10000)
}

View File

@ -140,9 +140,13 @@ ZEND_FUNCTION(gc_status)
array_init_size(return_value, 3);
add_assoc_bool_ex(return_value, "running", sizeof("running")-1, status.active);
add_assoc_bool_ex(return_value, "protected", sizeof("protected")-1, status.gc_protected);
add_assoc_bool_ex(return_value, "full", sizeof("full")-1, status.full);
add_assoc_long_ex(return_value, "runs", sizeof("runs")-1, (long)status.runs);
add_assoc_long_ex(return_value, "collected", sizeof("collected")-1, (long)status.collected);
add_assoc_long_ex(return_value, "threshold", sizeof("threshold")-1, (long)status.threshold);
add_assoc_long_ex(return_value, "buffer_size", sizeof("buffer_size")-1, (long)status.buf_size);
add_assoc_long_ex(return_value, "roots", sizeof("roots")-1, (long)status.num_roots);
}
/* }}} */

View File

@ -194,7 +194,7 @@ function gc_enable(): void {}
function gc_disable(): void {}
/**
* @return array<string, int>
* @return array<string, int|bool>
* @refcount 1
*/
function gc_status(): array {}

View File

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 80355bb52d643177e3a661a515d9ea915bd1e2fc */
* Stub hash: 73e9ef76bde5ab44254185175d4d8dae2e797d12 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_version, 0, 0, IS_STRING, 0)
ZEND_END_ARG_INFO()

View File

@ -1675,9 +1675,13 @@ finish:
ZEND_API void zend_gc_get_status(zend_gc_status *status)
{
status->active = GC_G(gc_active);
status->gc_protected = GC_G(gc_protected);
status->full = GC_G(gc_full);
status->runs = GC_G(gc_runs);
status->collected = GC_G(collected);
status->threshold = GC_G(gc_threshold);
status->buf_size = GC_G(buf_size);
status->num_roots = GC_G(num_roots);
}

View File

@ -23,9 +23,13 @@
BEGIN_EXTERN_C()
typedef struct _zend_gc_status {
bool active;
bool gc_protected;
bool full;
uint32_t runs;
uint32_t collected;
uint32_t threshold;
uint32_t buf_size;
uint32_t num_roots;
} zend_gc_status;