Search in sources :

Example 1 with CpuUtils

use of com.tencent.wstt.gt.api.utils.CpuUtils 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)

Aggregations

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