/** 记录单点的性能数据(start和end这种成对的称为双点性能数据),也按tid区分全局的还是线程的 */ public void recordDigital(long tid, String group, String tag, long[] datas, int funcId) { if (!started) { return; } 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 staticsTagTimeEntry = groupEntry.getStaticsEntry(tag, tid); if (null == staticsTagTimeEntry) { staticsTagTimeEntry = new TagTimeEntry(groupEntry); staticsTagTimeEntry.setName(tag); staticsTagTimeEntry.setTid(tid); staticsTagTimeEntry.setFunctionId(funcId); staticsTagTimeEntry.initChildren(datas.length - 1); groupEntry.addStaticsEntry(staticsTagTimeEntry); } if (Functions.PERF_DIGITAL_MULT == funcId || Functions.PERF_DIGITAL_MULT_MEM == funcId) { TagTimeEntry[] subEntrys = staticsTagTimeEntry.getSubTagEntrys(); for (int i = 0; i < subEntrys.length; i++) { TagTimeEntry subEntry = subEntrys[i]; subEntry.add(datas[i]); } staticsTagTimeEntry.add(datas[0]); // TODO 得记录一个维度的值,否则外面UI无法展示 } else { staticsTagTimeEntry.add(datas[0]); } } }
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; }