首页 > 代码库 > 腾讯GT的流畅度测试方案研究
腾讯GT的流畅度测试方案研究
GT源码:https://github.com/TencentOpen/GT
一.流畅度模块的代码结构
流畅度插件总共就几个类,其实处理方式也比较简单粗暴,就是通过Choreographer输出的log信息获取跳帧数据。SMActivity.java为插件的入口类,你可以通过预设环境操作来实现log打印操作,然后通过SMLogService.java过滤出当前进程的丢帧值,最后由SMServiceHelper.java来进行数据处理。流畅度值为60减去1s内的跳帧数。
二.流畅度测试
1.简要流程
- 执行setprop debug.choreographer.skipwarning 1
- 执行getprop debug.choreographer.skipwarning判断,为1则可以进行测试
- 执行adb logcat -v time -s Choreographer:I *:S
- 过滤获取当前pid丢帧值
- 数据处理得到sm值
2.代码流程
-
执行setprop debug.choreographer.skipwarning 1
View.OnClickListener button_write_property = new View.OnClickListener() { @Override public void onClick(View v) { String cmd = "setprop debug.choreographer.skipwarning 1"; ProcessBuilder execBuilder = new ProcessBuilder("su", "-c", cmd); execBuilder.redirectErrorStream(true); try { execBuilder.start(); } catch (IOException e) { e.printStackTrace(); } } };
-
执行getprop debug.choreographer.skipwarning判断,为1则可以进行测试
View.OnClickListener button_check_status = new View.OnClickListener() { @Override public void onClick(View v) { String cmd = "getprop debug.choreographer.skipwarning"; ProcessBuilder execBuilder = new ProcessBuilder("sh", "-c", cmd); execBuilder.redirectErrorStream(true); try { TextView textview = (TextView) findViewById(R.id.textviewInformation); Process p = execBuilder.start(); InputStream is = p.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); Boolean flag = false; String line; while ((line = br.readLine()) != null) { if (line.compareTo("1") == 0) { flag = true; break; } } if (flag) { textview.setText("OK"); } else { textview.setText("NOT OK"); } } catch (IOException e) { e.printStackTrace(); } } };
- 执行adb logcat -v time -s Choreographer:I *:S
-
过滤获取当前pid丢帧值
protected void onHandleIntent(Intent intent) { try { String str = intent.getStringExtra("pid"); int pid = Integer.parseInt(str); List<String> args = new ArrayList<String>(Arrays.asList("logcat", "-v", "time", "Choreographer:I", "*:S")); dumpLogcatProcess = RuntimeHelper.exec(args); reader = new BufferedReader(new InputStreamReader(dumpLogcatProcess.getInputStream()), 8192); String line; while ((line = reader.readLine()) != null && !killed) { // filter "The application may be doing too much work on its main thread." if (!line.contains("uch work on its main t")) { continue; } int pID = LogLine.newLogLine(line, false).getProcessId(); if (pID != pid){ continue; } line = line.substring(50, line.length() - 71); Integer value = Integer.parseInt(line.trim()); SMServiceHelper.getInstance().dataQueue.offer(value); } } catch (IOException e) { Log.e(TAG, e.toString() + "unexpected exception"); } finally { killProcess(); } }
-
数据处理得到sm值
while (true) { if (pause) { break; } int x = count.getAndSet(0); // 卡顿大于60时,要将之前几次SM计数做修正 if (x > 60) { int n = x / 60; int v = x % 60; TagTimeEntry tte = OpPerfBridge.getProfilerData(key); int len = tte.getRecordSize(); // 补偿参数 int p = n; //Math.min(len, n); /* * n > len是刚启动测试的情况,日志中的亡灵作祟,这种情况不做补偿; * 并且本次也记为60。本逻辑在两次测试间会清理数据的情况生效。 */ if (n > len) { globalClient.setOutPara(key, 60); // globalClient.setOutPara(SFKey, 0); } else { for (int i = 0; i < p; i++) { TimeEntry te = tte.getRecord(len - 1 - i); te.reduce = 0; } globalClient.setOutPara(key, v); // globalClient.setOutPara(SFKey, 60 - v); } } else { int sm = 60 - x; globalClient.setOutPara(key, sm); // globalClient.setOutPara(SFKey, x); }
腾讯GT的流畅度测试方案研究
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。