コード例 #1
0
  protected void reload() {
    table.removeAll();
    MapPack mp = ServerDataProxy.getThreadDetail(threadid, serverId);

    String[] names = scouter.util.SortUtil.sort_string(mp.keys(), mp.size());
    for (int i = 0, j = 0; i < names.length; i++) {
      String key = names[i];
      Value value = mp.get(key);
      if ("Stack Trace".equals(key)) {
        stacktrace.setText(CastUtil.cString(value));
        //				JavaColor.setJavaCode(stacktrace, new Cast(value).cString());
        continue;
      }
      String text = null;
      TableItem ti = new TableItem(table, SWT.NONE, j++);
      if (value instanceof TextValue) {
        text = CastUtil.cString(value);
        ti.setText(0, key);
        ti.setText(1, text);
      } else {
        if (value instanceof DecimalValue) {
          text = FormatUtil.print(value, "#,##0");
        } else if (value instanceof DoubleValue || value instanceof FloatValue) {
          text = FormatUtil.print(value, "#,##0.0##");
        }
        ti.setText(new String[] {key, text});
      }
    }
  }
コード例 #2
0
  public static void buildXLogData(final String date, StyledText text, XLogPack p, int serverId) {

    final int servId = serverId;

    String error = TextProxy.error.getLoadText(date, p.error, servId);
    String objName = TextProxy.object.getLoadText(date, p.objHash, servId);

    int slen = 0;
    java.util.List<StyleRange> sr = new ArrayList<StyleRange>();

    Color red = text.getDisplay().getSystemColor(SWT.COLOR_RED);

    final StringBuffer sb = new StringBuffer();
    sb.append("► txid    = ").append(Hexa32.toString32(p.txid)).append("\n");
    sb.append("► objName = ").append(objName).append("\n");
    sb.append("► endtime = ").append(DateUtil.timestamp(p.endTime)).append("\n");
    sb.append("► elapsed = ").append(FormatUtil.print(p.elapsed, "#,##0")).append(" ms\n");
    sb.append("► service = ").append(TextProxy.service.getText(p.service)).append("\n");
    if (error != null) {
      sb.append("► error   = ");
      slen = sb.length();
      sb.append(error).append("\n");
      sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.NORMAL));
    }

    sb.append("► ipaddr=" + IPUtil.toString(p.ipaddr) + ", ");
    sb.append("userid=" + p.userid);
    sb.append("\n► cpu=" + FormatUtil.print(p.cpu, "#,##0") + " ms, ");
    sb.append("bytes=" + p.bytes + ", ");
    sb.append("status=" + p.status);
    if (p.sqlCount > 0) {
      sb.append("\n► sqlCount=" + p.sqlCount + ", ");
      sb.append("sqlTime=" + FormatUtil.print(p.sqlTime, "#,##0") + " ms");
    }
    if (p.apicallCount > 0) {
      sb.append("\n► ApiCallCount=" + p.apicallCount + ", ");
      sb.append("ApiCallTime=" + FormatUtil.print(p.apicallTime, "#,##0") + " ms");
    }

    String t = TextProxy.userAgent.getLoadText(date, p.userAgent, serverId);
    if (StringUtil.isNotEmpty(t)) {
      sb.append("\n► userAgent=" + t);
    }

    t = TextProxy.referer.getLoadText(date, p.referer, serverId);
    if (StringUtil.isNotEmpty(t)) {
      sb.append("\n► referer=" + t);
    }

    t = TextProxy.group.getLoadText(date, p.group, serverId);
    if (StringUtil.isNotEmpty(t)) {
      sb.append("\n► group=" + t);
    }

    sb.append("\n");

    text.setText(sb.toString());
    text.setStyleRanges(sr.toArray(new StyleRange[sr.size()]));
  }
コード例 #3
0
 public void writeValue(int ex) {
   double x = xyGraph.primaryXAxis.getPositionValue(ex, false);
   int index = (int) x;
   if (index < 0) {
     return;
   }
   Sample sample = (Sample) trace.getDataProvider().getSample(index);
   if (sample != null) {
     double y = sample.getYValue();
     int height = xyGraph.primaryYAxis.getValuePosition(y, false);
     int startX = xyGraph.primaryXAxis.getValuePosition((int) x, false);
     GC gc = new GC(canvas);
     Font font = new Font(null, "Verdana", 10, SWT.BOLD);
     gc.setFont(font);
     String value = FormatUtil.print(y, "#,###");
     Point textSize = gc.textExtent(value);
     gc.drawText(value, startX + (xAxisUnitWidth - textSize.x) / 2, height - 20, true);
     int ground = xyGraph.primaryYAxis.getValuePosition(0, false);
     gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
     gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_MAGENTA));
     gc.drawRectangle(
         startX + (xAxisUnitWidth - lineWidth) / 2, height, lineWidth, ground - height);
     gc.fillRectangle(
         startX + (xAxisUnitWidth - lineWidth) / 2, height, lineWidth, ground - height);
     gc.dispose();
     writedValueMode = true;
     lastWritedX = ex;
   }
 }
コード例 #4
0
ファイル: XLogCallView.java プロジェクト: daisyleenr/scouter
 public String getText(Object element) {
   if (element instanceof XLogData) {
     XLogData d = (XLogData) element;
     return d.objName;
   } else if (element instanceof XLogConnection) {
     XLogConnection conn = (XLogConnection) element;
     return conn.name + "(" + FormatUtil.print(conn.elapsed, "#,###") + " ms)";
   } else if (element instanceof StartHome) {
     return ((StartHome) element).ip;
   }
   return null;
 }
コード例 #5
0
  public static void buildProfile(
      final String date,
      StyledText text,
      XLogPack pack,
      StepWrapper[] orgProfiles,
      int pageNum,
      int rowPerPage,
      Button prevBtn,
      Button nextBtn,
      Button startBtn,
      Button endBtn,
      int length,
      int serverId,
      int searchLineIndex,
      boolean isSummary) {

    String spaceStr = "";
    String astarStr = "";
    for (int j = 0; j < length; j++) {
      spaceStr += " ";
      astarStr += "*";
    }

    if (orgProfiles == null) {
      orgProfiles = new StepWrapper[0];
    }

    boolean lastPage = false;
    int startIdx = pageNum * rowPerPage;
    int lastIdx = (pageNum * rowPerPage) + rowPerPage;
    if (lastIdx >= orgProfiles.length) {
      lastIdx = orgProfiles.length;
      lastPage = true;
    }

    int ix = 0;
    StepWrapper[] profiles = new StepWrapper[lastIdx - startIdx];
    for (int inx = startIdx; inx < lastIdx; inx++) {
      profiles[ix] = orgProfiles[inx];
      ix++;
    }

    int slen = 0;
    java.util.List<StyleRange> sr = new ArrayList<StyleRange>();

    Color blue = text.getDisplay().getSystemColor(SWT.COLOR_BLUE);
    Color dmagenta = text.getDisplay().getSystemColor(SWT.COLOR_DARK_MAGENTA);
    Color red = text.getDisplay().getSystemColor(SWT.COLOR_RED);
    Color yellow = text.getDisplay().getSystemColor(SWT.COLOR_YELLOW);

    Color dgreen = text.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN);

    final StringBuffer sb = new StringBuffer();

    sb.append(
        "------------------------------------------------------------------------------------------\n");
    sb.append(
        "  p# " + spaceStr + "# " + spaceStr + " TIME         T-GAP   CPU          CONTENTS\n");
    sb.append(
        "------------------------------------------------------------------------------------------\n");

    if (profiles.length == 0) {
      sb.append("\n                     ( No xlog profile collected ) ");
      text.setText(sb.toString());
      text.setStyleRanges(sr.toArray(new StyleRange[sr.size()]));
      return;
    }
    long stime = pack.endTime - pack.elapsed;
    long prev_tm = stime;
    if (pageNum > 0) {
      prev_tm = orgProfiles[startIdx - 1].time;
    }
    long prev_cpu = 0;
    if (pageNum > 0) {
      prev_cpu = orgProfiles[startIdx - 1].cpu;
    }

    if (pageNum == 0) {
      sb.append(" " + spaceStr + " ");
      sb.append(" ");
      sb.append("[" + astarStr + "]");
      sb.append(" ");
      sb.append(DateUtil.getLogTime(stime));
      sb.append("   ");
      sb.append(String.format("%6s", "0"));
      sb.append(" ");
      sb.append(String.format("%6s", "0"));
      sb.append("  start transaction \n");
    }

    long tm = pack.endTime;
    long cpu = pack.cpu;

    for (int i = 0; i < profiles.length; i++) {

      if (profiles[i].step instanceof StepSummary) {
        int p1 = sb.length();
        sb.append(spaceStr).append("   ");
        sb.append(String.format("[%0" + length + "d]", profiles[i].sSummaryIdx));
        sb.append(" ");
        int lineHead = sb.length() - p1;

        StepSummary sum = (StepSummary) profiles[i].step;
        switch (sum.getStepType()) {
          case StepEnum.METHOD_SUM:
            MethodSum p = (MethodSum) sum;
            slen = sb.length();

            String m = TextProxy.method.getText(p.hash);
            if (m == null) m = Hexa32.toString32(p.hash);
            sb.append(m).append(" ");

            if (searchLineIndex == profiles[i].sSummaryIdx) {
              sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.BOLD, yellow));
            } else {
              sr.add(ProfileText.style(slen, sb.length() - slen, blue, SWT.NORMAL));
            }

            sb.append(" count=").append(FormatUtil.print(p.count, "#,##0"));
            sb.append(" time=").append(FormatUtil.print(p.elapsed, "#,##0")).append(" ms");
            sb.append(" cpu=").append(FormatUtil.print(p.cputime, "#,##0"));

            sb.append("\n");
            break;
          case StepEnum.SQL_SUM:
            SqlSum sql = (SqlSum) sum;
            slen = sb.length();
            ProfileText.toString(sb, sql, serverId);
            if (searchLineIndex == profiles[i].sSummaryIdx) {
              sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.BOLD, yellow));
            } else {
              sr.add(ProfileText.style(slen, sb.length() - slen, blue, SWT.NORMAL));
            }
            sb.append("\n");
            break;
          case StepEnum.APICALL_SUM:
            ApiCallSum apicall = (ApiCallSum) sum;
            slen = sb.length();
            ProfileText.toString(sb, apicall);
            if (searchLineIndex == profiles[i].sSummaryIdx) {
              sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.BOLD, yellow));
            } else {
              sr.add(ProfileText.style(slen, sb.length() - slen, dmagenta, SWT.NORMAL));
            }
            sb.append("\n");
            break;
          case StepEnum.SOCKET_SUM:
            XLogProfileView.isSummary = true;
            SocketSum socketSum = (SocketSum) sum;
            slen = sb.length();
            ProfileText.toString(sb, socketSum);
            sr.add(ProfileText.style(slen, sb.length() - slen, dmagenta, SWT.NORMAL));
            sb.append("\n");
            break;
        }
        continue;
      }

      StepSingle stepSingle = (StepSingle) profiles[i].step;
      tm = profiles[i].time;
      cpu = profiles[i].cpu;

      int p1 = sb.length();
      String pid = String.format("[%0" + length + "d]", stepSingle.parent);
      sb.append((stepSingle.parent == -1) ? spaceStr + "  " : pid);
      sb.append(" ");
      sb.append(String.format("[%0" + length + "d]", stepSingle.index));
      sb.append(" ");
      sb.append(DateUtil.getLogTime(tm));
      sb.append("   ");
      sb.append(String.format("%6s", FormatUtil.print(tm - prev_tm, "#,##0")));
      sb.append(" ");
      sb.append(String.format("%6s", FormatUtil.print(cpu - prev_cpu, "#,##0")));
      sb.append("  ");
      int lineHead = sb.length() - p1;

      int space = profiles[i].indent;
      while (space > 0) {
        sb.append(" ");
        space--;
      }

      switch (stepSingle.getStepType()) {
        case StepEnum.METHOD:
          slen = sb.length();
          ProfileText.toString(sb, (MethodStep) stepSingle);
          if (searchLineIndex == stepSingle.index) {
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.BOLD, yellow));
          }
          break;
        case StepEnum.METHOD2:
          slen = sb.length();
          ProfileText.toString(sb, (MethodStep) stepSingle);
          if (searchLineIndex == stepSingle.index) {
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.BOLD, yellow));
          }
          MethodStep2 m2 = (MethodStep2) stepSingle;
          if (m2.error != 0) {
            slen = sb.length();
            sb.append("\n").append(TextProxy.error.getText(m2.error));
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.NORMAL));
          }
          break;
        case StepEnum.SQL:
        case StepEnum.SQL2:
        case StepEnum.SQL3:
          SqlStep sql = (SqlStep) stepSingle;
          slen = sb.length();
          ProfileText.toString(sb, sql, serverId, lineHead, false);
          if (searchLineIndex == stepSingle.index) {
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.BOLD, yellow));
          } else {
            sr.add(ProfileText.style(slen, sb.length() - slen, blue, SWT.NORMAL));
          }
          if (sql.error != 0) {
            slen = sb.length();
            sb.append("\n").append(TextProxy.error.getText(sql.error));
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.NORMAL));
          }
          break;
        case StepEnum.MESSAGE:
          slen = sb.length();
          ProfileText.toString(sb, (MessageStep) stepSingle);
          if (searchLineIndex == stepSingle.index) {
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.BOLD, yellow));
          } else {
            sr.add(ProfileText.style(slen, sb.length() - slen, dgreen, SWT.NORMAL));
          }
          break;
        case StepEnum.HASHED_MESSAGE:
          slen = sb.length();
          ProfileText.toString(sb, (HashedMessageStep) stepSingle);
          if (searchLineIndex == stepSingle.index) {
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.BOLD, yellow));
          } else {
            sr.add(ProfileText.style(slen, sb.length() - slen, dgreen, SWT.NORMAL));
          }
          break;
        case StepEnum.APICALL:
          ApiCallStep apicall = (ApiCallStep) stepSingle;
          slen = sb.length();
          ProfileText.toString(sb, apicall);
          if (searchLineIndex == stepSingle.index) {
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.BOLD, yellow));
          } else {
            sr.add(ProfileText.style(slen, sb.length() - slen, dmagenta, SWT.NORMAL));
          }
          if (apicall.error != 0) {
            slen = sb.length();
            sb.append("\n").append(TextProxy.error.getText(apicall.error));
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.NORMAL));
          }
          break;
        case StepEnum.SOCKET:
          SocketStep socket = (SocketStep) stepSingle;
          slen = sb.length();
          ProfileText.toString(sb, socket);
          sr.add(ProfileText.style(slen, sb.length() - slen, dmagenta, SWT.NORMAL));
          if (socket.error != 0) {
            slen = sb.length();
            sb.append("\n").append(TextProxy.error.getText(socket.error));
            sr.add(ProfileText.style(slen, sb.length() - slen, red, SWT.NORMAL));
          }
          break;
      }
      sb.append("\n");
      prev_cpu = cpu;
      prev_tm = tm;
    }

    if (lastPage) {

      nextBtn.setEnabled(false);
      endBtn.setEnabled(false);

      tm = pack.endTime;
      cpu = pack.cpu;
      // slen = sb.length();
      sb.append(" " + spaceStr + " ");
      sb.append(" ");
      sb.append("[" + astarStr + "]");
      sb.append(" ");
      sb.append(DateUtil.getLogTime(tm));
      sb.append("   ");
      if (!isSummary) {
        sb.append(String.format("%6s", FormatUtil.print(tm - prev_tm, "#,##0")));
      } else {
        sb.append(String.format("%6s", FormatUtil.print(pack.elapsed, "#,##0")));
      }
      sb.append(" ");
      sb.append(String.format("%6s", FormatUtil.print(cpu - prev_cpu, "#,##0")));
      sb.append("  end of transaction \n");

      // sr.add(ProfileText.style(slen, sb.length() - slen, dblue, SWT.NORMAL));
      sb.append(
          "------------------------------------------------------------------------------------------\n");
    } else {
      nextBtn.setEnabled(true);
      endBtn.setEnabled(true);
    }

    if (pageNum == 0) {
      prevBtn.setEnabled(false);
      startBtn.setEnabled(false);
    } else {
      prevBtn.setEnabled(true);
      startBtn.setEnabled(true);
    }
    text.setText(sb.toString());
    text.setStyleRanges(sr.toArray(new StyleRange[sr.size()]));
  }