From 1fec208583e4423c8407965ad021be2fbcef550a Mon Sep 17 00:00:00 2001 From: Woonduk Kang Date: Tue, 1 Oct 2013 08:49:31 +0000 Subject: [PATCH] =?UTF-8?q?[=EA=B0=95=EC=9A=B4=EB=8D=95]=20[LUCYSUS-1744]?= =?UTF-8?q?=20api=EC=9D=98=20depth=EA=B3=84=EC=82=B0=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=EC=9D=84=20=EA=B0=84=EB=9E=B5=ED=95=9C=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81=EC=8B=A4=EC=8B=9C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-web/trunk@2380 84d0f5b1-2673-498c-a247-62c4ff18d310 --- .../nhn/pinpoint/web/service/CallStack.java | 60 ------------------- .../web/service/RecordSetServiceImpl.java | 50 ++++++++-------- .../nhn/pinpoint/web/service/SpanDepth.java | 28 +++++++++ .../pinpoint/web/service/SpanServiceImpl.java | 2 +- .../java/com/nhn/pinpoint/web/util/Stack.java | 37 ++++++++++++ .../pinpoint/web/vo/callstacks/Record.java | 12 ++-- .../webapp/WEB-INF/views/transactionInfo.jsp | 4 +- 7 files changed, 98 insertions(+), 95 deletions(-) delete mode 100644 src/main/java/com/nhn/pinpoint/web/service/CallStack.java create mode 100644 src/main/java/com/nhn/pinpoint/web/service/SpanDepth.java create mode 100644 src/main/java/com/nhn/pinpoint/web/util/Stack.java diff --git a/src/main/java/com/nhn/pinpoint/web/service/CallStack.java b/src/main/java/com/nhn/pinpoint/web/service/CallStack.java deleted file mode 100644 index ddb5300d9..000000000 --- a/src/main/java/com/nhn/pinpoint/web/service/CallStack.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.nhn.pinpoint.web.service; - -import com.nhn.pinpoint.web.calltree.span.SpanAlign; - -import java.util.LinkedList; - -/** - * - */ -public class CallStack { - private final LinkedList stack = new LinkedList(); - - public static class Depth { - private SpanAlign spanAlign; - private int id; - - public Depth(SpanAlign spanAlign, int id) { - this.spanAlign = spanAlign; - this.id = id; - } - - public SpanAlign getSpanAlign() { - return spanAlign; - } - - public void setSpanAlign(SpanAlign spanAlign) { - this.spanAlign = spanAlign; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - } - - public void push(Depth depth) { - stack.add(depth); - } - - public Depth getLast() { - return stack.getLast(); - } - - public Depth pop() { - return stack.pollLast(); - } - - public Depth getParent(){ - int parent = stack.size() - 2; - if (parent < 0) { - return null; - } - return stack.get(stack.size()-2); - } - - -} diff --git a/src/main/java/com/nhn/pinpoint/web/service/RecordSetServiceImpl.java b/src/main/java/com/nhn/pinpoint/web/service/RecordSetServiceImpl.java index b9a100d62..5bcb75ccf 100644 --- a/src/main/java/com/nhn/pinpoint/web/service/RecordSetServiceImpl.java +++ b/src/main/java/com/nhn/pinpoint/web/service/RecordSetServiceImpl.java @@ -4,6 +4,7 @@ package com.nhn.pinpoint.web.service; import java.util.ArrayList; import java.util.List; +import com.nhn.pinpoint.web.util.Stack; import org.apache.commons.lang.ObjectUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,7 +56,8 @@ public class RecordSetServiceImpl implements RecordSetService { long endTime = getEndTime(spanAlignList); recordSet.setEndTime(endTime); - List recordList = new SpanPopulator().populateSpanRecord(spanAlignList); + final SpanAlignPopulate spanAlignPopulate = new SpanAlignPopulate(); + List recordList = spanAlignPopulate.populateSpanRecord(spanAlignList); logger.debug("RecordList:{}", recordList); // focus 대상 record를 체크한다. @@ -108,12 +110,6 @@ public class RecordSetServiceImpl implements RecordSetService { } - - - - - - private SpanBo findFocusTimeSpanBo(List spanAlignList, long focusTimestamp) { SpanBo firstSpan = null; for (SpanAlign spanAlign : spanAlignList) { @@ -131,21 +127,24 @@ public class RecordSetServiceImpl implements RecordSetService { return firstSpan; } - private static class SpanPopulator { + private static class SpanAlignPopulate { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private ApiDescriptionParser apiDescriptionParser = new ApiDescriptionParser(); + + private final ApiDescriptionParser apiDescriptionParser = new ApiDescriptionParser(); private int idGen = 0; + private final Stack stack = new Stack(); private int getNextId() { return idGen++; } private List populateSpanRecord(List spanAlignList) { + if (spanAlignList == null) { + throw new NullPointerException("spanAlignList must not be null"); + } List recordList = new ArrayList(spanAlignList.size() * 2); // annotation id는 spanalign의 seq와 무관하게 순서대로 따도 됨. 겹치지만 않으면 됨. - final CallStack stack = new CallStack(); - for (int i = 0; i < spanAlignList.size(); i++) { SpanAlign spanAlign = spanAlignList.get(i); @@ -153,30 +152,32 @@ public class RecordSetServiceImpl implements RecordSetService { if (!spanAlign.isSpan()) { throw new IllegalArgumentException("root is not span"); } - stack.push(new CallStack.Depth(spanAlign, getNextId())); + stack.push(new SpanDepth(spanAlign, getNextId())); } else { - CallStack.Depth last = stack.getLast(); - final int parentDepth = last.getSpanAlign().getDepth(); + final SpanDepth lastSpanDepth = stack.getLast(); + final int parentDepth = lastSpanDepth.getSpanAlign().getDepth(); final int currentDepth = spanAlign.getDepth(); - logger.debug("parentDepth:{} currentDepth:{} sequence:{}", parentDepth, currentDepth, last.getId()); + logger.debug("parentDepth:{} currentDepth:{} sequence:{}", parentDepth, currentDepth, lastSpanDepth.getId()); if (parentDepth < spanAlign.getDepth()) { // 부모의 깊이가 더 작을 경우 push해야 한다. - stack.push(new CallStack.Depth(spanAlign, getNextId())); + stack.push(new SpanDepth(spanAlign, getNextId())); } else if (parentDepth > currentDepth) { // 부모의 깊이가 클 경우 pop해야 한다. + // 단 depth차가 1depth이상 날수 있기 때문에. depth를 확인하면서 pop을 해야 한다. while (true) { logger.debug("pop"); stack.pop(); - CallStack.Depth popLast = stack.getLast(); + SpanDepth popLast = stack.getLast(); if (popLast.getSpanAlign().getDepth() < currentDepth) { break; } } - stack.push(new CallStack.Depth(spanAlign, getNextId())); + stack.push(new SpanDepth(spanAlign, getNextId())); } else { + // 바로 앞 동일 depth의 object는 버려야 한다. stack.pop(); - stack.push(new CallStack.Depth(spanAlign, getNextId())); + stack.push(new SpanDepth(spanAlign, getNextId())); } } @@ -261,13 +262,13 @@ public class RecordSetServiceImpl implements RecordSetService { return recordList; } - private List createAnnotationRecord(int depth, int pId, List annotationBoList) { + private List createAnnotationRecord(int depth, int parentId, List annotationBoList) { List recordList = new ArrayList(annotationBoList.size()); for (AnnotationBo ann : annotationBoList) { AnnotationKey annotation = AnnotationKey.findAnnotationKey(ann.getKey()); if (annotation.isViewInRecordSet()) { - Record record = new Record(depth, getNextId(), pId, false, annotation.getValue(), ann.getValue().toString(), 0L, 0L, null, null, null, null, false); + Record record = new Record(depth, getNextId(), parentId, false, annotation.getValue(), ann.getValue().toString(), 0L, 0L, null, null, null, null, false); recordList.add(record); } } @@ -275,13 +276,10 @@ public class RecordSetServiceImpl implements RecordSetService { return recordList; } - private Record createParameterRecord(int depth, int pId, String method, String argument) { - return new Record(depth, getNextId(), pId, false, method, argument, 0L, 0L, null, null, null, null, false); + private Record createParameterRecord(int depth, int parentId, String method, String argument) { + return new Record(depth, getNextId(), parentId, false, method, argument, 0L, 0L, null, null, null, null, false); } - - - } private static String getDisplayArgument(SpanBo spanBo) { diff --git a/src/main/java/com/nhn/pinpoint/web/service/SpanDepth.java b/src/main/java/com/nhn/pinpoint/web/service/SpanDepth.java new file mode 100644 index 000000000..759c5b1f7 --- /dev/null +++ b/src/main/java/com/nhn/pinpoint/web/service/SpanDepth.java @@ -0,0 +1,28 @@ +package com.nhn.pinpoint.web.service; + +import com.nhn.pinpoint.web.calltree.span.SpanAlign; + +/** + * + */ +public class SpanDepth { + private SpanAlign spanAlign; + private int id; + + public SpanDepth(SpanAlign spanAlign, int id) { + if (spanAlign == null) { + throw new NullPointerException("spanAlign must not be null"); + } + this.spanAlign = spanAlign; + this.id = id; + } + + public SpanAlign getSpanAlign() { + return spanAlign; + } + + public int getId() { + return id; + } + +} diff --git a/src/main/java/com/nhn/pinpoint/web/service/SpanServiceImpl.java b/src/main/java/com/nhn/pinpoint/web/service/SpanServiceImpl.java index 04c5591d3..1f18bf9f2 100644 --- a/src/main/java/com/nhn/pinpoint/web/service/SpanServiceImpl.java +++ b/src/main/java/com/nhn/pinpoint/web/service/SpanServiceImpl.java @@ -323,7 +323,7 @@ public class SpanServiceImpl implements SpanService { private List order(List spans) { SpanAligner2 spanAligner = new SpanAligner2(spans); List sort = spanAligner.sort(); - logger.debug("SpanAlignList:{}", sort); + logger.trace("SpanAlignList:{}", sort); return sort; } diff --git a/src/main/java/com/nhn/pinpoint/web/util/Stack.java b/src/main/java/com/nhn/pinpoint/web/util/Stack.java new file mode 100644 index 000000000..c3d4ec282 --- /dev/null +++ b/src/main/java/com/nhn/pinpoint/web/util/Stack.java @@ -0,0 +1,37 @@ +package com.nhn.pinpoint.web.util; + +import java.util.LinkedList; + +/** + * + */ +public class Stack { + + private final LinkedList stack = new LinkedList(); + + public void push(T obj) { + if (obj == null) { + throw new NullPointerException("obj must not be null"); + } + + stack.add(obj); + } + + public T getLast() { + return stack.getLast(); + } + + public T pop() { + return stack.pollLast(); + } + + public T getParent() { + final int parent = stack.size() - 2; + if (parent < 0) { + return null; + } + return stack.get(parent); + } + + +} diff --git a/src/main/java/com/nhn/pinpoint/web/vo/callstacks/Record.java b/src/main/java/com/nhn/pinpoint/web/vo/callstacks/Record.java index 4665b90de..27c6eb02d 100644 --- a/src/main/java/com/nhn/pinpoint/web/vo/callstacks/Record.java +++ b/src/main/java/com/nhn/pinpoint/web/vo/callstacks/Record.java @@ -11,7 +11,7 @@ import com.nhn.pinpoint.common.ServiceType; public class Record { private final int tab; private final int id; - private final int pId; + private final int parentId; private final boolean method; private final String title; @@ -30,10 +30,10 @@ public class Record { private boolean focused; private boolean hasChild; - public Record(int tab, int id, int pId, boolean method, String title, String arguments, long begin, long elapsed, String agent, String service, ServiceType serviceType, String destinationId, boolean hasChild) { + public Record(int tab, int id, int parentId, boolean method, String title, String arguments, long begin, long elapsed, String agent, String service, ServiceType serviceType, String destinationId, boolean hasChild) { this.tab = tab; this.id = id; - this.pId = pId; + this.parentId = parentId; this.method = method; this.title = title; @@ -54,8 +54,8 @@ public class Record { return id; } - public int getpId() { - return pId; + public int getParentId() { + return parentId; } public int getTab() { @@ -153,7 +153,7 @@ public class Record { final StringBuilder sb = new StringBuilder("Record{"); sb.append("tab=").append(tab); sb.append(", id=").append(id); - sb.append(", pId=").append(pId); + sb.append(", parentId=").append(parentId); sb.append(", method=").append(method); sb.append(", title='").append(title).append('\''); sb.append(", simpleClassName='").append(simpleClassName).append('\''); diff --git a/src/main/webapp/WEB-INF/views/transactionInfo.jsp b/src/main/webapp/WEB-INF/views/transactionInfo.jsp index 7af49a5a9..e70046399 100644 --- a/src/main/webapp/WEB-INF/views/transactionInfo.jsp +++ b/src/main/webapp/WEB-INF/views/transactionInfo.jsp @@ -204,8 +204,8 @@ - - + +