Authored by 张文文

添加app基础性能采集

... ... @@ -35,6 +35,8 @@
29FB39AA1F7C9D67000E3B27 /* UIImageView+GestureAutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 29FB39A91F7C9D67000E3B27 /* UIImageView+GestureAutoTrack.m */; };
29FB39AD1F7C9D73000E3B27 /* UILabel+GestureAutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 29FB39AC1F7C9D73000E3B27 /* UILabel+GestureAutoTrack.m */; };
2EEBB0A520A978C60069D069 /* YH_DeviceInfoMonitor.m in Sources */ = {isa = PBXBuildFile; fileRef = 2EEBB0A420A978C60069D069 /* YH_DeviceInfoMonitor.m */; };
4D82B8CF211BE71F00506E8C /* YH_AppInfoMonitor.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D82B8CB211BE71F00506E8C /* YH_AppInfoMonitor.m */; };
4D82B8D0211BE71F00506E8C /* YH_AppCollectManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D82B8CC211BE71F00506E8C /* YH_AppCollectManager.m */; };
52540FAD1F8F6BAD001907B3 /* YH_CrashReporter.m in Sources */ = {isa = PBXBuildFile; fileRef = 52540FA91F8F6BAD001907B3 /* YH_CrashReporter.m */; };
52540FAE1F8F6BAD001907B3 /* YH_CrashDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 52540FAC1F8F6BAD001907B3 /* YH_CrashDataManager.m */; };
5255C2B91F5D25F400A8FC5F /* UICollectionView+AutoTrack.m in Sources */ = {isa = PBXBuildFile; fileRef = 5255C2A61F5D25F400A8FC5F /* UICollectionView+AutoTrack.m */; };
... ... @@ -136,6 +138,10 @@
2EEBB0A320A978C60069D069 /* YH_DeviceInfoMonitor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YH_DeviceInfoMonitor.h; sourceTree = "<group>"; };
2EEBB0A420A978C60069D069 /* YH_DeviceInfoMonitor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YH_DeviceInfoMonitor.m; sourceTree = "<group>"; };
3C62E62ACAF80A817D6B5ED0 /* Pods-YHEventReport.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YHEventReport.release.xcconfig"; path = "Pods/Target Support Files/Pods-YHEventReport/Pods-YHEventReport.release.xcconfig"; sourceTree = "<group>"; };
4D82B8CB211BE71F00506E8C /* YH_AppInfoMonitor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YH_AppInfoMonitor.m; sourceTree = "<group>"; };
4D82B8CC211BE71F00506E8C /* YH_AppCollectManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YH_AppCollectManager.m; sourceTree = "<group>"; };
4D82B8CD211BE71F00506E8C /* YH_AppInfoMonitor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YH_AppInfoMonitor.h; sourceTree = "<group>"; };
4D82B8CE211BE71F00506E8C /* YH_AppCollectManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YH_AppCollectManager.h; sourceTree = "<group>"; };
52540FA91F8F6BAD001907B3 /* YH_CrashReporter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YH_CrashReporter.m; sourceTree = "<group>"; };
52540FAA1F8F6BAD001907B3 /* YH_CrashDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YH_CrashDataManager.h; sourceTree = "<group>"; };
52540FAB1F8F6BAD001907B3 /* YH_CrashReporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YH_CrashReporter.h; sourceTree = "<group>"; };
... ... @@ -300,8 +306,12 @@
2EEBB0A220A978460069D069 /* YH_DeviceInfo */ = {
isa = PBXGroup;
children = (
2EEBB0A420A978C60069D069 /* YH_DeviceInfoMonitor.m */,
4D82B8CE211BE71F00506E8C /* YH_AppCollectManager.h */,
4D82B8CC211BE71F00506E8C /* YH_AppCollectManager.m */,
4D82B8CD211BE71F00506E8C /* YH_AppInfoMonitor.h */,
4D82B8CB211BE71F00506E8C /* YH_AppInfoMonitor.m */,
2EEBB0A320A978C60069D069 /* YH_DeviceInfoMonitor.h */,
2EEBB0A420A978C60069D069 /* YH_DeviceInfoMonitor.m */,
);
path = YH_DeviceInfo;
sourceTree = "<group>";
... ... @@ -687,12 +697,14 @@
29CDB4B11F6FA5A500AAD350 /* PowerfulBannerView+AutoTrack.m in Sources */,
B1475E6D1F7F38280066B514 /* NSURLSession+AutoTrack.m in Sources */,
52D204E81F60E6F900CB7F1A /* UITabBar+AutoTrack.m in Sources */,
4D82B8D0211BE71F00506E8C /* YH_AppCollectManager.m in Sources */,
B1B6C3A41F74AD3100627DF3 /* YHExposureManager.m in Sources */,
5255C2C01F5D25F400A8FC5F /* YH_Reachability.m in Sources */,
295504111F67B78F006A3F14 /* UITableViewCell+AutoTrack.m in Sources */,
5255C2BB1F5D25F400A8FC5F /* YHSwizzle.m in Sources */,
52D204EE1F61360200CB7F1A /* UIActionSheet+AutoTrack.m in Sources */,
B14C0C991F8E2E9B00D963F3 /* UITapGestureRecognizer+AutoTrack.m in Sources */,
4D82B8CF211BE71F00506E8C /* YH_AppInfoMonitor.m in Sources */,
290617661FEB9D0C00BD569F /* NSData+YHERGZip.m in Sources */,
52540FAD1F8F6BAD001907B3 /* YH_CrashReporter.m in Sources */,
29FB39AA1F7C9D67000E3B27 /* UIImageView+GestureAutoTrack.m in Sources */,
... ...
... ... @@ -135,6 +135,11 @@ typedef NS_ENUM(NSInteger, YHEventReportPointName) {
YHPN_NETWORK_NO_ACTIVENET,//无可用网络
YHPH_MEMORY,//内存使用状态
YHPN_AD_UNION,//联盟激活事件
YHPN_APPCPU,//CPU使用状态
YHPN_APPMEMORY,//CPU使用状态
YHPN_APPTRAFFIC,//CPU使用状态
YHPN_APPFPS,//CPU使用状态
};
typedef NS_ENUM(NSInteger, YHEventReportType) {
... ... @@ -160,7 +165,8 @@ typedef NS_ENUM(NSInteger, YHPointType) {
YHPT_LIFECYCLE,
YHPT_BUSINESS,
YHPT_PERFORMANCE,
YHPT_AD
YHPT_AD,
YHPT_APPTARGET
};
#define YHEventReportDebugModeEnableKey @"YHEventReportDebugModeEnableKey"
... ...
... ... @@ -268,6 +268,18 @@
case YHPN_AD_UNION:
str = @"UNION";
break;
case YHPN_APPCPU:
str = @"CPU";
break;
case YHPN_APPMEMORY:
str = @"MEMORY";
break;
case YHPN_APPTRAFFIC:
str = @"TRAFFIC";
break;
case YHPN_APPFPS:
str = @"FPS";
break;
default:
break;
}
... ... @@ -305,6 +317,9 @@
case YHPT_AD:
str = @"AD";
break;
case YHPT_APPTARGET:
str = @"APPTARGET";
break;
default:
break;
}
... ...
... ... @@ -13,6 +13,7 @@
#import "YHLog.h"
#import "YH_EventCollector.h"
#import "YHEventReport.h"
#import "YH_AppCollectManager.h"
@interface UIViewController (AutoTrackPrivate)
... ... @@ -183,12 +184,16 @@
//如果是YH_ViewController及其子类,则加入统计
if ([self isKindOfClass:NSClassFromString(@"YH_ViewController")]) {
[[YH_EventCollector sharedInstance] pageChainEventWithViewController:self];
[[YH_AppCollectManager sharedInstance] setAppLogPageName:[NSString stringWithFormat:@"%@", [self class]]];
}else if ([self isKindOfClass:[UIViewController class]]){
//UICompatibilityInputViewController,UIInputWindowController,UISystemKeyboardDockController
//如果是UIViewController以及子类,根据类型处理,类名为YH开头的认为是自己的控制器,避免统计系统控制器(上行注释为部分系统控制器)
NSString *controllerName = NSStringFromClass([self class]);
if ([controllerName hasPrefix:@"YH"]) {
[[YH_EventCollector sharedInstance] pageChainEventWithViewController:self];
[[YH_AppCollectManager sharedInstance] setAppLogPageName:[NSString stringWithFormat:@"%@", [self class]]];
}
}
}
... ...
//
// YH_AppCollectManager.h
// YH_Mall
//
// Created by Misty on 2018/8/2.
// Copyright © 2018年 YOHO. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface YH_AppCollectManager : NSObject
+ (YH_AppCollectManager *)sharedInstance;
- (void)setAppLogEnableStatus:(BOOL)enabled;
- (void)setTrackTimeInterval:(double)interval;
- (void)setAppLogPageName:(NSString *)pageName;
@end
... ...
//
// YH_AppCollectManager.m
// YH_Mall
//
// Created by Misty on 2018/8/2.
// Copyright © 2018年 YOHO. All rights reserved.
//
#import "YH_AppCollectManager.h"
#import "YH_AppInfoMonitor.h"
#import <UIKit/UIKit.h>
#import <mach/mach.h>
#import "YHEventReport.h"
@interface YH_AppCollectManager()
@property (nonatomic, strong) YH_AppInfoMonitor *infoMonitor;
//基础参数
@property (nonatomic, assign) BOOL appLogEnable;
@property (nonatomic, assign) double timeInterval;
@property (nonatomic, copy) NSString *pageName;
@property (nonatomic, copy) NSString *cpuRate;
@property (nonatomic, copy) NSString *cpuAllJiffies;
@property (nonatomic, copy) NSString *appUsedJiffies;
@property (nonatomic, copy) NSString *memRate;
@property (nonatomic, copy) NSString *memUsedValue;
@property (nonatomic, copy) NSString *memAllValue;
@property (nonatomic, copy) NSString *fpsValue;
@property (nonatomic, copy) NSString *sendBytes;
@property (nonatomic, copy) NSString *receivedBytes;
@end
@implementation YH_AppCollectManager
+ (YH_AppCollectManager *)sharedInstance {
static YH_AppCollectManager *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[YH_AppCollectManager alloc] init];
});
return sharedInstance;
}
- (instancetype)init {
self = [super init];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startAppInfoMonitor) name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAppInfoMonitor) name:UIApplicationDidEnterBackgroundNotification object:nil];
}
return self;
}
- (void)setAppLogEnableStatus:(BOOL)enabled {
self.appLogEnable = enabled;
}
- (void)setAppLogPageName:(NSString *)pageName {
self.pageName = pageName;
}
- (void)setTrackTimeInterval:(double)interval {
self.timeInterval = interval;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
// notification
- (void)stopAppInfoMonitor {
[self.infoMonitor stopMonitoring];
}
- (void)startAppInfoMonitor {
if (!self.appLogEnable) {
return;
}
self.infoMonitor = [[YH_AppInfoMonitor alloc] init];
self.infoMonitor.timeInterval = self.timeInterval;
WS(weakSelf);
[self.infoMonitor startMonitorBlock:^(CGFloat cpuUsage, CGFloat usedMem, CGFloat allMem, CGFloat fpsValue, int64_t sendBytes, int64_t receivedBytes) {
weakSelf.cpuRate = [NSString stringWithFormat:@"%.4f", cpuUsage];
weakSelf.cpuAllJiffies = [NSString stringWithFormat:@"%.0f", (float)TH_USAGE_SCALE];
weakSelf.appUsedJiffies = [NSString stringWithFormat:@"%.0f", cpuUsage*(float)TH_USAGE_SCALE];
weakSelf.memRate = [NSString stringWithFormat:@"%.4f", usedMem/allMem];
weakSelf.memUsedValue = [NSString stringWithFormat:@"%.0f", usedMem];
weakSelf.memAllValue = [NSString stringWithFormat:@"%.0f", allMem];
weakSelf.fpsValue = [NSString stringWithFormat:@"%.0f", fpsValue];
weakSelf.sendBytes = [NSString stringWithFormat:@"%lld", sendBytes];
weakSelf.receivedBytes = [NSString stringWithFormat:@"%lld", receivedBytes];
[weakSelf reportSystemInfo];
}];
}
//数据上报
- (void)reportSystemInfo {
NSDictionary *cpuDict = @{ @"url" : self.pageName?self.pageName:@"",
@"rate" : self.cpuRate?self.cpuRate:@"",
@"target" : self.appUsedJiffies?self.appUsedJiffies:@"",
@"assist" : self.cpuAllJiffies?self.cpuAllJiffies:@""
};
NSDictionary *memDict = @{ @"url" : self.pageName?self.pageName:@"",
@"rate" : self.memRate?self.memRate:@"",
@"target" : self.memUsedValue?self.memUsedValue:@"",
@"assist" : self.memAllValue?self.memAllValue:@""
};
NSDictionary *fpsDict = @{ @"url" : self.pageName?self.pageName:@"",
@"rate" : @"0",
@"target" : self.fpsValue?self.fpsValue:@"",
@"assist" : @"0"
};
NSDictionary *trafficDict = @{ @"url" : self.pageName?self.pageName:@"",
@"rate" : @"0",
@"target" : self.receivedBytes?self.receivedBytes:@"",
@"assist" : self.sendBytes?self.sendBytes:@""
};
#ifdef DEBUG
NSLog(@"appLog status:%@\n%@\n%@\n%@", cpuDict, memDict, fpsDict, trafficDict);
#endif
[[YHEventReport sharedInstance] reportWithPointType:YHPT_APPTARGET pointName:YHPN_APPCPU parameters:cpuDict];
[[YHEventReport sharedInstance] reportWithPointType:YHPT_APPTARGET pointName:YHPN_APPMEMORY parameters:memDict];
[[YHEventReport sharedInstance] reportWithPointType:YHPT_APPTARGET pointName:YHPN_APPFPS parameters:fpsDict];
[[YHEventReport sharedInstance] reportWithPointType:YHPT_APPTARGET pointName:YHPN_APPTRAFFIC parameters:trafficDict];
}
@end
... ...
//
// YH_AppInfoMonitor.h
// YH_Mall
//
// Created by Misty on 2018/8/2.
// Copyright © 2018年 YOHO. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface YH_AppInfoMonitor : NSObject
@property (nonatomic, assign) double timeInterval;
- (void)startMonitorBlock:(void (^)(CGFloat cpuUsage, CGFloat usedMem, CGFloat allMem, CGFloat fpsValue, int64_t sendBytes, int64_t receivedBytes))block;
- (void)stopMonitoring;
@end
... ...
//
// YH_AppInfoMonitor.m
// YH_Mall
//
// Created by Misty on 2018/8/2.
// Copyright © 2018年 YOHO. All rights reserved.
//
#import "YH_AppInfoMonitor.h"
#import <mach/mach.h>
#include <ifaddrs.h>
#include <net/if.h>
@interface YH_AppInfoMonitor() {
NSTimeInterval lastTime;
NSUInteger count;
BOOL prevValid;
}
@property (nonatomic, strong) CADisplayLink *displayLink;
@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, copy) void (^monitorBlock)(CGFloat cpuUsage, CGFloat usedMem, CGFloat allMem, CGFloat fpsValue, int64_t sendBytes, int64_t receivedBytes); //每秒获取
@property (nonatomic, assign) CGFloat fpsValue;
@property (nonatomic, assign) int64_t prevWiFiSent;
@property (nonatomic, assign) int64_t prevWiFiReceived;
@property (nonatomic, assign) int64_t prevWWANSent;
@property (nonatomic, assign) int64_t prevWWANReceived;
@property (nonatomic, assign) int64_t WiFiSent;
@property (nonatomic, assign) int64_t WiFiReceived;
@property (nonatomic, assign) int64_t WWANSent;
@property (nonatomic, assign) int64_t WWANReceived;
@end
@implementation YH_AppInfoMonitor
- (instancetype)init {
if ([super init]) {
if (self) {
prevValid = false;
_prevWiFiSent = 0;
_prevWiFiReceived = 0;
_prevWWANSent = 0;
_prevWWANReceived = 0;
_WiFiSent = 0;
_WiFiReceived = 0;
_WWANSent = 0;
_WWANReceived = 0;
}
}
return self;
}
- (void)startMonitorBlock:(void (^)(CGFloat, CGFloat, CGFloat, CGFloat, int64_t, int64_t))block {
self.monitorBlock = block;
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(handleDisplayLink:)];
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
self.timer = [NSTimer timerWithTimeInterval:self.timeInterval target:self selector:@selector(getAppCollectData) userInfo:nil repeats:YES];
[self.timer fire];
[[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
}
- (void)stopMonitoring {
[self.displayLink invalidate];
self.displayLink = nil;
[self.timer invalidate];
self.timer = nil;
prevValid = false;
_prevWiFiSent = 0;
_prevWiFiReceived = 0;
_prevWWANSent = 0;
_prevWWANReceived = 0;
_WiFiSent = 0;
_WiFiReceived = 0;
_WWANSent = 0;
_WWANReceived = 0;
}
- (void)getAppCollectData {
CGFloat cpu = [self getCpuUsage];
CGFloat usedMem = [self getMemUsage];
CGFloat allMem = [self getMemAllUsage];
CGFloat fps = self.fpsValue;
[self getNetFlowData];
int64_t nowSent = _WiFiSent + _WWANSent;
int64_t nowRecived = _WiFiReceived + _WWANReceived;
if (self.monitorBlock) {
self.monitorBlock(cpu, usedMem, allMem, fps, nowSent, nowRecived);
}
}
#pragma mark - cpu
//流量消耗
- (CGFloat)getCpuUsage {
return [YH_AppInfoMonitor getCpuUsage];
}
// 获取应用当前的CPU
+ (CGFloat)getCpuUsage {
kern_return_t kr;
task_info_data_t tinfo;
mach_msg_type_number_t task_info_count;
task_info_count = TASK_INFO_MAX;
kr = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)tinfo, &task_info_count);
if (kr != KERN_SUCCESS) {
return -1;
}
thread_array_t thread_list;
mach_msg_type_number_t thread_count;
thread_info_data_t thinfo;
mach_msg_type_number_t thread_info_count;
thread_basic_info_t basic_info_th;
// get threads in the task
kr = task_threads(mach_task_self(), &thread_list, &thread_count);
if (kr != KERN_SUCCESS) {
return -1;
}
long total_time = 0;
long total_userTime = 0;
CGFloat total_cpu = 0;
int j;
// for each thread
for (j = 0; j < (int)thread_count; j++) {
thread_info_count = THREAD_INFO_MAX;
kr = thread_info(thread_list[j], THREAD_BASIC_INFO,
(thread_info_t)thinfo, &thread_info_count);
if (kr != KERN_SUCCESS) {
return -1;
}
basic_info_th = (thread_basic_info_t)thinfo;
if (!(basic_info_th->flags & TH_FLAGS_IDLE)) {
total_time = total_time + basic_info_th->user_time.seconds + basic_info_th->system_time.seconds;
total_userTime = total_userTime + basic_info_th->user_time.microseconds + basic_info_th->system_time.microseconds;
total_cpu = total_cpu + basic_info_th->cpu_usage / (float)TH_USAGE_SCALE;
}
}
kr = vm_deallocate(mach_task_self(), (vm_offset_t)thread_list, thread_count * sizeof(thread_t));
assert(kr == KERN_SUCCESS);
return total_cpu;
}
#pragma mark - mem
//内存占用
- (CGFloat)getMemAllUsage {
return [YH_AppInfoMonitor allUsedMemory];
}
//内存占用
- (CGFloat)getMemUsage {
return [YH_AppInfoMonitor appUsedMemory];
}
+ (CGFloat)appUsedMemory {
//app 当前的驻留内存
struct mach_task_basic_info info;
mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
int r = task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)& info, & count);
if (r == KERN_SUCCESS) {
return info.resident_size;
}
else {
NSParameterAssert(NO);
return 0;
}
}
+ (CGFloat)allUsedMemory {
//app 相关的内存总量,不一定都处于使用状态,可能是未被回收
mach_port_t host_port = mach_host_self();
mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
vm_size_t page_size;
vm_statistics64_data_t vm_stat;
kern_return_t kern;
kern = host_page_size(host_port, &page_size);
if (kern != KERN_SUCCESS) {
NSParameterAssert(NO);
return 0;
}
kern = host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size);
if (kern != KERN_SUCCESS) {
NSParameterAssert(NO);
return 0;
}
return page_size * (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count);
}
#pragma mark - fps
- (void)handleDisplayLink:(CADisplayLink *)displayLink {
if (lastTime == 0)
{
lastTime = self.displayLink.timestamp;
return ;
}
count++;
NSTimeInterval timeout = self.displayLink.timestamp - lastTime;
if (timeout < 1)
{
return ;
}
lastTime = self.displayLink.timestamp;
CGFloat fps = count / timeout;
count = 0;
self.fpsValue = fps;
}
#pragma mark - net
- (void)getNetFlowData
{
BOOL success;
struct ifaddrs *addrs;
const struct ifaddrs *cursor;
const struct if_data *networkStatisc;
int64_t WiFiSent = 0;
int64_t WiFiReceived = 0;
int64_t WWANSent = 0;
int64_t WWANReceived = 0;
NSString *name = @"";
success = getifaddrs(&addrs) == 0;
if (success)
{
cursor = addrs;
while (cursor != NULL)
{
name=[NSString stringWithFormat:@"%s",cursor->ifa_name];
// names of interfaces: en0 is WiFi ,pdp_ip0 is WWAN
if (cursor->ifa_addr->sa_family == AF_LINK)
{
if ([name hasPrefix:@"en"]) {
networkStatisc = (const struct if_data *) cursor->ifa_data;
WiFiSent+=networkStatisc->ifi_obytes;
WiFiReceived+=networkStatisc->ifi_ibytes;
}
if ([name hasPrefix:@"pdp_ip"]) {
networkStatisc = (const struct if_data *) cursor->ifa_data;
WWANSent+=networkStatisc->ifi_obytes;
WWANReceived+=networkStatisc->ifi_ibytes;
}
}
cursor = cursor->ifa_next;
}
freeifaddrs(addrs);
}
if (prevValid == true)
{
_WiFiSent = WiFiSent - _prevWiFiSent;
_WiFiReceived = WiFiReceived - _prevWiFiReceived;
_WWANSent = WWANSent - _prevWWANSent;
_WWANReceived = WWANReceived - _prevWWANReceived;
_prevWiFiSent = WiFiSent;
_prevWiFiReceived = WiFiReceived;
_prevWWANSent = WWANSent;
_prevWWANReceived = WWANReceived;
}
else
{
prevValid = true;
//记录第一次启动监控的流量
_prevWiFiSent = WiFiSent;
_prevWiFiReceived = WiFiReceived;
_prevWWANSent = WWANSent;
_prevWWANReceived = WWANReceived;
}
}
@end
... ...