Search in sources :

Example 1 with TimeEntry

use of com.tencent.wstt.gt.ui.model.TimeEntry in project GT by Tencent.

the class LogUtils method writeTimeDetail.

public static void writeTimeDetail(TagTimeEntry tte, String fileName) {
    if (!GTUtils.isSDCardExist()) {
        return;
    }
    int la = fileName.lastIndexOf(".");
    if (la < 0) {
        fileName = fileName + LogUtils.TLOG_POSFIX;
    } else {
        String temp = fileName.substring(la);
        if (temp.contains(FileUtil.separator) || temp.contains("\\")) {
            // "."是目录名的一部分而不是后缀名的情况
            fileName = fileName + LogUtils.TLOG_POSFIX;
        }
    // else fileName = fileName
    }
    File f = null;
    if (fileName.contains(FileUtil.separator) || fileName.contains("\\")) {
        f = new File(fileName);
    } else {
        Env.ROOT_TIME_FOLDER.mkdirs();
        f = new File(Env.ROOT_TIME_FOLDER, fileName);
    }
    if (f.exists()) {
        f.delete();
    }
    FileWriter fw = null;
    try {
        fw = new FileWriter(f, true);
    } catch (IOException e) {
        e.printStackTrace();
    }
    StringBuffer sb = new StringBuffer();
    if (null != tte.getParent() && tte.getParent() instanceof GroupTimeEntry) {
        sb.append("group,");
        sb.append(tte.getParent().getName());
        sb.append("\r\n");
    }
    sb.append("tag,");
    sb.append(tte.getName());
    sb.append("\r\n");
    sb.append("isInThread,");
    sb.append(tte.getTid() == 0 ? "false" : "true");
    sb.append("\r\n");
    if (!tte.hasChild()) {
        for (TimeEntry time : tte.getRecordList()) {
            if (sb.length() > 8192) {
                writeNotClose(sb.toString(), f, fw);
                sb = new StringBuffer();
            }
            sb.append(time);
            sb.append("\r\n");
        }
    } else // 支持多组数据的保存
    {
        for (int i = 0; i < tte.getSubTagEntrys()[0].getRecordSize(); i++) {
            for (int j = 0; j < tte.getSubTagEntrys().length; j++) {
                TagTimeEntry subEntry = tte.getSubTagEntrys()[j];
                TimeEntry time = subEntry.getRecord(i);
                if (sb.length() > 8192) {
                    writeNotClose(sb.toString(), f, fw);
                    sb = new StringBuffer();
                }
                if (j == 0) {
                    sb.append(time);
                } else {
                    sb.append(time.reduce);
                }
                if (j == tte.getSubTagEntrys().length - 1) {
                    sb.append("\r\n");
                } else {
                    sb.append(",");
                }
            }
        }
    }
    if (tte.getRecordSize() != 0) {
        sb.deleteCharAt(sb.length() - 1);
    }
    sb.append("\r\n");
    writeNotClose(sb.toString(), f, fw);
    FileUtil.closeWriter(fw);
}
Also used : TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) GroupTimeEntry(com.tencent.wstt.gt.ui.model.GroupTimeEntry) TimeEntry(com.tencent.wstt.gt.ui.model.TimeEntry) FileWriter(java.io.FileWriter) IOException(java.io.IOException) GroupTimeEntry(com.tencent.wstt.gt.ui.model.GroupTimeEntry) File(java.io.File)

Example 2 with TimeEntry

use of com.tencent.wstt.gt.ui.model.TimeEntry in project GT by Tencent.

the class GTMulOpPerfDetailView method setInput.

/**
 * 需要传入微秒单位的数据
 *
 * @param input
 *            页面显示的数据源
 * @param ave
 *            整体的平均值, 现在页面显示的不是这个数,是页面显示那几条的平均值
 */
private void setInput(@SuppressWarnings("rawtypes") List[] input) {
    curSize = input[0].size();
    for (int i = 0; i < curSize; i++) {
        for (int j = 0; j < input.length; j++) {
            this.cache[i][j].time = ((TimeEntry) (input[j].get(i))).time;
            this.cache[i][j].value = ((TimeEntry) (input[j].get(i))).reduce / dataSet.getCarry();
            this.cache[i][j].i = i;
            this.cache[i][j].y = 0;
        }
    }
    // 找出y最大值,并给出每个点的坐标
    curYMax = 0;
    curYMin = 0;
    if (curSize > 0) {
        // 随便取一个值作为初始最小值
        curYMin = cache[0][0].value;
    }
    long aveCount = 0;
    long tempAve = 0;
    for (int i = 0; i < curSize; i++) {
        for (int j = 0; j < input.length; j++) {
            curYMax = Math.max(curYMax, cache[i][j].value);
            curYMin = Math.min(curYMin, cache[i][j].value);
            // 顺便算页面显示的平均值,平均值只取一维的
            aveCount += cache[i][0].value;
        }
    }
    if (curSize > 0) {
        tempAve = Math.round((float) aveCount / (float) curSize);
    }
    curYMax = Math.max(curYMax, yGridMinMax);
    if (// 纵坐标要求是100的整数倍
    curYMax > yGridMinMax) {
        curYMax = (curYMax / yGridMinMax + 1) * yGridMinMax;
    }
    if (curYMax > yMax) {
        curYMax = yMax;
    }
    if (curYMin > 0) {
        curYMin = (curYMin / yGridMinMax) * yGridMinMax;
    }
    if (curYMin > 0) {
        curYMin = curYMin - (curYMax - curYMin) / yMaxGridNum;
        // 别减成负数了
        curYMin = Math.max(0, curYMin);
    }
    if (curYMin > yMax) {
        // 要保证curYMin比curYMax小,因为这个减数会做分母
        curYMin = yMax - 1;
    }
    // 注意分母
    if (tempAve > curYMin) {
        this.curAve = calcY(tempAve);
    }
    // 手动触发一次onDrow
    postInvalidate();
}
Also used : TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) TimeEntry(com.tencent.wstt.gt.ui.model.TimeEntry) Paint(android.graphics.Paint)

Example 3 with TimeEntry

use of com.tencent.wstt.gt.ui.model.TimeEntry in project GT by Tencent.

the class SMDataService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    String pkgName = intent.getStringExtra("pkgName");
    String key = "SM:" + pkgName;
    //		String SFKey = "SF:" + pkgName;
    Client globalClient = ClientManager.getInstance().getGlobalClient();
    globalClient.registerOutPara(key, "SM");
    globalClient.setOutparaMonitor(key, true);
    OpPerfBridge.startProfier(globalClient.getOutPara(key), Functions.PERF_DIGITAL_NORMAL, "", "");
    /*
		 * SM设置默认的告警阈值为40,
		 * TODO 这里设置是简单支持SM的告警需求,SDK命令支持比较麻烦,就先加在这里了
		 */
    OpPerfBridge.getProfilerData(key).getThresholdEntry().setThreshold(1, Integer.MAX_VALUE, 40);
    // 主动刷新出参页面的列表
    GTApp.getOpHandler().sendEmptyMessage(5);
    GTApp.getOpEditHandler().sendEmptyMessage(0);
    //		
    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();
            // 补偿参数
            //Math.min(len, n);
            int p = 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, 60 - v);
            //					globalClient.setOutPara(SFKey, v);
            }
        } else {
            int sm = 60 - x;
            globalClient.setOutPara(key, sm);
        //				globalClient.setOutPara(SFKey, x);
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
Also used : TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) TimeEntry(com.tencent.wstt.gt.ui.model.TimeEntry) Client(com.tencent.wstt.gt.manager.Client)

Example 4 with TimeEntry

use of com.tencent.wstt.gt.ui.model.TimeEntry in project GT by Tencent.

the class LogUtils method writeGWDataForSM.

public static void writeGWDataForSM(final GWSaveEntry saveEntry, TagTimeEntry tte) {
    if (!GTUtils.isSDCardExist() || tte == null) {
        return;
    }
    if (!tte.hasChild() && tte.getRecordSize() == 0) {
        return;
    } else if (tte.hasChild() && tte.getSubTagEntrys()[0].getRecordSize() == 0) {
        return;
    }
    String sFolder = Env.S_ROOT_GW_FOLDER + saveEntry.path1 + FileUtil.separator + saveEntry.path2 + FileUtil.separator + saveEntry.path3 + FileUtil.separator;
    File folder = new File(sFolder);
    folder.mkdirs();
    // SM的保存文件名使用出参名,这样多个Client同时保存不会出现重名覆盖问题
    String fName = getTagTimeEntryFileName(tte, saveEntry);
    File f = new File(folder, fName);
    if (f.exists()) {
        return;
    }
    FileWriter fw = null;
    // 在这里最后算一下分,否则没进具体页没有算分的机会
    List<Integer> smrs = SMUtils.getSmDetail(tte.getRecordList());
    tte.exInt_1 = smrs.get(1);
    tte.exInt_2 = smrs.get(3);
    tte.exInt_3 = smrs.get(5);
    try {
        fw = new FileWriter(f, true);
        StringBuffer sb = new StringBuffer();
        sb.append("key,");
        sb.append(tte.getName());
        sb.append("\r\n");
        sb.append("alias,");
        sb.append(tte.getAlias());
        sb.append("\r\n");
        sb.append("unit,");
        // PSS和PD的单位特殊,保存的KB,曲线图上显示的MB
        sb.append(tte.getUnit());
        sb.append("\r\n");
        int size = tte.getRecordSize();
        long firstTime = tte.getRecord(0).time;
        long lastTime = tte.getRecord(size - 1).time;
        ArrayList<TimeEntry> tempRecordList = tte.getRecordList();
        sb.append("begin date,");
        sb.append(GTUtils.getDate(firstTime));
        sb.append("\r\n");
        sb.append("end date,");
        sb.append(GTUtils.getDate(lastTime));
        sb.append("\r\n");
        sb.append("count,");
        sb.append(size);
        sb.append("\r\n");
        sb.append("\r\n");
        sb.append("bad time,");
        sb.append(tte.exInt_1);
        sb.append("\r\n");
        sb.append("good time,");
        sb.append(tte.exInt_2);
        sb.append("\r\n");
        sb.append("score,");
        sb.append(tte.exInt_3);
        sb.append("\r\n");
        sb.append("min,");
        sb.append(tte.getMin());
        sb.append("\r\n");
        sb.append("avg,");
        sb.append(tte.getAve());
        sb.append("\r\n");
        sb.append("\r\n");
        for (TimeEntry time : tempRecordList) {
            if (sb.length() > 8192) {
                writeNotClose(sb.toString(), f, fw);
                sb = new StringBuffer();
            }
            sb.append(time);
            sb.append("\r\n");
        }
        if (tte.getRecordSize() != 0) {
            sb.deleteCharAt(sb.length() - 1);
        }
        sb.append("\r\n");
        writeNotClose(sb.toString(), f, fw);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        FileUtil.closeWriter(fw);
    }
}
Also used : TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) GroupTimeEntry(com.tencent.wstt.gt.ui.model.GroupTimeEntry) TimeEntry(com.tencent.wstt.gt.ui.model.TimeEntry) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 5 with TimeEntry

use of com.tencent.wstt.gt.ui.model.TimeEntry in project GT by Tencent.

the class LogUtils method writeGWData.

public static void writeGWData(final GWSaveEntry saveEntry, TagTimeEntry tte) {
    if (!GTUtils.isSDCardExist() || tte == null) {
        return;
    }
    if (!tte.hasChild() && tte.getRecordSize() == 0) {
        return;
    } else if (tte.hasChild() && tte.getSubTagEntrys()[0].getRecordSize() == 0) {
        return;
    }
    String sFolder = Env.S_ROOT_GW_FOLDER + saveEntry.path1 + FileUtil.separator + saveEntry.path2 + FileUtil.separator + saveEntry.path3 + FileUtil.separator;
    File folder = new File(sFolder);
    folder.mkdirs();
    String fName = getTagTimeEntryFileName(tte, saveEntry);
    File f = new File(folder, fName);
    if (f.exists()) {
        return;
    }
    FileWriter fw = null;
    try {
        fw = new FileWriter(f, true);
        StringBuffer sb = new StringBuffer();
        sb.append("key,");
        sb.append(tte.getName());
        sb.append("\r\n");
        sb.append("alias,");
        sb.append(tte.getAlias());
        sb.append("\r\n");
        sb.append("unit,");
        // PSS和PD的单位特殊,保存的KB,曲线图上显示的MB
        if (tte.getFunctionId() == Functions.PERF_DIGITAL_MULT_MEM) {
            sb.append("(KB)");
        } else {
            sb.append(tte.getUnit());
        }
        sb.append("\r\n");
        if (!tte.hasChild()) {
            int size = tte.getRecordSize();
            long firstTime = tte.getRecord(0).time;
            long lastTime = tte.getRecord(size - 1).time;
            ArrayList<TimeEntry> tempRecordList = tte.getRecordList();
            sb.append("begin date,");
            sb.append(GTUtils.getDate(firstTime));
            sb.append("\r\n");
            sb.append("end date,");
            sb.append(GTUtils.getDate(lastTime));
            sb.append("\r\n");
            sb.append("count,");
            sb.append(size);
            sb.append("\r\n");
            sb.append("\r\n");
            sb.append("min,");
            sb.append(tte.getMin());
            sb.append("\r\n");
            sb.append("max,");
            sb.append(tte.getMax());
            sb.append("\r\n");
            sb.append("avg,");
            sb.append(tte.getAve());
            sb.append("\r\n");
            sb.append("\r\n");
            for (TimeEntry time : tempRecordList) {
                if (sb.length() > 8192) {
                    writeNotClose(sb.toString(), f, fw);
                    sb = new StringBuffer();
                }
                sb.append(time);
                sb.append("\r\n");
            }
        } else // 支持多组数据的保存
        {
            TagTimeEntry temp = tte.getChildren()[0];
            int size = temp.getRecordSize();
            long firstTime = temp.getRecord(0).time;
            long lastTime = temp.getRecord(size - 1).time;
            sb.append("begin date,");
            sb.append(GTUtils.getDate(firstTime));
            sb.append("\r\n");
            sb.append("end date,");
            sb.append(GTUtils.getDate(lastTime));
            sb.append("\r\n");
            sb.append("count,");
            sb.append(size);
            sb.append("\r\n");
            sb.append("\r\n");
            sb.append(",");
            for (TagTimeEntry child : tte.getChildren()) {
                sb.append(child.getName());
                sb.append(",");
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append("\r\n");
            sb.append("min,");
            for (TagTimeEntry child : tte.getChildren()) {
                sb.append(child.getMin());
                sb.append(",");
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append("\r\n");
            sb.append("max,");
            for (TagTimeEntry child : tte.getChildren()) {
                sb.append(child.getMax());
                sb.append(",");
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append("\r\n");
            sb.append("avg,");
            for (TagTimeEntry child : tte.getChildren()) {
                sb.append(child.getAve());
                sb.append(",");
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append("\r\n");
            sb.append("\r\n");
            for (int i = 0; i < size; i++) {
                for (int j = 0; j < tte.getSubTagEntrys().length; j++) {
                    TagTimeEntry subEntry = tte.getSubTagEntrys()[j];
                    TimeEntry time = subEntry.getRecord(i);
                    if (sb.length() > 8192) {
                        writeNotClose(sb.toString(), f, fw);
                        sb = new StringBuffer();
                    }
                    if (j == 0) {
                        sb.append(time);
                    } else {
                        sb.append(time.reduce);
                    }
                    if (j == tte.getSubTagEntrys().length - 1) {
                        sb.append("\r\n");
                    } else {
                        sb.append(",");
                    }
                }
            }
        }
        if (tte.getRecordSize() != 0) {
            sb.deleteCharAt(sb.length() - 1);
        }
        sb.append("\r\n");
        writeNotClose(sb.toString(), f, fw);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        FileUtil.closeWriter(fw);
    }
    // 简单过滤保存
    if (GTMemHelperFloatview.memInfoList.size() <= 0) {
        // 不存在这种数据直接return
        return;
    }
    File tagFile = new File(folder, "tagMem_" + saveEntry.now + LogUtils.GW_POSFIX);
    if (tagFile.exists()) {
        tagFile.delete();
    }
    FileWriter fwTagFile = null;
    try {
        fwTagFile = new FileWriter(tagFile, true);
    } catch (IOException e) {
        e.printStackTrace();
    }
    StringBuffer sb = null;
    sb = new StringBuffer();
    sb.append("time(ms)");
    sb.append(",");
    sb.append("DalvikHeapSize(KB)");
    sb.append(",");
    sb.append("DalvikAllocated(KB)");
    sb.append(",");
    sb.append("private_dirty(KB)");
    sb.append(",");
    sb.append("PSS_Total(KB)");
    sb.append(",");
    sb.append("PSS_Dalvik(KB)");
    sb.append(",");
    sb.append("PSS_Native(KB)");
    sb.append(",");
    sb.append("PSS_OtherDev(KB)");
    sb.append(",");
    sb.append("PSS_Graphics(KB)");
    sb.append(",");
    sb.append("PSS_GL(KB)");
    sb.append(",");
    sb.append("PSS_Unknow(KB)");
    sb.append("\r\n");
    for (MemInfo mem : GTMemHelperFloatview.memInfoList) {
        if (sb.length() > 8192) {
            writeNotClose(sb.toString(), tagFile, fwTagFile);
            sb = new StringBuffer();
        }
        sb.append(GTUtils.getSaveTime(mem.time));
        sb.append(",");
        sb.append(mem.dalvikHeapSize);
        sb.append(",");
        sb.append(mem.dalvikAllocated);
        sb.append(",");
        sb.append(mem.private_dirty);
        sb.append(",");
        sb.append(mem.pss_total);
        sb.append(",");
        sb.append(mem.pss_Dalvik);
        sb.append(",");
        sb.append(mem.pss_Native);
        sb.append(",");
        sb.append(mem.pss_OtherDev);
        sb.append(",");
        sb.append(mem.pss_graphics);
        sb.append(",");
        sb.append(mem.pss_gl);
        sb.append(",");
        sb.append(mem.pss_UnKnown);
        sb.append("\r\n");
    }
    writeNotClose(sb.toString(), tagFile, fwTagFile);
    FileUtil.closeWriter(fwTagFile);
// add on 20131225 有手动tag记录内存值的情况,先把tag的内存值保存了 end
}
Also used : TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) TagTimeEntry(com.tencent.wstt.gt.ui.model.TagTimeEntry) GroupTimeEntry(com.tencent.wstt.gt.ui.model.GroupTimeEntry) TimeEntry(com.tencent.wstt.gt.ui.model.TimeEntry) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) MemInfo(com.tencent.wstt.gt.proInfo.floatView.MemInfo)

Aggregations

TagTimeEntry (com.tencent.wstt.gt.ui.model.TagTimeEntry)6 TimeEntry (com.tencent.wstt.gt.ui.model.TimeEntry)6 GroupTimeEntry (com.tencent.wstt.gt.ui.model.GroupTimeEntry)4 File (java.io.File)4 FileWriter (java.io.FileWriter)4 IOException (java.io.IOException)4 Paint (android.graphics.Paint)1 Client (com.tencent.wstt.gt.manager.Client)1 MemInfo (com.tencent.wstt.gt.proInfo.floatView.MemInfo)1