一,什么是GT?
GT(隨身調)是APP的隨身調試平臺,它是直接運行在手機上的“集成調試環(huán)境”(IDTE, Integrated Debug Environment)。
利用GT,僅憑一部手機,無需連接電腦,即可對APP進行快速的性能測試(CPU、內存、流量、電量、幀率/流暢度等等)、開發(fā)日志的查看、Crash日志查看、網(wǎng)絡數(shù)據(jù)包的抓取、APP內部參數(shù)的調試、真機代碼耗時統(tǒng)計等。
詳情請見官網(wǎng):http://gt.qq.com
二,如何使用?
1> 導入 GT 包
- 解壓以下 GT 壓縮文件,把 GT 文件夾導入到工程中(copy items if needed).
- 下載地址http://download.csdn.net/detail/lz465350/9902126
2> 更改 AppDelegate 中的代碼
-
AppDelegate.h 中導入頭文件,遵循協(xié)議
#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(輸入?yún)?shù)) 注冊輸入?yún)?shù)
NSArray *array = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
GT_OC_IN_REGISTER(@"并發(fā)線程數(shù)", @"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(輸入?yún)?shù)) 設置在懸浮框上展示的輸入?yún)?shù)
GT_OC_IN_DEFAULT_ON_AC(@"并發(fā)線程數(shù)", @"KeepAlive", nil);
// GT Usage(輸出參數(shù)) 注冊輸出參數(shù)
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(輸出參數(shù)) 設置在懸浮框上展示的輸出參數(shù)
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
}
三,可能出現(xiàn)的問題
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' ", 重新編譯即可.