You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -6,74 +6,138 @@ Please read the main documentation at: http://avaje-metrics.github.io
6
6
7
7
```xml
8
8
<dependency>
9
-
<groupId>org.avaje.metric</groupId>
10
-
<artifactId>avaje-metric-core</artifactId>
11
-
<version>4.4.1</version>
9
+
<groupId>io.avaje</groupId>
10
+
<artifactId>avaje-metrics</artifactId>
11
+
<version>9.2</version>
12
12
</dependency>
13
13
```
14
14
15
15
16
16
## License - Apache 2
17
17
Published under Apache Software License 2.0, see LICENSE
18
18
19
-
## Overhead
20
-
Micro benchmarks are notoriously difficult but that said the overhead using version 4.1 has been measured at 140 nanos per method invocation (with request collection count of 0 meaning per request timing isn't collected). For perspective if the overhead was 200 nanos then executing 5000 methods would add 1 millisecond of overhead.
21
-
22
-
Request timing would not add much more to execution time per say but relatively speaking can produce a lot of output (that is reported in a background thread) and creates objects so adds some extra GC cost. In production you would expect to limit the number of metrics you collect on and limit the number of request timings you collect.
23
-
24
-
## Example Metrics output (typically reported every 60 seconds)
25
-
Below is a sample of the metric log output. The metrics are periodically collected
> Per Request timing is a little bit more expensive to collect and can produce a lot of output. As such it is expected that you only turn it on when needed. For example, for the next 5 invocations of CustomerResource.asBean() collect per request timings.
90
+
## Timer
55
91
56
-
Per request timing can be set for specific timing metrics - for example, collect per request timing on the next 5 invocations of the CustomerResource.asBean() method.
92
+
A Timer measures the time on an event in microseconds.
93
+
It provides count, total time in micros, mean time in micros, max time in micros.
57
94
58
-
Per request timing output shows the nested calls and where the time went for that single request. The p column shows the percentage of total execution - for example 81% of execution time was taken in Muse.iDoTheRealWorkAroundHere. Typically in looking at this output you ignore/remove/collapse anything that has percentage of 0.
95
+
Timers can be obtained and used via code or via `@Timed` enhancement. We can also
96
+
apply timers on "All non-private methods of Spring Beans"
97
+
or "All non-private methods of Avaje Inject Beans"
59
98
60
-
The columns are: d=depth, p=percentage, ms=milliseconds, us=microseconds, m=metric name
Timers can be added by putting `@Timed` on a class. Then enhancement will add timers to
102
+
all non-private methods on that class. We use `@NotTimed` to not have a method timed.
103
+
104
+
105
+
#### Using Timer programmatically
106
+
107
+
Obtain a Timer from the `MetricRegistry` or via `Metrics.timer(...)` which uses the default registry.
108
+
109
+
```java
110
+
Timer metric =Metrics.timer("test.runnable");
76
111
```
77
-
CustomerResource.asBean took 612 milliseconds to execute. If you look at Muse.iDoTheRealWorkAroundHere it took 81% of the total execution time (500 milliseconds, 500204 microseconds).
78
112
113
+
#### Time Runnable
114
+
115
+
The Timer can take a runnable like:
116
+
117
+
```java
118
+
Timer timer =Metrics.timer("test.runnable");
119
+
120
+
// using runnable
121
+
timer.time( //* ... runnable */ );
122
+
```
123
+
124
+
#### Time using start nanos
125
+
```java
126
+
long startNanos =System.nanoTime();
127
+
128
+
// do something we want to time ...
129
+
timer.add(startNanos);
130
+
```
131
+
This is an efficient way to time events with no extra object allocation.
132
+
133
+
The time is the difference between startNanos and when that is added to
0 commit comments