Skip to content

Add timing to garbage collection when system supports gettimeofday(). #930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Zend/zend_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@

#include "zend.h"
#include "zend_API.h"
#ifdef PHP_WIN32
#include "win32/time.h"
#elif defined(NETWARE)
#include <sys/timeval.h>
#include <sys/time.h>
#else
#include <sys/time.h>
#endif

/* one (0) is reserved */
#define GC_ROOT_BUFFER_MAX_ENTRIES 10001
Expand Down Expand Up @@ -68,6 +76,7 @@ static void gc_globals_ctor_ex(zend_gc_globals *gc_globals TSRMLS_DC)

gc_globals->gc_runs = 0;
gc_globals->collected = 0;
gc_globals->duration = 0;

#if GC_BENCH
gc_globals->root_buf_length = 0;
Expand Down Expand Up @@ -99,6 +108,7 @@ ZEND_API void gc_reset(TSRMLS_D)
{
GC_G(gc_runs) = 0;
GC_G(collected) = 0;
GC_G(duration) = 0;
GC_G(gc_full) = 0;

#if GC_BENCH
Expand Down Expand Up @@ -709,6 +719,10 @@ static void gc_remove_nested_data_from_buffer(zend_refcounted *ref TSRMLS_DC)
ZEND_API int gc_collect_cycles(TSRMLS_D)
{
int count = 0;
#ifdef HAVE_GETTIMEOFDAY
struct timeval start = {0}, end = {0};
double gc_timing = 1;
#endif

if (GC_G(roots).next != &GC_G(roots)) {
gc_root_buffer *current, *orig_next_to_free;
Expand All @@ -718,6 +732,13 @@ ZEND_API int gc_collect_cycles(TSRMLS_D)
if (GC_G(gc_active)) {
return 0;
}

#ifdef HAVE_GETTIMEOFDAY
if (gettimeofday(&start, NULL)) {
gc_timing = 0;
}
#endif

GC_G(gc_runs)++;
GC_G(gc_active) = 1;
gc_mark_roots(TSRMLS_C);
Expand Down Expand Up @@ -832,6 +853,12 @@ ZEND_API int gc_collect_cycles(TSRMLS_D)

GC_G(collected) += count;
GC_G(next_to_free) = orig_next_to_free;

#ifdef HAVE_GETTIMEOFDAY
if (gc_timing == 1 && gettimeofday(&end, NULL) == 0) {
GC_G(duration) += (((end.tv_sec - start.tv_sec) * 1000000) + (end.tv_usec - start.tv_usec));
}
#endif
}

return count;
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ typedef struct _zend_gc_globals {

uint32_t gc_runs;
uint32_t collected;
long duration;

#if GC_BENCH
uint32_t root_buf_length;
Expand Down