Skip to content

Commit

Permalink
Fixed issue #2001: Add 'xdebug.use_compression' setting to turn on/of…
Browse files Browse the repository at this point in the history
…f compression for profiling files
  • Loading branch information
derickr committed Aug 15, 2021
1 parent 7ab872f commit 47e5428
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 20 deletions.
1 change: 1 addition & 0 deletions .azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
configurationName: 'OSX_PHP_80_ZTS'
phpVersion: '8.0.0'
configurationParameters: '--enable-debug --enable-zts'
xdebugConfigurationParameters: '--without-xdebug-compression'
- template: .azure/macos/job.yml
parameters:
configurationName: 'OSX_PHP_74_ZTS'
Expand Down
3 changes: 2 additions & 1 deletion .azure/macos/job.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
configurationName: ''
configurationParameters: ''
xdebugConfigurationParameters: '--with-xdebug-compression'

jobs:
- job: ${{ parameters.configurationName }}
Expand All @@ -14,7 +15,7 @@ jobs:
configurationParameters: ${{ parameters.configurationParameters }}
- script: |
export PATH="/usr/local/bin:$PATH"
phpize && ./configure && make clean && make all && sudo make install
phpize && ./configure ${{ parameters.xdebugConfigurationParameters }} && make clean && make all && sudo make install
displayName: 'Compile Xdebug'
- template: test.yml
parameters:
Expand Down
4 changes: 4 additions & 0 deletions src/lib/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ typedef struct _xdebug_library_settings_t {
char *file_link_format;
char *filename_format;

/* Whether to use zlib compression for profiling and trace files, if ZLIB support
* is enabled */
zend_bool use_compression;

/* variable dumping limitation settings */
zend_long display_max_children;
zend_long display_max_data;
Expand Down
26 changes: 26 additions & 0 deletions src/lib/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,18 @@ void xdebug_print_info(void)
print_feature_row("Tracing", XDEBUG_MODE_TRACING, "trace");

php_info_print_table_end();

/* Optional compiled in features */
php_info_print_table_start();
php_info_print_table_colspan_header(2, (char*) "Optional Features");

#if HAVE_XDEBUG_ZLIB
php_info_print_table_row(2, "Compressed File Support", "yes (gzip)");
#else
php_info_print_table_row(2, "Compressed File Support", "no");
#endif

php_info_print_table_end();
}

PHPAPI extern char *php_ini_opened_path;
Expand Down Expand Up @@ -770,6 +782,16 @@ static void info_modes_set(INTERNAL_FUNCTION_PARAMETERS)
}
}

static void info_extension_flags_set(INTERNAL_FUNCTION_PARAMETERS)
{
array_init_size(return_value, 1);

#if HAVE_XDEBUG_ZLIB
add_next_index_stringl(return_value, "compression", 11);
#endif
}


PHP_FUNCTION(xdebug_info)
{
zend_string *group = NULL;
Expand All @@ -788,6 +810,10 @@ PHP_FUNCTION(xdebug_info)
info_modes_set(INTERNAL_FUNCTION_PARAM_PASSTHRU);
return;
}
if (zend_string_equals_literal(group, "extension-flags")) {
info_extension_flags_set(INTERNAL_FUNCTION_PARAM_PASSTHRU);
return;
}

php_error_docref(NULL, E_WARNING, "The information group '%s' is not available", ZSTR_VAL(group));
}
Expand Down
25 changes: 14 additions & 11 deletions src/lib/usefulstuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,22 +511,26 @@ void xdebug_free_generic_file(xdebug_file *xf)

int xdebug_generic_fopen(xdebug_file *file, const char *filename, const char *mode)
{
if (XINI_LIB(use_compression)) {
#ifdef HAVE_XDEBUG_ZLIB
FILE *tmp_file = xdebug_fopen((char*) filename, mode, "gz", &(file->name));
FILE *tmp_file = xdebug_fopen((char*) filename, mode, "gz", &(file->name));

if (!tmp_file) {
return 0;
}
if (!tmp_file) {
return 0;
}

file->type = XDEBUG_FILE_TYPE_GZ;
file->fp.gz = gzdopen(fileno(tmp_file), mode);
file->type = XDEBUG_FILE_TYPE_GZ;
file->fp.gz = gzdopen(fileno(tmp_file), mode);

if (!file->fp.gz) {
return 0;
}
if (!file->fp.gz) {
return 0;
}

return 1;
return 1;
#else
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "NOZLIB", "Cannot create a compressed file, because support for zlib has not been compiled in");
#endif
}
file->type = XDEBUG_FILE_TYPE_NORMAL;
file->fp.normal = xdebug_fopen((char*) filename, mode, NULL, &(file->name));

Expand All @@ -535,7 +539,6 @@ int xdebug_generic_fopen(xdebug_file *file, const char *filename, const char *mo
}

return 1;
#endif
}

int XDEBUG_ATTRIBUTE_FORMAT(printf, 2, 3) xdebug_generic_fprintf(xdebug_file *file, const char *fmt, ...)
Expand Down
28 changes: 28 additions & 0 deletions tests/profiler/bug02001-no-zlib-compression.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
Test for bug #2001: no zlib, use_compression=1
--SKIPIF--
<?php
require __DIR__ . '/../utils.inc';
check_reqs('!ext-flag compression; !win');
?>
--INI--
xdebug.mode=profile
xdebug.start_with_request=default
xdebug.use_compression=1
xdebug.profiler_output_name=cachegrind.out.%R.end
xdebug.log={TMPDIR}/{RUNID}bug2001-no-zlib-compression.txt
--FILE--
<?php
$file = xdebug_get_profiler_filename();
var_dump($file);
if ($file) {
unlink($file);
}

echo file_get_contents(sys_get_temp_dir() . '/' . getenv('UNIQ_RUN_ID') . 'bug2001-no-zlib-compression.txt' );
unlink (sys_get_temp_dir() . '/' . getenv('UNIQ_RUN_ID') . 'bug2001-no-zlib-compression.txt' );
?>
--EXPECTF--
string(%d) "%send"
[%d] Log opened at %s
[%d] [Config] WARN: Cannot create a compressed file, because support for zlib has not been compiled in
22 changes: 22 additions & 0 deletions tests/profiler/bug02001-no-zlib-no-compression.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Test for bug #2001: no zlib, use_compression=0
--SKIPIF--
<?php
require __DIR__ . '/../utils.inc';
check_reqs('!ext-flag compression; !win');
?>
--INI--
xdebug.mode=profile
xdebug.start_with_request=default
xdebug.use_compression=0
xdebug.profiler_output_name=cachegrind.out.%R.end
--FILE--
<?php
$file = xdebug_get_profiler_filename();
var_dump($file);
if ($file) {
unlink($file);
}
?>
--EXPECTF--
string(%d) "%send"
22 changes: 22 additions & 0 deletions tests/profiler/bug02001-zlib-compression.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Test for bug #2001: zlib, use_compression=1
--SKIPIF--
<?php
require __DIR__ . '/../utils.inc';
check_reqs('ext-flag compression; !win');
?>
--INI--
xdebug.mode=profile
xdebug.start_with_request=default
xdebug.use_compression=1
xdebug.profiler_output_name=cachegrind.out.%R.end
--FILE--
<?php
$file = xdebug_get_profiler_filename();
var_dump($file);
if ($file) {
unlink($file);
}
?>
--EXPECTF--
string(%d) "%send.gz"
22 changes: 22 additions & 0 deletions tests/profiler/bug02001-zlib-no-compression.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Test for bug #2001: zlib, use_compression=0
--SKIPIF--
<?php
require __DIR__ . '/../utils.inc';
check_reqs('ext-flag compression; !win');
?>
--INI--
xdebug.mode=profile
xdebug.start_with_request=default
xdebug.use_compression=0
xdebug.profiler_output_name=cachegrind.out.%R.end
--FILE--
<?php
$file = xdebug_get_profiler_filename();
var_dump($file);
if ($file) {
unlink($file);
}
?>
--EXPECTF--
string(%d) "%send"
13 changes: 12 additions & 1 deletion tests/utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,18 @@ function check_reqs( $req_str )
}
}

if ( substr( $req, 0, 3 ) === 'ext' )
if ( substr( $req, 0, 9 ) === '!ext-flag' )
{
$missing += (int) ( in_array( substr( $req, 10 ), xdebug_info( 'extension-flags' ) ) );
$req = "absence of 'xdebug-" . substr( $req, 10 ) . '\' compile flag';
}

if ( substr( $req, 0, 8 ) === 'ext-flag' )
{
$missing += (int) ( ! in_array( substr( $req, 9 ), xdebug_info( 'extension-flags' ) ) );
$req = "'xdebug-" . substr( $req, 9 ) . '\' compile flag';
}
else if ( substr( $req, 0, 3 ) === 'ext' )
{
$missing += (int) ( ! extension_loaded( substr( $req, 4 ) ) );
$req = "'" . substr( $req, 4 ) . '\' extension';
Expand Down
21 changes: 14 additions & 7 deletions xdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,22 @@ ZEND_INI_DISP(display_start_upon_error)
}


#if HAVE_XDEBUG_ZLIB
# define USE_COMPRESSION_DEFAULT "1"
#else
# define USE_COMPRESSION_DEFAULT "0"
#endif

PHP_INI_BEGIN()
/* Library settings */
PHP_INI_ENTRY( "xdebug.mode", "develop", PHP_INI_SYSTEM, OnUpdateMode)
PHP_INI_ENTRY_EX( "xdebug.start_with_request", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartWithRequest, display_start_with_request)
PHP_INI_ENTRY_EX( "xdebug.start_upon_error", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartUponError, display_start_upon_error)
STD_PHP_INI_ENTRY("xdebug.output_dir", XDEBUG_TEMP_DIR, PHP_INI_ALL, OnUpdateString, settings.library.output_dir, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trigger_value", "", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, settings.library.trigger_value, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.file_link_format", "", PHP_INI_ALL, OnUpdateString, settings.library.file_link_format, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.filename_format", "", PHP_INI_ALL, OnUpdateString, settings.library.filename_format, zend_xdebug_globals, xdebug_globals)
PHP_INI_ENTRY( "xdebug.mode", "develop", PHP_INI_SYSTEM, OnUpdateMode)
PHP_INI_ENTRY_EX( "xdebug.start_with_request", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartWithRequest, display_start_with_request)
PHP_INI_ENTRY_EX( "xdebug.start_upon_error", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartUponError, display_start_upon_error)
STD_PHP_INI_ENTRY("xdebug.output_dir", XDEBUG_TEMP_DIR, PHP_INI_ALL, OnUpdateString, settings.library.output_dir, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.use_compression", USE_COMPRESSION_DEFAULT, PHP_INI_ALL, OnUpdateBool, settings.library.use_compression, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.trigger_value", "", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, settings.library.trigger_value, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.file_link_format", "", PHP_INI_ALL, OnUpdateString, settings.library.file_link_format, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.filename_format", "", PHP_INI_ALL, OnUpdateString, settings.library.filename_format, zend_xdebug_globals, xdebug_globals)

STD_PHP_INI_ENTRY("xdebug.log", "", PHP_INI_ALL, OnUpdateString, settings.library.log, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.log_level", XLOG_DEFAULT, PHP_INI_ALL, OnUpdateLong, settings.library.log_level, zend_xdebug_globals, xdebug_globals)
Expand Down

0 comments on commit 47e5428

Please sign in to comment.