一,什么是GT?
GT(随身调)是APP的随身调试平台,它是直接运行在手机上的“集成调试环境”(IDTE, Integrated Debug Environment)。
利用GT,仅凭一部手机,无需连接电脑,即可对APP进行快速的性能测试(CPU、内存、流量、电量、帧率/流畅度等等)、开发日志的查看、Crash日志查看、网络数据包的抓取、APP内部参数的调试、真机代码耗时统计等。
详情请见官网:http://gt.qq.com
二,如何使用?
1> 导入 GT 包
- 解压以下 GT 压缩文件,把 GT 文件夹导入到工程中(copy items if needed).
- 下载地址http://download.csdn.net/detail/lz465350/9902126
2> 更改 AppDelegate 中的代码
-
AppDelegate.h 中导入头文件,遵循协议
#import <GT/GT.h> #ifdef CONSOLE_DEBUG @interface AppDelegate : UIResponder <UIApplicationDelegate,iConsoleDelegate,GTParaDelegate> #else @interface AppDelegate : UIResponder <UIApplicationDelegate,GTParaDelegate> #endif
-
AppDelegate.h 添加电池属性:
@property (strong, nonatomic) NSTimer *batteryTimer;
-
AppDelegate.m 导入头文件
#import "GTBattery.h"
-
AppDelegate.m application:didFinishLaunchingWithOptions:方法返回值前面加上以下语句
[self initGT];
AppDelegate.m 添加如下五个方法即可:
- (void)switchEnable
{
// NSLog(@"%s in", __FUNCTION__);
self.batteryTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(batteryTimerNotify:) userInfo:nil repeats:YES];
}
- (void)switchDisable
{
// NSLog(@"%s in", __FUNCTION__);
if (self.batteryTimer) {
[self.batteryTimer invalidate];
self.batteryTimer = nil;
}
}
- (void)batteryTimerNotify:(id)sender
{
// NSLog(@"%s in", __FUNCTION__);
// debug
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
// GT_OC_OUT_SET(@"Battery Level", NO, @"%.0f", [[UIDevice currentDevice] batteryLevel] * 100);
GT_OC_OUT_SET(@"Battery Temperature", NO, @"%f", [self batteryTemperature]);
}
- (CGFloat)batteryTemperature
{
static PTVBattery * s_battery = nil;
if (s_battery == nil) {
s_battery = [[PTVBattery alloc] init];
}
[s_battery handleTick];
return s_battery.info.temperature/100.0f;
}
- (void)initGT
{
// [MTA startWithAppkey:@"IP49TXV1MH9M"];
#ifndef GT_DEBUG_DISABLE
NSLog(@"Start GT");
GT_LOG_START("icaftest");
GT_LOG_D("tagFun","%.2lldMB",GT_UTIL_GET_APP_MEM/(1024*1024));
GT_LOG_END("icaftest");
GT_LOG_D("UTIL","cpuUsage:69.");
GT_LOG_D("UTIL","cpuUsage:%f", GT_UTIL_GET_CPU_USAGE);
GT_OC_LOG_D(@"UTIL",@"cpuUsage:%f", GT_UTIL_GET_CPU_USAGE);
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
///GT Usage(合入) 初始化
GT_DEBUG_INIT;
//GT_LOGO_POINT_SET(300,200);
//GT_AC_SHOW;
// GT Usage(合入) 设置GT logo不旋转及支持方向
GT_DEBUG_SET_AUTOROTATE(YES);
GT_DEBUG_SET_SUPPORT_ORIENTATIONS(UIInterfaceOrientationMaskAllButUpsideDown);
// GT Usage(profiler) 打开profiler功能
GT_TIME_SWITCH_SET(YES);
// GT Usage(输入参数) 注册输入参数
NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
GT_OC_IN_REGISTER(@"并发线程数", @"TN", array);
array = [NSArray arrayWithObjects:@"true", @"false", nil];
GT_OC_IN_REGISTER(@"KeepAlive", @"KA", array);
array = [NSArray arrayWithObjects:@"15", @"10", @"20", nil];
GT_OC_IN_REGISTER(@"读超时", @"超时", array);
array = [NSArray arrayWithObjects:@"false", @"true", nil];
GT_OC_IN_REGISTER(@"Cache缓存", @"缓存", array);
array = [NSArray arrayWithObjects:@"150", @"200", nil];
GT_OC_IN_REGISTER(@"AddedMem", @"ADDM", array);
array = [NSArray arrayWithObjects:@"5", @"4", @"3",@"2",@"1",nil];
GT_OC_IN_REGISTER(@"Interval", @"INTE", array);
// GT Usage(输入参数) 设置在悬浮框上展示的输入参数
GT_OC_IN_DEFAULT_ON_AC(@"并发线程数", @"KeepAlive", nil);
// GT Usage(输出参数) 注册输出参数
GT_OC_OUT_REGISTER(@"下载耗时", @"耗时");
GT_OC_OUT_REGISTER(@"实际带宽", @"带宽");
GT_OC_OUT_REGISTER(@"singlePicSpeed", @"SSPD");
GT_OC_OUT_HISTORY_CHECKED_SET(@"下载耗时", YES);
GT_OC_OUT_REGISTER(@"numberOfDownloadedPics", @"NDP");
GT_OC_OUT_REGISTER(@"本次消耗流量", @"流量");
// GT_OC_OUT_WARNING_OUT_OF_RANGE_SET(@"App Smoothness", 2, 60, M_GT_UPPER_WARNING_INVALID);
// debug
GT_OC_OUT_REGISTER(@"Battery Temperature", @"BT");
//GT_OC_OUT_WARNING_OUT_OF_RANGE_SET(@"Battery Level", 1, 0, 75);
GT_OC_OUT_HISTORY_CHECKED_SET(@"Battery Temperature", YES);
GT_OC_OUT_DELEGATE_SET(@"Battery Temperature", self);
// GT Usage(输出参数) 设置在悬浮框上展示的输出参数
GT_OC_OUT_DEFAULT_ON_AC(@"App CPU", @"App Memory", @"App Smoothness");
GT_OC_OUT_DEFAULT_ON_DISABLED(@"singlePicSpeed", @"numberOfDownloadedPics", @"本次消耗流量", nil);
// GT_OUT_MONITOR_INTERVAL_SET(0.1);
// GT_OUT_GATHER_SWITCH_SET(YES);
GT_OC_LOG_D(@"DEMO", @"DEMO GT INIT FINISH.");
NSLog(@"End GT");
#endif
}
三,可能出现的问题
1> GT/GT.h file not found
可以参考文章 http://blog.csdn.net/zhang_biao_1991/article/details/43057159.
- 方法一(添加丢失的编译文件):把 target 和 project 的 Buld settings --> framework search paths都添加上$(PROJECT_DIR)/PandaTV-ios/GT 这一项
- 方法二( 避开Xcode 拖拽引入文件的 bug):删除文件结构中的 GT 包, 把 GT 包文件夹考入到目的路径, 右键"add files to 'xxx' ", 重新编译即可.