Пример #1
0
  @Override
  public void sampleAllocation(int count, String name, Object instance, long sizeBytes) {
    if (count != -1) {
      AtomicLongMap<Integer> lengths = arrayLengths.get(name);
      if (lengths != null) lengths.getAndIncrement(count);
    }

    Long threshold = trackSources.get(name);
    Long now = totalBytes.addAndGet(name, sizeBytes);

    if (threshold != null) {
      // if this whole lookup/check/put could be made atomic, that'd be awesome
      if (now - threshold >= lastSampledSize.get(name)) {
        lastSampledSize.put(name, now);
        // eek, object creation getting the trace
        StackTraceElement[] trace = AllocationEfficientStacktrace.stack(2, 50);
        traces.get(name).offer(trace);
      }
    }
  }