use of com.tencent.wstt.gt.ui.model.GroupTimeEntry in project GT by Tencent.
the class LogTimeController method startTime.
/**
* 规定不区分线程的tid为0,被测程序的线程号为正数,GT控制台的线程号为负数
*/
public void startTime(long tid, String group, String tag, int exKey, long start, int funcId) {
if (null != group && null != tag) {
GroupTimeEntry groupEntry = groupMap.get(group);
if (null == groupEntry) {
groupEntry = new GroupTimeEntry(group);
lock.lock();
groupMap.put(group, groupEntry);
lock.unlock();
}
// 从Group中取出由tag, tid, exKey共同标示的TagTimeEntry对象
TagTimeEntry tagEntry = groupEntry.getThreadEntry(tag, tid, exKey);
if (null == tagEntry) {
tagEntry = new TagTimeEntry(groupEntry);
tagEntry.setName(tag);
tagEntry.setTid(tid);
tagEntry.setExkey(exKey);
/*
* funcId用的是PERF_START_TIME_GLOBAL或PERF_START_DIGITAL_GLOBAL
* 对于后面的使用只是保证UI精度,不会做其他依赖funcId的逻辑计算
*/
tagEntry.setFunctionId(funcId);
groupEntry.addEntry(tagEntry);
}
tagEntry.setLastStart(start);
}
}
use of com.tencent.wstt.gt.ui.model.GroupTimeEntry in project GT by Tencent.
the class LogTimeController method getTagTimeEntry.
/**
* 给详情页返回数据源,要么返回全局的统计,要么返回区分线程的统计
* @param tid
* @param parentName
* @param name
* @return
*/
public TagTimeEntry getTagTimeEntry(long tid, String parentName, String name) {
GroupTimeEntry groupTimeEntry = groupMap.get(parentName);
TagTimeEntry tagTimeEntry = null;
if (null != groupTimeEntry) {
tagTimeEntry = groupTimeEntry.getStaticsEntry(name, tid);
}
return tagTimeEntry;
}
use of com.tencent.wstt.gt.ui.model.GroupTimeEntry in project GT by Tencent.
the class LogTimeController method endTime.
public long endTime(long tid, String group, String tag, int exKey, long end, int funcId) {
if (null != group && null != tag) {
GroupTimeEntry groupEntry = null;
TagTimeEntry tagEntry = null;
if (null == groupMap.get(group)) {
return -1;
}
groupEntry = groupMap.get(group);
if (null == groupEntry) {
return -1;
}
tagEntry = groupEntry.getThreadEntry(tag, tid, exKey);
if (null == tagEntry) {
return -1;
}
if (tagEntry.getLastStart() <= 0) {
return -1;
}
long reduce = end - tagEntry.getLastStart();
tagEntry.setLastStart(0);
if (started) {
// 在对应的统计对象中加入差值,注意统计值是不关注exKey的
TagTimeEntry staticsTagTimeEntry = groupEntry.getStaticsEntry(tag, tid);
staticsTagTimeEntry.add(reduce);
}
return reduce;
}
return -1;
}
use of com.tencent.wstt.gt.ui.model.GroupTimeEntry in project GT by Tencent.
the class LogUtils method writeTimeLog.
public static void writeTimeLog(List<GroupTimeEntry> list, 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 = null;
for (GroupTimeEntry gte : list) {
for (TagTimeEntry tte : gte.entrys()) {
sb = new StringBuffer();
sb.append("group,");
sb.append(gte.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");
ArrayList<TimeEntry> tempRecordList = tte.getRecordList();
for (TimeEntry time : tempRecordList) {
if (sb.length() > 8192) {
writeNotClose(sb.toString(), f, fw);
sb = new StringBuffer();
}
sb.append(time);
// sb.append(",");
sb.append("\r\n");
}
if (!tempRecordList.isEmpty()) {
sb.deleteCharAt(sb.length() - 1);
}
// 可以及时释放
tempRecordList = null;
sb.append("\r\n");
writeNotClose(sb.toString(), f, fw);
}
}
FileUtil.closeWriter(fw);
}
Aggregations