diff --git a/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxyImpl.java b/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxyImpl.java index db76323977..c8aa5d33b8 100644 --- a/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxyImpl.java +++ b/src/main/java/com/alibaba/druid/proxy/jdbc/StatementProxyImpl.java @@ -48,7 +48,7 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro protected StatementExecuteType lastExecuteType; - protected Integer updateCount = null; + protected Integer updateCount = null; private FilterChainImpl filterChain = null; @@ -319,9 +319,11 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro @Override public boolean getMoreResults() throws SQLException { - updateCount = null; FilterChainImpl chain = createChain(); boolean value = chain.statement_getMoreResults(this); + if (value) { + updateCount = null; + } recycleFilterChain(chain); return value; } @@ -549,21 +551,21 @@ public class StatementProxyImpl extends WrapperProxyImpl implements StatementPro public boolean isFirstResultSet() { return firstResultSet; } - + @SuppressWarnings("unchecked") public T unwrap(Class iface) throws SQLException { if (iface == StatementProxy.class) { return (T) this; } - + return super.unwrap(iface); } - + public boolean isWrapperFor(Class iface) throws SQLException { if (iface == StatementProxy.class) { return true; } - + return super.isWrapperFor(iface); } diff --git a/src/main/java/com/alibaba/druid/support/http/stat/WebURIStat.java b/src/main/java/com/alibaba/druid/support/http/stat/WebURIStat.java index c32a5fd87c..54d18882d6 100644 --- a/src/main/java/com/alibaba/druid/support/http/stat/WebURIStat.java +++ b/src/main/java/com/alibaba/druid/support/http/stat/WebURIStat.java @@ -102,6 +102,32 @@ public class WebURIStat { private final static ThreadLocal currentLocal = new ThreadLocal(); + private volatile long histogram_0_1; + private volatile long histogram_1_10; + private volatile long histogram_10_100; + private volatile long histogram_100_1000; + private volatile int histogram_1000_10000; + private volatile int histogram_10000_100000; + private volatile int histogram_100000_1000000; + private volatile int histogram_1000000_more; + + final static AtomicLongFieldUpdater histogram_0_1_Updater = AtomicLongFieldUpdater.newUpdater(WebURIStat.class, + "histogram_0_1"); + final static AtomicLongFieldUpdater histogram_1_10_Updater = AtomicLongFieldUpdater.newUpdater(WebURIStat.class, + "histogram_1_10"); + final static AtomicLongFieldUpdater histogram_10_100_Updater = AtomicLongFieldUpdater.newUpdater(WebURIStat.class, + "histogram_10_100"); + final static AtomicLongFieldUpdater histogram_100_1000_Updater = AtomicLongFieldUpdater.newUpdater(WebURIStat.class, + "histogram_100_1000"); + final static AtomicIntegerFieldUpdater histogram_1000_10000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebURIStat.class, + "histogram_1000_10000"); + final static AtomicIntegerFieldUpdater histogram_10000_100000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebURIStat.class, + "histogram_10000_100000"); + final static AtomicIntegerFieldUpdater histogram_100000_1000000_Updater = AtomicIntegerFieldUpdater.newUpdater(WebURIStat.class, + "histogram_100000_1000000"); + final static AtomicIntegerFieldUpdater histogram_1000000_more_Updater = AtomicIntegerFieldUpdater.newUpdater(WebURIStat.class, + "histogram_1000000_more"); + public WebURIStat(String uri){ super(); this.uri = uri; @@ -145,6 +171,8 @@ public class WebURIStat { runningCountUpdater.decrementAndGet(this); requestTimeNanoUpdater.addAndGet(this, nanos); + histogramRecord(nanos); + if (error != null) { errorCountUpdater.incrementAndGet(this); } @@ -212,6 +240,28 @@ public class WebURIStat { currentLocal.set(null); } + private void histogramRecord(long nanos) { + final long millis = nanos / 1000 / 1000; + + if (millis < 1) { + histogram_0_1_Updater.incrementAndGet(this); + } else if (millis < 10) { + histogram_1_10_Updater.incrementAndGet(this); + } else if (millis < 100) { + histogram_10_100_Updater.incrementAndGet(this); + } else if (millis < 1000) { + histogram_100_1000_Updater.incrementAndGet(this); + } else if (millis < 10000) { + histogram_1000_10000_Updater.incrementAndGet(this); + } else if (millis < 100000) { + histogram_10000_100000_Updater.incrementAndGet(this); + } else if (millis < 1000000) { + histogram_100000_1000000_Updater.incrementAndGet(this); + } else { + histogram_1000000_more_Updater.incrementAndGet(this); + } + } + public int getRunningCount() { return this.runningCount; } @@ -364,6 +414,20 @@ public class WebURIStat { return profiletat; } + public long[] getHistogramValues() { + return new long[] { + // + histogram_0_1, // + histogram_1_10, // + histogram_10_100, // + histogram_100_1000, // + histogram_1000_10000, // + histogram_10000_100000, // + histogram_100000_1000000, // + histogram_1000000_more // + }; + } + public WebURIStatValue getValue(boolean reset) { WebURIStatValue val = new WebURIStatValue(); @@ -399,11 +463,20 @@ public class WebURIStat { val.setLastAccessTimeMillis(get(this, lastAccessTimeMillisUpdater, reset)); val.setProfileEntryStatValueList(this.getProfiletat().getStatValue(reset)); + + val.histogram_0_1 = get(this, histogram_0_1_Updater, reset); + val.histogram_1_10 = get(this, histogram_1_10_Updater, reset); + val.histogram_10_100 = get(this, histogram_10_100_Updater, reset); + val.histogram_100_1000 = get(this, histogram_100_1000_Updater, reset); + val.histogram_1000_10000 = get(this, histogram_1000_10000_Updater, reset); + val.histogram_10000_100000 = get(this, histogram_10000_100000_Updater, reset); + val.histogram_100000_1000000 = get(this, histogram_100000_1000000_Updater, reset); + val.histogram_1000000_more = get(this, histogram_1000000_more_Updater, reset); return val; } public Map getStatData() { - return getValue(false).getStatData(); + return getValue(false).getStatData(); } } diff --git a/src/main/java/com/alibaba/druid/support/http/stat/WebURIStatValue.java b/src/main/java/com/alibaba/druid/support/http/stat/WebURIStatValue.java index 13434cc1af..712f9abf63 100644 --- a/src/main/java/com/alibaba/druid/support/http/stat/WebURIStatValue.java +++ b/src/main/java/com/alibaba/druid/support/http/stat/WebURIStatValue.java @@ -58,6 +58,27 @@ public class WebURIStatValue { private List profileEntryStatValueList; + protected long histogram_0_1; + protected long histogram_1_10; + protected long histogram_10_100; + protected long histogram_100_1000; + protected int histogram_1000_10000; + protected int histogram_10000_100000; + protected int histogram_100000_1000000; + protected int histogram_1000000_more; + + public long[] getHistogram() { + return new long[] { histogram_0_1, // + histogram_1_10, // + histogram_10_100, // + histogram_100_1000, // + histogram_1000_10000, // + histogram_10000_100000, // + histogram_100000_1000000, // + histogram_1000000_more, // + }; + } + public List getProfileEntryStatValueList() { return profileEntryStatValueList; } @@ -280,6 +301,7 @@ public class WebURIStatValue { data.put("JdbcResultSetOpenCount", this.getJdbcResultSetOpenCount()); data.put("JdbcResultSetCloseCount", this.getJdbcResultSetCloseCount()); + data.put("Histogram", this.getHistogram()); if (this.profileEntryStatValueList != null) { int size = profileEntryStatValueList.size();