Tuesday, May 27, 2008

DTrace for Cocoa Developers

Update: Sorry people I didn't know the default Viddler downloading permissions. If you logged in and tried to download the video and couldn't before, login again and you should be able to download it now.

So in this Screencast Im going to show you how to use DTrace and how to ultimately turn that knowledge into a custom DTrace Instrument for Instruments. Honestly I would login and download the full quality version of this from Viddler. I apologize for the hisses in the s's that I make, I was slightly tired and trying to control that. As always if I said something wrong and made a mistake please let me know right away and i'll make a correction here.

DTrace Examples in the movie

Example #1

colinw$ sudo dtrace -n 'syscall:::/execname == "Safari"/{@num[probefunc] = count();}' -q ^C

lstat 2 sigaltstack 2 sigprocmask 2 stat 2 getuid 16 mmap 32 munmap 36 geteuid 94 gettimeofday 128 stat64 248

Example #2

colinw$ sudo dtrace -n 'syscall::*open*:entry{printf("%s %s",execname,copyinstr(arg0));}' dtrace: description 'syscall::*open*:entry' matched 7 probes CPU ID FUNCTION:NAME 0 17604 open:entry mds . 1 17604 open:entry nmbd /private/var/samba/browse.dat. 0 17604 open:entry Safari /.vol/234881026/1644952 1 17604 open:entry mdworker /private/var/samba/browse.dat 1 17604 open:entry mds . 1 17604 open:entry Safari /.vol/234881026/230745/QuickTime Preferences ^C

Example #3

colinw$ sudo dtrace -n 'syscall:::/execname == "Safari"/{@num[ustack()] = count();}' -q Password: ^C

libSystem.B.dylib`sendto$UNIX2003+0xa CoreFoundation`__CFSocketEnableCallBacks+0x255 CoreFoundation`CFSocketEnableCallBacks+0x4f CFNetwork`_SocketStreamRead+0x5e5 CoreFoundation`CFReadStreamRead+0x1dd CFNetwork`httpRdFilterRead+0x5ef CoreFoundation`CFReadStreamRead+0x1dd CFNetwork`httpStreamRead+0x2aa CoreFoundation`CFReadStreamRead+0x1dd CFNetwork`httpReadStreamCB+0x94 CoreFoundation`_CFStreamSignalEventSynch+0x89 CoreFoundation`CFRunLoopRunSpecific+0xca8 CoreFoundation`CFRunLoopRunInMode+0x58 Foundation`+[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:]+0x140 Foundation`-[NSThread main]+0x2d Foundation`__NSThread__main__+0x134 libSystem.B.dylib`_pthread_start+0x141 libSystem.B.dylib`thread_start+0x22 2

Example #4

sh-3.2# dtrace -n 'objc16675:NSMutableArray::entry{@num[ustack()] = count();}' dtrace: description 'objc16675:NSMutableArray::entry' matched 24 probes ^C

CoreFoundation`+[NSMutableArray arrayWithCapacity:] Keynote`0x201ab Keynote`0x35289 Keynote`0x9d981 AppKit`-[NSWindow makeFirstResponder:]+0x12e Keynote`0xa1b29 AppKit`-[NSWindow sendEvent:]+0x1505 Keynote`0x18c7e7 AppKit`-[NSApplication sendEvent:]+0xadc SFApplication`-[SFAppApplication sendEvent:]+0x283 Keynote`0x26d69 AppKit`-[NSApplication run]+0x34f Keynote`0x352f Keynote`0x34a5 Keynote`0x4cc36 Keynote`0x4cb5d 0x2 1

Useful DTrace Links Solaris DTrace Guide (PDF) from Sun Solaris DTrace Guide (HTML) from Sun DTrace Review (Google Tech Talk) MacTech: Exploring Leopard with DTrace

Friday, May 09, 2008

I am on the Mac Developer Roundtable 007 Source Code Management

I was an invited guest on the Mac Developer Roundtable and came on to talk Source Code Management and to advocate for GIT. It was my first time ever on a podcast and I was a bit nervous, still listening to the first part of it right now, but it sounds pretty good so far. Please forgive all the "uhs" I do, Im normally a lot more confident speaking publicly, but I didn't know what to expect on the podcast. Give it a listen and let me know what you think. Be gentle, it's my first time :P ... Mac Developer Roundtable Episode 007 - Source Code Management My Recommendations from the podcast F-Script If I remember correctly, I think I just glanced over F-Script and didn't give it much explanation. Im a huge fan of creating experimental projects and playing around with API's and that's one reason Im a fan of F-Script because then I don't have 30 small projects cluttering up my desktop or a temp directory and so now I do much less tiny projects in Xcode and use F-Script to see how the API's work. You can start F-Script up in a console and create an app from scratch or just create temp objects and see how they work and play around with Cocoa in a way that's not possible in Xcode without creating loads of small projects. You can download F-Script from http://www.fscript.org/ though if you are on Leopard you will need to download and install a special version of FScript Anywhere from http://osiris.laya.com/blog/?p=24 Mac OS X Internals Mac OS X Internals is a great book explaining the guts of Mac OS X and its individual components to you in how they work and comes with many source code examples to demo what's going on. It's a very big book, but it's well worth it for the content it offers you. The books website is at http://www.osxbook.com/

 
...