Search in sources :

Example 1 with MemInfo

use of com.tencent.wstt.gt.proInfo.floatView.MemInfo in project GT by Tencent.

the class LogUtils method writeTagMemData.

public static void writeTagMemData(String pkgName, 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 {
        String parentFolder = Env.S_ROOT_GW_MAN_FOLDER + Env.CUR_APP_NAME + FileUtil.separator;
        File folder = new File(parentFolder);
        folder.mkdirs();
        f = new File(folder, fileName);
    }
    if (f.exists()) {
        f.delete();
    }
    FileWriter fw = null;
    try {
        fw = new FileWriter(f, true);
    } catch (IOException e) {
        e.printStackTrace();
    }
    StringBuffer sb = null;
    sb = new StringBuffer();
    sb.append(pkgName);
    sb.append("\r\n");
    sb.append("time(ms)");
    sb.append(",");
    sb.append("DalvikHeapSize(KB)");
    sb.append(",");
    sb.append("DalvikAllocated(KB)");
    sb.append(",");
    sb.append("NativeHeapSize(KB)");
    sb.append(",");
    sb.append("NativeAllocated(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(), f, fw);
            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.nativeHeapSize);
        sb.append(",");
        sb.append(mem.nativeAllocated);
        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(), f, fw);
    FileUtil.closeWriter(fw);
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) MemInfo(com.tencent.wstt.gt.proInfo.floatView.MemInfo)

Example 2 with MemInfo

use of com.tencent.wstt.gt.proInfo.floatView.MemInfo 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

MemInfo (com.tencent.wstt.gt.proInfo.floatView.MemInfo)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 GroupTimeEntry (com.tencent.wstt.gt.ui.model.GroupTimeEntry)1 TagTimeEntry (com.tencent.wstt.gt.ui.model.TagTimeEntry)1 TimeEntry (com.tencent.wstt.gt.ui.model.TimeEntry)1