调试技能

2018年9月5日
1.submitToken日志打印分支提交

if ([url containsString:HuFuncItem_updateResourceStudyStatus]) {
            wyLog(@"wy_posturl=%@,param=%@,headerParam=%@",url, param,manager.requestSerializer.HTTPRequestHeaders);
        }

if ([response.URL.absoluteString containsString:HuFuncItem_updateResourceStudyStatus]) {
                wyLog(@"url=%@,responseHeader=%@",response.URL.absoluteString,response.allHeaderFields)
            }

2018年7月18日
1打印当前线程

(lldb) po [NSThread currentThread]
<NSThread: 0x7fd1a7546fb0>{number = 6, name = (null)}
(lldb) po [NSThread currentThread]
<NSThread: 0x7fd1a92073a0>{number = 1, name = main}  如果是主线程会有如下标识

另外gcd计时器 触发接口wy0 和 和超时执行wy1 是同一个子线程,不会让wy1执行多次

dispatch_source_set_event_handler(_timer, ^{
        
         wyLog(@"wy0")
        //时间到了回调
        if (_timeNum <= 0) {
            if(_timeOut){
                _timeOut(); //时间到了回调
            }
        }else{
            _timeNum --;
            
        }
    });
    
    //3.启动timer
    dispatch_resume(_timer);
_coutTimeV.timeOut = ^() {
                [weakSelf uploadPaper:HuUploadTypeTimeOut];
                dispatch_async(dispatch_get_main_queue(), ^{
                    //因为有ui操作所以在主线程上做
                    [weakSelf.coutTimeV endCountDown];
                });
                wyLog(@"wy1")
            }

2017年3月29日
1.文件中文乱码,可以用文本编辑器打开或者转换格式(文本编辑器,另存为 UTF8 编码)

Paste_Image.png

2.如何测试发包到回报时间
法1:自定义宏日志调试(推荐)
效果如下:


Paste_Image.png

实现原理:

#define pLogTime(tag) ([HuConfigration printLogTime:tag])

//  HuConfigration.m
+ (NSDateComponents *)getCurrentDate
{
   // 获取代表公历的NSCalendar对象
   NSCalendar *gregorian = [[NSCalendar alloc]
                            initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
   // 获取当前日期
   NSDate* dt = [NSDate date];
   // 定义一个时间字段的旗标,指定将会获取指定年、月、日、时、分、秒的信息
   unsigned unitFlags = NSCalendarUnitYear |
   NSCalendarUnitMonth |  NSCalendarUnitDay |
   NSCalendarUnitHour |  NSCalendarUnitMinute |
   NSCalendarUnitSecond | NSCalendarUnitWeekday;
   // 获取不同时间字段的信息
   NSDateComponents* comp = [gregorian components: unitFlags
                                         fromDate:dt];
   return comp;
}

+ (void)printLogTime:(NSString*)tag
{
   if ([tag length] <= 0) {
       tag = @"date";
   }
   NSDateComponents *comp = [HuConfigration getCurrentDate];
   NSLog(@"%@=%ld:%ld:%ld",tag,comp.hour,comp.minute,comp.second);
}

法2:发包处

 _currenttime = [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970] * 1;  //NSTimeInterval类型

回包处

 NSTimeInterval temp = [[NSDate dateWithTimeIntervalSinceNow:0] timeIntervalSince1970] * 1;
 NSLog(@"发包到回包的时间  %fms",(temp - _currenttime)*1000);

法3:还有就是直接看输出端日志 在发包和回包处添加NSLog(@"send");NSLog(@"return");
两个时间自己减一下就 以下差不多要6s

Paste_Image.png

如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容