<commit_before>package io.sniffy;

import com.codahale.metrics.Timer;
import io.sniffy.configuration.SniffyConfiguration;
import io.sniffy.socket.SnifferSocketImplFactory;
import io.sniffy.socket.SocketMetaData;
import io.sniffy.socket.SocketStats;
import io.sniffy.sql.SqlStatement;
import io.sniffy.sql.SqlUtil;
import io.sniffy.sql.StatementMetaData;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.util.Iterator;
import java.util.Queue;
import java.util.concurrent.*;

import static io.sniffy.util.StackTraceExtractor.*;

/**
 * Sniffy allows you to validate the number of SQL queries executed by a given block of code
 * Example usage:
 * <pre>
 * <code>
 *     Connection connection = DriverManager.getConnection("sniffy:jdbc:h2:mem:", "sa", "sa");
 *     Spy{@literal <}?{@literal >} spy = Sniffy.spy();
 *     connection.createStatement().execute("SELECT 1 FROM DUAL");
 *     spy.verify(SqlQueries.atMostOneQuery());
 * </code>
 * </pre>
 * @since 3.1
 */
public class Sniffy {

    protected static final Queue<WeakReference<Spy>> registeredSpies =
            new ConcurrentLinkedQueue<WeakReference<Spy>>();
    protected static final ConcurrentMap<Long, WeakReference<CurrentThreadSpy>> currentThreadSpies =
            new ConcurrentHashMap<Long, WeakReference<CurrentThreadSpy>>();
    protected static final ConcurrentMap<String, Timer> globalSqlStats =
            new ConcurrentHashMap<String, Timer>(); // TODO: use bounded LRU cache

    private static ThreadLocal<SocketStats> socketStatsAccumulator = new ThreadLocal<SocketStats>();

    protected Sniffy() {
    }

    static {<commit_msg>Use bounded LRU cache instead of unbounded ConcurrentHashMap for storing top SQL<commit_after>package io.sniffy;

import com.codahale.metrics.Timer;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import io.sniffy.configuration.SniffyConfiguration;
import io.sniffy.socket.SnifferSocketImplFactory;
import io.sniffy.socket.SocketMetaData;
import io.sniffy.socket.SocketStats;
import io.sniffy.sql.SqlStatement;
import io.sniffy.sql.SqlUtil;
import io.sniffy.sql.StatementMetaData;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.util.Iterator;
import java.util.Queue;
import java.util.concurrent.*;

import static io.sniffy.util.StackTraceExtractor.*;

/**
 * Sniffy allows you to validate the number of SQL queries executed by a given block of code
 * Example usage:
 * <pre>
 * <code>
 *     Connection connection = DriverManager.getConnection("sniffy:jdbc:h2:mem:", "sa", "sa");
 *     Spy{@literal <}?{@literal >} spy = Sniffy.spy();
 *     connection.createStatement().execute("SELECT 1 FROM DUAL");
 *     spy.verify(SqlQueries.atMostOneQuery());
 * </code>
 * </pre>
 * @since 3.1
 */
public class Sniffy {

    public static final int TOP_SQL_CAPACITY = 1024;

    protected static final Queue<WeakReference<Spy>> registeredSpies =
            new ConcurrentLinkedQueue<WeakReference<Spy>>();
    protected static final ConcurrentMap<Long, WeakReference<CurrentThreadSpy>> currentThreadSpies =
            new ConcurrentHashMap<Long, WeakReference<CurrentThreadSpy>>();
    protected static final ConcurrentLinkedHashMap<String, Timer> globalSqlStats =
            new ConcurrentLinkedHashMap.Builder<String, Timer>().
                    maximumWeightedCapacity(TOP_SQL_CAPACITY).
                    build();

    private static ThreadLocal<SocketStats> socketStatsAccumulator = new ThreadLocal<SocketStats>();

    protected Sniffy() {
    }

    static {
{'fraction_non_alphanumeric': 0.10933694181326116, 'fraction_numerical': 0.003247631935047361, 'mean_word_length': 4.566265060240964, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '3863058', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1084, 'n_words': 248}