[강운덕] [LUCYSUS-1744] api의 depth계산 로직을 간략한 리팩토링실시.

git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-web/trunk@2380 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
Woonduk Kang
2013-10-01 08:49:31 +00:00
parent aef563e65e
commit 1fec208583
7 changed files with 98 additions and 95 deletions
@@ -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<Depth> stack = new LinkedList<Depth>();
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);
}
}
@@ -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<Record> recordList = new SpanPopulator().populateSpanRecord(spanAlignList);
final SpanAlignPopulate spanAlignPopulate = new SpanAlignPopulate();
List<Record> recordList = spanAlignPopulate.populateSpanRecord(spanAlignList);
logger.debug("RecordList:{}", recordList);
// focus 대상 record를 체크한다.
@@ -108,12 +110,6 @@ public class RecordSetServiceImpl implements RecordSetService {
}
private SpanBo findFocusTimeSpanBo(List<SpanAlign> 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<SpanDepth> stack = new Stack<SpanDepth>();
private int getNextId() {
return idGen++;
}
private List<Record> populateSpanRecord(List<SpanAlign> spanAlignList) {
if (spanAlignList == null) {
throw new NullPointerException("spanAlignList must not be null");
}
List<Record> recordList = new ArrayList<Record>(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<Record> createAnnotationRecord(int depth, int pId, List<AnnotationBo> annotationBoList) {
private List<Record> createAnnotationRecord(int depth, int parentId, List<AnnotationBo> annotationBoList) {
List<Record> recordList = new ArrayList<Record>(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) {
@@ -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;
}
}
@@ -323,7 +323,7 @@ public class SpanServiceImpl implements SpanService {
private List<SpanAlign> order(List<SpanBo> spans) {
SpanAligner2 spanAligner = new SpanAligner2(spans);
List<SpanAlign> sort = spanAligner.sort();
logger.debug("SpanAlignList:{}", sort);
logger.trace("SpanAlignList:{}", sort);
return sort;
}
@@ -0,0 +1,37 @@
package com.nhn.pinpoint.web.util;
import java.util.LinkedList;
/**
*
*/
public class Stack<T> {
private final LinkedList<T> stack = new LinkedList<T>();
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);
}
}
@@ -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('\'');
@@ -204,8 +204,8 @@
</c:if>
<c:choose>
<c:when test="${record.pId > 0}">
<c:set var="pid" value="${record.pId}" />
<c:when test="${record.parentId > 0}">
<c:set var="pid" value="${record.parentId}" />
</c:when>
<c:otherwise>
<c:set var="pid" value="" />