一、性能数据上报项

1. CPU模块

上报键值说明采集平台
cpu当前进程cpu使用率平均值Android & iOS
totcpu系统cpu总使用率平均值Android & iOS
cpu_temp_maxcpu最高温度Android
cpu_temp_avgcpu温度平均值Android
gpu_temp_avggpu温度平均值Android
gpu_temp_maxgpu最高温度Android
gpugpu使用率平均值Android
gpu_modelgpu型号Android
cpu_modelcpu型号Android
cpu_corecpu核心数Android
cpu_freqcpu最大时钟频率Android

2. memory及存储模块

上报键值说明采集平台
mem当前进程内存使用量平均值Android & iOS
availmem当前设备可用内存量平均值Android & iOS
max_mem内存使用量最大值Android & iOS
start_mem开始对局时内存使用量Android & iOS
end_mem结束对局时内存使用量Android & iOS
totalmem当前设备总内存量Android & iOS
total_storage当前设备总存储空间大小Android & iOS
free_storage当前设备可用存储空间大小Android & iOS

3. 网卡模块

上报键值说明采集平台
wsndpkt无线网卡发包总数Android & iOS
wrcvpkt无线网卡收包总数Android & iOS
wsnddrop无线网卡发包丢包Android & iOS
wrcvdrop无线网卡收包丢包Android & iOS
wsnderr无线网卡发包错包Android & iOS
wrcverr无线网卡收包错包Android & iOS
msndpkt移动网卡发包总数Android & iOS
mrcvpkt移动网卡收包总数Android & iOS
msnddrop移动网卡发包丢包Android & iOS
mrcvdrop移动网卡收包丢包Android & iOS
msnderr移动网卡发包错包Android & iOS
mrcverr移动网卡收包错包Android & iOS

4. FPS模块

上报键值说明采集平台
fminfps最小值Android & iOS
fmaxfps最大值Android & iOS
favgfps平均值Android & iOS
fheavyfps严重抖动个数(本次fps值比上次fps值低10以上)Android & iOS
flightfps轻微抖动个数(本次fps值比上次fps值低4以上,10以下)Android & iOS
ftotalfps采集总个数Android & iOS
fcntx0fps自定义抖动个数(阈值由云控下发)Android & iOS
lfps1低于云控下发的lfps1阈值的个数Android & iOS
lfps2低于云控下发的lfps2阈值的个数Android & iOS
lfps3低于云控下发的lfps3阈值的个数Android & iOS

5. 电量模块

上报键值说明采集平台
battery电量消耗(开始-结束)Android & iOS
start_battery开始对局时电量值Android & iOS
end_battery结束对局时电量值Android & iOS
bs对局过程中是否有充电操作Android & iOS
bt电池温度平均值Android
max_battery_temp电池温度最大值Android

6. 网络相关模块

上报键值说明采集平台
netflow流量消耗Android & iOS
devices当前wifi下连接设备数Android & iOS
wifi_numwifi个数Android
wifi_rssi当前wifi信号强度Android
wifi_speed当前wifi链接速度Android
gate_delay到网关延迟(ping)Android & iOS
signal_level移动信号强度Android
xg当前网络类型Android & iOS
ldns本机DNS服务器Android & iOS

7. 机型相关

上报键值说明采集平台
manufacturer厂商Android
brand品牌Android
model型号Android
resolution分辨率Android

cpu&memory采集具体实现代码

1. cpu

  • Android采集代码:

    public static float totalCpuUsageRate() {return getTotalCpuUsageRate(USAGE_RATE_CAL_INTERVAL_MILLS_DEFAULT);}public static float getTotalCpuUsageRate(long calIntervalMills) {if (0 > calIntervalMills) {return VALUE_GET_FAILED;}float totalCpuUsageRate = VALUE_GET_FAILED;try {TotalCpuStatInfo totalCpuStatInfo1 = TotalCpuStatInfo.get();long cpuTotal1 = totalCpuStatInfo1.getCpuTotal();if (0 > cpuTotal1) {return totalCpuUsageRate;}long total1 = totalCpuStatInfo1.getTotal();if (0 > total1) {return totalCpuUsageRate;}try {Thread.sleep(calIntervalMills);} catch (Exception e) {GPMLogger.w(e, "getTotalCpuUsageRate failed");}TotalCpuStatInfo totalCpuStatInfo2 = TotalCpuStatInfo.get();long cpuTotal2 = totalCpuStatInfo2.getCpuTotal();if (0 > cpuTotal2) {return totalCpuUsageRate;}long total2 = totalCpuStatInfo2.getTotal();if (0 > total2) {return totalCpuUsageRate;}long totalDiff = total2 - total1;if (0 == totalDiff) {// NOTE: totalDiff为分母return totalCpuUsageRate;}long cpuTotalDiff = cpuTotal2 - cpuTotal1;return 100 * cpuTotalDiff / (totalDiff + 0f);} catch (Exception e) {GPMLogger.w(e, "getTotalCpuUsageRate failed");}return totalCpuUsageRate;}public static float myCpuUsageRate() {return getMyCpuUsageRate(USAGE_RATE_CAL_INTERVAL_MILLS_DEFAULT);}public static float getMyCpuUsageRate(long calIntervalMills) {if (0 > calIntervalMills) {return VALUE_GET_FAILED;}float myCpuUsageRate = VALUE_GET_FAILED;try {TotalCpuStatInfo totalCpuStatInfo1 = TotalCpuStatInfo.get();long total1 = totalCpuStatInfo1.getTotal();if (0 > total1) {return myCpuUsageRate;}MyCpuStatInfo myCpuStatInfo1 = MyCpuStatInfo.get();long myCpuTotal1 = myCpuStatInfo1.getCpuTotal();if (0 > myCpuTotal1) {return myCpuUsageRate;}try {Thread.sleep(calIntervalMills);} catch (Exception e) {GPMLogger.w(e, "getMyCpuUsageRate failed");}TotalCpuStatInfo totalCpuStatInfo2 = TotalCpuStatInfo.get();long total2 = totalCpuStatInfo2.getTotal();if (0 > total2) {return myCpuUsageRate;}MyCpuStatInfo myCpuStatInfo2 = MyCpuStatInfo.get();long myCpuTotal2 = myCpuStatInfo2.getCpuTotal();if (0 > myCpuTotal2) {return myCpuUsageRate;}long totalDiff = total2 - total1;if (0 == totalDiff) {// NOTE: totalDiff为分母return myCpuUsageRate;}long myCpuTotalDiff = myCpuTotal2 - myCpuTotal1;return 100 * myCpuTotalDiff / (totalDiff + 0f);} catch (Exception e) {GPMLogger.w(e, "getTotalCpuUsageRate failed");}return myCpuUsageRate;}private static class TotalCpuStatInfo {private static final int MIN_CPU_STAT_ITEM_NUM = 9;private static final String[] INVALID_RAW_CPU_STAT_ITEMS =new String[MIN_CPU_STAT_ITEM_NUM];public final long user;public final long nice;public final long system;public final long idle;public final long iowait;public final long irq;public final long softirq;public static TotalCpuStatInfo get() {BufferedReader cpuStatInfoReader = null;try {cpuStatInfoReader = new BufferedReader(new InputStreamReader(new FileInputStream(STAT_ABS_DIR), UTF8_CHARSET));return new TotalCpuStatInfo(cpuStatInfoReader.readLine());} catch (Exception e) {// NOTE: 高版本上获取不到, 不打印堆栈GPMLogger.d("get total cpu stat info failed");return new TotalCpuStatInfo(null);} finally {if (null != cpuStatInfoReader) {try {cpuStatInfoReader.close();} catch (IOException ignored) {}}}}private TotalCpuStatInfo(String cpuStatLine) {String[] rawCpuStatItems = CpuStatInfoHelper.buildRawCpuStatItems(cpuStatLine, MIN_CPU_STAT_ITEM_NUM, INVALID_RAW_CPU_STAT_ITEMS);user = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[2]);nice = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[3]);system = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[4]);idle = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[5]);iowait = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[6]);irq = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[7]);softirq = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[8]);}public long getCpuTotal() {return user + nice + system + iowait + irq + softirq;}public long getTotal() {return user + nice + system + idle + iowait + irq + softirq;}}private static class MyCpuStatInfo {private static final int MIN_CPU_STAT_ITEM_NUM = 17;private static final String[] INVALID_RAW_CPU_STAT_ITEMS = new String[MIN_CPU_STAT_ITEM_NUM];public final long utime;public final long stime;public final long cutime;public final long cstime;public static MyCpuStatInfo get() {BufferedReader cpuStatInfoReader = null;try {cpuStatInfoReader = new BufferedReader(new InputStreamReader(new FileInputStream(MY_STAT_ABS_DIR), UTF8_CHARSET));return new MyCpuStatInfo(cpuStatInfoReader.readLine());} catch (Exception e) {GPMLogger.w(e, "get my cpu stat info failed");return new MyCpuStatInfo(null);} finally {if (null != cpuStatInfoReader) {try {cpuStatInfoReader.close();} catch (IOException ignored) {}}}}private MyCpuStatInfo(String cpuStatLine) {String[] rawCpuStatItems = CpuStatInfoHelper.buildRawCpuStatItems(cpuStatLine, MIN_CPU_STAT_ITEM_NUM, INVALID_RAW_CPU_STAT_ITEMS);utime = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[13]);stime = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[14]);cutime = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[15]);cstime = CpuStatInfoHelper.buildCpuStatItem(rawCpuStatItems[16]);}public long getCurrentThreadCpuTotal() {return utime + stime;}public long getCpuTotal() {return utime + stime + cutime + cstime;}}
  • IOS采集代码:

    // ============当前进程cpu使用率============- (double) getCPU {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(), TASK_BASIC_INFO, (task_info_t)tinfo, &task_info_count);if (kr != KERN_SUCCESS) {GSDKLOG(@"================CPU:%.2f",-1.0f);return -1;}task_basic_info_tbasic_info;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;uint32_t stat_thread = 0; // Mach threadsbasic_info = (task_basic_info_t)tinfo;// get threads in the taskkr = task_threads(mach_task_self(), &thread_list, &thread_count);if (kr != KERN_SUCCESS) {GSDKLOG(@"=============CPU:%.2f",-1.0f);return -1;}if (thread_count > 0)stat_thread += thread_count;long tot_sec = 0;long tot_usec = 0;float tot_cpu = 0;int j;for (j = 0; j flags & TH_FLAGS_IDLE)) {tot_sec = tot_sec + basic_info_th->user_time.seconds + basic_info_th->system_time.seconds;tot_usec = tot_usec + basic_info_th->system_time.microseconds + basic_info_th->system_time.microseconds;tot_cpu = tot_cpu + basic_info_th->cpu_usage / (float)TH_USAGE_SCALE * 100.0;}} // for each threadkr = vm_deallocate(mach_task_self(), (vm_offset_t)thread_list, thread_count * sizeof(thread_t));GSDKLOG(@"=============CPU:%.2f",tot_cpu);return tot_cpu;}// ============当前进程cpu使用率============processor_info_array_t cpuInfo, prevCpuInfo;mach_msg_type_number_t numCpuInfo, numPrevCpuInfo;unsigned numCPUs;NSLock * CPUUsageLock;- (void) getSystemCPU {int mib[2U] = { CTL_HW, HW_NCPU };size_t sizeOfNumCPUs = sizeof(numCPUs);int status = sysctl(mib, 2U, &numCPUs, &sizeOfNumCPUs, NULL, 0U);if (status)numCPUs = 1;CPUUsageLock = [[NSLock alloc] init];}- (double) getSystemCPUCircle {natural_t numCPUsU = 0U;kern_return_t err = host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numCPUsU, &cpuInfo, &numCpuInfo);if (err == KERN_SUCCESS) {[CPUUsageLock lock];float tot_inUse = 0;float tot_total = 0;for(unsigned i = 0U; i  0) {GSDKLOG(@"CPU Usage: %.2f%%",tot_inUse/tot_total * 100.f);return tot_inUse/tot_total * 100.f;} else {return -1;}} else {GSDKLOG(@"Error!");return -1;}}

2. memory

  • Android采集代码:

    public static long getAvailableMemory(Context context) {if (null == context) {return VALUE_GET_FAILED;}@SuppressWarnings("AlibabaLowerCamelCaseVariableNaming")long availableMemoryInMB = VALUE_GET_FAILED;try {ActivityManager activityManager =(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);if (null == activityManager) {return availableMemoryInMB;}ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();activityManager.getMemoryInfo(memoryInfo);availableMemoryInMB = memoryInfo.availMem / (1024 * 1024);} catch (Exception e) {GPMLogger.w(e, "availableMemoryInMB failed");}return availableMemoryInMB;}// ============当前设备可用内存大小(原方案)============public static long getProcessMemery() {// TODO: 厂商反馈Debug.getPss()计算还是过于复杂,后续考虑使用Process.getPss()或者仿照Process.getPss()实现// NOTE: 当前实现应该在低优先级后台线程调用if (Build.VERSION_CODES.ICE_CREAM_SANDWICH  0) {memSize = memoryInfo[0].getTotalPss();}return memSize;} catch (Exception e) {Logger.e("PSS fetch error: " + e.getMessage());}return -1;}
  • IOS采集代码:

    // ============当前设备可用内存大小============- (double) getSystemAvailableMemory {// 获取当前设备可用内存(单位:MB)vm_statistics_data_t vmStats;mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;kern_return_t kernReturn = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmStats, &infoCount);if (kernReturn != KERN_SUCCESS) {GSDKLOG(@"AvailableMemory=====%.2f",-1.0f);return -1;}double availMem = (vm_page_size * vmStats.free_count + vm_page_size * vmStats.inactive_count) / 1024.0 / 1024.0;GSDKLOG(@"AvailableMemory=====%.2f",availMem);return availMem;}// ============当前进程使用内存大小(原方案)============- (double) getFootPrint {task_vm_info_data_t vmInfo;mach_msg_type_number_t count = TASK_VM_INFO_COUNT;kern_return_t result = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);if (result != KERN_SUCCESS) {GSDKLOG(@"FootPrint=====%.2f",-1.0f);return -1;}GSDKLOG(@"FootPrint=====%i",(int)((vmInfo.phys_footprint) / 1024.0 / 1024.0));return vmInfo.phys_footprint / 1024.0 / 1024.0;}// ============当前进程使用内存大小(优化后方案)============- (instancetype) init {if (self = [super init]) {_isLowLevelDevice = NO;struct utsname systemInfo;uname(&systemInfo);NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];if ([platform isEqualToString:@"iPhone7,1"] || [platform isEqualToString:@"iPhone7,2"] || [platform isEqualToString:@"iPhone6,1"] || [platform isEqualToString:@"iPhone6,2"]) {_isLowLevelDevice = YES;}}return self;}- (double) getFootPrint {task_vm_info_data_t vmInfo;mach_msg_type_number_t count = TASK_VM_INFO_COUNT;kern_return_t result = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);if (result != KERN_SUCCESS) {GSDKLOG(@"FootPrint=====%.2f",-1.0f);return -1;}double footPrint = -1;if (_isLowLevelDevice || [UIDevice.currentDevice.systemVersion doubleValue] >= 12.0) {footPrint = vmInfo.phys_footprint / 1024.0 / 1024.0;}if ([UIDevice.currentDevice.systemVersion doubleValue] < 12.0) {footPrint = (vmInfo.internal + vmInfo.compressed - vmInfo.purgeable_volatile_pmap) / 1024.0 / 1024.0;}GSDKLOG(@"FootPrint=====%i",int((vmInfo.phys_footprint) / 1024.0 / 1024.0));return footPrint;}

二、性能数据统一上报类示例

使用同一个TDMReportHelper实例进行上报即可:

TDMReportHelper eventReportHandler = new TDMReportHelper(eventName);eventReportHandler.addSS(key, value);eventReportHandler.report();eventReportHandler.destory();