phpspy icon indicating copy to clipboard operation
phpspy copied to clipboard

Add option to retry reading the stack trace of a running application immediately

Open TysonAndre opened this issue 1 year ago • 2 comments

See https://github.com/adsr/phpspy/pull/111#issuecomment-1288298776 for context

--- a/phpspy.c
+++ b/phpspy.c
@@ -428,6 +428,9 @@ int main_pid(pid_t pid) {
         if (opt_pause) rv |= pause_pid(pid);
         rv |= do_trace_ptr(&context);
         if (opt_pause) rv |= unpause_pid(pid);
+        struct timeval cur;
+        gettimeofday(&cur, NULL);
+        fprintf(stderr, "%.6f rv=%d\n", cur.tv_sec + 1.e-6 * cur.tv_usec, (int)rv);

Observed: When copy_proc_mem fails (i.e. both rv != 0 and the context's depth < 0 ) for the first function on the stack trace, it sleeps for --sleep-ms seconds Expected: There should be an option to aggressively retry printing the stack from the first step immediately without sleeping, on failure, so that the phpspy output reflects a running application's stack trace accurately, and has traces from as many milliseconds as possible. (Optionally suppress the repeated warnings until the time elapses or the first success) Alternative: Print a suggestion to use --pause-process when copy_proc_mem fails if that option is not set, mentioning that it is not safe in production

1666575804.829005 rv=0
copy_proc_mem: Failed to copy zfunc; err=Bad address raddr=0x7f7e00000308 size=156
1666575804.839143 rv=0
1666575804.849331 Printed frames 2 skipped 1
0 Phan\Language\Type::make /path/to/phan/src/Phan/Language/Type.php:427
0 Phan\Language\Type::make /path/to/phan/src/Phan/Language/Type.php:427

1666575804.849365 rv=0
copy_proc_mem: Failed to copy zfunc; err=Bad address raddr=0x7f7e00000007 size=156
1666575804.859566 rv=0
copy_proc_mem: Failed to copy zfunc; err=Bad address raddr=0x307 size=156
1666575804.869782 rv=0
0 file_get_contents <internal>:-1
1 Phan\Library\FileCache::getOrReadEntry /path/to/phan/src/Phan/Library/FileCache.php:91
2 Phan\Analysis::parseFile /path/to/phan/src/Phan/Analysis.php:73
3 Phan\Phan::analyzeFileList /path/to/phan/src/Phan/Phan.php:196
4 <main> /path/to/phan/src/phan.php:1
5 <main> /path/to/phan/phan:1

Workarounds

https://github.com/adsr/phpspy#demos doesn't mention --pause-process in the instructions for profiling, but the help text in the README does.

  -S, --pause-process                Pause process while reading stacktrace
                                       (unsafe for production!)

TysonAndre avatar Oct 24 '22 01:10 TysonAndre