You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.5 KiB

1 month ago
  1. % Copyright (C) 2001-2023 Artifex Software, Inc.
  2. % All Rights Reserved.
  3. %
  4. % This software is provided AS-IS with no warranty, either express or
  5. % implied.
  6. %
  7. % This software is distributed under license and may not be copied,
  8. % modified or distributed except as expressly authorized under the terms
  9. % of the license contained in the file LICENSE in this distribution.
  10. %
  11. % Refer to licensing information at http://www.artifex.com or contact
  12. % Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  13. % CA 94129, USA, for further information.
  14. %
  15. % Trace individual operators or procedures.
  16. % <opref> is <opname> or <opname> <dict>
  17. % (dict defaults to dict where op is currently defined, if writable;
  18. % otherwise uses userdict)
  19. % <opref> traceop prints vmem usage before;
  20. % <opref> <numargs|preproc> prints arguments or runs proc before;
  21. % <opref> <numargs|preproc> <numresults|postproc>
  22. % also prints results or runs proc after.
  23. % If traceflush is true, flush the output after each printout.
  24. /traceflush true def
  25. currentpacking true setpacking
  26. currentglobal true setglobal
  27. % Define the default "before" action
  28. /tracebefore { vmstatus 3 traceprint pop pop pop } def
  29. % Define the default "after" action
  30. /traceafter { } def
  31. /traceprint {
  32. dup type /integertype eq {
  33. 1 sub -1 0 { ( ) print index ==only } for
  34. } {
  35. exec
  36. } ifelse
  37. } bind def
  38. /traceend {
  39. traceflush { flush } if
  40. } bind def
  41. /traceop {
  42. userdict begin
  43. dup type dup /nametype eq exch /dicttype eq or { { tracebefore } } if
  44. 1 index type dup /nametype eq exch /dicttype eq or { { traceafter } } if
  45. /.tpost exch def /.tpre exch def
  46. dup type /dicttype ne {
  47. dup where not { userdict 1 index {} put userdict } if
  48. } if
  49. dup dup wcheck not {
  50. (Warning: substituting userdict for non-writable dictionary.) =
  51. pop userdict
  52. } if
  53. /.tddict exch def /.tdict exch def /.tname exch cvlit def
  54. currentglobal [
  55. .tname /=only cvx ( ) /print cvx
  56. /.tpre load /traceprint cvx /traceend cvx
  57. .tdict .tname get /.tdef 1 index cvlit def
  58. dup xcheck {
  59. dup type dup /arraytype eq exch /packedarraytype eq or {
  60. /exec cvx
  61. } if
  62. } if
  63. /.tpost load /traceprint cvx () /= cvx /traceend cvx
  64. .tdef gcheck /.tpre load gcheck and /.tpost load gcheck and setglobal
  65. ] cvx
  66. .tdef type /operatortype eq {
  67. .tname exch .makeoperator
  68. } if
  69. exch setglobal
  70. .tddict exch .tname exch put
  71. end % userdict
  72. } bind def
  73. /tracebind /bind load def % in case someone wants to put it back
  74. /bind { } def % disable
  75. setglobal
  76. setpacking