dispatch_timers.d 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/sbin/dtrace -s
  2. /*
  3. * Copyright (c) 2012-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_timers.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. typedef struct dispatch_trace_timer_params_s {
  30. int64_t deadline, interval, leeway;
  31. } *dispatch_trace_timer_params_t;
  32. dispatch$target:libdispatch*.dylib::timer-configure,
  33. dispatch$target:libdispatch*.dylib::timer-program,
  34. dispatch$target:libdispatch*.dylib::timer-wake,
  35. dispatch$target:libdispatch*.dylib::timer-fire /!start/ {
  36. start = walltimestamp;
  37. }
  38. /*
  39. * Trace dispatch timer configuration and programming:
  40. * Timer configuration indicates that dispatch_source_set_timer() was called.
  41. * Timer programming indicates that the dispatch manager is about to sleep
  42. * for 'deadline' ns (but may wake up earlier if non-timer events occur).
  43. * Time parameters are in nanoseconds, a value of -1 means "forever".
  44. *
  45. * probe timer-configure/-program(dispatch_source_t source,
  46. * dispatch_function_t function, dispatch_trace_timer_params_t params)
  47. */
  48. dispatch$target:libdispatch*.dylib::timer-configure,
  49. dispatch$target:libdispatch*.dylib::timer-program {
  50. this->p = (dispatch_trace_timer_params_t)copyin(arg2,
  51. sizeof(struct dispatch_trace_timer_params_s));
  52. printf("%8dus %-15s: 0x%0?p deadline: %11dns interval: %11dns leeway: %11dns",
  53. (walltimestamp-start)/1000, probename, arg0,
  54. this->p ? this->p->deadline : 0, this->p ? this->p->interval : 0,
  55. this->p ? this->p->leeway : 0);
  56. usym(arg1);
  57. printf("\n");
  58. }
  59. dispatch$target:libdispatch*.dylib::timer-configure {
  60. printf(" / --- Begin ustack");
  61. ustack();
  62. printf(" \ --- End ustack\n");
  63. }
  64. /*
  65. * Trace dispatch timer wakes and fires:
  66. * Timer wakes indicate that the dispatch manager woke up due to expiry of the
  67. * deadline for the specified timer.
  68. * Timer fires indicate that that the dispatch manager scheduled the event
  69. * handler of the specified timer for asynchronous execution (may occur without
  70. * a corresponding timer wake if the manager was awake processing other events
  71. * when the timer deadline expired).
  72. *
  73. * probe timer-wake/-fire(dispatch_source_t source,
  74. * dispatch_function_t function)
  75. */
  76. dispatch$target:libdispatch*.dylib::timer-wake,
  77. dispatch$target:libdispatch*.dylib::timer-fire {
  78. printf("%8dus %-15s: 0x%0?p%-70s", (walltimestamp-start)/1000, probename,
  79. arg0, "");
  80. usym(arg1);
  81. printf("\n");
  82. }