4  * Copyright (c) 2012-2013 Apple Inc. All rights reserved.
 
   6  * @APPLE_APACHE_LICENSE_HEADER_START@
 
   8  * Licensed under the Apache License, Version 2.0 (the "License");
 
   9  * you may not use this file except in compliance with the License.
 
  10  * You may obtain a copy of the License at
 
  12  *     http://www.apache.org/licenses/LICENSE-2.0
 
  14  * Unless required by applicable law or agreed to in writing, software
 
  15  * distributed under the License is distributed on an "AS IS" BASIS,
 
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  17  * See the License for the specific language governing permissions and
 
  18  * limitations under the License.
 
  20  * @APPLE_APACHE_LICENSE_HEADER_END@
 
  24  * Usage: dispatch_timers.d -p [pid]
 
  25  *        traced process must have been executed with
 
  26  *        DYLD_LIBRARY_PATH=/usr/lib/system/introspection or with
 
  27  *        DYLD_IMAGE_SUFFIX=_profile or DYLD_IMAGE_SUFFIX=_debug
 
  30 #pragma D option quiet
 
  31 #pragma D option zdefs
 
  33 typedef struct dispatch_trace_timer_params_s {
 
  34         int64_t deadline, interval, leeway;
 
  35 } *dispatch_trace_timer_params_t;
 
  37 dispatch$target:libdispatch*.dylib::timer-configure,
 
  38 dispatch$target:libdispatch*.dylib::timer-program,
 
  39 dispatch$target:libdispatch*.dylib::timer-wake,
 
  40 dispatch$target:libdispatch*.dylib::timer-fire /!start/ {
 
  41         start = walltimestamp;
 
  45  * Trace dispatch timer configuration and programming:
 
  46  * Timer configuration indicates that dispatch_source_set_timer() was called.
 
  47  * Timer programming indicates that the dispatch manager is about to sleep
 
  48  * for 'deadline' ns (but may wake up earlier if non-timer events occur).
 
  49  * Time parameters are in nanoseconds, a value of -1 means "forever".
 
  51  * probe timer-configure/-program(dispatch_source_t source,
 
  52  *         dispatch_function_t function, dispatch_trace_timer_params_t params)
 
  54 dispatch$target:libdispatch*.dylib::timer-configure,
 
  55 dispatch$target:libdispatch*.dylib::timer-program {
 
  56         this->p = (dispatch_trace_timer_params_t)copyin(arg2,
 
  57                         sizeof(struct dispatch_trace_timer_params_s));
 
  58         printf("%8dus %-15s: 0x%0?p deadline: %11dns interval: %11dns leeway: %11dns",
 
  59                         (walltimestamp-start)/1000, probename, arg0,
 
  60                         this->p ? this->p->deadline : 0, this->p ? this->p->interval : 0,
 
  61                         this->p ? this->p->leeway : 0);
 
  65 dispatch$target:libdispatch*.dylib::timer-configure {
 
  66         printf("              / --- Begin ustack");
 
  68         printf("              \ --- End ustack\n");
 
  72  * Trace dispatch timer wakes and fires:
 
  73  * Timer wakes indicate that the dispatch manager woke up due to expiry of the
 
  74  * deadline for the specified timer.
 
  75  * Timer fires indicate that that the dispatch manager scheduled the event
 
  76  * handler of the specified timer for asynchronous execution (may occur without
 
  77  * a corresponding timer wake if the manager was awake processing other events
 
  78  * when the timer deadline expired).
 
  80  * probe timer-wake/-fire(dispatch_source_t source,
 
  81  *         dispatch_function_t function)
 
  83 dispatch$target:libdispatch*.dylib::timer-wake,
 
  84 dispatch$target:libdispatch*.dylib::timer-fire {
 
  85         printf("%8dus %-15s: 0x%0?p%-70s", (walltimestamp-start)/1000, probename,