All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickhouse.client.api.internal.ClientStatisticsHolder Maven / Gradle / Ivy

The newest version!
package com.clickhouse.client.api.internal;

import com.clickhouse.client.api.metrics.ClientMetrics;

import java.util.HashMap;
import java.util.Map;

public class ClientStatisticsHolder {

    private final Map stopWatches = new HashMap<>();

    public void start(ClientMetrics metric) {
        start(metric.getKey());
    }

    public void start(String spanName) {
        stopWatches.computeIfAbsent(spanName, k -> new StopWatch()).start();
    }

    public StopWatch stop(ClientMetrics metric) {
        return stop(metric.getKey());
    }

    public StopWatch stop(String spanName) {
        StopWatch timer = stopWatches.computeIfAbsent(spanName, k -> new StopWatch());
        timer.stop();
        return timer;
    }

    public long getElapsedTime(String spanName) {
        StopWatch sw = stopWatches.get(spanName);
        return sw == null ? -1 : sw.getElapsedTime();
    }

    public Map getStopWatches() {
        return stopWatches;
    }

    @Override
    public String toString() {
        return "ClientStatistics{" +
                "\"spans\"=" + stopWatches +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy