]> git.saurik.com Git - apple/libdispatch.git/blob - tools/dispatch_trace.d
libdispatch-339.1.9.tar.gz
[apple/libdispatch.git] / tools / dispatch_trace.d
1 #!/usr/sbin/dtrace -s
2
3 /*
4 * Copyright (c) 2010-2013 Apple Inc. All rights reserved.
5 *
6 * @APPLE_APACHE_LICENSE_HEADER_START@
7 *
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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.
19 *
20 * @APPLE_APACHE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * Usage: dispatch_trace.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
28 */
29
30 #pragma D option quiet
31 #pragma D option zdefs
32 #pragma D option bufsize=16m
33
34 BEGIN {
35 printf("%-8s %-3s %-8s %-35s%-15s%-?s %-43s%-?s %-14s%-?s %s\n",
36 "Time us", "CPU", "Thread", "Function", "Probe", "Queue", "Label",
37 "Item", "Kind", "Context", "Symbol");
38 }
39
40 dispatch$target:libdispatch*.dylib::queue-push,
41 dispatch$target:libdispatch*.dylib::queue-pop,
42 dispatch$target:libdispatch*.dylib::callout-entry,
43 dispatch$target:libdispatch*.dylib::callout-return /!start/ {
44 start = walltimestamp;
45 }
46
47 /*
48 * Trace queue push and pop operations:
49 *
50 * probe queue-push/-pop(dispatch_queue_t queue, const char *label,
51 * dispatch_object_t item, const char *kind,
52 * dispatch_function_t function, void *context)
53 */
54 dispatch$target:libdispatch*.dylib::queue-push,
55 dispatch$target:libdispatch*.dylib::queue-pop {
56 printf("%-8d %-3d 0x%08p %-35s%-15s0x%0?p %-43s0x%0?p %-14s0x%0?p",
57 (walltimestamp-start)/1000, cpu, tid, probefunc, probename, arg0,
58 copyinstr(arg1, 42), arg2, copyinstr(arg3, 13), arg5);
59 usym(arg4);
60 printf("\n");
61 }
62
63 /*
64 * Trace callouts to client functions:
65 *
66 * probe callout-entry/-return(dispatch_queue_t queue, const char *label,
67 * dispatch_function_t function, void *context)
68 */
69 dispatch$target:libdispatch*.dylib::callout-entry,
70 dispatch$target:libdispatch*.dylib::callout-return {
71 printf("%-8d %-3d 0x%08p %-35s%-15s0x%0?p %-43s%-?s %-14s0x%0?p",
72 (walltimestamp-start)/1000, cpu, tid, probefunc, probename, arg0,
73 copyinstr(arg1, 42), "", "", arg3);
74 usym(arg2);
75 printf("\n");
76 }