Esempio n. 1
0
 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);
 }
Esempio n. 2
0
  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;
  }
Esempio n. 3
0
  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;
  }
Esempio n. 4
0
  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()));
        }
      }
    }
  }
Esempio n. 5
0
  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) {
        }
      }
    }
  }
Esempio n. 6
0
  private static void loadStackAnalyzedInfo(StackFileInfo stackFileInfo) {
    File file = null;
    StackAnalyzedInfo analyzedInfo = null;
    try {
      analyzedInfo =
          readStackAnalyzedInfo(stackFileInfo, file, StackParser.TOP_NAME, StackParser.TOP_EXT);
      if (analyzedInfo != null) stackFileInfo.addStackAnalyzedInfo(analyzedInfo);

      analyzedInfo =
          readStackAnalyzedInfo(stackFileInfo, file, StackParser.SQL_NAME, StackParser.SQL_EXT);
      if (analyzedInfo != null) stackFileInfo.addStackAnalyzedInfo(analyzedInfo);

      analyzedInfo =
          readStackAnalyzedInfo(
              stackFileInfo, file, StackParser.SERVICE_NAME, StackParser.SERVICE_EXT);
      if (analyzedInfo != null) stackFileInfo.addStackAnalyzedInfo(analyzedInfo);

      analyzedInfo =
          readStackAnalyzedInfo(stackFileInfo, file, StackParser.LOG_NAME, StackParser.LOG_EXT);
      if (analyzedInfo != null) stackFileInfo.addStackAnalyzedInfo(analyzedInfo);

      ArrayList<AnalyzerValue> list = stackFileInfo.getParserConfig().getAnalyzerList();
      if (list != null) {
        for (int i = 0; i < list.size(); i++) {
          analyzedInfo =
              readStackAnalyzedInfo(
                  stackFileInfo, file, list.get(i).getName(), list.get(i).getExtension());
          if (analyzedInfo != null) stackFileInfo.addStackAnalyzedInfo(analyzedInfo);
        }
      }

      analyzedInfo =
          readStackAnalyzedInfo(
              stackFileInfo, file, StackParser.UNIQUE_NAME, StackParser.UNIQUE_EXT);
      readUniqueStackExtraInfo(
          analyzedInfo, stackFileInfo, file, StackParser.UNIQUE_NAME, StackParser.UNIQUE_EXT);
      if (analyzedInfo != null) stackFileInfo.addStackAnalyzedInfo(analyzedInfo);
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
  }
Esempio n. 7
0
  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;
  }
Esempio n. 8
0
  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;
  }
Esempio n. 9
0
  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;
  }
Esempio n. 10
0
  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;
  }
Esempio n. 11
0
  @SuppressWarnings("unchecked")
  private void saveAll() {
    m_stackFile.setDumpCount(m_dumpCount);
    m_stackFile.setTotalWorkerCount(m_totalWorkerCount);
    m_stackFile.setTotalWorkingCount(m_totalWorkingCount);
    m_stackFile.setTotalSecond(m_totalSecond);

    StackAnalyzedInfo info = saveStackAnalyzedInfo(m_topList, TOP_NAME, TOP_EXT);
    if (info != null) m_stackFile.addStackAnalyzedInfo(info);
    info = saveStackAnalyzedInfo(m_sqlList, SQL_NAME, SQL_EXT);
    if (info != null) m_stackFile.addStackAnalyzedInfo(info);
    info = saveStackAnalyzedInfo(m_serviceList, SERVICE_NAME, SERVICE_EXT);
    if (info != null) m_stackFile.addStackAnalyzedInfo(info);
    info = saveStackAnalyzedInfo(m_logList, LOG_NAME, LOG_EXT);
    if (info != null) m_stackFile.addStackAnalyzedInfo(info);

    for (int i = 0; i < m_analyzerCount; i++) {
      info =
          saveStackAnalyzedInfo(
              m_analyzerList[i], m_analyzer.get(i).getName(), m_analyzer.get(i).getExtension());
      if (info != null) m_stackFile.addStackAnalyzedInfo(info);
    }

    // unique Stack
    info = saveUniqueStackAnalyzedInfo(m_uniqueStackMap, UNIQUE_NAME, UNIQUE_EXT);
    if (info != null) m_stackFile.addStackAnalyzedInfo(info);

    if (m_timeList.size() > 0) {
      m_stackFile.setTimeList(m_timeList);
    }
    if (m_threadStatusList.size() > 0) {
      m_stackFile.setThreadStatusList(m_threadStatusList);
    }

    saveAnalyzedInfo();
  }