Search in sources :

Example 1 with NetUtils

use of com.tencent.wstt.gt.api.utils.NetUtils in project GT by Tencent.

the class GTAUTFragment method registerOutpara.

/**
	 * 注册选中应用的指定性能出参,2.1.1版本开始支持指定进程
	 * @param type 指定的性能参数类型
	 * @param designatedPid 指定进程的pid
	 * @return 返回指定pid进程在出参记录中的序号
	 */
public static List<OutPara> registerOutpara(int type, int designatedPid) {
    List<OutPara> result = new ArrayList<OutPara>();
    OpUIManager.list_change = true;
    cb_status[type] = true;
    if (!AUTManager.appstatus.equals("running")) {
        return result;
    }
    List<String> registOutList = new ArrayList<String>();
    AUTManager.registOpTable.put(cb_alias[type], registOutList);
    if (AUTManager.pIds != null) {
        String[] tempPids = AUTManager.pIds;
        if (// 指定pid的情况
        designatedPid >= 0) {
            tempPids = new String[1];
            for (int i = 0; i < AUTManager.pIds.length; i++) {
                if (AUTManager.pIds[i].equals(Integer.toString(designatedPid))) {
                    tempPids[0] = AUTManager.pIds[i];
                    break;
                }
            }
        }
        for (int i = 0; i < tempPids.length; i++) {
            // 出参的前缀
            String preOpName;
            String key;
            String alias;
            if (type == AUTManager.SEQ_NET) {
                preOpName = cb_key[type] + ":";
                key = preOpName + AUTManager.pkn;
                alias = cb_alias[type];
            } else {
                preOpName = cb_key[type] + i + ":";
                key = preOpName + AUTManager.pNames[i];
                alias = cb_alias[type] + i;
            }
            Client autClient = ClientManager.getInstance().getAUTClient();
            autClient.registerOutPara(key, alias);
            // FIXME 默认设置为已采集,应和上一步合并
            autClient.setOutparaMonitor(key, true);
            registOutList.add(key);
            OutPara op = autClient.getOutPara(key);
            result.add(op);
            // 对应的统计对象
            switch(type) {
                case AUTManager.SEQ_CPU:
                    OpPerfBridge.startProfier(op, Functions.PERF_DIGITAL_CPU, "Process CPU occupy", "%");
                    // 设置CPU记录对象
                    CpuUtils.cpuInfoMap.put(key, new CpuUtils());
                    break;
                case AUTManager.SEQ_JIF:
                    // 需要有对应的CPU记录对象,JIF才可用
                    String keyCpu = cb_key[AUTManager.SEQ_CPU] + i + ":" + AUTManager.pNames[i];
                    if (null == CpuUtils.cpuInfoMap.get(keyCpu)) {
                        // 设置CPU记录对象
                        CpuUtils.cpuInfoMap.put(keyCpu, new CpuUtils());
                    }
                    OpPerfBridge.startProfier(op, Functions.PERF_DIGITAL_NORMAL, "", "");
                    break;
                case AUTManager.SEQ_NET:
                    String[] subKeys = { "transmitted", "received" };
                    int[] funIds = { Functions.PERF_DIGITAL_MULT, Functions.PERF_DIGITAL_MULT };
                    OpPerfBridge.startProfier(op, subKeys, funIds, "", "KB");
                    NetUtils mNetUtils = new NetUtils(AUTManager.pkn.toString());
                    NetUtils.netInfoMap.put(AUTManager.pkn, mNetUtils);
                    break;
                case AUTManager.SEQ_PSS:
                    String[] subKeys_pss = { "total", "dalvik", "native" };
                    int[] funIds_pss = { Functions.PERF_DIGITAL_MULT_MEM, Functions.PERF_DIGITAL_MULT_MEM, Functions.PERF_DIGITAL_MULT_MEM };
                    OpPerfBridge.startProfier(op, subKeys_pss, funIds_pss, "", "MB");
                    break;
                case AUTManager.SEQ_PD:
                    String[] subKeys_pd = { "total", "dalvik", "native" };
                    int[] funIds_pd = { Functions.PERF_DIGITAL_MULT_MEM, Functions.PERF_DIGITAL_MULT_MEM, Functions.PERF_DIGITAL_MULT_MEM };
                    OpPerfBridge.startProfier(op, subKeys_pd, funIds_pd, "", "MB");
                    break;
            }
        }
    }
    return result;
}
Also used : NetUtils(com.tencent.wstt.gt.api.utils.NetUtils) OutPara(com.tencent.wstt.gt.OutPara) ArrayList(java.util.ArrayList) CpuUtils(com.tencent.wstt.gt.api.utils.CpuUtils) CommonString(com.tencent.wstt.gt.utils.CommonString) Client(com.tencent.wstt.gt.manager.Client)

Example 2 with NetUtils

use of com.tencent.wstt.gt.api.utils.NetUtils in project GT by Tencent.

the class ProcPerfParaRunEngine method getProcPerfParasValue.

private String getProcPerfParasValue(OutPara op) {
    String value = "";
    try {
        int size = AUTManager.pIds.length;
        for (int i = 0; i < size; i++) {
            if (!ProcessUtils.isProcessAlive(AUTManager.pIds[i])) {
                value = "";
                break;
            }
            if (op.getKey().contains(CommonString.pcpu_key + i + ":" + AUTManager.pNames[i])) {
                value = CpuUtils.cpuInfoMap.get(CommonString.pcpu_key + i + ":" + AUTManager.pNames[i]).getProcessCpuUsage(Integer.valueOf(AUTManager.pIds[i]));
                long tempValue = Double.valueOf((Double.valueOf(value.substring(0, value.length() - 1)) * 100)).longValue();
                OpPerfBridge.addHistory(op, value, tempValue);
                return value;
            } else if (op.getKey().contains(CommonString.pjif_key + i + ":" + AUTManager.pNames[i])) {
                // 如果需要刷新的列表中也包含对应进程的CPU,那不需要重复刷CPU值了
                String tempCpuKey = CommonString.pcpu_key + i + ":" + AUTManager.pNames[i];
                boolean hasCpuObservered = false;
                for (OutPara opTemp : enable_procPerf_ops) {
                    if (opTemp.getKey().equals(tempCpuKey)) {
                        hasCpuObservered = true;
                        break;
                    }
                }
                if (!hasCpuObservered) {
                    CpuUtils.cpuInfoMap.get(tempCpuKey).getProcessCpuUsage(Integer.valueOf(AUTManager.pIds[i]));
                }
                long tempValue = CpuUtils.cpuInfoMap.get(tempCpuKey).getJif();
                value = String.valueOf(tempValue);
                OpPerfBridge.addHistory(op, value, tempValue);
                return value;
            } else if (op.getKey().contains(CommonString.pnet_key)) {
                String pName = AUTManager.pkn.toString();
                NetUtils netUtils = NetUtils.netInfoMap.get(pName);
                // 实际使用时候发现,收发的数据分成两条曲线最合理
                double lastT = netUtils.getP_t_add();
                double lastR = netUtils.getP_r_add();
                value = netUtils.getProcessNetValue(pName);
                double nowT = netUtils.getP_t_add();
                double nowR = netUtils.getP_r_add();
                // modify on 20120616 过滤有的手机进程流量偶尔输出负数的情况
                if ((nowT != lastT || nowR != lastR) && nowT >= 0 && nowR >= 0) {
                    OpPerfBridge.addHistory(op, value, new long[] { (long) nowT, (long) nowR });
                }
                return value;
            } else if (op.getKey().equals(CommonString.pm_pss_key + i + ":" + AUTManager.pNames[i])) {
                long[] long_value = MemUtils.getPSS(GTApp.getContext(), Integer.parseInt(AUTManager.pIds[i]));
                long tmp = long_value[0];
                long_value[0] = long_value[2];
                long_value[2] = tmp;
                for (int p = 0; p < long_value.length; p++) {
                    if (p == 2) {
                        value += " | Native:" + String.valueOf(long_value[p] + "KB");
                    } else if (p == 1) {
                        value += " | Dalvik:" + String.valueOf(long_value[p] + "KB");
                    } else if (p == 0) {
                        value += "Total:" + String.valueOf(long_value[p] + "KB");
                    }
                }
                OpPerfBridge.addHistory(op, value, long_value);
                return value;
            } else if (op.getKey().equals(CommonString.pm_pd_key + i + ":" + AUTManager.pNames[i])) {
                long[] long_value1 = MemUtils.getPrivDirty(GTApp.getContext(), Integer.parseInt(AUTManager.pIds[i]));
                long tmp = long_value1[0];
                long_value1[0] = long_value1[2];
                long_value1[2] = tmp;
                for (int pos = 0; pos < long_value1.length; pos++) {
                    if (pos == 2) {
                        value += " | Native:" + String.valueOf(long_value1[pos]);
                    } else if (pos == 1) {
                        value += " | Dalvik:" + String.valueOf(long_value1[pos]);
                    } else if (pos == 0) {
                        value += "Total:" + String.valueOf(long_value1[pos]);
                    }
                }
                OpPerfBridge.addHistory(op, value, long_value1);
                return value;
            } else if (op.getKey().equals(CommonString.pm_hp_key + i + ":" + AUTManager.pNames[i])) {
                long[] longhp_value = MemUtils.getHeapDalvik();
                long[] longhp_value2 = MemUtils.getHeapNative();
                long[] long_value3 = new long[2];
                // .getHeapDalvik();(GTSettingActivity.Pid[i]);
                long_value3[0] = longhp_value2[1];
                long_value3[1] = longhp_value[1];
                value += "Native:" + String.valueOf(longhp_value2[1] + "/" + String.valueOf(longhp_value2[0]));
                value += " | Dalvik:" + String.valueOf(longhp_value[1] + "/" + String.valueOf(longhp_value[0]));
                OpPerfBridge.addHistory(op, value, long_value3);
                return value;
            }
        }
    } catch (Exception e) {
    }
    return value;
}
Also used : NetUtils(com.tencent.wstt.gt.api.utils.NetUtils) OutPara(com.tencent.wstt.gt.OutPara) CommonString(com.tencent.wstt.gt.utils.CommonString)

Aggregations

OutPara (com.tencent.wstt.gt.OutPara)2 NetUtils (com.tencent.wstt.gt.api.utils.NetUtils)2 CommonString (com.tencent.wstt.gt.utils.CommonString)2 CpuUtils (com.tencent.wstt.gt.api.utils.CpuUtils)1 Client (com.tencent.wstt.gt.manager.Client)1 ArrayList (java.util.ArrayList)1