@Override public void onSubscribe(Subscription s) { if (Operators.validate(this.s, s)) { this.subscribedCounter.increment(); this.subscribeToTerminateSample = Timer.start(clock); this.lastNextEventNanos = clock.monotonicTime(); if (s instanceof Fuseable.QueueSubscription) { //noinspection unchecked this.qs = (Fuseable.QueueSubscription<T>) s; } this.s = s; actual.onSubscribe(this); } }
@Override public void onNext(T t) { if (done) { this.malformedSourceCounter.increment(); Operators.onNextDropped(t, actual.currentContext()); return; } //record the delay since previous onNext/onSubscribe. This also records the count. long last = this.lastNextEventNanos; this.lastNextEventNanos = clock.monotonicTime(); this.onNextIntervalTimer.record(lastNextEventNanos - last, TimeUnit.NANOSECONDS); actual.onNext(t); }
@Override @Nullable public T poll() { if (qs == null) { return null; } try { T v = qs.poll(); if (v == null && fusionMode == SYNC) { //this is also a complete event this.subscribeToTerminateSample.stop(subscribeToCompleteTimer); } if (v != null) { //this is an onNext event //record the delay since previous onNext/onSubscribe. This also records the count. long last = this.lastNextEventNanos; this.lastNextEventNanos = clock.monotonicTime(); this.onNextIntervalTimer.record(lastNextEventNanos - last, TimeUnit.NANOSECONDS); } return v; } catch (Throwable e) { //register a timer for that particular exception Timer timer = subscribeToErrorTimerFactory.apply(e); //record error termination this.subscribeToTerminateSample.stop(timer); throw e; } }
@Override public void onNext(T t) { if (this.fusionMode == Fuseable.ASYNC) { actual.onNext(null); return; } if (done) { this.malformedSourceCounter.increment(); Operators.onNextDropped(t, actual.currentContext()); return; } //record the delay since previous onNext/onSubscribe. This also records the count. long last = this.lastNextEventNanos; this.lastNextEventNanos = clock.monotonicTime(); this.onNextIntervalTimer.record(lastNextEventNanos - last, TimeUnit.NANOSECONDS); actual.onNext(t); }
@Override public long monotonicTime() { return clock.monotonicTime(); } }, config);
@Override public long monotonicTime() { return clock.monotonicTime(); } }), clock, config.step().toMillis());
@Override public long monotonicTime() { return impl.monotonicTime(); } }
public long start() { long task = nextTask.getAndIncrement(); tasks.put(task, clock.monotonicTime()); return task; }
public long stop(long task) { Long startTime = tasks.get(task); if (startTime != null) { tasks.remove(task); return clock.monotonicTime() - startTime; } else { return -1L; } }
public double duration(TimeUnit unit) { long now = clock.monotonicTime(); long sum = 0L; for (long startTime : tasks.values()) { sum += now - startTime; } return TimeUtils.nanosToUnit(sum, unit); }
public double duration(long task, TimeUnit unit) { Long startTime = tasks.get(task); return (startTime != null) ? TimeUtils.nanosToUnit(clock.monotonicTime() - startTime, unit) : -1L; }
@Override public void onSuccess(final ClientHttpResponse response) { getTimeBuilder(urlTemplate, request, response).register(meterRegistry) .record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS); }
@Override public void onFailure(final Throwable ex) { getTimeBuilder(urlTemplate, request, null).register(meterRegistry) .record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS); } });
void record(final ClientHttpResponse response, final Throwable throwable) throws IOException { final long endTime = clock.monotonicTime(); final Iterable<Tag> tags = concat(defaultTags, generator.tags(arguments, response, throwable)); final Timer timer = registry.timer(metricName, tags); final long duration = endTime - startTime; timer.record(duration, NANOSECONDS); }
void record(final ClientHttpResponse response, final Throwable throwable) throws IOException { final long endTime = clock.monotonicTime(); final Iterable<Tag> tags = concat(defaultTags, generator.tags(arguments, response, throwable)); final Timer timer = registry.timer(metricName, tags); final long duration = endTime - startTime; timer.record(duration, NANOSECONDS); }
private Object recordThrowable(Timer timer, ThrowableCallable f) throws Throwable { long start = registry.config().clock().monotonicTime(); try { return f.call(); } finally { timer.record(registry.config().clock().monotonicTime() - start, TimeUnit.NANOSECONDS); } }
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { final String urlTemplate = urlTemplateHolder.get(); urlTemplateHolder.remove(); final Clock clock = meterRegistry.config().clock(); final long startTime = clock.monotonicTime(); ClientHttpResponse response = null; try { response = execution.execute(request, body); return response; } finally { getTimeBuilder(urlTemplate, request, response).register(this.meterRegistry) .record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS); } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { final long startTime = clock.monotonicTime(); if (!exchange.isComplete()) { exchange.addExchangeCompleteListener((exchange1, nextListener) -> { getTimeBuilder(exchange).register(registry) .record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS); nextListener.proceed(); }); } next.handleRequest(exchange); }
@Override public void onSubscribe(Subscription s) { if (Operators.validate(this.s, s)) { this.subscribedCounter.increment(); this.subscribeToTerminateSample = Timer.start(clock); this.lastNextEventNanos = clock.monotonicTime(); if (s instanceof Fuseable.QueueSubscription) { //noinspection unchecked this.qs = (Fuseable.QueueSubscription<T>) s; } this.s = s; actual.onSubscribe(this); } }
@Override public void onNext(T t) { if (done) { this.malformedSourceCounter.increment(); Operators.onNextDropped(t, actual.currentContext()); return; } //record the delay since previous onNext/onSubscribe. This also records the count. long last = this.lastNextEventNanos; this.lastNextEventNanos = clock.monotonicTime(); this.onNextIntervalTimer.record(lastNextEventNanos - last, TimeUnit.NANOSECONDS); actual.onNext(t); }