aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-10-28 14:28:57 +0000
committerGodin <mandrikov@gmail.com>2010-10-28 14:28:57 +0000
commitd7869519b8a56a36617cdcdd4a057398750e1a38 (patch)
tree620f67dbf179737238bbe7080fc0b46f03010348 /sonar-plugin-api
parent8793034838a4c4e54652b5a48466212c02f016d4 (diff)
downloadsonarqube-d7869519b8a56a36617cdcdd4a057398750e1a38.tar.gz
sonarqube-d7869519b8a56a36617cdcdd4a057398750e1a38.zip
SONAR-1837:
* Add profiling logs to database optimization tasks * Extend TimeProfiler to produce logs using debug level
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/TimeProfiler.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/TimeProfiler.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/TimeProfiler.java
index 000d0c9f06d..d081de68d40 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/TimeProfiler.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/TimeProfiler.java
@@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory;
/**
* A very simple profiler to log the time elapsed performing some tasks.
* This implementation is not thread-safe.
- *
+ *
* @since 2.0
*/
public class TimeProfiler {
@@ -33,6 +33,7 @@ public class TimeProfiler {
private Logger logger;
private long start = 0;
private String name;
+ private boolean debug = false;
public TimeProfiler(Logger logger) {
this.logger = logger;
@@ -52,7 +53,11 @@ public class TimeProfiler {
public TimeProfiler start(String name) {
this.name = name;
this.start = System.currentTimeMillis();
- logger.info(name + "...");
+ if (debug) {
+ logger.debug(name + "...");
+ } else {
+ logger.info(name + "...");
+ }
return this;
}
@@ -65,11 +70,23 @@ public class TimeProfiler {
return logger;
}
+ /**
+ * @since 2.4
+ */
+ public TimeProfiler setLevelToDebug() {
+ debug = true;
+ return this;
+ }
+
public TimeProfiler stop() {
if (start > 0) {
- logger.info("{} done: {} ms", name, (System.currentTimeMillis() - start));
+ if (debug) {
+ logger.debug("{} done: {} ms", name, (System.currentTimeMillis() - start));
+ } else {
+ logger.info("{} done: {} ms", name, (System.currentTimeMillis() - start));
+ }
}
start = 0;
return this;
}
-} \ No newline at end of file
+}