devinteske

systop dwatch module

Jul 20th, 2018
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.30 KB | None | 0 0
  1. # -*- tab-width: 4 -*- ;; Emacs
  2. # vi: set filetype=sh tabstop=8 shiftwidth=8 noexpandtab :: Vi/ViM
  3. ############################################################ IDENT(1)
  4. #
  5. # $Title: dwatch(8) profile for top-like syscall $
  6. # $Copyright: 2014-2018 Devin Teske. All rights reserved. $
  7. # $FreeBSD$
  8. #
  9. ############################################################ DESCRIPTION
  10. #
  11. # Every 3 seconds update the screen with syscall histogram.
  12. #
  13. ############################################################ PRAGMAS
  14.  
  15. # Optional: You can override the default pragmas (shown below)
  16.  
  17. DTRACE_PRAGMA="
  18.     option quiet
  19.     option aggsortrev
  20. " # END-QUOTE
  21.  
  22. ############################################################ PROBE
  23.  
  24. : ${PROBE:=profile:::tick-3s}
  25.  
  26. ############################################################ ACTIONS
  27.  
  28. exec 9<<EOF
  29. BEGIN { printf("Sampling ...") } /* probe ID $ID */
  30.  
  31. syscall:::entry /* probe ID $(( $ID + 1 )) */
  32. {
  33.     @num[probefunc,execname] = count();
  34. }
  35.  
  36. END { trunc(@num) } /* probe ID $(( $ID + 2 )) */
  37. EOF
  38. ACTIONS=$( cat <&9 )
  39. ID=$(( $ID + 3 ))
  40.  
  41. ############################################################ EVENT TAG
  42.  
  43. # The EVENT_TAG is run inside the print action after the timestamp has been
  44. # printed. By default, `UID.GID CMD[PID]: ' of the process is printed.
  45. #
  46. # Here we override the default EVENT_TAG to include ANSI cursor-homing and
  47. # screen-clearing codes.
  48.  
  49. size=$( stty size 2> /dev/null )
  50. rows="${size%% *}"
  51. cols="${size#* }"
  52.  
  53. exec 9<<EOF
  54.     printf("\033[H"); /* Position the cursor at top-left */
  55.     printf("\033[J"); /* Clear display from cursor to end */
  56.  
  57.     /* Header line containing probe (left) and date (right) */
  58.     printf("%-*s%s%Y%s\n",
  59.         $(( ${cols:-80} - 20 )), "$PROBE",
  60.         console ? "\033[32m" : "",
  61.         walltimestamp,
  62.         console ? "\033[39m" : "");
  63.  
  64.     /* Column headers */
  65.     printf("%s%8s %-20s %s%s\n",
  66.         console ? "\033[1m" : "",
  67.         "COUNT",
  68.         "SYSCALL",
  69.         "EXECNAME",
  70.         console ? "\033[22m" : "");
  71. EOF
  72. EVENT_TAG=$( cat <&9 )
  73.  
  74. ############################################################ EVENT DETAILS
  75.  
  76. exec 9<<EOF
  77.     printa("%@8u %-20s %s\n", @num);
  78.     trunc(@num);
  79. EOF
  80. EVENT_DETAILS=$( cat <&9 )
  81.  
  82. ################################################################################
  83. # END
  84. ################################################################################
Add Comment
Please, Sign In to add comment