cairo-trace 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/sh
  2. prefix=/usr
  3. exec_prefix=/usr
  4. nofile=
  5. flush=
  6. nocallers=
  7. nomarkdirty=
  8. compress=
  9. usage() {
  10. cat << EOF
  11. usage: cairo-trace [--no-file] command
  12. cairo-trace will generate a log of all calls made by command to
  13. cairo. This log will be stored in a file in the local directory
  14. called command.pid.trace.
  15. Whatever else happens is driven by its argument:
  16. --flush - Flush the output trace after every call.
  17. --no-file - Disable the creation of an output file. Outputs to the
  18. terminal instead.
  19. --no-callers - Do not lookup the caller address/symbol/line whilst tracing.
  20. --mark-dirty - Record image data for cairo_mark_dirty() [default]
  21. --no-mark-dirty - Do not record image data for cairo_mark_dirty()
  22. --compress - Compress the output with LZMA
  23. --profile - Combine --no-callers and --no-mark-dirty and --compress
  24. Environment variables understood by cairo-trace:
  25. CAIRO_TRACE_FLUSH - flush the output after every function call.
  26. CAIRO_TRACE_LINE_INFO - emit line information for most function calls.
  27. EOF
  28. exit
  29. }
  30. skip=1
  31. while test $skip -eq 1; do
  32. skip=0
  33. case $1 in
  34. --flush)
  35. skip=1
  36. flush=1
  37. ;;
  38. --no-file)
  39. skip=1
  40. nofile=1
  41. ;;
  42. --no-callers)
  43. skip=1
  44. nocallers=1
  45. ;;
  46. --mark-dirty)
  47. skip=1
  48. nomarkdirty=
  49. ;;
  50. --no-mark-dirty)
  51. skip=1
  52. nomarkdirty=1
  53. ;;
  54. --compress)
  55. skip=1
  56. compress=1
  57. nofile=1
  58. ;;
  59. --profile)
  60. skip=1
  61. compress=1
  62. nomarkdirty=1
  63. nocallers=1
  64. nofile=1
  65. ;;
  66. --version)
  67. echo "cairo-trace, version 1.14.6."
  68. exit
  69. ;;
  70. --help)
  71. usage
  72. ;;
  73. esac
  74. if test $skip -eq 1; then
  75. shift
  76. fi
  77. done
  78. if test $# -eq 0; then
  79. usage
  80. fi
  81. CAIRO_TRACE_PROG_NAME="$1"
  82. export CAIRO_TRACE_PROG_NAME
  83. if test "x$CAIRO_TRACE_SO" = "x"; then
  84. CAIRO_TRACE_SO=""
  85. for lib in /usr/lib/cairo/libcairo-trace.so /usr/lib/cairo/libcairo-trace.so* /usr/lib/cairo/libcairo-trace.*.so ; do
  86. if test -h "$lib" -o -f "$lib"; then
  87. CAIRO_TRACE_SO="$lib"
  88. break
  89. fi
  90. done
  91. fi
  92. if test "x$CAIRO_TRACE_SO" = "x"; then
  93. echo "Could not find the cairo-trace shared library in /usr/lib/cairo/." >&2
  94. echo "Set the CAIRO_TRACE_SO environment variable to the full path of the library." >&2
  95. exit 15
  96. fi
  97. LD_PRELOAD="$CAIRO_TRACE_SO"
  98. DYLD_INSERT_LIBRARIES="$CAIRO_TRACE_SO"
  99. DYLD_FORCE_FLAT_NAMESPACE=1
  100. export LD_PRELOAD
  101. export DYLD_INSERT_LIBRARIES
  102. export DYLD_FORCE_FLAT_NAMESPACE
  103. if test -n "$nocallers"; then
  104. CAIRO_TRACE_LINE_INFO=0
  105. export CAIRO_TRACE_LINE_INFO
  106. fi
  107. if test -n "$nomarkdirty"; then
  108. CAIRO_TRACE_MARK_DIRTY=0
  109. export CAIRO_TRACE_MARK_DIRTY
  110. fi
  111. if test -n "$flush"; then
  112. CAIRO_TRACE_FLUSH=1
  113. export CAIRO_TRACE_FLUSH
  114. fi
  115. if test -z "$nofile"; then
  116. CAIRO_TRACE_OUTDIR=`pwd` "$@"
  117. elif test -n "$compress"; then
  118. name=`basename $1`
  119. echo Generating compressed trace file $name.$$.lzma
  120. CAIRO_TRACE_FD=3 "$@" 3>&1 >/dev/null | lzma -cz9 > $name.$$.lzma
  121. else
  122. CAIRO_TRACE_FD=3 "$@" 3>&1 >/dev/null
  123. fi