public static StackParser getParser(ParserConfig config, String filter, boolean isInclude) { StackParser parser = null; if (filter != null) { if (isInclude) { parser = new FilterStackParser(); } else { parser = new FilterExcludeStackParser(); } parser.setFilter(filter); } else { String parserName = config.getParserName(); if (parserName == null) { parser = new BasicFileStackParser(); } else { if (parserName.indexOf(',') < 0) { parserName = "scouter.client.stack.data." + parserName; } try { @SuppressWarnings("rawtypes") Class cl = Class.forName(parserName); parser = (StackParser) cl.newInstance(); } catch (Exception ex) { throw new RuntimeException(ex); } } } parser.setConfig(config); return parser; }
private void reanalyzeStackFileInfo() { TreeItem item = getSelectedRootItemFromMainTree(); if (item == null) { return; } StackFileInfo stackFileInfo = (StackFileInfo) item.getData(); if (stackFileInfo == null) { return; } try { ParserConfigReader reader = new ParserConfigReader(stackFileInfo.getParserConfig().getConfigFilename()); ParserConfig config = reader.read(); StackParser.removeAllAnalyzedFile(stackFileInfo); processStackFile(stackFileInfo, config, null, false, true); } catch (RuntimeException ex) { closeStackFileInfo(); throw ex; } item.removeAll(); item.setText(stackFileInfo.toTreeInfo()); addMainTreeSubItem(item, stackFileInfo.getStackAnalyzedInfoList()); item.setExpanded(true); clearTable(); }
public void analyzeFilterStack(String inputFilter, boolean isInclude) { String filter = null; if (inputFilter == null) { filter = getSelectedAnalyzedFunction(); } else { filter = inputFilter; } if (filter == null) return; StackFileInfo stackFileInfo = getSelectedStackFileInfo(); if (stackFileInfo == null) return; ParserConfigReader reader = new ParserConfigReader(stackFileInfo.getParserConfig().getConfigFilename()); ParserConfig config = reader.read(); StackFileInfo filteredStackFileInfo = processStackFile( StackParser.getWorkingThreadFilename(stackFileInfo.getFilename()), config, filter, false, isInclude); addProcessedStack(filteredStackFileInfo); }
private StackFileInfo processStackFile( StackFileInfo stackFileInfo, ParserConfig config, String filter, boolean isRecent, boolean isInclude) { try { StackParser parser = StackParser.getParser(config, filter, isInclude); parser.analyze(stackFileInfo); stackFileInfo = postSTackFile(stackFileInfo, config, filter, isRecent); } catch (RuntimeException ex) { StackParser.removeAllAnalyzedFile(stackFileInfo); throw ex; } return stackFileInfo; }
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 viewServiceCall(String filter) { if (filter == null) return; StackFileInfo stackFileInfo = getSelectedStackFileInfo(); if (stackFileInfo == null) return; String filename = StackParser.getWorkingThreadFilename(stackFileInfo.getFilename()); int stackStartLine = stackFileInfo.getParserConfig().getStackStartLine(); if (filename != null && filter != null) { getBrowser() .setText( HtmlUtils.filterServiceCall( filename, filter, stackFileInfo.getParserConfig().getService(), stackStartLine)); } }
public void viewThreadStack(String filter) { if (filter == null) return; StackFileInfo stackFileInfo = getSelectedStackFileInfo(); if (stackFileInfo == null) return; String filename = StackParser.getWorkingThreadFilename(stackFileInfo.getFilename()); int stackStartLine = stackFileInfo.getParserConfig().getStackStartLine(); if (filename != null && filter != null) { Browser broswer = getBrowser(); if (m_isExcludeStack) broswer.setText( HtmlUtils.filterThreadStack( filename, filter, stackFileInfo.getParserConfig().getExcludeStack(), stackStartLine)); else broswer.setText(HtmlUtils.filterThreadStack(filename, filter, null, stackStartLine)); } }
private void viewRawIndexFile() { Object object = getSelectedFromMainTree(); if (object == null) { return; } if (!(object instanceof StackAnalyzedInfo)) { return; } StackAnalyzedInfo analyzedInfo = (StackAnalyzedInfo) object; if (analyzedInfo.getExtension().equals(StackParser.UNIQUE_EXT)) { return; } StackFileInfo stackFileInfo = analyzedInfo.getStackFileInfo(); System.out.println("StackFile:" + stackFileInfo.toString()); System.out.println("File:" + analyzedInfo.toString()); String analyzedFilename = StackParser.getAnaylzedFilename(stackFileInfo.getFilename(), analyzedInfo.getExtension()); File file = new File(analyzedFilename); if (!file.isFile()) return; BufferedReader reader = null; boolean isDetail = false; boolean isStart = false; try { reader = new BufferedReader(new FileReader(file)); String line = null; int totalCount = 0; HashMap<String, Integer> map = new HashMap<String, Integer>(); while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() > 0) { isStart = true; } if (line.length() == 0) { if (isStart) { isDetail = true; } continue; } if (isDetail) { totalCount++; HtmlUtils.caculCounter(line, map); } } ArrayList<ValueObject> list = HtmlUtils.sortCounter(map); StringBuilder buffer = new StringBuilder(102400); buffer.append(HtmlUtils.getMainBodyStart()); buffer.append(HtmlUtils.getCurrentConfigurationBody()).append("<br><br>"); buffer.append("<b>[ ").append(stackFileInfo.getFilename()).append(" ]</b><BR>"); buffer .append("<b>") .append(analyzedInfo.toString()) .append(" - ") .append(analyzedFilename) .append("</b><br><br>"); buffer.append( "<table border='1'><tr align='center'><th>Count</th><th>Percent</th><th>Class.method</th></tr>"); int value; for (ValueObject valueObject : list) { value = valueObject.getValue(); buffer .append("<tr><td align='right'>") .append(value) .append("</td><td align='right'>") .append((int) ((100 * value) / totalCount)) .append('%') .append("</td>"); buffer.append("<td align='left'>").append(valueObject.getKey()).append("</td></tr>"); } buffer.append("</table>"); buffer.append(HtmlUtils.getMainBodyEnd()); displayContent(buffer.toString()); } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { if (reader != null) reader.close(); } catch (Exception ex) { } } }
private void openAnalyzedFile(String filename) { StackFileInfo fileInfo = StackParser.loadAnalyzedInfo(filename); addProcessedStack(fileInfo); }
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; }
public static StackFileInfo loadAnalyzedInfo(String filename) { String endString = new StringBuilder(20) .append(StackParser.INFO_EXT) .append('.') .append(INFO_EXTENSION) .toString(); if (!filename.endsWith(endString)) throw new RuntimeException(filename + " is not a Scouter analyzed info file!"); String stackFilename = filename.substring(0, filename.indexOf(endString) - 1); StackFileInfo stackFileInfo = new StackFileInfo(stackFilename); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(new File(filename))); String line = null; int lineCount = 0; ArrayList<String> timeList = new ArrayList<String>(); ArrayList<String> threadStatusList = new ArrayList<String>(); while ((line = reader.readLine()) != null) { line = line.trim(); if (line.length() == 0) continue; if (lineCount == 0) { ParserConfigReader ConfigReader = new ParserConfigReader(line); ParserConfig config = ConfigReader.read(); stackFileInfo.setParserConfig(config); StackParser parser = StackParser.getParser(config, null, true); stackFileInfo.setUsedParser(parser); } else if (lineCount == 1) { StringTokenizer token = new StringTokenizer(line, "\t"); String value = null; int index = 0; while (token.hasMoreElements()) { value = token.nextToken(); if (index == 0) { stackFileInfo.setDumpCount(Integer.parseInt(value)); } else if (index == 1) { stackFileInfo.setTotalWorkerCount(Integer.parseInt(value)); } else if (index == 2) { stackFileInfo.setTotalWorkingCount(Integer.parseInt(value)); } else if (index == 3) { stackFileInfo.setTotalSecond(Integer.parseInt(value)); } else { threadStatusList.add(value); } index++; } } else { timeList.add(line); } lineCount++; } if (timeList.size() > 0) { stackFileInfo.setTimeList(timeList); } if (threadStatusList.size() > 0) { stackFileInfo.setThreadStatusList(threadStatusList); } loadStackAnalyzedInfo(stackFileInfo); } catch (Exception ex) { throw new RuntimeException(ex); } finally { try { if (reader != null) reader.close(); } catch (Exception ex) { } } return stackFileInfo; }