<commit_before>package crazypants.util;

import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import crazypants.enderio.EnderIO;
import crazypants.enderio.Log;

public class Profiler {

  public static final Profiler client = new Profiler();
  public static final Profiler server = client;

  private ConcurrentHashMap<String, Long> profiler = new ConcurrentHashMap<String, Long>();
  private ConcurrentHashMap<String, Long> profilerC = new ConcurrentHashMap<String, Long>();
  private long lastProfiled = 0;
  private boolean on = false;

  public long start() {
    on = /* info.loenwind.enderioaddons.config.Config.profilingEnabled.getBoolean() && */EnderIO.proxy.getTickCount() > 20 * 30;
    return on ? System.nanoTime() : Long.MAX_VALUE;
  }

  public long start_always() {
    on = true;
    return System.nanoTime();
  }

  public long pause(long start) {
    return on ? System.nanoTime() - start : Long.MAX_VALUE;
  }

  public long resume(long start) {
    return on ? System.nanoTime() - start : Long.MAX_VALUE;
  }

  public void stop(long start, String source) {
    long elapsed = on ? System.nanoTime() - start : -1;
    if (elapsed >= 0) {
      profiler.putIfAbsent(source, 0L);
      profilerC.putIfAbsent(source, 0L);
      profiler.put(source, profiler.get(source) + elapsed);
      profilerC.put(source, profilerC.get(source) + 1);
      if (EnderIO.proxy.getTickCount() > lastProfiled) {
        lastProfiled = EnderIO.proxy.getTickCount() + 200;
        for (Entry<String, Long> e : profiler.entrySet()) {
          long avg = e.getValue() / profilerC.get(e.getKey());
          Log.info(e.getKey() + ": " + avg + " ns avg over " + profilerC.get(e.getKey()) + " calls");
        }
      }
    }
  }

}<commit_msg>Better handling of thread-related crashes<commit_after>package crazypants.util;

import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;

import crazypants.enderio.EnderIO;
import crazypants.enderio.Log;

public class Profiler {

  public static final Profiler client = new Profiler();
  public static final Profiler server = client;

  private ConcurrentHashMap<String, Long> profiler = new ConcurrentHashMap<String, Long>();
  private ConcurrentHashMap<String, Long> profilerC = new ConcurrentHashMap<String, Long>();
  private long lastProfiled = 0;
  private boolean on = false;

  public long start() {
    on = /* info.loenwind.enderioaddons.config.Config.profilingEnabled.getBoolean() && */EnderIO.proxy.getTickCount() > 20 * 30;
    return on ? System.nanoTime() : Long.MAX_VALUE;
  }

  public long start_always() {
    on = true;
    return System.nanoTime();
  }

  public long pause(long start) {
    return on ? System.nanoTime() - start : Long.MAX_VALUE;
  }

  public long resume(long start) {
    return on ? System.nanoTime() - start : Long.MAX_VALUE;
  }

  public void stop(long start, String source) {
    long elapsed = on ? System.nanoTime() - start : -1;
    if (elapsed >= 0) {
      try {
        profiler.putIfAbsent(source, 0L);
        profilerC.putIfAbsent(source, 0L);
        profiler.put(source, profiler.get(source) + elapsed);
        profilerC.put(source, profilerC.get(source) + 1);
        if (EnderIO.proxy.getTickCount() > lastProfiled) {
          lastProfiled = EnderIO.proxy.getTickCount() + 200;
          for (Entry<String, Long> e : profiler.entrySet()) {
            long avg = e.getValue() / profilerC.get(e.getKey());
            Log.info(e.getKey() + ": " + avg + " ns avg over " + profilerC.get(e.getKey()) + " calls");
          }
        }
      } catch (Throwable t) {
        // NOP
      }
    }
  }

}
{'fraction_non_alphanumeric': 0.12895243332416828, 'fraction_numerical': 0.0071487489689304375, 'mean_word_length': 3.1720183486238533, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 19, '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': '6878051', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1203, 'n_words': 273}