1""" 2Warning: this script uses an undocumented, private API of the Objective-C 3runtime. 4 5It sometimes is useful to see which Objective-C methods are called in a 6program. Luckily the Objective-C runtime contains a private API for logging 7all method calls. This file shows how to call that API. 8""" 9import objc 10import Foundation 11 12objc.loadBundleFunctions(Foundation.__bundle__, globals(), 13[ 14 ('instrumentObjcMessageSends', objc._C_VOID + 15 objc._C_NSBOOL), 16]) 17 18# To enable 19# - the logfile will be created as ``/tmp/msgSends-<PID>`` (where ``<PID>`` 20# is the process-id of the process that calls the function. 21# - the file contains a list of method names, somethink like this:: 22# 23# - NSClassicMapTable NSClassicMapTable objectForKey: 24# - NSClassicMapTable NSClassicMapTable objectForKey: 25# - NSClassicMapTable NSClassicMapTable objectForKey: 26# + NSObject NSObject alloc 27# + NSObject NSObject allocWithZone: 28# 29# - in PyObjC scripts you'll see a lot of calls that have nothing to do 30# with you're program itself but are generated by the bridge code (such 31# as all NSClassicMapTable calls in the example in the previous item). 32 33instrumentObjcMessageSends(True) 34 35# To disable 36instrumentObjcMessageSends(False) 37