Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Running the stopwatch and logging the result only if debug lvl is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkremser committed Mar 21, 2014
1 parent 08d9fcb commit 9e1b17f
Showing 1 changed file with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private void reset() {
@Override
@RequiredPermission(Permission.MANAGE_SETTINGS)
public StorageNodeLoadComposite getLoad(Subject subject, StorageNode node, long beginTime, long endTime) {
Stopwatch stopwatch = new Stopwatch().start();
Stopwatch stopwatch = stopwatchStart();
try {
if (!storageClientManager.isClusterAvailable()) {
return new StorageNodeLoadComposite(node, beginTime, endTime);
Expand Down Expand Up @@ -442,8 +442,9 @@ public StorageNodeLoadComposite getLoad(Subject subject, StorageNode node, long

return result;
} finally {
stopwatch.stop();
log.info("Retrieved load metrics for " + node + " in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
if (log.isDebugEnabled()) {
stopwatchEnd(stopwatch, "Retrieved load metrics for " + node + " in ");
}
}
}

Expand All @@ -452,7 +453,7 @@ public StorageNodeLoadComposite getLoad(Subject subject, StorageNode node, long
@RequiredPermission(Permission.MANAGE_SETTINGS)
public ListenableFuture<List<StorageNodeLoadComposite>> getLoadAsync(Subject subject, StorageNode node,
long beginTime, long endTime) {
Stopwatch stopwatch = new Stopwatch().start();
Stopwatch stopwatch = stopwatchStart();
final StorageNodeLoadComposite result = new StorageNodeLoadComposite(node, beginTime, endTime);
try {
if (!storageClientManager.isClusterAvailable()) {
Expand Down Expand Up @@ -529,8 +530,9 @@ public StorageNodeLoadComposite apply(

return Futures.successfulAsList(compositeFutures);
} finally {
stopwatch.stop();
log.debug("Retrieved load metrics for " + node + " in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
if (log.isDebugEnabled()) {
stopwatchEnd(stopwatch, "Retrieved load metrics for " + node + " in ");
}
}
}

Expand Down Expand Up @@ -605,7 +607,7 @@ public List<StorageNode> getClusterNodes() {
@Override
@RequiredPermission(Permission.MANAGE_SETTINGS)
public PageList<StorageNodeLoadComposite> getStorageNodeComposites(Subject subject) {
Stopwatch stopwatch = new Stopwatch().start();
Stopwatch stopwatch = stopwatchStart();
List<StorageNode> nodes = getStorageNodes();
final CountDownLatch latch = new CountDownLatch(nodes.size());
final PageList<StorageNodeLoadComposite> result = new PageList<StorageNodeLoadComposite>();
Expand Down Expand Up @@ -656,8 +658,9 @@ public void onFailure(Throwable t) {
log.info("There was an interrupt while waiting for storage node load data.", e);
return result;
} finally {
stopwatch.stop();
log.debug("Retrieved storage node composites in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
if (log.isDebugEnabled()) {
stopwatchEnd(stopwatch, "Retrieved storage node composites in ");
}
}
}

Expand Down Expand Up @@ -794,12 +797,13 @@ public PageList<Alert> findNotAcknowledgedStorageNodeAlerts(Subject subject) {
@Override
@RequiredPermission(Permission.MANAGE_SETTINGS)
public PageList<Alert> findNotAcknowledgedStorageNodeAlerts(Subject subject, StorageNode storageNode) {
Stopwatch stopwatch = new Stopwatch().start();
Stopwatch stopwatch = stopwatchStart();
try {
return findStorageNodeAlerts(subject, false, storageNode);
} finally {
stopwatch.stop();
log.info("Retrieved unacked alerts for " + storageNode + " in " + stopwatch.elapsed(TimeUnit.MILLISECONDS));
if (log.isDebugEnabled()) {
stopwatchEnd(stopwatch, "Retrieved unacked alerts for " + storageNode + " in ");
}
}
}

Expand Down Expand Up @@ -851,7 +855,7 @@ private PageList<Alert> findStorageNodeAlerts(Subject subject, boolean allAlerts
}

private Map<Integer, Integer> findUnackedAlertCounts(List<StorageNode> storageNodes) {
Stopwatch stopwatch = new Stopwatch().start();
Stopwatch stopwatch = stopwatchStart();
try {
Map<Integer, StorageNode> resourceIdToStorageNodeMap = new TreeMap<Integer, StorageNode>();
for (StorageNode storageNode : storageNodes) {
Expand Down Expand Up @@ -881,9 +885,7 @@ private Map<Integer, Integer> findUnackedAlertCounts(List<StorageNode> storageNo

return storageNodeAlertCounts;
} finally {
stopwatch.stop();
log.debug("Finished calculating storage node alert counts in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) +
" ms");
stopwatchEnd(stopwatch, "Finished calculating storage node alert counts in ");
}
}

Expand Down Expand Up @@ -921,7 +923,7 @@ public Integer[] findResourcesWithAlertDefinitions(StorageNode storageNode) {
}

private Map<Integer, Integer> findResourcesWithAlertsToStorageNodeMap(StorageNode storageNode) {
Stopwatch stopwatch = new Stopwatch().start();
Stopwatch stopwatch = stopwatchStart();
List<StorageNode> initialStorageNodes = getStorageNodes();
try {
if (storageNode == null) {
Expand Down Expand Up @@ -956,9 +958,9 @@ private Map<Integer, Integer> findResourcesWithAlertsToStorageNodeMap(StorageNod

return resourceIdsToStorageNodeMap;
} finally {
stopwatch.stop();
log.debug("Found storage node resources with alert defs in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) +
" ms");
if (log.isDebugEnabled()) {
stopwatchEnd(stopwatch, "Found storage node resources with alert defs in ");
}
}
}

Expand Down Expand Up @@ -1235,5 +1237,19 @@ private boolean runOperationAndWaitForResult(Subject subject, Resource storageNo

return successResultFound;
}

private Stopwatch stopwatchStart() {
if (log.isDebugEnabled()) {
return new Stopwatch().start();
}
return null;
}

private void stopwatchEnd(Stopwatch stopwatch, String message) {
if (stopwatch != null && log.isDebugEnabled()) {
stopwatch.stop();
log.debug(message + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
}
}

}

0 comments on commit 9e1b17f

Please sign in to comment.