diff --git a/cat-home/src/main/java/com/dianping/cat/report/page/cache/CacheReport.java b/cat-home/src/main/java/com/dianping/cat/report/page/cache/CacheReport.java index 16b2cd79a91e0b5ac8d6ce9d713074e4dc1dea18..7b83b848763deb3fef22eb4fbc804118ced55b2b 100644 --- a/cat-home/src/main/java/com/dianping/cat/report/page/cache/CacheReport.java +++ b/cat-home/src/main/java/com/dianping/cat/report/page/cache/CacheReport.java @@ -9,6 +9,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.hsqldb.lib.StringUtil; + import com.dianping.cat.consumer.event.model.entity.EventName; import com.dianping.cat.consumer.event.model.entity.EventType; import com.dianping.cat.consumer.transaction.model.entity.TransactionName; @@ -37,8 +39,14 @@ public class CacheReport { private Map m_typeItems = new HashMap(); public void addNewNameItem(TransactionName transactionName, EventName eventName) { - String key = transactionName.getId(); - CacheNameItem item = m_nameItems.get(key); + String arrays[] = transactionName.getId().split(":"); + String categroy = arrays[0]; + String method = ""; + + if (arrays.length > 1) { + method = arrays[1]; + } + CacheNameItem item = m_nameItems.get(categroy); CacheNameItem all = m_nameItems.get(ALL); if (all == null) { @@ -46,17 +54,14 @@ public class CacheReport { all.setName(new TransactionName(ALL)); m_nameItems.put(ALL, all); } - all.add(transactionName, eventName); + all.add(transactionName, eventName, method); if (item == null) { item = new CacheNameItem(); - item.setName(transactionName); - item.setMissed(eventName.getTotalCount()); - item.setHited(1 - (double) eventName.getTotalCount() / transactionName.getTotalCount()); - m_nameItems.put(key, item); - } else { - throw new RuntimeException("duplicate transaction name in cache report!"); + item.setName(new TransactionName(categroy)); + m_nameItems.put(categroy, item); } + item.add(transactionName, eventName, method); } public void addNewTypeItem(TransactionType transactionType, EventType eventType) { @@ -98,6 +103,16 @@ public class CacheReport { return result; } + public List getAllMethods() { + CacheNameItem allItem = m_nameItems.get(ALL); + + if (allItem != null) { + return new ArrayList(allItem.getMethodCounts().keySet()); + } else { + return new ArrayList(); + } + } + public java.util.Date getStartTime() { return m_startTime; } @@ -145,15 +160,35 @@ public class CacheReport { private long m_missed; + private long m_getCount; + private TransactionName m_name; - public void add(TransactionName transactionName, EventName eventName) { - m_name.setTotalCount(m_name.getTotalCount() + transactionName.getTotalCount()); + private String m_category; + + private Map m_methodCounts = new HashMap(); + + public void add(TransactionName transactionName, EventName eventName, String method) { + long transactionTotalCount = transactionName.getTotalCount(); + + m_name.setTotalCount(m_name.getTotalCount() + transactionTotalCount); m_name.setSum(m_name.getSum() + transactionName.getSum()); m_name.setAvg((double) m_name.getSum() / m_name.getTotalCount()); m_name.setTps(m_name.getTps() + transactionName.getTps()); - m_missed = m_missed + eventName.getTotalCount(); - m_hited = 1 - (double) m_missed / m_name.getTotalCount(); + + if (!StringUtil.isEmpty(method)) { + Long value = m_methodCounts.get(method); + + if (value == null) { + value = 0L; + } + m_methodCounts.put(method, value + transactionTotalCount); + if ("get".equals(method)) { + m_missed = m_missed + eventName.getTotalCount(); + m_getCount = m_getCount + transactionTotalCount; + m_hited = 1 - (double) m_missed / m_getCount; + } + } } public double getHited() { @@ -168,6 +203,24 @@ public class CacheReport { return m_name; } + public String getCategory() { + return m_category; + } + + public Map getMethodCounts() { + return m_methodCounts; + } + + public long getMethodCount(String method) { + Long count = m_methodCounts.get(method); + + if (count == null) { + return 0L; + } else { + return count; + } + } + public void setHited(double hited) { m_hited = hited; } @@ -207,6 +260,9 @@ public class CacheReport { return (int) (o2.getName().getAvg() * 1000 - o1.getName().getAvg() * 1000); } else if (m_sort.equals("name")) { return o1.getName().getId().compareTo(o2.getName().getId()); + } else if (m_sort.startsWith("method:")) { + String method = m_sort.substring(7); + return (int) (o2.getMethodCount(method) - o1.getMethodCount(method)); } return 0; } diff --git a/cat-home/src/main/webapp/jsp/report/cache/cache.jsp b/cat-home/src/main/webapp/jsp/report/cache/cache.jsp index dd186738c841d8243214f510856109a8c2b66696..18ce42dd86a6139f59e695099646e4632c17b53d 100644 --- a/cat-home/src/main/webapp/jsp/report/cache/cache.jsp +++ b/cat-home/src/main/webapp/jsp/report/cache/cache.jsp @@ -4,6 +4,7 @@ <%@ taglib prefix="w" uri="http://www.unidal.org/web/core"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="res" uri="http://www.unidal.org/webres"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> @@ -85,8 +86,9 @@
+ - + + + + + + + + + + + + + diff --git a/cat-home/src/main/webapp/jsp/report/cache/cacheHistory.jsp b/cat-home/src/main/webapp/jsp/report/cache/cacheHistory.jsp index 107afb59f102298211f03600de0b70fbf8445dd6..92a14952b8b836f4e3e1e5f1186e7673df8ea873 100644 --- a/cat-home/src/main/webapp/jsp/report/cache/cacheHistory.jsp +++ b/cat-home/src/main/webapp/jsp/report/cache/cacheHistory.jsp @@ -4,6 +4,7 @@ <%@ taglib prefix="w" uri="http://www.unidal.org/web/core"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="res" uri="http://www.unidal.org/webres"%> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> @@ -76,8 +77,9 @@
Total${method} Missed ${w:shorten(e.id, 80)} ${w:format(e.totalCount,'#,###,###,###,##0')}0${w:format(item.methodCounts[method],'#,###,###,###,##0')} ${item.missed} ${w:format(item.hited,'0.0000%')} ${w:format(e.avg,'0.0')}
+ - + + + + + + + + + + + + +
Total${method} Missed ${w:shorten(e.id, 80)} ${w:format(e.totalCount,'#,###,###,###,##0')}0${w:format(item.methodCounts[method],'#,###,###,###,##0')} ${item.missed} ${w:format(item.hited,'0.0000%')} ${w:format(e.avg,'0.0')}