HdM
HdM

Reputation: 169

Tutorial for creating custom Instrument in XCode

I want to create my own custom Instrument in XCode. Unfortunately, I can't seem to find any Tutorial; the only help I found is the manual, which is in my opinion hardly self-contained. Does anyone know of a tutorial? Actually, I would already be happy if I could insepct one custom Instrument (even one of the built-ins), since I can figure the rest out better if I jsut have an example by hand.

In case it's relevant, I am planning on building a time/cpu profiler for JAVA.

Upvotes: 0

Views: 1165

Answers (1)

Swift Dev Journal
Swift Dev Journal

Reputation: 20088

Some of the built-in instruments can be examined. Add an instrument to the trace document window and select it. Choose Instrument > Edit Instrument. If the Edit Instrument menu item is enabled, you can examine that instrument. Some of the built-in instruments that can be examined are Cocoa Layout, Sudden Termination, and the Core Data instruments.

A custom instrument has the following sections: DATA, BEGIN, one or more probes, and END. The DATA section contains global variables. Use the DATA section to supply any variables you want to use in multiple probes. The BEGIN section does any initialization your custom instrument needs. The END section does any cleanup that needs to be performed after the custom instrument runs.

A probe is the custom instrument equivalent of a function in a traditional programming language. You supply a condition that must be met for the probe to fire, a DTrace script to execute, and any data you want to record. Instruments' custom instrument editor provides a UI to supply a condition and choose the data to record.

The site dtrace.org has a guide to DTrace and its scripting language, which should help you learn to write scripts for custom instruments.

Upvotes: 2

Related Questions