<commit_before>package com.netflix.evcache.metrics;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import com.netflix.spectator.api.BasicTag;
import com.netflix.spectator.api.Counter;
//import com.netflix.servo.DefaultMonitorRegistry;
//import com.netflix.servo.annotations.DataSourceType;
//import com.netflix.servo.monitor.BasicCounter;
//import com.netflix.servo.monitor.Counter;
//import com.netflix.servo.monitor.LongGauge;
//import com.netflix.servo.monitor.Monitor;
//import com.netflix.servo.monitor.MonitorConfig;
//import com.netflix.servo.monitor.Monitors;
//import com.netflix.servo.monitor.MonitorConfig.Builder;
//import com.netflix.servo.monitor.PercentileTimer;
//import com.netflix.servo.monitor.StepCounter;
//import com.netflix.servo.monitor.Timer;
//import com.netflix.servo.stats.StatsConfig;
//import com.netflix.servo.tag.BasicTagList;
//import com.netflix.servo.tag.Tag;
//import com.netflix.servo.tag.TagList;
import com.netflix.spectator.api.DistributionSummary;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Spectator;
import com.netflix.spectator.api.Tag;
//import com.netflix.servo.tag.BasicTag;
import com.netflix.spectator.api.Timer;
import com.netflix.spectator.api.histogram.PercentileTimer;

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = { "NF_LOCAL_FAST_PROPERTY",
        "PMB_POSSIBLE_MEMORY_BLOAT" }, justification = "Creates only when needed")
public final class EVCacheMetricsFactory {

    private final Map<String, Number> monitorMap = new ConcurrentHashMap<String, Number>();
    private final Map<String, Counter> counterMap = new ConcurrentHashMap<String, Counter>();
    private final Map<String, DistributionSummary> distributionSummaryMap = new ConcurrentHashMap<String, DistributionSummary>();
    private final Lock writeLock = (new ReentrantReadWriteLock()).writeLock();
    private final Map<String, Timer> timerMap = new HashMap<String, Timer>();

    private static final EVCacheMetricsFactory INSTANCE = new EVCacheMetricsFactory();

    private EVCacheMetricsFactory() {
        
    }
    
    public static EVCacheMetricsFactory getInstance() {
        return INSTANCE;
    }

    public Map<String, Counter> getAllCounters() {
        return counterMap;
    }
    
    public Map<String, Timer> getAllTimers() {
        return timerMap;
    }
    
    public Map<String, Number> getAllMonitor() {
        return monitorMap;
    }
    
    public Map<String, DistributionSummary> getAllDistributionSummaryMap() {
        return distributionSummaryMap;
    }

    public Registry getRegistry() {
        return Spectator.globalRegistry();
    }

    public AtomicLong getLongGauge(String name) {
        return getLongGauge(name, null);
    }

    public AtomicLong getLongGauge(String cName, Collection<Tag> tags) {
        final String name = tags != null ? cName + tags.toString() : cName;
        AtomicLong gauge = (AtomicLong)monitorMap.get(name);
        if (gauge == null) {
            writeLock.lock();
            try {
                if (monitorMap.containsKey(name)) {
                    gauge = (AtomicLong)monitorMap.get(name);
                } else {
                    if(tags != null) {
                        gauge = getRegistry().gauge(cName, tags, new AtomicLong());
                    } else {
                        gauge = getRegistry().gauge(cName, new AtomicLong());
                    }
                    monitorMap.put(name, gauge);
                }
            } finally {
                writeLock.unlock();
            }
        }
        return gauge;
    }
    
    public Id getId(String name, List<Tag> tags) {
        tags.add(new BasicTag("owner", "evcache"));
        return getRegistry().createId(name, tags);
    }

    public Counter getCounter(String cName, List<Tag> tags) {
        final String name = tags != null ? cName + tags.toString() : cName;
        Counter counter = counterMap.get(name);
        if (counter == null) {
            writeLock.lock();
            try {
                if (counterMap.containsKey(name)) {
                    counter = counterMap.get(name);
                } else {
                    if(tags == null) {
                        tags = new ArrayList<Tag>(1);
                    }
                    tags.add(new BasicTag("owner", "evcache"));
                    counter = getRegistry().counter(cName, tags);
                    counterMap.put(name, counter);
                }
            } finally {
                writeLock.unlock();
            }
        }<commit_msg>metric changes<commit_after>package com.netflix.evcache.metrics;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import com.netflix.spectator.api.BasicTag;
import com.netflix.spectator.api.Counter;
//import com.netflix.servo.DefaultMonitorRegistry;
//import com.netflix.servo.annotations.DataSourceType;
//import com.netflix.servo.monitor.BasicCounter;
//import com.netflix.servo.monitor.Counter;
//import com.netflix.servo.monitor.LongGauge;
//import com.netflix.servo.monitor.Monitor;
//import com.netflix.servo.monitor.MonitorConfig;
//import com.netflix.servo.monitor.Monitors;
//import com.netflix.servo.monitor.MonitorConfig.Builder;
//import com.netflix.servo.monitor.PercentileTimer;
//import com.netflix.servo.monitor.StepCounter;
//import com.netflix.servo.monitor.Timer;
//import com.netflix.servo.stats.StatsConfig;
//import com.netflix.servo.tag.BasicTagList;
//import com.netflix.servo.tag.Tag;
//import com.netflix.servo.tag.TagList;
import com.netflix.spectator.api.DistributionSummary;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Spectator;
import com.netflix.spectator.api.Tag;
//import com.netflix.servo.tag.BasicTag;
import com.netflix.spectator.api.Timer;
import com.netflix.spectator.api.histogram.PercentileTimer;

@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = { "NF_LOCAL_FAST_PROPERTY",
        "PMB_POSSIBLE_MEMORY_BLOAT" }, justification = "Creates only when needed")
public final class EVCacheMetricsFactory {

    private final Map<String, Number> monitorMap = new ConcurrentHashMap<String, Number>();
    private final Map<String, Counter> counterMap = new ConcurrentHashMap<String, Counter>();
    private final Map<String, DistributionSummary> distributionSummaryMap = new ConcurrentHashMap<String, DistributionSummary>();
    private final Lock writeLock = (new ReentrantReadWriteLock()).writeLock();
    private final Map<String, Timer> timerMap = new HashMap<String, Timer>();

    private static final EVCacheMetricsFactory INSTANCE = new EVCacheMetricsFactory();

    private EVCacheMetricsFactory() {
        
    }
    
    public static EVCacheMetricsFactory getInstance() {
        return INSTANCE;
    }

    public Map<String, Counter> getAllCounters() {
        return counterMap;
    }
    
    public Map<String, Timer> getAllTimers() {
        return timerMap;
    }
    
    public Map<String, Number> getAllMonitor() {
        return monitorMap;
    }
    
    public Map<String, DistributionSummary> getAllDistributionSummaryMap() {
        return distributionSummaryMap;
    }

    public Registry getRegistry() {
        return Spectator.globalRegistry();
    }

    public AtomicLong getLongGauge(String name) {
        return getLongGauge(name, null);
    }

    public AtomicLong getLongGauge(String cName, Collection<Tag> tags) {
        final String name = tags != null ? cName + tags.toString() : cName;
        AtomicLong gauge = (AtomicLong)monitorMap.get(name);
        if (gauge == null) {
            writeLock.lock();
            try {
                if (monitorMap.containsKey(name)) {
                    gauge = (AtomicLong)monitorMap.get(name);
                } else {
                    if(tags != null) {
                        gauge = getRegistry().gauge(cName, tags, new AtomicLong());
                    } else {
                        gauge = getRegistry().gauge(cName, new AtomicLong());
                    }
                    monitorMap.put(name, gauge);
                }
            } finally {
                writeLock.unlock();
            }
        }
        return gauge;
    }
    
    public Id getId(String name, List<Tag> tags) {
        List<Tag> tagList = new ArrayList<Tag>(1);
        tagList.addAll(tags);
        tagList.add(new BasicTag("owner", "evcache"));
        return getRegistry().createId(name, tagList);
    }

    public Counter getCounter(String cName, List<Tag> tags) {
        final String name = tags != null ? cName + tags.toString() : cName;
        Counter counter = counterMap.get(name);
        if (counter == null) {
            writeLock.lock();
            try {
                if (counterMap.containsKey(name)) {
                    counter = counterMap.get(name);
                } else {
                    List<Tag> tagList = new ArrayList<Tag>(1);
                    tagList.addAll(tags);
                    tagList.add(new BasicTag("owner", "evcache"));
                    counter = getRegistry().counter(cName, tagList);
                    counterMap.put(name, counter);
                }
            } finally {
                writeLock.unlock();
            }
        }
{'fraction_non_alphanumeric': 0.1116751269035533, 'fraction_numerical': 0.00030456852791878173, 'mean_word_length': 2.6071036250457706, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5399383', 'n_tokens_mistral': 2844, 'n_tokens_neox': 2751, 'n_words': 550}