-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Clay Reimann
committed
Jan 26, 2017
1 parent
f013e1a
commit 6a283a6
Showing
11 changed files
with
182 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
fili-core/src/main/java/com/yahoo/bard/webservice/logging/TimedPhase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2017 Yahoo Inc. All rights reserved. | ||
*/ | ||
package com.yahoo.bard.webservice.logging; | ||
|
||
import com.yahoo.bard.webservice.application.MetricRegistryFactory; | ||
|
||
import com.codahale.metrics.MetricRegistry; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Represents a phase that is timed. | ||
* TimedPhase is used to associate a Timer located in the registry with the exact duration of such a phase for a | ||
* specific request. | ||
*/ | ||
public class TimedPhase { | ||
private static final MetricRegistry REGISTRY = MetricRegistryFactory.getRegistry(); | ||
private static final Logger LOG = LoggerFactory.getLogger(RequestLog.class); | ||
|
||
protected final String name; | ||
protected long start; | ||
protected long duration; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param name Name of the phase | ||
*/ | ||
protected TimedPhase(String name) { | ||
this.name = name; | ||
} | ||
|
||
/** | ||
* Start the phase. | ||
*/ | ||
protected void start() { | ||
if (start != 0) { | ||
LOG.warn("Tried to start timer that is already running: {}", name); | ||
return; | ||
} | ||
start = System.nanoTime(); | ||
} | ||
|
||
/** | ||
* Stop the phase. | ||
*/ | ||
protected void stop() { | ||
if (start == 0) { | ||
LOG.warn("Tried to stop timer that has not been started: {}", name); | ||
return; | ||
} | ||
duration += System.nanoTime() - start; | ||
REGISTRY.timer(name).update(duration, TimeUnit.NANOSECONDS); | ||
start = 0; | ||
} | ||
|
||
protected boolean isRunning() { | ||
return start != 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.