home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / uccs / root.14 / udk / usr / ccs / bin / fprof < prev    next >
Text File  |  1998-08-19  |  3KB  |  151 lines

  1. #!/usr/bin/xksh
  2.  
  3. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  4. #                                                                         
  5. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  6. #                   SANTA CRUZ OPERATION INC.                             
  7. #                                                                         
  8. #   The copyright notice above does not evidence any actual or intended   
  9. #   publication of such source code.                                      
  10.  
  11. #    Copyright (c) 1990, 1991, 1992, 1993 Novell, Inc. All Rights Reserved.
  12. #    Copyright (c) 1988, 1990 Novell, Inc. All Rights Reserved.
  13. #      All Rights Reserved
  14.  
  15. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Novell Inc.
  16. #    The copyright notice above does not evidence any
  17. #    actual or intended publication of such source code.
  18.  
  19. #ident    "@(#)fprof:common/fprof.sh    1.4"
  20.  
  21. function usage
  22. {
  23.     echo "Usage:
  24.       fprof [log] . . .
  25.       fprof -C[Logging=on|off,][StartState=on|off,][Accuracy=accurate|normal,][LogPrefix=pathname-for-prefix]
  26.       fprof -s [-C[Logging=on|off,][StartState=on|off,][Accuracy=accurate|normal,][LogPrefix=pathname-for-prefix]] command
  27.       fprof [-o|-O] [-m] log [log] . . ."
  28.     exit 1
  29. }
  30.  
  31. [ -n "$_SECOND_TIME_IN" ] && set -- $_FPROF_ARGS
  32. test= compile= off= on= info= mark= config=
  33. [ ! -r /udk/usr/ccs/lib/fprof.cfg ] || . /udk/usr/ccs/lib/fprof.cfg
  34. _FprofLogging=on
  35. _FprofAccuracy=normal
  36. _FprofLogPrefix=/tmp/out
  37. _FprofStartState=on
  38. while getopts '?C:oOsimc' c
  39. do
  40.     case "$c" in
  41.     C)
  42.         config=on
  43.         OIFS="$IFS"
  44.         IFS=,
  45.         set -A a $OPTARG
  46.         IFS="$OIFS"
  47.         for i in "${a[@]}"
  48.         do
  49.             case "$i" in
  50.             Logging=*|Accuracy=*|LogPrefix=*|StartState=*)
  51.                 export "_Fprof$i"
  52.                 ;;
  53.             *)
  54.                 print -u2 Illegal configuration parameter $i
  55.                 usage
  56.             esac
  57.         done
  58.         ;;
  59.     s)
  60.         test=on
  61.         ;;
  62.     c)
  63.         [ -n "$test" ] && usage
  64.         compile=on
  65.         ;;
  66.     m)
  67.         [ -n "$test" ] && usage
  68.         mark=on
  69.         ;;
  70.     o)
  71.         [ -n "$test" ] && usage
  72.         on=on
  73.         ;;
  74.     i)
  75.         [ -n "$test" ] && usage
  76.         info=on
  77.         ;;
  78.     O)
  79.         [ -n "$test" ] && usage
  80.         off=on
  81.         ;;
  82.     \?)
  83.         usage
  84.         ;;
  85.     *)
  86.         echo Illegal option: $c
  87.         usage
  88.     esac
  89. done
  90.  
  91. let OPTIND=OPTIND-1
  92. shift $OPTIND
  93.  
  94. if [ "$test" ]
  95. then
  96.     exec "$@"
  97. fi
  98.  
  99. if [ "$config" ]
  100. then
  101.     call getuid || {
  102.         print -u2 System-wide configuration requires root privilege
  103.         usage
  104.         exit 1
  105.     }
  106.     echo "Logging=$_FprofLogging\nAccuracy=$_FprofAccuracy\nStartState=$_FprofStartState\nLogPrefix=$_FprofLogPrefix" > /udk/usr/ccs/lib/fprof.cfg
  107.     exit 0
  108. fi
  109. libload /udk/usr/ccs/lib/libfprof.so.1
  110.  
  111. nl='
  112. '
  113. call do_cmdload 2 '@char *[2]:{ "cmdload", "do_cmdload=cmdload" }'
  114. cmdload open output output_until_mark bracket search rewind count close callers callees stats info compile
  115.  
  116. if [ "$compile$mark$on$off$info" ]
  117. then
  118.     [ -n "$1" ] || usage
  119.     open "$@" || {
  120.         echo Cannot open "$@"
  121.         usage
  122.     }
  123.     [ -z "$compile" ] || compile
  124.     [ -z "$mark" ] || call do_mark
  125.     [ -z "$info" ] || info
  126.     [ -z "$on" ] || call do_switch 1
  127.     [ -z "$off" ] || call do_switch 0
  128. elif [ -z "$_SECOND_TIME_IN" ]
  129. then
  130.     export _SECOND_TIME_IN=on
  131.     export _OLDENV=$ENV
  132.     export ENV=$(whence -p $0)
  133.     export _FPROF_ARGS="$@"
  134.     exec /usr/bin/xksh
  135. else
  136.     unset _SECOND_TIME_IN
  137.     unset _FPROF_ARGS
  138.     ENV=$_OLDENV
  139.     unset _OLDENV
  140.     [ -z "$ENV" ] || . $ENV
  141.     PS1='fprof: '
  142.     alias q=exit
  143.     if [ -n "$1" ]
  144.     then
  145.         open "$@" || {
  146.             echo Cannot open "$@"
  147.             usage
  148.         }
  149.     fi
  150. fi
  151.