提交 5f6d8e36 编写于 作者: Y yixiang

性能曲线图 代码重构,代码收口到基类

上级 038c2053
......@@ -6,10 +6,18 @@
//
#import <UIKit/UIKit.h>
#import "DoraemonOscillogramView.h"
@interface DoraemonOscillogramViewController : UIViewController
@property (nonatomic, strong) DoraemonOscillogramView *oscillogramView;
- (NSString *)title;
- (NSString *)lowValue;
- (NSString *)highValue;
- (void)closeBtnClick;
- (void)startRecord;
- (void)endRecord;
- (void)doSecondFunction;
@end
......@@ -10,9 +10,74 @@
@interface DoraemonOscillogramViewController ()
//每秒运行一次
@property (nonatomic, strong) NSTimer *secondTimer;
@end
@implementation DoraemonOscillogramViewController
- (void)viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[self setEdgesForExtendedLayout:UIRectEdgeNone];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = [self title];
titleLabel.font = [UIFont systemFontOfSize:kDoraemonSizeFrom750_Landscape(20)];
titleLabel.textColor = [UIColor whiteColor];
[self.view addSubview:titleLabel];
[titleLabel sizeToFit];
titleLabel.frame = CGRectMake(kDoraemonSizeFrom750_Landscape(20), IPHONE_TOPSENSOR_HEIGHT + kDoraemonSizeFrom750_Landscape(10), titleLabel.doraemon_width, titleLabel.doraemon_height);
UIButton *closeBtn = [[UIButton alloc] init];
[closeBtn setImage:[UIImage doraemon_imageNamed:@"doraemon_close_white"] forState:UIControlStateNormal];
closeBtn.frame = CGRectMake((kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight)-kDoraemonSizeFrom750_Landscape(60), IPHONE_TOPSENSOR_HEIGHT, kDoraemonSizeFrom750_Landscape(60), kDoraemonSizeFrom750_Landscape(60));
[closeBtn addTarget:self action:@selector(closeBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:closeBtn];
_oscillogramView = [[DoraemonOscillogramView alloc] initWithFrame:CGRectMake(0, titleLabel.doraemon_bottom+kDoraemonSizeFrom750_Landscape(24), (kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight), kDoraemonSizeFrom750_Landscape(400))];
_oscillogramView.backgroundColor = [UIColor clearColor];
[_oscillogramView setLowValue:[self lowValue]];
[_oscillogramView setHightValue:[self highValue]];
[self.view addSubview:_oscillogramView];
}
- (NSString *)title{
return @"";
}
- (NSString *)lowValue{
return @"0";
}
- (NSString *)highValue{
return @"100";
}
- (void)closeBtnClick{
}
- (void)startRecord{
if(!_secondTimer){
_secondTimer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(doSecondFunction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_secondTimer forMode:NSRunLoopCommonModes];
}
}
- (void)doSecondFunction{
}
- (void)endRecord{
if(_secondTimer){
[_secondTimer invalidate];
_secondTimer = nil;
[self.oscillogramView clear];
}
}
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
dispatch_async(dispatch_get_main_queue(), ^{
......
......@@ -14,11 +14,6 @@
@interface DoraemonCPUOscillogramViewController ()
@property (nonatomic, strong) DoraemonOscillogramView *oscillogramView;
//每秒运行一次
@property (nonatomic, strong) NSTimer *secondTimer;
@end
......@@ -26,49 +21,23 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[self setEdgesForExtendedLayout:UIRectEdgeNone];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = DoraemonLocalizedString(@"CPU检测");
titleLabel.font = [UIFont systemFontOfSize:kDoraemonSizeFrom750_Landscape(20)];
titleLabel.textColor = [UIColor whiteColor];
[self.view addSubview:titleLabel];
[titleLabel sizeToFit];
titleLabel.frame = CGRectMake(kDoraemonSizeFrom750_Landscape(20), IPHONE_TOPSENSOR_HEIGHT + kDoraemonSizeFrom750_Landscape(10), titleLabel.doraemon_width, titleLabel.doraemon_height);
UIButton *closeBtn = [[UIButton alloc] init];
[closeBtn setImage:[UIImage doraemon_imageNamed:@"doraemon_close_white"] forState:UIControlStateNormal];
closeBtn.frame = CGRectMake((kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight)-kDoraemonSizeFrom750_Landscape(60), IPHONE_TOPSENSOR_HEIGHT, kDoraemonSizeFrom750_Landscape(60), kDoraemonSizeFrom750_Landscape(60));
[closeBtn addTarget:self action:@selector(closeBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:closeBtn];
_oscillogramView = [[DoraemonOscillogramView alloc] initWithFrame:CGRectMake(0, titleLabel.doraemon_bottom+kDoraemonSizeFrom750_Landscape(24), (kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight), kDoraemonSizeFrom750_Landscape(400))];
_oscillogramView.backgroundColor = [UIColor clearColor];
[_oscillogramView setLowValue:@"0"];
[_oscillogramView setHightValue:@"100"];
[self.view addSubview:_oscillogramView];
}
- (void)closeBtnClick{
[[DoraemonCacheManager sharedInstance] saveCpuSwitch:NO];
[[DoraemonCPUOscillogramWindow shareInstance] hide];
- (NSString *)title{
return DoraemonLocalizedString(@"CPU检测");
}
- (void)startRecord{
if(!_secondTimer){
_secondTimer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(doSecondFunction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_secondTimer forMode:NSRunLoopCommonModes];
}
- (NSString *)lowValue{
return @"0";
}
- (void)endRecord{
if(_secondTimer){
[_secondTimer invalidate];
_secondTimer = nil;
[_oscillogramView clear];
}
- (NSString *)highValue{
return @"100";
}
- (void)closeBtnClick{
[[DoraemonCacheManager sharedInstance] saveCpuSwitch:NO];
[[DoraemonCPUOscillogramWindow shareInstance] hide];
}
//每一秒钟采样一次cpu使用率
......@@ -81,7 +50,7 @@
}
// 0~100 对应 高度0~_oscillogramView.doraemon_height
NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
[_oscillogramView addHeightValue:cpuUsage*_oscillogramView.doraemon_height/100. andTipValue:[NSString stringWithFormat:@"%.f",cpuUsage]];
[self.oscillogramView addHeightValue:cpuUsage*self.oscillogramView.doraemon_height/100. andTipValue:[NSString stringWithFormat:@"%.f",cpuUsage]];
}
@end
......@@ -15,7 +15,6 @@
@interface DoraemonFPSOscillogramViewController ()
@property (nonatomic, strong) DoraemonOscillogramView *oscillogramView;
@property (nonatomic, strong) DoraemonFPSUtil *fpsUtil;
@end
......@@ -24,35 +23,21 @@
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[self setEdgesForExtendedLayout:UIRectEdgeNone];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = DoraemonLocalizedString(@"帧率检测");
titleLabel.font = [UIFont systemFontOfSize:kDoraemonSizeFrom750_Landscape(20)];
titleLabel.textColor = [UIColor whiteColor];
[self.view addSubview:titleLabel];
[titleLabel sizeToFit];
titleLabel.frame = CGRectMake(kDoraemonSizeFrom750_Landscape(20), IPHONE_TOPSENSOR_HEIGHT + kDoraemonSizeFrom750_Landscape(10), titleLabel.doraemon_width, titleLabel.doraemon_height);
UIButton *closeBtn = [[UIButton alloc] init];
[closeBtn setImage:[UIImage doraemon_imageNamed:@"doraemon_close_white"] forState:UIControlStateNormal];
closeBtn.frame = CGRectMake((kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight)-kDoraemonSizeFrom750_Landscape(60), IPHONE_TOPSENSOR_HEIGHT, kDoraemonSizeFrom750_Landscape(60), kDoraemonSizeFrom750_Landscape(60));
[closeBtn addTarget:self action:@selector(closeBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:closeBtn];
_oscillogramView = [[DoraemonOscillogramView alloc] initWithFrame:CGRectMake(0, titleLabel.doraemon_bottom+kDoraemonSizeFrom750_Landscape(24), (kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight), kDoraemonSizeFrom750_Landscape(400))];
_oscillogramView.backgroundColor = [UIColor clearColor];
[_oscillogramView setLowValue:@"0"];
[_oscillogramView setHightValue:@"60"];
[self.view addSubview:_oscillogramView];
}
- (NSString *)title{
return DoraemonLocalizedString(@"帧率检测");
}
- (NSString *)lowValue{
return @"0";
}
- (NSString *)highValue{
return @"60";
}
- (void)closeBtnClick{
[[DoraemonCacheManager sharedInstance] saveFpsSwitch:NO];
[[DoraemonFPSOscillogramWindow shareInstance] hide];
......@@ -64,7 +49,7 @@
__weak typeof(self) weakSelf = self;
[_fpsUtil addFPSBlock:^(NSInteger fps) {
// 0~60 对应 高度0~_oscillogramView.doraemon_height
[weakSelf.oscillogramView addHeightValue:fps*_oscillogramView.doraemon_height/60. andTipValue:[NSString stringWithFormat:@"%zi",fps]];
[weakSelf.oscillogramView addHeightValue:fps*weakSelf.oscillogramView.doraemon_height/60. andTipValue:[NSString stringWithFormat:@"%zi",fps]];
}];
}
[_fpsUtil start];
......@@ -74,7 +59,7 @@
if (_fpsUtil) {
[_fpsUtil end];
}
[_oscillogramView clear];
[self.oscillogramView clear];
}
@end
......@@ -15,62 +15,29 @@
@interface DoraemonMemoryOscillogramViewController ()
@property (nonatomic, strong) DoraemonOscillogramView *oscillogramView;
//每秒运行一次
@property (nonatomic, strong) NSTimer *secondTimer;
@end
@implementation DoraemonMemoryOscillogramViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[self setEdgesForExtendedLayout:UIRectEdgeNone];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = DoraemonLocalizedString(@"内存检测");
titleLabel.font = [UIFont systemFontOfSize:kDoraemonSizeFrom750_Landscape(20)];
titleLabel.textColor = [UIColor whiteColor];
[self.view addSubview:titleLabel];
[titleLabel sizeToFit];
titleLabel.frame = CGRectMake(kDoraemonSizeFrom750_Landscape(20), IPHONE_TOPSENSOR_HEIGHT + kDoraemonSizeFrom750_Landscape(10), titleLabel.doraemon_width, titleLabel.doraemon_height);
UIButton *closeBtn = [[UIButton alloc] init];
[closeBtn setImage:[UIImage doraemon_imageNamed:@"doraemon_close_white"] forState:UIControlStateNormal];
closeBtn.frame = CGRectMake((kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight)-kDoraemonSizeFrom750_Landscape(60), IPHONE_TOPSENSOR_HEIGHT, kDoraemonSizeFrom750_Landscape(60), kDoraemonSizeFrom750_Landscape(60));
[closeBtn addTarget:self action:@selector(closeBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:closeBtn];
_oscillogramView = [[DoraemonOscillogramView alloc] initWithFrame:CGRectMake(0, titleLabel.doraemon_bottom+kDoraemonSizeFrom750_Landscape(24), (kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight), kDoraemonSizeFrom750_Landscape(400))];
_oscillogramView.backgroundColor = [UIColor clearColor];
[_oscillogramView setLowValue:@"0"];
[_oscillogramView setHightValue:[NSString stringWithFormat:@"%zi",[self deviceMemory]]];
[self.view addSubview:_oscillogramView];
}
- (void)closeBtnClick{
[[DoraemonCacheManager sharedInstance] saveMemorySwitch:NO];
[[DoraemonMemoryOscillogramWindow shareInstance] hide];
- (NSString *)title{
return DoraemonLocalizedString(@"内存检测");
}
- (NSString *)lowValue{
return @"0";
}
- (void)startRecord{
if(!_secondTimer){
_secondTimer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(doSecondFunction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_secondTimer forMode:NSRunLoopCommonModes];
}
- (NSString *)highValue{
return [NSString stringWithFormat:@"%zi",[self deviceMemory]];
}
- (void)endRecord{
if(_secondTimer){
[_secondTimer invalidate];
_secondTimer = nil;
[_oscillogramView clear];
}
- (void)closeBtnClick{
[[DoraemonCacheManager sharedInstance] saveMemorySwitch:NO];
[[DoraemonMemoryOscillogramWindow shareInstance] hide];
}
//每一秒钟采样一次内存使用率
......@@ -79,7 +46,7 @@
NSUInteger totalMemoryForDevice = [self deviceMemory];
// 0~totalMemoryForDevice 对应 高度0~_oscillogramView.doraemon_height
[_oscillogramView addHeightValue:useMemoryForApp*_oscillogramView.doraemon_height/totalMemoryForDevice andTipValue:[NSString stringWithFormat:@"%zi",useMemoryForApp]];
[self.oscillogramView addHeightValue:useMemoryForApp*self.oscillogramView.doraemon_height/totalMemoryForDevice andTipValue:[NSString stringWithFormat:@"%zi",useMemoryForApp]];
}
- (NSUInteger)deviceMemory {
......
......@@ -14,61 +14,29 @@
@interface DoraemonNetFlowOscillogramViewController ()
@property (nonatomic, strong) DoraemonOscillogramView *oscillogramView;
//每秒运行一次
@property (nonatomic, strong) NSTimer *secondTimer;
@end
@implementation DoraemonNetFlowOscillogramViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
[self setEdgesForExtendedLayout:UIRectEdgeNone];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = DoraemonLocalizedString(@"流量检测");
titleLabel.font = [UIFont systemFontOfSize:kDoraemonSizeFrom750_Landscape(20)];
titleLabel.textColor = [UIColor whiteColor];
[self.view addSubview:titleLabel];
[titleLabel sizeToFit];
titleLabel.frame = CGRectMake(kDoraemonSizeFrom750_Landscape(20), IPHONE_TOPSENSOR_HEIGHT + kDoraemonSizeFrom750_Landscape(10), titleLabel.doraemon_width, titleLabel.doraemon_height);
UIButton *closeBtn = [[UIButton alloc] init];
[closeBtn setImage:[UIImage doraemon_imageNamed:@"doraemon_close_white"] forState:UIControlStateNormal];
closeBtn.frame = CGRectMake((kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight)-kDoraemonSizeFrom750_Landscape(60), IPHONE_TOPSENSOR_HEIGHT, kDoraemonSizeFrom750_Landscape(60), kDoraemonSizeFrom750_Landscape(60));
[closeBtn addTarget:self action:@selector(closeBtnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:closeBtn];
_oscillogramView = [[DoraemonOscillogramView alloc] initWithFrame:CGRectMake(0, titleLabel.doraemon_bottom+kDoraemonSizeFrom750_Landscape(24), (kInterfaceOrientationPortrait ? DoraemonScreenWidth : DoraemonScreenHeight), kDoraemonSizeFrom750_Landscape(400))];
_oscillogramView.backgroundColor = [UIColor clearColor];
[_oscillogramView setLowValue:@"0"];
[_oscillogramView setHightValue:[NSString stringWithFormat:@"%zi",[self highestNetFlow]]];
[self.view addSubview:_oscillogramView];
}
- (void)closeBtnClick{
[[DoraemonCacheManager sharedInstance] saveNetFlowSwitch:NO];
[[DoraemonNetFlowOscillogramWindow shareInstance] hide];
- (NSString *)title{
return DoraemonLocalizedString(@"流量检测");
}
- (NSString *)lowValue{
return @"0";
}
- (void)startRecord{
if(!_secondTimer){
_secondTimer = [NSTimer timerWithTimeInterval:1.0f target:self selector:@selector(doSecondFunction) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_secondTimer forMode:NSRunLoopCommonModes];
}
- (NSString *)highValue{
return [NSString stringWithFormat:@"%zi",[self highestNetFlow]];
}
- (void)endRecord{
if(_secondTimer){
[_secondTimer invalidate];
_secondTimer = nil;
[_oscillogramView clear];
}
- (void)closeBtnClick{
[[DoraemonCacheManager sharedInstance] saveNetFlowSwitch:NO];
[[DoraemonNetFlowOscillogramWindow shareInstance] hide];
}
//每一秒钟采样一次流量情况
......@@ -96,7 +64,7 @@
useNetFlowForApp = totalNetFlow;
// 0~highestNetFlow 对应 高度0~200
[_oscillogramView addHeightValue:useNetFlowForApp*_oscillogramView.doraemon_height/totalNetFlowForDevice andTipValue:[NSString stringWithFormat:@"%ziB",useNetFlowForApp]];
[self.oscillogramView addHeightValue:useNetFlowForApp*self.oscillogramView.doraemon_height/totalNetFlowForDevice andTipValue:[NSString stringWithFormat:@"%ziB",useNetFlowForApp]];
}
- (NSUInteger)highestNetFlow {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册