标签:image top http -name and web comment 环境 false
GT源码:https://github.com/TencentOpen/GT
流畅度插件总共就几个类,其实处理方式也比较简单粗暴,就是通过Choreographer输出的log信息获取跳帧数据。SMActivity.java为插件的入口类,你可以通过预设环境操作来实现log打印操作,然后通过SMLogService.java过滤出当前进程的丢帧值,最后由SMServiceHelper.java来进行数据处理。流畅度值为60减去1s内的跳帧数。
1.简要流程
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(); } } };
过滤获取当前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); }
标签:image top http -name and web comment 环境 false
原文地址:http://www.cnblogs.com/alexkn/p/6234788.html