Advertisement
Danack

StraceAllTheThings

Jul 15th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.20 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Prevent strace from abbreviating arguments?
  4. # You want the -s strsize option, which specifies the maximum length of a string to display (the default is 32).
  5.  
  6.  
  7. # running siege
  8. # siege -d10 -c50 http://basereality.test
  9.  
  10.  
  11. #Before reboot
  12. #[root@vagrant /]# wrk -t12 -c20 -d30s http://basereality.test/
  13. #Running 30s test @ http://basereality.test/
  14. #  12 threads and 20 connections
  15. #  Thread Stats   Avg      Stdev     Max   +/- Stdev
  16. #    Latency   264.55ms   60.96ms 574.54ms   79.09%
  17. #    Req/Sec     3.43      0.97     6.00     80.23%
  18. #  1398 requests in 30.02s, 8.29MB read
  19. #Requests/sec:     46.57
  20. #Transfer/sec:    282.85KB
  21.  
  22.  
  23. # By contrast, -etrace=!open means to trace every system call except open. In addition, the special values all and none have the obvious meanings.
  24. #-etrace=!open
  25. #-e trace=!write.
  26.  
  27. # -s strsize
  28.  
  29. # Specify the maximum string size to print (the default is 32). Note that
  30. # filenames are not considered strings and are always printed in full.
  31.  
  32.  
  33.  
  34. rm -rf trc/*.trc
  35.  
  36. #this check doesn't work, as the script gives a compile error before it's run.
  37. if [[ ! $BASH ]]
  38. then
  39.   echo "This script needs to run in bash, not sh."
  40.   exit -1
  41. fi
  42.  
  43. additional_strace_args="$1"
  44.  
  45. mkdir trc
  46.  
  47. MASTER_PID=$(ps auwx | grep php-fpm | grep -v grep | grep 'master process'  | cut -d ' ' -f 7)
  48.  
  49.  
  50.  
  51. # ls -l /tmp/foobar | awk '{print $1"\t"$9}'
  52. # This code takes some input, such as this:
  53. # -rw-rw-rw-   1 root     root            1 Jul 14  1997 tmpmsg
  54. # and generates output like this:
  55. # -rw-rw-rw-      tmpmsg
  56.  
  57.  
  58.  
  59.  
  60. #shows total of calls
  61. summarise=""
  62. # summarise="-c"
  63. #Jimbo you probably want to start with summarise enabled.
  64.  
  65.  
  66.  
  67. nohup strace -r $summarise -p $MASTER_PID -ff -o ./trc/master.follow.trc >"trc/master.$MASTER_PID.trc" 2>&1 &
  68.  
  69. while read -r pid;
  70. do
  71.     if [[ $pid != $MASTER_PID ]]; then
  72.  
  73.         #shows individual calls
  74.             #nohup strace -r -p "$pid" $additional_strace_args >"trc/$pid.trc" 2>&1 &
  75.  
  76.         #shows total of calls
  77.         nohup strace -r $summarise -p "$pid" $additional_strace_args >"trc/$pid.summary.trc" 2>&1 &
  78.     fi
  79. done < <(pgrep php-fpm)
  80.  
  81. #This needs bash not SH
  82.  
  83. read -p "Strace running - press [Enter] to stop"
  84.  
  85. pkill strace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement