BBAProbeLogInfo.h 1.93 KB
//
//  BBAProbeLogInfo.h
//  BBAAPIRequest
//
//  Created by liumuye on 2021/3/5.
//
//  Copyright © 2021年 baidu. All rights reserved.

#import <Foundation/Foundation.h>
#import "BBABaseAPIRequest.h"
#import "BBAAPIRequestConfiguration.h"

@class BBABaseAPIRequest;

NS_ASSUME_NONNULL_BEGIN

//  探测类型
typedef NS_ENUM(NSInteger, APIRequestProbeType) {
    APIRequestProbeTypeFailure,    // 好网下连续失败
    APIRequestProbeTypeSuccess,    // 弱网下连续成功
    APIRequestProbeTypeTTFBWeak,   // 好网下ttfb慢
    APIRequestProbeTypeTTFBGood    // 弱网下ttfb快
};

/// 记录探测过程, 用于日志打点
@interface BBAProbeLogInfo : NSObject

/// 初始化方法
/// @param type 探测类型
- (instancetype)initWithType:(APIRequestProbeType)type;

/// 增加一条触发探测的日志
/// @param task 触发探测对应的请求
/// @param from 请求业务来源
/// @param subFrom 请求业务子来源
/// @param bdTraceId TraceID
/// @param isSuccess 成功/失败的请求
/// @param ttfb 请求的TTFB
/// @param err 请求错误
- (void)addRequest:(NSURLSessionTask *)task
              from:(APIRequestFrom)from
           subFrom:(APIRequestSubFrom)subFrom
         bdTraceId:(NSString *)bdTraceId
         isSuccess:(BOOL)isSuccess
              ttfb:(NSTimeInterval)ttfb
             error:(NSError * _Nullable)err;

/// 重置日志信息
- (void)reset;

/// 检测前网络质量
@property (nonatomic, assign) NSUInteger netQualityBefore;

/// 检测后网络质量
@property (nonatomic, assign) NSUInteger netQualityAfter;

/// 引起检测的类型 (TTFB、成功、失败)
@property (nonatomic, assign) NSUInteger probeType;

/// 触发探测的请求列表信息
@property (atomic, strong) NSArray <NSDictionary *> *requestInfoList;

/// 检测开始时间
@property (atomic, assign) NSTimeInterval startTime;

/// 检测结束时间
@property (atomic, assign) NSTimeInterval endTime;

@end

NS_ASSUME_NONNULL_END