猎豆优选

TBSDKUTUtility.h 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // '########'########::'######:'########:'##:::'##:
  2. // ... ##..::##.... ##'##... ##:##.... ##:##::'##::
  3. // ::: ##::::##:::: ##:##:::..::##:::: ##:##:'##:::
  4. // ::: ##::::########:. ######::##:::: ##:#####::::
  5. // ::: ##::::##.... ##:..... ##:##:::: ##:##. ##:::
  6. // ::: ##::::##:::: ##'##::: ##:##:::: ##:##:. ##::
  7. // ::: ##::::########:. ######::########::##::. ##:
  8. // :::..::::........:::......::........::..::::..::
  9. //
  10. // UTListener.h
  11. // TBSDK
  12. //
  13. // Created by Roger.Mu on 3/19/14.
  14. // Copyright (c) 2014 Taobao.com. All rights reserved.
  15. //
  16. #import <Foundation/Foundation.h>
  17. @protocol MtopLaunchTypeProtocol;
  18. @class MtopExtResponse;
  19. @class MtopExtRequest;
  20. #define UT_TYPE_PERF @"performace"
  21. #define UT_TYPE_TOTALTCP @"totalTcp"
  22. #define UT_TYPE_DEMOTELEVEL @"demote"
  23. #define UT_TYPE_STD @"stdUTLog"
  24. #define UT_TYPE_ERROR @"error"
  25. #define UT_TYPE_MTOPUT @"mtoput"
  26. #define NOTIFICATION_FILE_UPLOADED @"kTBSDKFileUploaded"
  27. // report cache
  28. @interface UTReportDataSet : NSObject
  29. @property (nonatomic, copy) NSNumber *spdyTotalTimes;
  30. @property (nonatomic, copy) NSNumber *spdyTotaldates;
  31. @property (nonatomic, copy) NSNumber *spdyTotalContentLength;
  32. @property (nonatomic, copy) NSNumber *httpTotalTimes;
  33. @property (nonatomic, copy) NSNumber *httpTotalDates;
  34. @property (nonatomic, copy) NSNumber *httpTotalContentLength;
  35. // cache properties
  36. @property (nonatomic, assign) int cacheTotalTimes;
  37. @property (nonatomic, assign) int cacheReadTotalDates;
  38. @property (nonatomic, assign) int cacheReadTotalTimes;
  39. @property (nonatomic, assign) int cacheWriteTotalDates;
  40. @property (nonatomic, assign) int cacheWriteTotalTimes;
  41. @property (nonatomic, assign) int cacheWriteTotalContentLength;
  42. + (UTReportDataSet *)shareInstance;
  43. - (void) saveHttpTotalData:(NSInteger) totalTimes
  44. withTotalDate:(NSNumber *) totalDate
  45. withTotalContentLength:(NSNumber *) totalContentLength;
  46. - (void) saveSPDYTotalData:(NSInteger) totalTimes
  47. withTotalDate:(NSNumber *) totalDate
  48. withTotalContentLength:(NSNumber *) totalContentLength;
  49. // increment tcp link times
  50. - (void) incrementTcpLinks:(NSNumber *) times;
  51. // increment cache hit times
  52. - (void) incrementCacheHitTimes:(NSNumber *) readDate;
  53. // increment cache times
  54. - (void) incrementCacheTimes;
  55. // increment cache
  56. - (void) incrementCacheWrite:(NSNumber *) writeDate withCacheSize: (long) cacheSize;
  57. - (int) getTotalTimes;
  58. - (double) getTotalDates;
  59. - (int) getTotalContantLength;
  60. - (NSInteger) getTcpLinkTimes;
  61. - (NSInteger) getTcpLinkDates;
  62. - (void) cleanAll;
  63. @end
  64. // write log data set of UT framework
  65. @interface UTDataSet : NSObject <NSCopying>
  66. @property (nonatomic, copy) NSNumber *dnsStartTime;
  67. @property (nonatomic, copy) NSNumber *dnsEndTime;
  68. @property (nonatomic, copy) NSString *tcpLinkDate;
  69. @property (nonatomic, copy) NSString *oneWayTime;
  70. @property (nonatomic, copy) NSString *dnsTime;
  71. @property (nonatomic, copy) NSString *utType;
  72. @property (nonatomic, copy) NSString *tcpTotalTimes;
  73. @property (nonatomic, copy) NSString *tcpTotalDates;
  74. @property (nonatomic, copy) NSString *SpdyTotalTimes;
  75. @property (nonatomic, copy) NSString *errorCode;
  76. @property (nonatomic, copy) NSString *errorInfo;
  77. @property (nonatomic, copy) NSString *errorMemo;
  78. @property (nonatomic, assign) int eventid;
  79. @property (nonatomic, copy) NSDictionary *args;
  80. @property (nonatomic, copy) NSString *arg1;
  81. @property (nonatomic, copy) NSString *arg2;
  82. @property (nonatomic, copy) NSString *arg3;
  83. @property (nonatomic, copy) NSString *cacheSwitch;
  84. @property (nonatomic, copy) NSString *cacheHitType;
  85. @property (nonatomic, copy) NSString *expression;
  86. // mtop properties
  87. @property (atomic, assign) CFAbsoluteTime mtopStartTime;
  88. @property (atomic, assign) CFAbsoluteTime mtopEndTime;
  89. @property (nonatomic, assign) CFAbsoluteTime jsonParseStartTime;
  90. @property (nonatomic, assign) CFAbsoluteTime jsonParseEndTime;
  91. @property (nonatomic, assign) CFAbsoluteTime sendWaitStart;
  92. @property (nonatomic, assign) CFAbsoluteTime sendWaitEnd;
  93. @property (nonatomic, copy) NSString *mtopOneWayTime;
  94. @property (nonatomic, copy) NSString *isSync;
  95. //mtop fullTrace measure
  96. @property (nonatomic,copy) NSString *mtopReqProcessStartT;
  97. @property (nonatomic,copy) NSString *mtopRspProcessStartT;
  98. @property (nonatomic,copy) NSString *mtopRspDispatchT;
  99. @property (nonatomic,copy) NSString *mtopRspCbStartT;
  100. @property (nonatomic,copy) NSString *mtopRspCbEndT;
  101. @property (nonatomic,copy) NSString *jsonPraseTime;
  102. -(UTDataSet *)initWithType: (NSString *)utype;
  103. @end
  104. // UT log base object
  105. @interface TBSDKUTUtility : NSObject
  106. // ----- properties -----
  107. @property (nonatomic, strong) NSMutableArray *utCacheArray;
  108. // ----------------------
  109. #pragma mark init
  110. // UT share instance
  111. + (TBSDKUTUtility *)shareInstance;
  112. - (TBSDKUTUtility *)init;
  113. #pragma mark event listener
  114. // dns parse event by listen
  115. - (void)onDnsParseTime: (UTDataSet *) dataSet;
  116. // tcp create link event by listen
  117. - (void)onTcpLinkTime: (long long) startDate withEndDate: (long long) endDate;
  118. // request start event
  119. - (void)onRequestStart: (NSString *) requestType;
  120. // request cache event
  121. - (void)onRequestCache;
  122. // request hit cache event
  123. - (void)onHitedRequestCache: (NSNumber *) readDate;
  124. // request write cache event
  125. - (void)onWriteResponseCache: (NSNumber *) writeDate withCacheSize: (long) cacheSize;
  126. // request end event
  127. - (void)onRequestEnd: (NSString *) requestType
  128. withContentLength: (int) contentLength
  129. withError : (NSError *) error;
  130. // handle error event
  131. - (void)onError: (NSError *) error;
  132. // on times finished event
  133. - (void)onOneTimesFinished: (UTDataSet *) dataSet;
  134. // write UT log
  135. - (void)writeUTLog: (UTDataSet *)dataSet;
  136. #pragma mark notification
  137. // home key event listener
  138. -(void) writeUtLogByHomeKey: (NSNotification *) notification;
  139. // spdy demote event listener
  140. + (void) writeUtLogByDemoteSpdy: (NSString *) errorInfo withUrl:(NSString *) url;
  141. @end
  142. /**
  143. * 全链路埋点类
  144. */
  145. @interface MtopFullTraceUtil : NSObject
  146. + (instancetype)sharedInstance;
  147. - (NSString *)fullTraceID;
  148. - (void)reportTraceData:(NSDictionary<NSString *,NSString *> *)reportData;
  149. - (void)reportTraceData:(MtopExtRequest *)erequest response:(MtopExtResponse *)response;
  150. - (id<MtopLaunchTypeProtocol>)fetchLaunchObj;
  151. @end