-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from zixun/feature/carthage
Feature/carthage
- Loading branch information
Showing
867 changed files
with
54,317 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
github "zixun/AppBaseKit" >= 0.2.0 | ||
github "zixun/Log4G" >= 0.2.0 | ||
github "zixun/AppSwizzle" >= 1.1.1 | ||
github "zixun/AssistiveButton" >= 1.1.0 | ||
github "zixun/ASLEye" >= 1.1.0 | ||
github "zixun/CrashEye" >= 1.1.0 | ||
github "zixun/ANREye" >= 1.1.0 | ||
github "zixun/SystemEye" >= 0.2.0 | ||
github "zixun/NetworkEye" >= 1.1.1 | ||
github "zixun/LeakEye" >= 1.1.1 | ||
|
||
github "marmelroy/FileBrowser" >= 0.2.0 | ||
github "startry/SwViewCapture" >= 1.0.5 | ||
github "stephencelis/SQLite.swift" ~> 0.11.1 | ||
github "eggswift/pull-to-refresh" ~> 2.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
github "eggswift/pull-to-refresh" "2.6" | ||
github "marmelroy/FileBrowser" "0.2.0" | ||
github "startry/SwViewCapture" "1.0.5" | ||
github "stephencelis/SQLite.swift" "0.11.2" | ||
github "zixun/ANREye" "1.1.0" | ||
github "zixun/ASLEye" "1.1.0" | ||
github "zixun/AppBaseKit" "0.2.0" | ||
github "zixun/AppSwizzle" "1.1.1" | ||
github "zixun/AssistiveButton" "1.1.0" | ||
github "zixun/CrashEye" "1.1.0" | ||
github "zixun/LeakEye" "1.1.1" | ||
github "zixun/Log4G" "0.2.0" | ||
github "zixun/NetworkEye" "1.1.1" | ||
github "zixun/SystemEye" "0.2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
build/ | ||
DerivedData/ | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata/ | ||
|
||
## Other | ||
*.moved-aside | ||
*.xcuserstate | ||
|
||
## Obj-C/Swift specific | ||
*.hmap | ||
*.ipa | ||
*.dSYM.zip | ||
*.dSYM | ||
|
||
## Playgrounds | ||
timeline.xctimeline | ||
playground.xcworkspace | ||
|
||
# Swift Package Manager | ||
# | ||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. | ||
# Packages/ | ||
.build/ | ||
|
||
# CocoaPods | ||
# | ||
# We recommend against adding the Pods directory to your .gitignore. However | ||
# you should judge for yourself, the pros and cons are mentioned at: | ||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control | ||
# | ||
Pods/ | ||
|
||
# Carthage | ||
# | ||
# Add this line if you want to avoid checking in source code from Carthage dependencies. | ||
# Carthage/Checkouts | ||
|
||
Carthage/Build | ||
|
||
# fastlane | ||
# | ||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the | ||
# screenshots whenever they are needed. | ||
# For more information about the recommended setup visit: | ||
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md | ||
|
||
fastlane/report.xml | ||
fastlane/Preview.html | ||
fastlane/screenshots | ||
fastlane/test_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# | ||
# Be sure to run `pod lib lint ANREye.podspec' to ensure this is a | ||
# valid spec before submitting. | ||
# | ||
# Any lines starting with a # are optional, but their use is encouraged | ||
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html | ||
# | ||
|
||
Pod::Spec.new do |s| | ||
s.name = 'ANREye' | ||
s.version = '1.1.0' | ||
s.summary = 'Class for monitor excessive blocking on the main thread.' | ||
|
||
s.description = <<-DESC | ||
Class for monitor excessive blocking on the main thread and return the stacetrace of all threads. | ||
DESC | ||
|
||
s.homepage = 'https://github.com/zixun/ANREye' | ||
s.license = { :type => 'MIT', :file => 'LICENSE' } | ||
s.author = { 'zixun' => '[email protected]' } | ||
s.source = { :git => 'https://github.com/zixun/ANREye.git', :tag => s.version.to_s } | ||
s.social_media_url = 'https://twitter.com/zixun_' | ||
|
||
s.ios.deployment_target = '8.0' | ||
s.source_files = 'ANREye/Classes/**/*' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// | ||
// ANREye.swift | ||
// Pods | ||
// | ||
// Created by zixun on 16/12/24. | ||
// | ||
// | ||
|
||
import Foundation | ||
|
||
//-------------------------------------------------------------------------- | ||
// MARK: - ANREyeDelegate | ||
//-------------------------------------------------------------------------- | ||
@objc public protocol ANREyeDelegate: class { | ||
@objc optional func anrEye(anrEye:ANREye, | ||
catchWithThreshold threshold:Double, | ||
mainThreadBacktrace:String?, | ||
allThreadBacktrace:String?) | ||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
// MARK: - ANREye | ||
//-------------------------------------------------------------------------- | ||
open class ANREye: NSObject { | ||
|
||
//-------------------------------------------------------------------------- | ||
// MARK: OPEN PROPERTY | ||
//-------------------------------------------------------------------------- | ||
open weak var delegate: ANREyeDelegate? | ||
|
||
open var isOpening: Bool { | ||
get { | ||
guard let pingThread = self.pingThread else { | ||
return false | ||
} | ||
return !pingThread.isCancelled | ||
} | ||
} | ||
//-------------------------------------------------------------------------- | ||
// MARK: OPEN FUNCTION | ||
//-------------------------------------------------------------------------- | ||
|
||
open func open(with threshold:Double) { | ||
if Thread.current.isMainThread { | ||
AppBacktrace.main_thread_id = mach_thread_self() | ||
}else { | ||
DispatchQueue.main.async { | ||
AppBacktrace.main_thread_id = mach_thread_self() | ||
} | ||
} | ||
|
||
self.pingThread = AppPingThread() | ||
self.pingThread?.start(threshold: threshold, handler: { [weak self] in | ||
guard let sself = self else { | ||
return | ||
} | ||
|
||
let main = AppBacktrace.mainThread() | ||
let all = AppBacktrace.allThread() | ||
sself.delegate?.anrEye?(anrEye: sself, | ||
catchWithThreshold: threshold, | ||
mainThreadBacktrace: main, | ||
allThreadBacktrace: all) | ||
|
||
}) | ||
} | ||
|
||
open func close() { | ||
self.pingThread?.cancel() | ||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
// MARK: LIFE CYCLE | ||
//-------------------------------------------------------------------------- | ||
deinit { | ||
self.pingThread?.cancel() | ||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
// MARK: PRIVATE PROPERTY | ||
//-------------------------------------------------------------------------- | ||
private var pingThread: AppPingThread? | ||
|
||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
// MARK: - GLOBAL DEFINE | ||
//-------------------------------------------------------------------------- | ||
public typealias AppPingThreadCallBack = () -> Void | ||
|
||
//-------------------------------------------------------------------------- | ||
// MARK: - AppPingThread | ||
//-------------------------------------------------------------------------- | ||
private class AppPingThread: Thread { | ||
|
||
func start(threshold:Double, handler: @escaping AppPingThreadCallBack) { | ||
self.handler = handler | ||
self.threshold = threshold | ||
self.start() | ||
} | ||
|
||
override func main() { | ||
|
||
while self.isCancelled == false { | ||
self.isMainThreadBlock = true | ||
DispatchQueue.main.async { | ||
self.isMainThreadBlock = false | ||
self.semaphore.signal() | ||
} | ||
|
||
Thread.sleep(forTimeInterval: self.threshold) | ||
if self.isMainThreadBlock { | ||
self.handler?() | ||
} | ||
|
||
self.semaphore.wait(timeout: DispatchTime.distantFuture) | ||
} | ||
} | ||
|
||
private let semaphore = DispatchSemaphore(value: 0) | ||
|
||
private var isMainThreadBlock = false | ||
|
||
private var threshold: Double = 0.4 | ||
|
||
fileprivate var handler: (() -> Void)? | ||
} |
100 changes: 100 additions & 0 deletions
100
Carthage/Checkouts/ANREye/ANREye/Classes/Backtrace/AppBacktrace.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// AppBacktrace.swift | ||
// Pods | ||
// | ||
// Created by zixun on 16/12/19. | ||
// | ||
// | ||
|
||
import Foundation | ||
|
||
class AppBacktrace: NSObject { | ||
|
||
|
||
class func with(thread: Thread) -> String { | ||
let machThread = self.bs_machThread(from: thread) | ||
return BSBacktraceLogger.backtrace(ofMachthread: machThread) | ||
} | ||
|
||
class func currentThread() -> String { | ||
return self.with(thread: Thread.current) | ||
} | ||
|
||
class func mainThread() -> String { | ||
return self.with(thread: Thread.main) | ||
} | ||
|
||
class func allThread() -> String { | ||
|
||
var threads: thread_act_array_t? = nil | ||
var thread_count = mach_msg_type_number_t() | ||
|
||
if task_threads(mach_task_self_, &(threads), &thread_count) != KERN_SUCCESS { | ||
return "" | ||
} | ||
|
||
var resultString = "Call Backtrace of \(thread_count) threads:\n" | ||
|
||
for i in 0..<thread_count { | ||
let index = Int(i) | ||
let bt = BSBacktraceLogger.backtrace(ofMachthread: threads![index]) | ||
resultString.append(bt!) | ||
} | ||
|
||
return resultString | ||
} | ||
|
||
|
||
|
||
static var main_thread_id: mach_port_t! | ||
|
||
|
||
private class func bs_machThread(from nsthread:Thread) -> thread_t { | ||
|
||
var name:[Int8] = Array(repeating:0, count:256) | ||
|
||
var list: thread_act_array_t? = nil | ||
var count = mach_msg_type_number_t() | ||
|
||
if task_threads(mach_task_self_, &(list), &count) != KERN_SUCCESS { | ||
return mach_thread_self() | ||
} | ||
|
||
let currentTimestamp = NSDate().timeIntervalSince1970 | ||
let originName = nsthread.name | ||
nsthread.name = "\(currentTimestamp)" | ||
|
||
if nsthread.isMainThread { | ||
return self.main_thread_id | ||
} | ||
|
||
for i in 0..<count { | ||
|
||
let index = Int(i) | ||
let pt = pthread_from_mach_thread_np(list![index]) | ||
if nsthread.isMainThread { | ||
|
||
if list![index] == self.main_thread_id { | ||
return list![index] | ||
} | ||
} | ||
|
||
if (pt != nil) { | ||
pthread_getname_np(pt!, &name, name.count) | ||
|
||
print(nsthread.name) | ||
|
||
print(String(utf8String: name)) | ||
|
||
if String(utf8String: name) == nsthread.name { | ||
nsthread.name = originName | ||
return list![index] | ||
} | ||
} | ||
|
||
|
||
} | ||
nsthread.name = originName | ||
return mach_thread_self() | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Carthage/Checkouts/ANREye/ANREye/Classes/Backtrace/BSBacktraceLogger.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// BSBacktraceLogger.h | ||
// BSBacktraceLogger | ||
// | ||
// Created by 张星宇 on 16/8/27. | ||
// Copyright © 2016年 bestswifter. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <mach/mach.h> | ||
#include <dlfcn.h> | ||
#include <pthread.h> | ||
#include <sys/types.h> | ||
#include <limits.h> | ||
#include <string.h> | ||
#include <mach-o/dyld.h> | ||
#include <mach-o/nlist.h> | ||
|
||
@interface BSBacktraceLogger : NSObject | ||
|
||
+ (NSString *)backtraceOfMachthread:(thread_t)thread; | ||
|
||
@end |
Oops, something went wrong.
b649314
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2 #15