<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KDBDallas &#187; DTrace</title>
	<atom:link href="http://kdbdallas.com/category/dtrace/feed/" rel="self" type="application/rss+xml" />
	<link>http://kdbdallas.com</link>
	<description>Mac and iPhone Developer, Lacrosse Fan and Coach, Husband, Father, all in one</description>
	<lastBuildDate>Fri, 13 Jan 2012 21:35:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Log all accessed methods in Objective-C with DTrace</title>
		<link>http://kdbdallas.com/2009/02/07/log-all-accessed-methods-in-objective-c-with-dtrace/</link>
		<comments>http://kdbdallas.com/2009/02/07/log-all-accessed-methods-in-objective-c-with-dtrace/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 07:10:46 +0000</pubDate>
		<dc:creator>Dallas</dc:creator>
				<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Cocoa Touch]]></category>
		<category><![CDATA[DTrace]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://kdbdallas.com/?p=173</guid>
		<description><![CDATA[I have recently been debugging some Objective-C and Cocoa/Cocoa Touch code. Not being familiar with all the code and with a TON of methods being accessed in milliseconds, my attempts at stepping through the code just wasn&#8217;t working, as clicking &#8216;Step Into&#8217; as fast as I could keep up and over an hour of stepping [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently been debugging some Objective-C and Cocoa/Cocoa Touch code.</p>
<p>Not being familiar with all the code and with a TON of methods being accessed in milliseconds, my attempts at stepping through the code just wasn&#8217;t working, as clicking &#8216;Step Into&#8217; as fast as I could keep up and over an hour of stepping through I was still not even close to figuring out what I needed to know.</p>
<p>This lead me to the thought of logging every method that was accessed and then I could step look through it and skip around as needed.<br />
However with 60 some odd files and say maybe 20 methods in each file, that would take a lot of NSLog&#8217;s.<br />
I started looking around and was pointed to bbums blog about <a href="http://www.friday.com/bbum/2008/01/01/objective-c-a-hack-to-log-all-methods/">doing something similar</a>.<br />
However it still would take adding some code, plus I couldn&#8217;t get it working right with the iPhone.</p>
<p>This lead me to wonder about <a href="http://en.wikipedia.org/wiki/Dtrace">DTrace</a>.<br />
After a recent podcast from <a href="http://twitter.com/macdevnet">Scotty</a> at the <a href="http://www.mac-developer-network.com/">Mac Developer Network</a>, featuring <a href="http://cocoasamurai.blogspot.com/">Colin Wheeler</a> talking about DTrace, I have been very interested in learning more about DTrace.</p>
<p>The difficult thing I have been finding is that since DTrace was originally written for Sun, it is hard to find info related to MacOS and more so Cocoa.</p>
<p>I then found a video from Colin about using DTrace with Cocoa and XCode.<br />
<a href="http://www.viddler.com/explore/Machx/videos/8">http://www.viddler.com/explore/Machx/videos/8</a></p>
<p>I wasn&#8217;t able to get what I wanted working, so I hit <a href="http://twitter.com/CocoaSamurai">Colin up on Twitter</a> and then talked to him a bit in email and he pointed me to the <strong>Golden Solution</strong>!</p>
<p>The solution is:<br />
<code>objc$target:::entry{}</code></p>
<p>So I took that and created a DTrace script.<br />
You can grab it here:<br />
<a href='http://kdbdallas.com/wp-content/uploads/2009/02/logallmethodsd.zip'>http://kdbdallas.com/wp-content/uploads/2009/02/logallmethodsd.zip</a></p>
<p>To run it open Terminal and run:<br />
sudo ./logAllMethods.d -p PID</p>
<p>Of course replacing &#8216;PID&#8217; with the PID of your running program and remembering that for DTrace &#8216;sudo&#8217; is required.</p>
<p>Also note that this works for iPhone programs running in the iPhone Simulator.<br />
Just look for the PID of your iPhone app within Activity Monitor once it&#8217;s running in the simulator.</p>
<p>Be careful as depending on the program it can spit out a TON of data VERY quickly.</p>
<p>Running this against Adium for only a fraction of a second gave me a couple hundred lines of output.</p>
<p>The output looks like this:</p>
<p>tesseract:Desktop dallas$ sudo ./logAllMethods.d -p 4371<br />
dtrace: script &#8216;./logAllMethods.d&#8217; matched 71222 probes<br />
CPU     ID                    FUNCTION:NAME<br />
  0  59398                    -retain:entry<br />
  0  34684                    +retain:entry<br />
  0  32061            +idleAllMovies::entry<br />
  0  32062                      -idle:entry<br />
  0  34707                    -retain:entry<br />
  0  32914       -_usingVisualContext:entry<br />
  0  32878        -_resyncNaturalSize:entry<br />
  0  31935                 -loadState:entry<br />
  0  31972               -naturalSize:entry</p>
<p>Hopefully this helps someone out there.<br />
Just remember always use the info I post for good.<br />
(or if its for evil make sure it profitable and then send me a cut)</p>
<p>Once again, special thanks to Colin Wheeler.</p>
]]></content:encoded>
			<wfw:commentRss>http://kdbdallas.com/2009/02/07/log-all-accessed-methods-in-objective-c-with-dtrace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

