Skip to content

Commit

Permalink
IGNITE-49 Implemented avg statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
niktikhonov committed Jan 16, 2015
1 parent c04013d commit d8ecf41
Show file tree
Hide file tree
Showing 4 changed files with 396 additions and 18 deletions.
Expand Up @@ -387,14 +387,24 @@ public GridCacheContext<K, V> context() {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public V get(K key) { @Override public V get(K key) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


V res;

try { try {
return delegate.get(key); res = delegate.get(key);
} }
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled)
ctx.cache().metrics0().addGetTimeNanos(System.nanoTime() - start);

return res;
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand All @@ -404,14 +414,24 @@ public GridCacheContext<K, V> context() {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public Map<K, V> getAll(Set<? extends K> keys) { @Override public Map<K, V> getAll(Set<? extends K> keys) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


Map<K, V> res;

try { try {
return delegate.getAll(keys); res = delegate.getAll(keys);
} }
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled)
ctx.cache().metrics0().addGetTimeNanos(System.nanoTime() - start);

return res;
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand All @@ -432,6 +452,9 @@ public Map<K, V> getAll(Collection<? extends K> keys) {
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled)
ctx.cache().metrics0().addPutTimeNanos(System.nanoTime() - start);
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand Down Expand Up @@ -495,6 +518,9 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public void put(K key, V val) { @Override public void put(K key, V val) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


try { try {
Expand All @@ -503,6 +529,9 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled)
ctx.cache().metrics0().addPutTimeNanos(System.nanoTime() - start);
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand All @@ -512,14 +541,26 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public V getAndPut(K key, V val) { @Override public V getAndPut(K key, V val) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


V ret;

try { try {
return delegate.put(key, val); ret = delegate.put(key, val);
} }
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled) {
ctx.cache().metrics0().addPutTimeNanos(System.nanoTime() - start);
ctx.cache().metrics0().addGetTimeNanos(System.nanoTime() - start);
}

return ret;
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand All @@ -529,6 +570,9 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public void putAll(Map<? extends K, ? extends V> map) { @Override public void putAll(Map<? extends K, ? extends V> map) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


try { try {
Expand All @@ -546,14 +590,24 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public boolean putIfAbsent(K key, V val) { @Override public boolean putIfAbsent(K key, V val) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


boolean stored;

try { try {
return delegate.putxIfAbsent(key, val); stored = delegate.putxIfAbsent(key, val);
} }
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled && stored)
ctx.cache().metrics0().addPutTimeNanos(System.nanoTime() - start);

return stored;
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand All @@ -563,14 +617,24 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public boolean remove(K key) { @Override public boolean remove(K key) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


boolean removed;

try { try {
return delegate.removex(key); removed = delegate.removex(key);
} }
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled)
ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() - start);

return removed;
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand All @@ -580,14 +644,24 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public boolean remove(K key, V oldVal) { @Override public boolean remove(K key, V oldVal) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


boolean removed;

try { try {
return delegate.remove(key, oldVal); removed = delegate.remove(key, oldVal);
} }
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled && removed)
ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() - start);

return removed;
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand All @@ -597,14 +671,24 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public V getAndRemove(K key) { @Override public V getAndRemove(K key) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


V removed;

try { try {
return delegate.remove(key); removed = delegate.remove(key);
} }
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled)
ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() - start);

return removed;
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand All @@ -622,6 +706,9 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
finally { finally {
gate.leave(prev); gate.leave(prev);
} }

if (statisticsEnabled)
ctx.cache().metrics0().addRemoveTimeNanos(System.nanoTime() - start);
} }
catch (IgniteCheckedException e) { catch (IgniteCheckedException e) {
throw cacheException(e); throw cacheException(e);
Expand Down Expand Up @@ -665,6 +752,9 @@ public void removeAll(IgnitePredicate<GridCacheEntry<K, V>>... filter) {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override public void removeAll(Set<? extends K> keys) { @Override public void removeAll(Set<? extends K> keys) {
try { try {
boolean statisticsEnabled = ctx.config().isStatisticsEnabled();
long start = statisticsEnabled ? System.nanoTime() : 0L;

GridCacheProjectionImpl<K, V> prev = gate.enter(prj); GridCacheProjectionImpl<K, V> prev = gate.enter(prj);


try { try {
Expand Down

0 comments on commit d8ecf41

Please sign in to comment.