public String getWorkingThreadFilename() { String filename = null; if (m_filter != null) { String stackFilename = m_stackFile.getFilename(); String ext = new StringBuilder(20) .append('_') .append(WORKINGTHREAD_EXT) .append('.') .append(EXTENSION) .toString(); int index = stackFilename.indexOf(ext); if (index > 0) { filename = new StringBuilder(200) .append(stackFilename.substring(0, index)) .append('.') .append(m_filter) .toString(); } } else { filename = m_stackFile.getFilename(); } return getWorkingThreadFilename(filename); }
private static StackAnalyzedInfo readUniqueStackExtraInfo( StackAnalyzedInfo analyzedInfo, StackFileInfo stackFileInfo, File file, String name, String extension) { String filename = stackFileInfo.getFilename(); String analyzedFilename = StackParser.getAnaylzedFilename(filename, extension); file = new File(analyzedFilename); if (!file.isFile()) return null; BufferedReader reader = null; ArrayList<StackAnalyzedValue> list = analyzedInfo.getAnalyzedList(); try { reader = new BufferedReader(new FileReader(file)); String line; int indexNum = 0; boolean isStack = false; ArrayList<String> stackList = null; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() == 0) continue; if (!isStack && line.startsWith("[[]]")) { isStack = true; } if (!isStack) { continue; } if (line.startsWith("[[]]")) { if (stackList != null && stackList.size() > 0) { ((UniqueStackValue) list.get(indexNum)).setStack(stackList); } indexNum = Integer.parseInt(line.substring(4)); stackList = new ArrayList<String>(); } else { stackList.add(line); } } if (stackList != null && stackList.size() > 0) { ((UniqueStackValue) list.get(indexNum)).setStack(stackList); } } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { if (reader != null) reader.close(); } catch (Exception ex) { } } return analyzedInfo; }
public void analyze(StackFileInfo stackFile) { m_stackFile = stackFile; m_stackFile.clearAll(); m_stackFile.setUsedParser(this); m_stackFile.setParserConfig(m_config); init(); m_progressBarWindow = new ProgressBarWindow( MainProcessor.instance().getParentComposite().getShell(), "Stack log file Analyzing"); try { process(); makeTotalSecond(); } finally { if (m_workingThread_writer != null) { try { m_workingThread_writer.close(); } catch (Exception e) { } } m_progressBarWindow.close(); } if (m_filter != null) { String stackFilename = m_stackFile.getFilename(); String ext = new StringBuilder(20) .append('_') .append(WORKINGTHREAD_EXT) .append('.') .append(EXTENSION) .toString(); int index = stackFilename.indexOf(ext); if (index > 0) { stackFilename = new StringBuilder(200) .append(stackFilename.substring(0, index)) .append('.') .append(m_filter) .toString(); m_stackFile.setFilename(stackFilename); } } saveAll(); clearAll(); m_stackFile = null; }
private void saveAnalyzedInfo() { BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(getAnaylzedInfoFilename(m_stackFile.getFilename()))); writer.write(m_config.getConfigFilename()); writer.write('\n'); writer.write("" + m_dumpCount); writer.write('\t'); writer.write("" + m_totalWorkerCount); writer.write('\t'); writer.write("" + m_totalWorkingCount); writer.write('\t'); writer.write("" + m_totalSecond); int i; if (m_threadStatusList.size() > 0) { for (i = 0; i < m_threadStatusList.size(); i++) { writer.write('\t'); writer.write(m_threadStatusList.get(i)); } } writer.write('\n'); int size = m_timeList.size(); for (i = 0; i < size; i++) { writer.write((String) m_timeList.get(i)); writer.write('\n'); } } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (writer != null) { try { writer.close(); } catch (Exception e) { } } } }
public static void removeAllAnalyzedFile(StackFileInfo stackFileInfo) { String filename = stackFileInfo.getFilename(); if (filename != null) { ResourceUtils.removeFile(getAnaylzedInfoFilename(filename)); ResourceUtils.removeFile(getAnaylzedFilename(filename, WORKINGTHREAD_EXT)); ResourceUtils.removeFile(getAnaylzedFilename(filename, SERVICE_EXT)); ResourceUtils.removeFile(getAnaylzedFilename(filename, SQL_EXT)); ResourceUtils.removeFile(getAnaylzedFilename(filename, TOP_EXT)); ResourceUtils.removeFile(getAnaylzedFilename(filename, LOG_EXT)); ResourceUtils.removeFile(getAnaylzedFilename(filename, UNIQUE_EXT)); } ParserConfig config = stackFileInfo.getParserConfig(); if (config != null) { ArrayList<AnalyzerValue> list = config.getAnalyzerList(); if (list != null) { for (int i = 0; i < list.size(); i++) { ResourceUtils.removeFile(getAnaylzedFilename(filename, list.get(i).getExtension())); } } } }
private static StackAnalyzedInfo readStackAnalyzedInfo( StackFileInfo stackFileInfo, File file, String name, String extension) { String filename = stackFileInfo.getFilename(); String analyzedFilename = StackParser.getAnaylzedFilename(filename, extension); file = new File(analyzedFilename); if (!file.isFile()) return null; BufferedReader reader = null; StackAnalyzedInfo analyzedInfo = new StackAnalyzedInfo(name, stackFileInfo, extension); ArrayList<StackAnalyzedValue> list = new ArrayList<StackAnalyzedValue>(); try { reader = new BufferedReader(new FileReader(file)); String line = null; int lineCount = 0; StringTokenizer token = null; int index; String value; int count; int extPct; int intPct; String keyValue; StackAnalyzedValue analyzedValue; boolean isUniqueStack = (name.equals(StackParser.UNIQUE_NAME)) ? true : false; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() == 0) continue; if (lineCount == 0) { token = new StringTokenizer(line, "\t"); index = 0; while (token.hasMoreElements()) { value = token.nextToken(); if (index == 0) { // skip total working count total count } else if (index == 1) { analyzedInfo.setTotalCount(Integer.parseInt(value)); } else if (index == 2) { // skip percentage; } index++; } } else { char ch = line.charAt(0); if (ch >= '0' && ch <= '9') { count = 0; extPct = 0; intPct = 0; keyValue = null; token = new StringTokenizer(line, "\t"); index = 0; while (token.hasMoreElements()) { value = token.nextToken(); if (index == 0) { count = Integer.parseInt(value); } else if (index == 1) { extPct = Integer.parseInt(value); } else if (index == 2) { intPct = Integer.parseInt(value); } else if (index == 3) { keyValue = value; } index++; } if (index == 4) { if (isUniqueStack) { analyzedValue = new UniqueStackValue(keyValue, count, intPct, extPct); } else { analyzedValue = new StackAnalyzedValue(keyValue, count, intPct, extPct); } list.add(analyzedValue); } } else { break; } } lineCount++; } } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { if (reader != null) reader.close(); } catch (Exception ex) { } } analyzedInfo.setAnaylizedList(list); return analyzedInfo; }
private StackAnalyzedInfo saveUniqueStackAnalyzedInfo( HashMap<Integer, UniqueStackValue> map, String analyzedName, String extension) { if (map == null || map.size() == 0) return null; BufferedWriter writer = null; StackAnalyzedInfo aynalyzedInfo = null; try { writer = new BufferedWriter( new FileWriter(getAnaylzedFilename(m_stackFile.getFilename(), extension))); int i = 0; ArrayList<StackAnalyzedValue> sortList = new ArrayList<StackAnalyzedValue>(400); UniqueStackValue value = null; int totalCount = 0; Iterator<UniqueStackValue> iter = map.values().iterator(); while (iter.hasNext()) { totalCount += iter.next().getCount(); } iter = map.values().iterator(); while (iter.hasNext()) { value = iter.next(); value.setExtPct((int) ((10000 * value.getCount()) / m_totalWorkingCount)); value.setIntPct((int) ((10000 * value.getCount()) / totalCount)); sortList.add(value); } Collections.sort(sortList, new StackAnalyzedValueComp()); aynalyzedInfo = new StackAnalyzedInfo(analyzedName, m_stackFile, extension); aynalyzedInfo.setTotalCount(totalCount); aynalyzedInfo.setAnaylizedList(sortList); StringBuilder buffer = new StringBuilder(100); buffer .append(m_totalWorkingCount) .append('\t') .append(totalCount) .append('\t') .append((int) ((10000 * totalCount) / m_totalWorkingCount)) .append('\n'); writer.write(buffer.toString()); for (i = 0; i < sortList.size(); i++) { value = (UniqueStackValue) sortList.get(i); buffer = new StringBuilder(100); buffer .append(value.getCount()) .append('\t') .append(value.getExtPct()) .append('\t') .append(value.getIntPct()) .append('\t') .append(value.getValue()) .append('\n'); writer.write(buffer.toString()); } writer.write("\n"); for (i = 0; i < sortList.size(); i++) { writer.write("[[]]" + i + "\n"); value = (UniqueStackValue) sortList.get(i); for (String stack : value.getStack()) { writer.write(stack); writer.write("\n"); } writer.write("\n"); } } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (writer != null) { try { writer.close(); } catch (Exception e) { } } } return aynalyzedInfo; }
private StackAnalyzedInfo saveStackAnalyzedInfo( ArrayList<String> list, String analyzedName, String extension) { if (list == null || list.size() == 0) return null; BufferedWriter writer = null; StackAnalyzedInfo aynalyzedInfo = null; try { writer = new BufferedWriter( new FileWriter(getAnaylzedFilename(m_stackFile.getFilename(), extension))); int i = 0; int size = list.size(); HashMap<String, StackAnalyzedValue> searchMap = new HashMap<String, StackAnalyzedValue>(400); ArrayList<StackAnalyzedValue> sortList = new ArrayList<StackAnalyzedValue>(400); String key = null; StackAnalyzedValue value = null; for (i = 0; i < size; i++) { key = StringUtils.makeStackValue((String) list.get(i), true); if ((value = (StackAnalyzedValue) searchMap.get(key)) == null) { value = new StackAnalyzedValue(key, 1, 0, 0); searchMap.put(key, value); sortList.add(value); } else { value.addCount(); } } searchMap = null; Collections.sort(sortList, new StackAnalyzedValueComp()); aynalyzedInfo = new StackAnalyzedInfo(analyzedName, m_stackFile, extension); aynalyzedInfo.setTotalCount(size); aynalyzedInfo.setAnaylizedList(sortList); StringBuilder buffer = new StringBuilder(100); buffer .append(m_totalWorkingCount) .append('\t') .append(size) .append('\t') .append((int) ((10000 * size) / m_totalWorkingCount)) .append('\n'); writer.write(buffer.toString()); for (i = 0; i < sortList.size(); i++) { value = sortList.get(i); value.setExtPct((int) ((10000 * value.getCount()) / m_totalWorkingCount)); value.setIntPct((int) ((10000 * value.getCount()) / size)); buffer = new StringBuilder(100); buffer .append(value.getCount()) .append('\t') .append(value.getExtPct()) .append('\t') .append(value.getIntPct()) .append('\t') .append(value.getValue()) .append('\n'); writer.write(buffer.toString()); } writer.write("\n"); for (i = 0; i < size; i++) { writer.write((String) list.get(i)); writer.write("\n"); } } catch (Exception ex) { throw new RuntimeException(ex); } finally { if (writer != null) { try { writer.close(); } catch (Exception e) { } } } return aynalyzedInfo; }