diff --git a/pom.xml b/pom.xml index 41d92d8..621aafc 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cn.langpy ko-time - 2.4.6 + 2.4.7 KoTime A springboot tool for tracking the paths of the methods,which can help you find method's performances easily. diff --git a/src/main/java/cn/langpy/kotime/constant/KoSqlConstant.java b/src/main/java/cn/langpy/kotime/constant/KoSqlConstant.java index 5506a76..344a992 100644 --- a/src/main/java/cn/langpy/kotime/constant/KoSqlConstant.java +++ b/src/main/java/cn/langpy/kotime/constant/KoSqlConstant.java @@ -12,11 +12,11 @@ public class KoSqlConstant { "join ko_exception_relation r on e.id = r.target_id"; public final static String queryException = "SELECT id, name, class_name FROM ko_exception_node WHERE id=?"; public final static String queryExceptionExist = "SELECT id FROM ko_exception_node WHERE id=?"; - public final static String addMethodRe = "INSERT INTO ko_method_relation(id, source_id, target_id, avg_run_time, max_run_time, min_run_time) VALUES (?, ?, ?, ?, ?, ?)"; - public final static String queryMethodRe = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time FROM ko_method_relation WHERE id=?"; - public final static String queryMethodReBySource = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time FROM ko_method_relation WHERE source_id=?"; - public final static String queryMethodReByTarget = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time FROM ko_method_relation WHERE target_id=?"; - public final static String updateMethodRe = "UPDATE ko_method_relation SET source_id=?, target_id=?, avg_run_time=?, max_run_time=?, min_run_time=? WHERE id=?"; + public final static String addMethodRe = "INSERT INTO ko_method_relation(id, source_id, target_id, avg_run_time, max_run_time, min_run_time, call_num) VALUES (?, ?, ?, ?, ?, ?, ?)"; + public final static String queryMethodRe = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time,call_num FROM ko_method_relation WHERE id=?"; + public final static String queryMethodReBySource = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time,call_num FROM ko_method_relation WHERE source_id=?"; + public final static String queryMethodReByTarget = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time,call_num FROM ko_method_relation WHERE target_id=?"; + public final static String updateMethodRe = "UPDATE ko_method_relation SET source_id=?, target_id=?, avg_run_time=?, max_run_time=?, min_run_time=?, call_num=? WHERE id=?"; public final static String addExceptionRe = "INSERT INTO ko_exception_relation(id, source_id, target_id, location,message) VALUES (?, ?, ?, ?, ?)"; public final static String queryExceptionRe = "SELECT id, source_id, target_id, location, message FROM ko_exception_relation WHERE id=?"; public final static String queryExceptionReExist = "SELECT id FROM ko_exception_relation WHERE id=?"; @@ -28,17 +28,17 @@ public class KoSqlConstant { public final static String updateParamsAna = "UPDATE ko_param_ana SET avg_run_time=?, max_run_time=?, min_run_time=? WHERE source_id=? and params=?"; - public final static String queryControllers = "select m.id,name,class_name,method_name,method_type,route_name,r.avg_run_time,r.max_run_time,r.min_run_time " + + public final static String queryControllers = "select m.id,name,class_name,method_name,method_type,route_name,r.avg_run_time,r.max_run_time,r.min_run_time,r.call_num " + "from ko_method_node m " + "join ko_method_relation r on m.id = r.target_id " + "where m.method_type='Controller'"; - public final static String searchMethodsByName = "select m.id,name,class_name,method_name,method_type,route_name,r.avg_run_time,r.max_run_time,r.min_run_time " + + public final static String searchMethodsByName = "select m.id,name,class_name,method_name,method_type,route_name,r.avg_run_time,r.max_run_time,r.min_run_time,r.call_num " + "from ko_method_node m " + "join ko_method_relation r on m.id = r.target_id " + "where m.name like ?"; - public final static String queryChildrenByParent ="select m.id,name,class_name,method_name,method_type,route_name,r.avg_run_time,r.max_run_time,r.min_run_time " + + public final static String queryChildrenByParent ="select m.id,name,class_name,method_name,method_type,route_name,r.avg_run_time,r.max_run_time,r.min_run_time,call_num " + "from ko_method_node m " + "join ko_method_relation r on m.id = r.target_id " + "where r.source_id=?"; diff --git a/src/main/java/cn/langpy/kotime/controller/KoInitController.java b/src/main/java/cn/langpy/kotime/controller/KoInitController.java index 3b2176e..5557e1b 100644 --- a/src/main/java/cn/langpy/kotime/controller/KoInitController.java +++ b/src/main/java/cn/langpy/kotime/controller/KoInitController.java @@ -40,6 +40,7 @@ public class KoInitController { private final String jQueryJsText = getResourceText("kostatic/JQuery.min.js"); private final String uiKitIconsJs = getResourceText("kostatic/uikit-icons.js"); private final String KoTimeUtil = getResourceText("kostatic/util.js"); + private final String commonCss = getResourceText("kostatic/common.css"); @PostMapping("/login") @ResponseBody @@ -146,6 +147,8 @@ public class KoInitController { line = line.replace("koTimeVersionValue", "'" + KoUtil.getVerssion()+ "'"); }else if (line.indexOf("abbreviationEnableValue") > -1) { line = line.replace("abbreviationEnableValue", Context.getConfig().getAbbreviationEnable()+""); + }else if (line.indexOf("commonCss") > -1) { + line = line.replace("commonCss", commonCss); } return line; } diff --git a/src/main/java/cn/langpy/kotime/data/DataBase.java b/src/main/java/cn/langpy/kotime/data/DataBase.java index 98ede3b..de1c279 100644 --- a/src/main/java/cn/langpy/kotime/data/DataBase.java +++ b/src/main/java/cn/langpy/kotime/data/DataBase.java @@ -127,13 +127,14 @@ public class DataBase implements GraphService { try { List> query = DataBaseUtil.query(getWriteConnection(), KoSqlConstant.queryMethodRe, new Object[]{sourceMethodNode.getId() + targetMethodNode.getId()}); if (query.size() > 0) { - if (Math.random() < Context.getConfig().getDiscardRate()) { - return null; - } +// if (Math.random() < Context.getConfig().getDiscardRate()) { +// return null; +// } Map old = query.get(0); double oldAvg = (double) old.get("avg_run_time"); double oldMax = (double) old.get("max_run_time"); double oldMin = (double) old.get("min_run_time"); + int callNum = ((int) old.get("call_num"))+1; BigDecimal bg = BigDecimal.valueOf((targetMethodNode.getValue() + oldAvg) / 2.0); double avg = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); double max = targetMethodNode.getValue() > oldMax ? targetMethodNode.getValue() : oldMax; @@ -144,6 +145,7 @@ public class DataBase implements GraphService { avg, max, min, + callNum, sourceMethodNode.getId() + targetMethodNode.getId() }; DataBaseUtil.update(getWriteConnection(), KoSqlConstant.updateMethodRe, params); @@ -155,7 +157,8 @@ public class DataBase implements GraphService { targetMethodNode.getId(), targetMethodNode.getValue(), targetMethodNode.getValue(), - targetMethodNode.getValue() + targetMethodNode.getValue(), + 1 }; DataBaseUtil.insert(getWriteConnection(), KoSqlConstant.addMethodRe, params); } @@ -245,6 +248,7 @@ public class DataBase implements GraphService { rootInfo.setAvgRunTime(methodRelation.getAvgRunTime()); rootInfo.setMaxRunTime(methodRelation.getMaxRunTime()); rootInfo.setMinRunTime(methodRelation.getMinRunTime()); + rootInfo.setCallNum(methodRelation.getCallNum()); List exceptionInfos = getExceptions(methodId); rootInfo.setExceptionNum(exceptionInfos.size()); rootInfo.setExceptions(exceptionInfos); diff --git a/src/main/java/cn/langpy/kotime/data/MemoryBase.java b/src/main/java/cn/langpy/kotime/data/MemoryBase.java index fec8ba7..7e9b0ba 100644 --- a/src/main/java/cn/langpy/kotime/data/MemoryBase.java +++ b/src/main/java/cn/langpy/kotime/data/MemoryBase.java @@ -117,11 +117,13 @@ public class MemoryBase implements GraphService { methodRelation.setAvgRunTime(targetMethodNode.getValue()); methodRelation.setMaxRunTime(targetMethodNode.getValue()); methodRelation.setMinRunTime(targetMethodNode.getValue()); + methodRelation.setCallNum(1); MethodRelation old = methodRelations.get(methodRelation.getId()); if (null == old) { methodRelations.put(methodRelation.getId(), methodRelation); return methodRelation; } else { + old.setCallNum(old.getCallNum()+1); if (Math.random() exceptionInfos = getExceptions(methodNode.getId()); methodInfo.setExceptionNum(exceptionInfos.size()); @@ -381,6 +386,7 @@ public class MemoryBase implements GraphService { rootInfo.setAvgRunTime(methodRelation.getAvgRunTime()); rootInfo.setMaxRunTime(methodRelation.getMaxRunTime()); rootInfo.setMinRunTime(methodRelation.getMinRunTime()); + rootInfo.setCallNum(methodRelation.getCallNum()); List exceptionInfos = getExceptions(methodId); rootInfo.setExceptionNum(exceptionInfos.size()); rootInfo.setExceptions(exceptionInfos); diff --git a/src/main/java/cn/langpy/kotime/data/RedisBase.java b/src/main/java/cn/langpy/kotime/data/RedisBase.java index 0fca248..b84dd58 100644 --- a/src/main/java/cn/langpy/kotime/data/RedisBase.java +++ b/src/main/java/cn/langpy/kotime/data/RedisBase.java @@ -124,13 +124,16 @@ public class RedisBase implements GraphService { methodRelation.setAvgRunTime(targetMethodNode.getValue()); methodRelation.setMaxRunTime(targetMethodNode.getValue()); methodRelation.setMinRunTime(targetMethodNode.getValue()); + methodRelation.setCallNum(1); String key = methodRelationPre + methodRelation.getId(); MethodRelation old = query(key, MethodRelation.class); if (null == old) { insert(key, methodRelation); return methodRelation; } else { + old.setCallNum(old.getCallNum()+1); if (Math.random() exceptionInfos = getExceptions(methodNode.getId()); methodInfo.setExceptionNum(exceptionInfos.size()); methodInfo.setExceptions(exceptionInfos); @@ -421,6 +426,7 @@ public class RedisBase implements GraphService { rootInfo.setAvgRunTime(methodRelation.getAvgRunTime()); rootInfo.setMaxRunTime(methodRelation.getMaxRunTime()); rootInfo.setMinRunTime(methodRelation.getMinRunTime()); + rootInfo.setCallNum(methodRelation.getCallNum()); List exceptionInfos = getExceptions(methodId); rootInfo.setExceptionNum(exceptionInfos.size()); rootInfo.setExceptions(exceptionInfos); diff --git a/src/main/java/cn/langpy/kotime/model/MethodInfo.java b/src/main/java/cn/langpy/kotime/model/MethodInfo.java index 75a98c5..92a1046 100644 --- a/src/main/java/cn/langpy/kotime/model/MethodInfo.java +++ b/src/main/java/cn/langpy/kotime/model/MethodInfo.java @@ -17,6 +17,7 @@ public class MethodInfo implements Comparable { private Double avgRunTime = 0.0; private Double maxRunTime = 0.0; private Double minRunTime = 0.0; + private Integer callNum = 0; private MethodType methodType; private Integer exceptionNum = 0; private List children = new ArrayList<>(); @@ -144,6 +145,14 @@ public class MethodInfo implements Comparable { this.children = children; } + public Integer getCallNum() { + return callNum; + } + + public void setCallNum(Integer callNum) { + this.callNum = callNum; + } + @Override public String toString() { return "RunTimeNode{" + diff --git a/src/main/java/cn/langpy/kotime/model/MethodRelation.java b/src/main/java/cn/langpy/kotime/model/MethodRelation.java index dbc7d26..9a6b093 100644 --- a/src/main/java/cn/langpy/kotime/model/MethodRelation.java +++ b/src/main/java/cn/langpy/kotime/model/MethodRelation.java @@ -7,6 +7,7 @@ public class MethodRelation { private Double avgRunTime = 0.0; private Double maxRunTime = 0.0; private Double minRunTime = 10000.0; + private Integer callNum = 0; public String getId() { return id; @@ -56,5 +57,11 @@ public class MethodRelation { this.minRunTime = minRunTime; } + public Integer getCallNum() { + return callNum; + } + public void setCallNum(Integer callNum) { + this.callNum = callNum; + } } diff --git a/src/main/java/cn/langpy/kotime/service/KoInvokedHandler.java b/src/main/java/cn/langpy/kotime/service/KoInvokedHandler.java index 25567e0..9ea62fa 100644 --- a/src/main/java/cn/langpy/kotime/service/KoInvokedHandler.java +++ b/src/main/java/cn/langpy/kotime/service/KoInvokedHandler.java @@ -17,7 +17,7 @@ public final class KoInvokedHandler implements InvokedHandler { @Override public void onInvoked(MethodNode current, MethodNode parent, Parameter[] names, Object[] values) { - if (current == null || (current != null && current.getValue() == 0.0)) { + if (current == null) { return; } GraphService graphService = GraphService.getInstance(); diff --git a/src/main/resources/kostatic/common.css b/src/main/resources/kostatic/common.css new file mode 100644 index 0000000..945da80 --- /dev/null +++ b/src/main/resources/kostatic/common.css @@ -0,0 +1,16 @@ +.common-li { + color: #333; + font-weight: 400; + font-size: 14px; +} + +.common-li-bolder { + font-size: 16px; + font-weight: 500; +} + +.common-li-special { + font-size: 14px; + font-weight: 430; + color: #3621a5; +} \ No newline at end of file diff --git a/src/main/resources/kostatic/dict/chinese.properties b/src/main/resources/kostatic/dict/chinese.properties index 5898f16..92b3714 100644 --- a/src/main/resources/kostatic/dict/chinese.properties +++ b/src/main/resources/kostatic/dict/chinese.properties @@ -42,6 +42,7 @@ tab.summary.sysusage-metric.physical-memory.current-used=此程序占用 tab.interface.search-tip=搜索方法名或者类名... tab.interface.interface-list.avg-tip=平均响应 +tab.interface.interface-list.call-num-tip=调用次数 tab.interface.interface-list.show-metric.type=类型 tab.interface.interface-list.show-metric.avg=平均耗时 tab.interface.interface-list.show-metric.max=最大耗时 diff --git a/src/main/resources/kostatic/dict/english.properties b/src/main/resources/kostatic/dict/english.properties index 74f4834..c752c7e 100644 --- a/src/main/resources/kostatic/dict/english.properties +++ b/src/main/resources/kostatic/dict/english.properties @@ -42,6 +42,7 @@ tab.summary.sysusage-metric.physical-memory.current-used=ThisUsed tab.interface.search-tip=search method name or class name... tab.interface.interface-list.avg-tip=avg +tab.interface.interface-list.call-num-tip=callNum tab.interface.interface-list.show-metric.type=type tab.interface.interface-list.show-metric.avg=avg time tab.interface.interface-list.show-metric.max=max time diff --git a/src/main/resources/kotime.html b/src/main/resources/kotime.html index 9c52ed8..0efadb5 100644 --- a/src/main/resources/kotime.html +++ b/src/main/resources/kotime.html @@ -3,6 +3,7 @@ KoTime