dispatch_trace.d 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/sbin/dtrace -s
  2. /*
  3. * Copyright (c) 2010-2013 Apple Inc. All rights reserved.
  4. *
  5. * @APPLE_APACHE_LICENSE_HEADER_START@
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @APPLE_APACHE_LICENSE_HEADER_END@
  20. */
  21. /*
  22. * Usage: dispatch_trace.d -p [pid]
  23. * traced process must have been executed with
  24. * DYLD_LIBRARY_PATH=/usr/lib/system/introspection or with
  25. * DYLD_IMAGE_SUFFIX=_profile or DYLD_IMAGE_SUFFIX=_debug
  26. */
  27. #pragma D option quiet
  28. #pragma D option zdefs
  29. #pragma D option bufsize=16m
  30. BEGIN {
  31. printf("%-8s %-3s %-8s %-35s%-15s%-?s %-43s%-?s %-14s%-?s %s\n",
  32. "Time us", "CPU", "Thread", "Function", "Probe", "Queue", "Label",
  33. "Item", "Kind", "Context", "Symbol");
  34. }
  35. dispatch$target:libdispatch*.dylib::queue-push,
  36. dispatch$target:libdispatch*.dylib::queue-pop,
  37. dispatch$target:libdispatch*.dylib::callout-entry,
  38. dispatch$target:libdispatch*.dylib::callout-return /!start/ {
  39. start = walltimestamp;
  40. }
  41. /*
  42. * Trace queue push and pop operations:
  43. *
  44. * probe queue-push/-pop(dispatch_queue_t queue, const char *label,
  45. * dispatch_object_t item, const char *kind,
  46. * dispatch_function_t function, void *context)
  47. */
  48. dispatch$target:libdispatch*.dylib::queue-push,
  49. dispatch$target:libdispatch*.dylib::queue-pop {
  50. printf("%-8d %-3d 0x%08p %-35s%-15s0x%0?p %-43s0x%0?p %-14s0x%0?p",
  51. (walltimestamp-start)/1000, cpu, tid, probefunc, probename, arg0,
  52. copyinstr(arg1, 42), arg2, copyinstr(arg3, 13), arg5);
  53. usym(arg4);
  54. printf("\n");
  55. }
  56. /*
  57. * Trace callouts to client functions:
  58. *
  59. * probe callout-entry/-return(dispatch_queue_t queue, const char *label,
  60. * dispatch_function_t function, void *context)
  61. */
  62. dispatch$target:libdispatch*.dylib::callout-entry,
  63. dispatch$target:libdispatch*.dylib::callout-return {
  64. printf("%-8d %-3d 0x%08p %-35s%-15s0x%0?p %-43s%-?s %-14s0x%0?p",
  65. (walltimestamp-start)/1000, cpu, tid, probefunc, probename, arg0,
  66. copyinstr(arg1, 42), "", "", arg3);
  67. usym(arg2);
  68. printf("\n");
  69. }