文章目录
一、使用 DYLD_PRINT_STATISTICS
获取启动时间
arguments里面加入环境变量 DYLD_PRINT_STATISTICS
= 1.
具体设置方法可见文章:ios app获取main函数之前的启动时间
https://www.jianshu.com/p/0e91993b2f4a
那么是否还有其他方法可以使用呢?
下面列表展示了 dyld 相关变量
二、DYLD_PRINT 变量列表
可以通过 manual page 来访问
或者在终端中输入 man dyld
DYLD_FRAMEWORK_PATH
DYLD_FALLBACK_FRAMEWORK_PATH
DYLD_VERSIONED_FRAMEWORK_PATH
DYLD_LIBRARY_PATH
DYLD_FALLBACK_LIBRARY_PATH
DYLD_VERSIONED_LIBRARY_PATH
DYLD_PRINT_TO_FILE
DYLD_SHARED_REGION
DYLD_INSERT_LIBRARIES
DYLD_FORCE_FLAT_NAMESPACE
DYLD_IMAGE_SUFFIX
DYLD_PRINT_OPTS
DYLD_PRINT_ENV
DYLD_PRINT_LIBRARIES
DYLD_BIND_AT_LAUNCH
DYLD_DISABLE_DOFS
DYLD_PRINT_APIS
DYLD_PRINT_BINDINGS
DYLD_PRINT_INITIALIZERS
DYLD_PRINT_REBASINGS
DYLD_PRINT_SEGMENTS
DYLD_PRINT_STATISTICS
DYLD_PRINT_DOFS
DYLD_PRINT_RPATHS
DYLD_SHARED_CACHE_DIR
DYLD_SHARED_CACHE_DONT_VALIDATE
这里列举一下常用的以及描述
Environment variable | Description |
---|---|
DYLD_PRINT_LIBRARIES | Logs when images are loaded. 镜像文件加载后打印 |
DYLD_PRINT_LIBRARIES_POST_LAUNCH | Logs when images are loaded as a result of a dlopen call. Includes a dynamic libraries’ dependent libraries. |
DYLD_PRINT_STATISTICS | Logs statistical information on an application’s launch process, such as how many images were loaded, when the application finishes launching. |
DYLD_PRINT_INITIALIZERS | Logs when the dynamic loader calls initializer and finalizer functions. |
DYLD_PRINT_SEGMENTS | Logs when the dynamic loader maps a segment of a dynamic library to the current process’s address space. |
DYLD_PRINT_BINDINGS | Logs when the dynamic loader binds an undefined external symbol with its definition. 动态库绑定未定义的外部符号文件。 |
三、调试示例
1、DYLD_PRINT_LIBRARIES
打印内容如下(不全),这里只截取前面几个文件。
dyld: loaded: /Users/administrator/Library/Developer/CoreSimulator/Devices/7E3D7605-368C-4DA1-BE76-1100849590C3/data/Containers/Bundle/Application/C503DC1E-4CE2-4A7E-A283-6406F6A43595/SocketDemo.app/SocketDemo
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libobjc.A.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libSystem.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit
可以发现,大都是 dylib 或者可执行文件。
2、DYLD_PRINT_LIBRARIES_POST_LAUNCH
dyld: loaded: /Users/administrator/Library/Developer/CoreSimulator/Devices/7E3D7605-368C-4DA1-BE76-1100849590C3/data/Containers/Bundle/Application/6C837C0F-CEDE-4215-B2B4-E67BADAB30BE/SocketDemo.app/SocketDemo
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libobjc.A.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libSystem.dylib
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
dyld: loaded: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/UIKit.framework/UIKit
可以发现,几乎和 DYLD_PRINT_LIBRARIES
一致。
3、DYLD_PRINT_STATISTICS
打印内容如下
Total pre-main time: 1.5 seconds (100.0%)
dylib loading time: 531.66 milliseconds (33.2%)
rebase/binding time: 876.81 milliseconds (54.8%)
ObjC setup time: 60.85 milliseconds (3.8%)
initializer time: 130.36 milliseconds (8.1%)
slowest intializers :
libSystem.dylib : 68.74 milliseconds (4.2%)
libMainThreadChecker.dylib : 43.35 milliseconds (2.7%)
4、DYLD_PRINT_INITIALIZERS
dyld: calling initializer function 0x1014f69ee in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libSystem.dylib
dyld: calling -init function 0x10041632a in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib
dyld: calling initializer function 0x102a172ba in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libc++.1.dylib
dyld: calling -init function 0x1014fe1f0 in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
dyld: calling initializer function 0x10165e8f0 in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
dyld: calling initializer function 0x1058804e0 in /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libnetwork.dylib
5、DYLD_PRINT_SEGMENTS
dyld: Main executable mapped /Users/administrator/Library/Developer/CoreSimulator/Devices/7E3D7605-368C-4DA1-BE76-1100849590C3/data/Containers/Bundle/Application/557FC56B-A0E1-4F55-A06D-AF74862C032F/SocketDemo.app/SocketDemo
__PAGEZERO at 0x00000000->0x100000000
__TEXT at 0x1046E9000->0x1046ED000
__DATA at 0x1046ED000->0x1046EF000
__LINKEDIT at 0x1046EF000->0x1046F7000
dyld: Mapping /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib
__TEXT at 0x10477A000->0x104781FFF with permissions r.x
__DATA at 0x104782000->0x104782FFF with permissions rw.
__LINKEDIT at 0x104783000->0x104788AFF with permissions r..
6、DYLD_PRINT_BINDINGS
一直打印,很疯狂
这就是所谓的动态绑定?
dyld: bind: GeoServices:0x11660C620 = libobjc.A.dylib:__objc_empty_cache, *0x11660C620 = 0x10373A610
dyld: bind: GeoServices:0x11660C648 = libobjc.A.dylib:__objc_empty_cache, *0x11660C648 = 0x10373A610
dyld: bind: GeoServices:0x11660C670 = libobjc.A.dylib:__objc_empty_cache, *0x11660C670 = 0x10373A610
dyld: bind: GeoServices:0x11660C698 = libobjc.A.dylib:__objc_empty_cache, *0x11660C698 = 0x10373A610
dyld: bind: GeoServices:0x11660C6C0 = libobjc.A.dylib:__objc_empty_cache, *0x11660C6C0 = 0x10373A610
dyld: bind: GeoServices:0x11660C6E8 = libobjc.A.dylib:__objc_empty_cache, *0x11660C6E8 = 0x10373A610
dyld: bind: Contacts:0x1142B71C0 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1142B71C0 = 0x103DCAE58
dyld: bind: Contacts:0x1142B71C8 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1142B71C8 = 0x103DCAE58
dyld: bind: Contacts:0x1142B7210 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1142B7210 = 0x103DCAE58
dyld: bind: vCard:0x1173B4DC0 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1173B4DC0 = 0x103DCAE58
dyld: bind: vCard:0x1173B4E08 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1173B4E08 = 0x103DCAE58
dyld: bind: vCard:0x1173B4E10 = libobjc.A.dylib:_OBJC_METACLASS_$_NSObject, *0x1173B4E10 = 0x103DCAE58
dyld: bind: vCard:0x1173A2068 = libobjc.A.dylib:___objc_personality_v0, *0x1173A2068 = 0x10371EF69
dyld: bind: vCard:0x1173B3838 = libobjc.A.dylib:__objc_empty_cache, *0x1173B3838 = 0x10373A610
dyld: bind: vCard:0x1173B3860 = libobjc.A.dylib:__objc_empty_cache, *0x1173B3860 = 0x10373A610
dyld: bind: vCard:0x1173B3888 = libobjc.A.dylib:__objc_empty_cache, *0x1173B3888 = 0x10373A610