HMDBUAppleBacktracesLog.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // HMDBUAppleBacktracesLog.h
  3. // HeimdallrBU
  4. //
  5. // Created by 谢俊逸 on 2019/3/18.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "HMDBUAsyncThread.h"
  9. #import "HMDBUThreadBacktrace.h"
  10. #import "HMDBULog.h"
  11. NS_ASSUME_NONNULL_BEGIN
  12. @interface HMDBUAppleBacktracesLog : NSObject
  13. #pragma mark - deprecated API
  14. + (NSString *)getAllThreadsLogByKeyThread:(thread_t)keyThread
  15. skippedDepth:(NSUInteger)skippedDepth
  16. logType:(HMDBULogType)type __attribute__((deprecated("已废弃,请使用New API")));
  17. + (NSString *)getAllThreadsLogBySkippedDepth:(NSUInteger)skippedDepth
  18. logType:(HMDBULogType)type __attribute__((deprecated("已废弃,请使用New API")));
  19. + (NSString *)getAllThreadsLogByKeyThread:(thread_t)keyThread
  20. skippedDepth:(NSUInteger)skippedDepth
  21. logType:(HMDBULogType)type
  22. exception:(NSString * _Nullable)exceptionField
  23. reason:(NSString * _Nullable)reasonField __attribute__((deprecated("已废弃,请使用New API")));
  24. + (NSString *)getMainThreadLogBySkippedDepth:(NSUInteger)skippedDepth
  25. logType:(HMDBULogType)type __attribute__((deprecated("已废弃,请使用New API")));
  26. + (NSString *)getCurrentThreadLogBySkippedDepth:(NSUInteger)skippedDepth
  27. logType:(HMDBULogType)type __attribute__((deprecated("已废弃,请使用New API")));
  28. + (NSString *)getThreadLog:(thread_t)thread
  29. BySkippedDepth:(NSUInteger)skippedDepth
  30. logType:(HMDBULogType)type __attribute__((deprecated("已废弃,请使用New API")));
  31. #pragma mark - New API
  32. + (thread_t)mainThread;
  33. + (thread_t)currentThread;
  34. /**
  35. * 参数说明:
  36. * @param keyThread 标注为崩溃的线程,Slardar平台根据该线程堆栈进行聚合。
  37. * - 主线程:[HMDBUAppleBacktracesLog mainThread]
  38. * - 当前线程:[HMDBUAppleBacktracesLog currentThread]
  39. * @param skippedDepth 当前调用的线程索要忽略的调用栈深度
  40. * @param maxThreadCount 限制生成日志的最大线程数
  41. * - 0表示不做限制
  42. * - 若当前线程数大于设置最大线程数,取线程队列的前N个生成堆栈信息
  43. * @param suspend 获取线程堆栈时是否对线程进行挂起
  44. * - 挂起线程获取的堆栈准确无误,但会损失部分性能
  45. * - 不进行挂起可能会造成堆栈信息失真
  46. */
  47. // 以下为同步获取log方法,堆栈获取为较耗操作,在主线程时调用,请使用下面的异步方法
  48. + (NSString * _Nullable)getAllThreadsLogByKeyThread:(thread_t)keyThread
  49. maxThreadCount:(NSUInteger)maxThreadCount
  50. skippedDepth:(NSUInteger)skippedDepth
  51. logType:(HMDBULogType)type
  52. suspend:(BOOL)suspend
  53. exception:(NSString * _Nullable)exception
  54. reason:(NSString * _Nullable)reason;
  55. + (NSString * _Nullable)getThreadLogByThread:(thread_t)keyThread
  56. skippedDepth:(NSUInteger)skippedDepth
  57. logType:(HMDBULogType)type
  58. suspend:(BOOL)suspend
  59. exception:(NSString * _Nullable)exception
  60. reason:(NSString * _Nullable)reason;
  61. // 以下为异步方法,在主线程调用推荐使用异步方法避免耗时而卡死
  62. + (void)getAllThreadsLogByKeyThread:(thread_t)keyThread
  63. maxThreadCount:(NSUInteger)maxThreadCount
  64. skippedDepth:(NSUInteger)skippedDepth
  65. logType:(HMDBULogType)type
  66. suspend:(BOOL)suspend
  67. exception:(NSString * _Nullable)exception
  68. reason:(NSString * _Nullable)reason
  69. callback:(void(^)(BOOL success, NSString *log))callback;
  70. + (void)getThreadLogByThread:(thread_t)keyThread
  71. skippedDepth:(NSUInteger)skippedDepth
  72. logType:(HMDBULogType)type
  73. suspend:(BOOL)suspend
  74. exception:(NSString * _Nullable)exception
  75. reason:(NSString * _Nullable)reason
  76. callback:(void(^)(BOOL success, NSString *log))callback;
  77. + (NSString *_Nullable)logWithBacktraces:(NSArray <HMDBUThreadBacktrace *>*)backtraces
  78. type:(HMDBULogType)type
  79. exception:(NSString * _Nullable)exceptionField
  80. reason:(NSString * _Nullable)reasonField;
  81. @end
  82. NS_ASSUME_NONNULL_END