Index: xdebug.c
===================================================================
RCS file: /repository/xdebug/xdebug.c,v
retrieving revision 1.425
diff -u -r1.425 xdebug.c
--- xdebug.c	30 Apr 2008 14:46:45 -0000	1.425
+++ xdebug.c	5 May 2008 14:59:32 -0000
@@ -332,6 +332,12 @@
 	STD_PHP_INI_ENTRY("xdebug.var_display_max_data",     "512",         PHP_INI_ALL,    OnUpdateLong,   display_max_data,     zend_xdebug_globals, xdebug_globals)
 	STD_PHP_INI_ENTRY("xdebug.var_display_max_depth",    "3",           PHP_INI_ALL,    OnUpdateLong,   display_max_depth,    zend_xdebug_globals, xdebug_globals)
 #endif
+
+	/* slow script log settings */
+	STD_PHP_INI_BOOLEAN("xdebug.slow_script_enable",    "0", PHP_INI_SYSTEM|PHP_INI_PERDIR,    OnUpdateBool,   slow_script_enable,      zend_xdebug_globals, xdebug_globals)
+	STD_PHP_INI_ENTRY("xdebug.slow_script_max_time",    "0",               PHP_INI_ALL,    OnUpdateReal,   slow_script_max_time,    zend_xdebug_globals, xdebug_globals)
+	STD_PHP_INI_ENTRY("xdebug.slow_script_output_dir",  "/tmp",            PHP_INI_ALL,    OnUpdateString, slow_script_output_dir,  zend_xdebug_globals, xdebug_globals)
+	STD_PHP_INI_ENTRY("xdebug.slow_script_output_name", "slowscripts.%c",  PHP_INI_ALL,    OnUpdateString, slow_script_output_name, zend_xdebug_globals, xdebug_globals)
 PHP_INI_END()
 
 static void php_xdebug_init_globals (zend_xdebug_globals *xg TSRMLS_DC)
@@ -846,6 +852,27 @@
 	zend_function *orig;
 #endif
 
+	if (XG(slow_script_enable) && XG(slow_script_max_time)) {
+				
+		double time_difference = xdebug_get_utime() - XG(start_time);
+
+		if (time_difference >= XG(slow_script_max_time)) {
+			if (XG(context).program_name) {
+				char *tmp_fname;
+				char *slow_log_filename;
+				FILE *slow_script_output_file;
+
+				if (strlen(XG(slow_script_output_name)) && 
+					xdebug_format_output_filename(&tmp_fname, XG(slow_script_output_name), NULL, 'c') >= 0) {
+					slow_log_filename = xdebug_sprintf("%s/%s", XG(slow_script_output_dir), tmp_fname);
+					slow_script_output_file = xdebug_fopen(slow_log_filename, "a", "log", NULL);
+					fprintf(slow_script_output_file, "[%s] %0.2lf %s\n", xdebug_get_time(), time_difference, XG(context).program_name);
+					fclose(slow_script_output_file);
+				}
+			}
+		}
+	}
+
 	if (XG(remote_enabled)) {
 		XG(context).handler->remote_deinit(&(XG(context)));
 		xdebug_close_socket(XG(context).socket); 
@@ -2945,7 +2972,7 @@
 		filename = xdstrdup(fname);
 	} else {
 		if (!strlen(XG(trace_output_name)) ||
-			xdebug_format_output_filename(&fname, XG(trace_output_name), NULL) <= 0
+			xdebug_format_output_filename(&fname, XG(trace_output_name), NULL, NULL) <= 0
 		) {
 			/* Invalid or empty xdebug.trace_output_name */
 			return NULL;
Index: usefulstuff.c
===================================================================
RCS file: /repository/xdebug/usefulstuff.c,v
retrieving revision 1.44
diff -u -r1.44 usefulstuff.c
--- usefulstuff.c	8 Jul 2007 20:04:01 -0000	1.44
+++ usefulstuff.c	5 May 2008 14:59:32 -0000
@@ -497,7 +497,7 @@
 }
 #endif
 
-int xdebug_format_output_filename(char **filename, char *format, char *script_name)
+int xdebug_format_output_filename(char **filename, char *format, char *script_name, char accept_only)
 {
 	xdebug_str fname = {0, 0, NULL};
 	char       cwd[128];
@@ -509,6 +509,11 @@
 			xdebug_str_addl(&fname, (char *) format, 1, 0);
 		} else {
 			format++;
+            
+			if (accept_only != NULL && *format != accept_only) {
+				return -1;
+			}
+
 			switch (*format)
 			{
 				case 'c': /* crc32 of the current working directory */
Index: usefulstuff.h
===================================================================
RCS file: /repository/xdebug/usefulstuff.h,v
retrieving revision 1.21
diff -u -r1.21 usefulstuff.h
--- usefulstuff.h	14 May 2007 14:20:40 -0000	1.21
+++ usefulstuff.h	5 May 2008 14:59:32 -0000
@@ -60,7 +60,7 @@
 char *xdebug_path_to_url(const char *fileurl TSRMLS_DC);
 char *xdebug_path_from_url(const char *fileurl TSRMLS_DC);
 FILE *xdebug_fopen(char *fname, char *mode, char *extension, char **new_fname);
-int xdebug_format_output_filename(char **filename, char *format, char *script_name);
+int xdebug_format_output_filename(char **filename, char *format, char *script_name, char accept_only);
 
 #define XDEBUG_CRC32(crc, ch)	 (crc = (crc >> 8) ^ xdebug_crc32tab[(crc ^ (ch)) & 0xff])
 
Index: xdebug_profiler.c
===================================================================
RCS file: /repository/xdebug/xdebug_profiler.c,v
retrieving revision 1.52
diff -u -r1.52 xdebug_profiler.c
--- xdebug_profiler.c	8 Jul 2007 18:35:00 -0000	1.52
+++ xdebug_profiler.c	5 May 2008 14:59:32 -0000
@@ -61,7 +61,7 @@
 	char *filename = NULL, *fname = NULL;
 	
 	if (!strlen(XG(profiler_output_name)) ||
-		xdebug_format_output_filename(&fname, XG(profiler_output_name), script_name) <= 0
+		xdebug_format_output_filename(&fname, XG(profiler_output_name), script_name, NULL) <= 0
 	) {
 		/* Invalid or empty xdebug.profiler_output_name */
 		return FAILURE;

