1 | Using Apple's CHUD metering tools from CCL |
---|
2 | ========================================== |
---|
3 | |
---|
4 | Prerequisites |
---|
5 | ------------- |
---|
6 | |
---|
7 | Apple's CHUD metering tools are available (as of this writing) from: |
---|
8 | |
---|
9 | <ftp://ftp.apple.com/developer/Tool_Chest/Testing_-_Debugging/Performance_tools/>. |
---|
10 | |
---|
11 | The CHUD tools are also generally bundled with Apple's XCode tools. |
---|
12 | CBUD 4.5.0 (which seems to be bundled with XCode 3.0) seems to work |
---|
13 | well with this interface; later versions may have problems. |
---|
14 | Versions of CHUD as old as 4.1.1 may work with 32-bit PPC versions |
---|
15 | of CCL; later versions (not sure exactly -what- versions) added |
---|
16 | x86, ppc64, and x86-64 support. |
---|
17 | |
---|
18 | One way to tell whether any version of the CHUD tools is installed |
---|
19 | is to try to invoke the "shark" command-line program (/usr/bin/shark) |
---|
20 | from the shell: |
---|
21 | |
---|
22 | shell> shark --help |
---|
23 | |
---|
24 | and verifying that that prints a usage summary. |
---|
25 | |
---|
26 | CHUD consists of several components, including command-line programs, |
---|
27 | GUI applications, kernel extensions, and "frameworks" (collections of |
---|
28 | libraries, headers, and other resources which applications can use to |
---|
29 | access functionality provided by the other components.) Past versions |
---|
30 | of CCL/OpenMCL have used the CHUD framework libraries to control the |
---|
31 | CHUD profiler. Even though the rest of CHUD is currently 64-bit aware, |
---|
32 | the frameworks are unfortunately still only available as 32-bit libraries, |
---|
33 | so the traditional way of controlling the profiling facility from OpenMCL |
---|
34 | has only worked from DarwinPPC32 versions. |
---|
35 | |
---|
36 | Two of the CHUD component programs are of particular interest: |
---|
37 | |
---|
38 | 1) The "Shark" application (often installed in |
---|
39 | "/Developer/Applications/Performance Tools/Shark.app"), which provides |
---|
40 | a graphical user interface for exploring and analyzing profiling results |
---|
41 | and provides tools for creating "sampling configurations" (see below), |
---|
42 | among other things. |
---|
43 | |
---|
44 | 2) the "shark" program ("/usr/bin/shark"), which can be used to control |
---|
45 | the CHUD profiling facility and to collect sampling data, which can then |
---|
46 | be displayed and analyzed in Shark.app. |
---|
47 | |
---|
48 | The fact that these two (substantially different) programs have names that |
---|
49 | differ only in alphabetic case may be confusing. The discussion below |
---|
50 | tries to consistently distinguish between "the shark program" and "the |
---|
51 | Shark application". |
---|
52 | |
---|
53 | Usage synopsis |
---|
54 | -------------- |
---|
55 | |
---|
56 | ? (defun fact (n) (if (zerop n) 1 (* n (fact (1- n))))) |
---|
57 | FACT |
---|
58 | ? (require "CHUD-METERING") |
---|
59 | "CHUD-METERING" |
---|
60 | ("CHUD-METERING") |
---|
61 | ? (chud:meter (null (fact 10000))) |
---|
62 | NIL ; since that large number is not NULL |
---|
63 | |
---|
64 | and, a few seconds after the result is returned, a file whose |
---|
65 | name is of the form "session_nnn.mshark" will open in Shark.app. |
---|
66 | |
---|
67 | The fist time that CHUD:METER is used in a lisp session, it'll do a |
---|
68 | few things to prepare subsequent profiling sessions. Those things |
---|
69 | include: |
---|
70 | |
---|
71 | 1) creating a directory to store files that are related to using |
---|
72 | the CHUD tools in this lisp session. This directory is created in |
---|
73 | the user's home directory and has a name of the form: |
---|
74 | |
---|
75 | profiling-session-<lisp-kernel>-<pid>_<mm>-<dd>-<yyyy>_<h>.<m>.<s> |
---|
76 | |
---|
77 | where <pid> is the lisp's process id, <lisp-kernel> is the name of |
---|
78 | the lisp kernel (of all things ...), and the other values provide |
---|
79 | a timestamp. |
---|
80 | |
---|
81 | 2) does whatever needs to be done to ensure that currently-defined |
---|
82 | lisp functions don't move around as the result of GC activity, then |
---|
83 | writes a text file describing the names and addresses of those functions |
---|
84 | to the profiling-session directory created above. (The naming conventions |
---|
85 | for and format of that file are described in |
---|
86 | |
---|
87 | <http://developer.apple.com/documentation/DeveloperTools/Conceptual/SharkUserGuide/MiscellaneousTopics/chapter_951_section_4.html#//apple_ref/doc/uid/TP40005233-CH14-DontLinkElementID_42> |
---|
88 | |
---|
89 | 3) run the shark program ("/usr/bin/shark") and wait until it's ready to |
---|
90 | receive signals that control its operation. |
---|
91 | |
---|
92 | This startup activity typically takes a few seconds; after it's been |
---|
93 | completed, subsequent use of CHUD:METER doesn't involve that overhead. |
---|
94 | (See the discussion of :RESET below.) |
---|
95 | |
---|
96 | After any startup activity is complete, CHUD:METER arranges to send |
---|
97 | a "start profiling" signal to the running shark program, executes |
---|
98 | the form, sends a "stop profiling" signal to the shark program, and |
---|
99 | reads its diagnostic output, looking for the name of the ".mshark" |
---|
100 | file it produces. If it's able to find this filename, it arranges |
---|
101 | for "Shark.app" to open it |
---|
102 | |
---|
103 | Profiling "configurations". |
---|
104 | -------------------------- |
---|
105 | |
---|
106 | By default, a shark profiling session will: |
---|
107 | a) use "time based" sampling, to periodically interrupt the lisp |
---|
108 | process and note the value of the program counter and at least |
---|
109 | a few levels of call history. |
---|
110 | b) do this sampling once every millisecond |
---|
111 | c) run for up to 30 seconds, unless told to stop earlier. |
---|
112 | |
---|
113 | This is known as "the default configuration"; it's possible to use |
---|
114 | items on the "Config" menu in the Shark application to create alternate |
---|
115 | configurations which provide different kinds of profiling parameters |
---|
116 | and to save these configurations in files for subsequent reuse. |
---|
117 | (The set of things that CHUD knows how to monitor is large and interesting.) |
---|
118 | |
---|
119 | You use alternate profiling configurations (created and "exported" via |
---|
120 | Shark.app) with CHUD:METER, but the interface is a little awkward. |
---|
121 | |
---|
122 | Reference |
---|
123 | --------- |
---|
124 | |
---|
125 | CHUD:*SHARK-CONFIG-FILE* [Variable] |
---|
126 | |
---|
127 | When non-null, this should be the pathname of an alternate profiling |
---|
128 | configuration file created by the "Config Editor" in Shark.app. |
---|
129 | |
---|
130 | (CHUD:METER form &key (reset nil) (debug-output nil)) [Macro] |
---|
131 | |
---|
132 | Executes FORM (an arbitrary lisp form) and returns whatever result(s) |
---|
133 | it returns, with CHUD profiling enabled during the form's execution. |
---|
134 | Tries to determine the name of the session file (*.mshark) to which |
---|
135 | the shark program wrote profiling data and opens this file in the |
---|
136 | Shark application. |
---|
137 | |
---|
138 | Arguments: |
---|
139 | |
---|
140 | debug-output - when non-nil, causes output generated by the shark program to |
---|
141 | be echoed to *TERMINAL-IO*. For debugging. |
---|
142 | reset - when non-nil, terminates any running instance of the |
---|
143 | shark program created by previous invocations of CHUD:METER |
---|
144 | in this lisp session, generates a new .spatch file |
---|
145 | (describing the names and addresses of lisp functions), |
---|
146 | and starts a new instance of the shark program; if |
---|
147 | CHUD:*SHARK-CONFIG-FILE* is non-NIL when this new instance |
---|
148 | is started, that instance is told to use the specified |
---|
149 | config file for profiling (in lieu of the default profiling |
---|
150 | configuration.) |
---|
151 | |
---|
152 | Acknowledgments |
---|
153 | --------------- |
---|
154 | |
---|
155 | Both Dan Knapp and Hamilton Link have posted similar CHUD interfaces |
---|
156 | to openmcl-devel in the past; Hamilton's also reported bugs in the |
---|
157 | spatch mechanism to CHUD developers (and gotten those bugs fixed.) |
---|