Skip to content

Commit d23bdc3

Browse files
committed
feat: add image monitor func.
1 parent 1b87fd9 commit d23bdc3

File tree

12 files changed

+351
-274
lines changed

12 files changed

+351
-274
lines changed

Example/Podfile.lock

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
PODS:
22
- Kingfisher (6.3.1)
3-
- SKApmTools (0.1.0):
3+
- SKApmTools (0.1.1):
4+
- SKApmTools/ANR (= 0.1.1)
5+
- SKApmTools/BackTrace (= 0.1.1)
6+
- SKApmTools/ImageTool (= 0.1.1)
7+
- SKApmTools/ANR (0.1.1):
8+
- SKApmTools/BackTrace
9+
- SKApmTools/BackTrace (0.1.1)
10+
- SKApmTools/ImageTool (0.1.1):
411
- Kingfisher
512

613
DEPENDENCIES:
@@ -16,7 +23,7 @@ EXTERNAL SOURCES:
1623

1724
SPEC CHECKSUMS:
1825
Kingfisher: 016c8b653a35add51dd34a3aba36b580041acc74
19-
SKApmTools: 1cdc19b3bbda3615500e79450155c4eca5d4594f
26+
SKApmTools: 72d09797ece888421c8930658e3c67c500dc2d72
2027

2128
PODFILE CHECKSUM: ef423484222a246d65153af8f35943a888efe5a3
2229

Example/Pods/Local Podspecs/SKApmTools.podspec.json

Lines changed: 27 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 200 additions & 199 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/SKApmTools/SKApmTools-Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/SKApmTools/AppDelegate.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1616

1717
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818

19-
UIImageView.initializeOnceSwift()
20-
// UIImage.initializeOnceSwift()
21-
2219
let root = UINavigationController(rootViewController: ViewController())
2320
root.view.backgroundColor = .white
2421
window?.rootViewController = root

Example/SKApmTools/ViewController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ViewController: UIViewController {
2424
btn.addTarget(self, action: #selector(btnClicked(_:)) , for: .touchUpInside)
2525
view.addSubview(btn)
2626
}
27-
27+
// 1.开启卡顿监测
2828
SKANRMonitor.start()
2929
let datas = SKANRMonitor.getPendingEntities()
3030
print("待处理的卡顿数据数目: \(datas.count)")
@@ -40,7 +40,8 @@ class ViewController: UIViewController {
4040
@objc func btnClicked(_ sender: UIButton) {
4141
if let title = sender.title(for: .normal) {
4242
if (title.elementsEqual("图片检测")) {
43-
print("图片检测")
43+
// 2.开启图片尺寸检查
44+
SKImageMonitor.start()
4445
let ctl = TestLoadImageController()
4546
self.navigationController?.pushViewController(ctl, animated: true)
4647
} else {

README.md

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,67 @@
11
# SKApmTools
22

3+
APM性能优化相关(swift版本 ):ANR卡顿监测、网络优化、内存监控、启动优化、常见crash防护、crash监控上报
34

4-
[![CI Status](https://img.shields.io/travis/Xcoder1011/SKApmTools.svg?style=flat)](https://travis-ci.org/Xcoder1011/SKApmTools)
5-
[![Version](https://img.shields.io/cocoapods/v/SKApmTools.svg?style=flat)](https://cocoapods.org/pods/SKApmTools)
6-
[![License](https://img.shields.io/cocoapods/l/SKApmTools.svg?style=flat)](https://cocoapods.org/pods/SKApmTools)
7-
[![Platform](https://img.shields.io/cocoapods/p/SKApmTools.svg?style=flat)](https://cocoapods.org/pods/SKApmTools)
5+
## Usage
86

9-
APM性能优化相关(swift版本 ):ANR卡顿监测、网络优化、内存监控、启动优化、常见crash防护、crash监控上报
7+
### 1.卡顿监测
8+
9+
开启卡顿监测
10+
11+
```swift
12+
// 1.开启卡顿监测
13+
SKANRMonitor.start()
14+
SKANRMonitor.monitorCallback { curEntity, allEntities in
15+
print("监测到卡顿: \(curEntity.validFunction)")
16+
print(curEntity.threadId)
17+
print(curEntity.occurenceTime)
18+
print(curEntity.validAddress)
19+
print(curEntity.traceContent)
20+
}
21+
```
22+
23+
控制台打印卡顿信息
1024

25+
```swift
26+
27+
监测到卡顿: SKApmTools_Example.ViewController.btnClicked(__C.UIButton) -> ()
28+
259
29+
692678740.80218
30+
0x000000010621ccce
31+
0 Foundation 0x00007ff800c7db5d +[NSThread sleepForTimeInterval:] + 163
32+
1 SKApmTools_Example 0x000000010621ccce SKApmTools_Example.ViewController.btnClicked(__C.UIButton) -> () + 654
33+
2 SKApmTools_Example 0x000000010621cd55 @objc SKApmTools_Example.ViewController.btnClicked(__C.UIButton) -> () + 53
34+
3 UIKitCore 0x0000000107b9cd05 -[UIApplication sendAction:to:from:forEvent:] + 95
35+
4 UIKitCore 0x00000001072fec74 -[UIControl sendAction:to:forEvent:] + 110
36+
5 UIKitCore 0x00000001072ff078 -[UIControl _sendActionsForEvents:withEvent:] + 345
37+
6 UIKitCore 0x00000001072fb203 -[UIButton _sendActionsForEvents:withEvent:] + 148
38+
7 UIKitCore 0x00000001072fd8cf -[UIControl touchesEnded:withEvent:] + 485
39+
8 UIKitCore 0x0000000107be1e95 -[UIWindow _sendTouchesForEvent:] + 1292
40+
9 UIKitCore 0x0000000107be3ef1 -[UIWindow sendEvent:] + 5304
41+
10 UIKitCore 0x0000000107bb77f2 -[UIApplication sendEvent:] + 898
42+
11 UIKitCore 0x0000000107c5ee61 __dispatchPreprocessedEventFromEventQueue + 9381
43+
12 UIKitCore 0x0000000107c61569 __processEventQueue + 8334
44+
13 UIKitCore 0x0000000107c578a1 __eventFetcherSourceCallback + 272
45+
14 CoreFoundation 0x00007ff800387035 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
46+
15 CoreFoundation 0x00007ff800386f74 __CFRunLoopDoSource0 + 157
47+
16 CoreFoundation 0x00007ff800386771 __CFRunLoopDoSources0 + 212
48+
17 CoreFoundation 0x00007ff800380e73 __CFRunLoopRun + 927
49+
18 CoreFoundation 0x00007ff8003806f7 CFRunLoopRunSpecific + 560
50+
19 GraphicsServices 0x00007ff809c5c28a GSEventRunModal + 139
51+
20 UIKitCore 0x0000000107b9662b -[UIApplication _run] + 994
52+
21 UIKitCore 0x0000000107b9b547 UIApplicationMain + 123
53+
22 SKApmTools_Example 0x000000010621e2df main + 63
54+
23 dyld 0x00000001063e32bf start_sim + 10
55+
24 ??? 0x0000000112c83310 0x0 + 4610077456
56+
```
57+
58+
### 2.图片尺寸检测
59+
60+
开启图片尺寸检测
61+
62+
```swift
63+
SKImageMonitor.start()
64+
```
1165

1266
## Example
1367

SKApmTools.podspec

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,34 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'SKApmTools'
11-
s.version = '0.1.0'
12-
s.summary = 'A short description of SKApmTools.'
13-
14-
# This description is used to generate tags and improve search results.
15-
# * Think: What does it do? Why did you write it? What is the focus?
16-
# * Try to keep it short, snappy and to the point.
17-
# * Write the description between the DESC delimiters below.
18-
# * Finally, don't worry about the indent, CocoaPods strips it!
19-
11+
s.version = '0.1.1'
12+
s.summary = 'APM性能优化相关(swift版本 ):ANR卡顿监测、网络优化、内存监控、启动优化、常见crash防护、crash监控上报'
2013
s.description = <<-DESC
21-
TODO: Add long description of the pod here.
14+
APM性能优化相关(swift版本 ):ANR卡顿监测、网络优化、内存监控、启动优化、常见crash防护、crash监控上报
2215
DESC
2316

2417
s.homepage = 'https://github.com/Xcoder1011/SKApmTools'
25-
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
2618
s.license = { :type => 'MIT', :file => 'LICENSE' }
2719
s.author = { 'Xcoder1011' => 'shangkunwu@msn.com' }
2820
s.source = { :git => 'https://github.com/Xcoder1011/SKApmTools.git', :tag => s.version.to_s }
29-
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
3021

3122
s.ios.deployment_target = '10.0'
32-
33-
s.source_files = 'SKApmTools/Classes/**/*.{swift,h,c}'
3423

3524
s.pod_target_xcconfig = {
3625
"DEFINES_MODULE" => "YES"
3726
}
3827

39-
# s.resource_bundles = {
40-
# 'SKApmTools' => ['SKApmTools/Assets/*.png']
41-
# }
42-
43-
# s.public_header_files = 'Pod/Classes/**/*.h'
44-
# s.frameworks = 'UIKit', 'MapKit'
45-
s.dependency 'Kingfisher'
28+
s.subspec 'BackTrace' do |ss|
29+
ss.source_files = 'SKApmTools/Classes/BackTrace/*'
30+
end
31+
32+
s.subspec 'ANR' do |ss|
33+
ss.source_files = 'SKApmTools/Classes/ANR/*'
34+
ss.dependency 'SKApmTools/BackTrace'
35+
end
36+
37+
s.subspec 'ImageTool' do |ss|
38+
ss.source_files = 'SKApmTools/Classes/ImageTool/*'
39+
ss.dependency 'Kingfisher'
40+
end
4641
end

SKApmTools/Classes/ANR/SKANRMonitor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import Foundation
99

10-
@objc open class SKANRMonitor: NSObject{
10+
@objc open class SKANRMonitor: NSObject {
1111

1212
@objc public static let sharedInstance = SKANRMonitor()
1313
/// 单次耗时较长的卡顿阈值: 默认值为300ms,单位:毫秒

0 commit comments

Comments
 (0)