Skip to content
Permalink
Browse files

Merged pull request #523

  • Loading branch information
derickr committed Dec 1, 2019
2 parents 122625c + 31d11c7 commit c9cbd5490d171e5f2d634b5680af7a930cef5fa4
Showing with 0 additions and 199 deletions.
  1. +0 −2 src/base/stack.c
  2. +0 −13 src/lib/private.h
  3. +0 −167 src/profiler/profiler.c
  4. +0 −10 src/profiler/profiler.h
  5. +0 −7 xdebug.c
@@ -1239,8 +1239,6 @@ function_stack_entry *xdebug_add_stack_frame(zend_execute_data *zdata, zend_op_a
xdebug_llist_insert_next(XG_BASE(stack), XDEBUG_LLIST_TAIL(XG_BASE(stack)), tmp);
}

xdebug_profiler_add_aggregate_entry(tmp);

return tmp;
}

@@ -153,18 +153,6 @@ typedef struct _xdebug_call_entry {
long mem_used;
} xdebug_call_entry;

typedef struct xdebug_aggregate_entry {
int user_defined;
char *filename;
char *function;
int lineno;
int call_count;
double time_own;
double time_inclusive;
long mem_used;
HashTable *call_list;
} xdebug_aggregate_entry;

typedef struct xdebug_profile {
double time;
double mark;
@@ -218,7 +206,6 @@ typedef struct _function_stack_entry {
int refcount;
struct _function_stack_entry *prev;
zend_op_array *op_array;
xdebug_aggregate_entry *aggr_entry;
} function_stack_entry;

function_stack_entry *xdebug_get_stack_head(void);
@@ -43,17 +43,10 @@ void xdebug_init_profiler_globals(xdebug_profiler_globals_t *xg)

void xdebug_profiler_minit(void)
{
/* initialize aggregate call information hash */
zend_hash_init_ex(&XG_PROF(aggr_calls), 50, NULL, (dtor_func_t) xdebug_profile_aggr_call_entry_dtor, 1, 0);
}

void xdebug_profiler_mshutdown(void)
{
if (XINI_PROF(profiler_aggregate)) {
xdebug_profiler_output_aggr_data(NULL);
}

zend_hash_destroy(&XG_PROF(aggr_calls));
}

void xdebug_profiler_rinit(void)
@@ -133,69 +126,6 @@ void xdebug_profiler_execute_internal_end(function_stack_entry *fse)
}
}

void xdebug_profiler_add_aggregate_entry(function_stack_entry *fse)
{
char *func_name;
char *aggr_key = NULL;
int aggr_key_len = 0;
zend_string *aggr_key_str = NULL;

if (!XINI_PROF(profiler_aggregate)) {
return;
}

func_name = xdebug_show_fname(fse->function, 0, 0);

aggr_key = xdebug_sprintf("%s.%s.%d", fse->filename, func_name, fse->lineno);
aggr_key_len = strlen(aggr_key);
aggr_key_str = zend_string_init(aggr_key, aggr_key_len, 0);
if ((fse->aggr_entry = zend_hash_find_ptr(&XG_PROF(aggr_calls), aggr_key_str)) == NULL) {
xdebug_aggregate_entry xae;

if (fse->user_defined == XDEBUG_USER_DEFINED) {
xae.filename = xdstrdup(fse->op_array->filename->val);
} else {
xae.filename = xdstrdup("php:internal");
}
xae.function = func_name;
xae.lineno = fse->lineno;
xae.user_defined = fse->user_defined;
xae.call_count = 0;
xae.time_own = 0;
xae.time_inclusive = 0;
xae.call_list = NULL;

zend_hash_add_ptr(&XG_PROF(aggr_calls), aggr_key_str, &xae);
}

if (XG_BASE(stack) && XDEBUG_LLIST_TAIL(XG_BASE(stack))) {
if (fse->prev->aggr_entry->call_list) {
if (!zend_hash_exists(fse->prev->aggr_entry->call_list, aggr_key_str)) {
zend_hash_add_ptr(fse->prev->aggr_entry->call_list, aggr_key_str, fse->aggr_entry);
}
} else {
fse->prev->aggr_entry->call_list = xdmalloc(sizeof(HashTable));
zend_hash_init_ex(fse->prev->aggr_entry->call_list, 1, NULL, NULL, 1, 0);
zend_hash_add_ptr(fse->prev->aggr_entry->call_list, aggr_key_str, fse->aggr_entry);
}
}

zend_string_release(aggr_key_str);
xdfree(aggr_key);
}


void xdebug_profile_aggr_call_entry_dtor(void *elem)
{
xdebug_aggregate_entry *xae = (xdebug_aggregate_entry *) elem;
if (xae->filename) {
xdfree(xae->filename);
}
if (xae->function) {
xdfree(xae->function);
}
}

void xdebug_profile_call_entry_dtor(void *dummy, void *elem)
{
xdebug_call_entry *ce = elem;
@@ -485,12 +415,6 @@ void xdebug_profiler_function_end(function_stack_entry *fse)
}


/* update aggregate data */
if (XINI_PROF(profiler_aggregate)) {
fse->aggr_entry->time_inclusive += fse->profile.time;
fse->aggr_entry->call_count++;
}

/* Subtract time in calledfunction from time here */
for (le = XDEBUG_LLIST_HEAD(fse->profile.call_list); le != NULL; le = XDEBUG_LLIST_NEXT(le))
{
@@ -500,12 +424,6 @@ void xdebug_profiler_function_end(function_stack_entry *fse)
}
fprintf(XG_PROF(profile_file), "%d %lu %ld\n", fse->profiler.lineno, (unsigned long) (fse->profile.time * 1000000), (fse->profile.memory));

/* update aggregate data */
if (XINI_PROF(profiler_aggregate)) {
fse->aggr_entry->time_own += fse->profile.time;
fse->aggr_entry->mem_used += fse->profile.memory;
}

/* dump call list */
for (le = XDEBUG_LLIST_HEAD(fse->profile.call_list); le != NULL; le = XDEBUG_LLIST_NEXT(le))
{
@@ -545,60 +463,6 @@ void xdebug_profiler_free_function_details(function_stack_entry *fse)
fse->profiler.filename = NULL;
}

static int xdebug_print_aggr_entry(zval *pDest, void *argument)
{
FILE *fp = (FILE *) argument;
xdebug_aggregate_entry *xae = (xdebug_aggregate_entry *) pDest;

fprintf(fp, "fl=%s\n", xae->filename);
fprintf(fp, "fn=%s\n", xae->function);
fprintf(fp, "%d %lu %ld\n", 0, (unsigned long) (xae->time_own * 1000000), (xae->mem_used));
if (strcmp(xae->function, "{main}") == 0) {
fprintf(fp, "\nsummary: %lu %lu\n\n", (unsigned long) (xae->time_inclusive * 1000000), (xae->mem_used));
}
if (xae->call_list) {
xdebug_aggregate_entry *xae_call;

ZEND_HASH_FOREACH_PTR(xae->call_list, xae_call) {
fprintf(fp, "cfn=%s\n", (xae_call)->function);
fprintf(fp, "calls=%d 0 0\n", (xae_call)->call_count);
fprintf(fp, "%d %lu %ld\n", (xae_call)->lineno, (unsigned long) ((xae_call)->time_inclusive * 1000000), ((xae_call)->mem_used));
} ZEND_HASH_FOREACH_END();
}
fprintf(fp, "\n");
fflush(fp);

return ZEND_HASH_APPLY_KEEP;
}

int xdebug_profiler_output_aggr_data(const char *prefix)
{
char *filename;
FILE *aggr_file;

fprintf(stderr, "in xdebug_profiler_output_aggr_data() with %d entries\n", zend_hash_num_elements(&XG_PROF(aggr_calls)));

if (zend_hash_num_elements(&XG_PROF(aggr_calls)) == 0) return SUCCESS;

if (prefix) {
filename = xdebug_sprintf("%s/cachegrind.out.aggregate.%s." ZEND_ULONG_FMT, XINI_PROF(profiler_output_dir), prefix, (zend_ulong) xdebug_get_pid());
} else {
filename = xdebug_sprintf("%s/cachegrind.out.aggregate." ZEND_ULONG_FMT, XINI_PROF(profiler_output_dir), (zend_ulong) xdebug_get_pid());
}

fprintf(stderr, "opening %s\n", filename);
aggr_file = xdebug_fopen(filename, "w", NULL, NULL);
if (!aggr_file) {
return FAILURE;
}
fprintf(aggr_file, "version: 0.9.6\ncmd: Aggregate\npart: 1\n\nevents: Time\n\n");
fflush(aggr_file);
zend_hash_apply_with_argument(&XG_PROF(aggr_calls), xdebug_print_aggr_entry, aggr_file);
fclose(aggr_file);
fprintf(stderr, "wrote info for %d entries to %s\n", zend_hash_num_elements(&XG_PROF(aggr_calls)), filename);
return SUCCESS;
}

/* Returns a *pointer* to the current profile filename, if active. NULL
* otherwise. Calling function is responsible for duplicating immediately */
char *xdebug_get_profiler_filename()
@@ -620,34 +484,3 @@ PHP_FUNCTION(xdebug_get_profiler_filename)
RETURN_FALSE;
}
}

PHP_FUNCTION(xdebug_dump_aggr_profiling_data)
{
char *prefix = NULL;
size_t prefix_len;

if (!XINI_PROF(profiler_aggregate)) {
RETURN_FALSE;
}

if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &prefix, &prefix_len) == FAILURE) {
return;
}

if (xdebug_profiler_output_aggr_data(prefix) == SUCCESS) {
RETURN_TRUE;
} else {
RETURN_FALSE;
}
}

PHP_FUNCTION(xdebug_clear_aggr_profiling_data)
{
if (!XINI_PROF(profiler_aggregate)) {
RETURN_FALSE;
}

zend_hash_clean(&XG_PROF(aggr_calls));

RETURN_TRUE;
}
@@ -32,9 +32,6 @@ typedef struct _xdebug_profiler_globals_t {
int profile_last_filename_ref;
xdebug_hash *profile_functionname_refs;
int profile_last_functionname_ref;

/* aggregate profiling */
HashTable aggr_calls;
} xdebug_profiler_globals_t;

typedef struct _xdebug_profiler_settings_t {
@@ -44,7 +41,6 @@ typedef struct _xdebug_profiler_settings_t {
zend_bool profiler_enable_trigger;
char *profiler_enable_trigger_value;
zend_bool profiler_append;
zend_bool profiler_aggregate;
} xdebug_profiler_settings_t;

void xdebug_init_profiler_globals(xdebug_profiler_globals_t *xg);
@@ -62,11 +58,8 @@ void xdebug_profiler_execute_ex_end(function_stack_entry *fse);
void xdebug_profiler_execute_internal(function_stack_entry *fse);
void xdebug_profiler_execute_internal_end(function_stack_entry *fse);

void xdebug_profiler_add_aggregate_entry(function_stack_entry *fse);

void xdebug_profiler_init(char *script_name);
void xdebug_profiler_deinit();
int xdebug_profiler_output_aggr_data(const char *prefix);

void xdebug_profiler_add_function_details_user(function_stack_entry *fse, zend_op_array *op_array);
void xdebug_profiler_add_function_details_internal(function_stack_entry *fse);
@@ -76,11 +69,8 @@ void xdebug_profiler_function_begin(function_stack_entry *fse);
void xdebug_profiler_function_end(function_stack_entry *fse);

void xdebug_profile_call_entry_dtor(void *dummy, void *elem);
void xdebug_profile_aggr_call_entry_dtor(void *elem);

char *xdebug_get_profiler_filename(void);

PHP_FUNCTION(xdebug_get_profiler_filename);
PHP_FUNCTION(xdebug_dump_aggr_profiling_data);
PHP_FUNCTION(xdebug_clear_aggr_profiling_data);
#endif
@@ -120,10 +120,6 @@ ZEND_BEGIN_ARG_INFO_EX(xdebug_start_trace_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VA
ZEND_ARG_INFO(0, options)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(xdebug_dump_aggr_profiling_data_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
ZEND_ARG_INFO(0, prefix)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(xdebug_get_collected_errors_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
ZEND_ARG_INFO(0, clear)
ZEND_END_ARG_INFO()
@@ -183,8 +179,6 @@ zend_function_entry xdebug_functions[] = {
PHP_FE(xdebug_get_tracefile_name, xdebug_void_args)

PHP_FE(xdebug_get_profiler_filename, xdebug_void_args)
PHP_FE(xdebug_dump_aggr_profiling_data, xdebug_dump_aggr_profiling_data_args)
PHP_FE(xdebug_clear_aggr_profiling_data, xdebug_void_args)

PHP_FE(xdebug_start_gcstats, xdebug_start_gcstats_args)
PHP_FE(xdebug_stop_gcstats, xdebug_stop_gcstats_args)
@@ -333,7 +327,6 @@ PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("xdebug.profiler_enable_trigger", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, settings.profiler.profiler_enable_trigger, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.profiler_enable_trigger_value", "", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, settings.profiler.profiler_enable_trigger_value, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.profiler_append", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, settings.profiler.profiler_append, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_BOOLEAN("xdebug.profiler_aggregate", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, settings.profiler.profiler_aggregate, zend_xdebug_globals, xdebug_globals)

/* Remote debugger settings */
STD_PHP_INI_BOOLEAN("xdebug.remote_enable", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, settings.debugger.remote_enable, zend_xdebug_globals, xdebug_globals)

0 comments on commit c9cbd54

Please sign in to comment.
You can’t perform that action at this time.