From 00bc49a8cfb1be84908628016da36e1985d4e3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alja=C5=BE=20Pavi=C5=A1i=C4=8D?= Date: Mon, 16 Mar 2020 10:28:39 +0100 Subject: [PATCH] Edited README to include SimpleTimer example. --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index ebb70ce..985ea60 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,37 @@ public void longLasting() { } ``` +### SimpleTimer + +A `SimpleTimer` measures the total amount of time a method or block of code has spent executing. Here is an example of a method simple timer: + +```java +@SimplyTimed(name = "simply_timed_method") +public void simplyTimedMethod() { + ... +} +``` + +In the following example, only a part of the method is timed: + +```java +@Inject +@Metric(name = "simply_timed_method") +private SimpleTimer simpleTimer; + +public void simplyTimedMethod() { + ... + final SimpleTimer.Context context = simpleTimer.time(); + try { + // complex computations + return; + } finally { + context.stop(); + } + ... +} +``` + ## Metric names & metadata Each metric name is prepended with the fully qualified class name, so they can be easily differentiated between classes