private Map<String, Counter> buildAllCounters() { Map<String, Counter> result = new HashMap<>(512); for (Counter c : instr.getAllCounters()) { result.put(c.getName(), c); } return result; }
private PerfData(int pid) throws IOException { ByteBuffer bb = Perf.getPerf().attach(pid, "r"); instr = new PerfInstrumentation(bb); counters = buildAllCounters(); long hz = (Long) counters.get("sun.os.hrt.frequency").getValue(); nanosPerTick = ((double) TimeUnit.SECONDS.toNanos(1)) / hz; }
@Override protected void innerCollect(StatisticsSink sink) { for (Counter counter : hsRuntime.getInternalRuntimeCounters()) { String counterName = counter.getName(); if (counters.contains(counterName)) { counterName = counterName.substring("sun.rt._sync_".length()).toLowerCase(); Object value = counter.getValue(); sink.add(counterName, value.toString()); } } } }
@Override public Variability getVariability() { Variability v = VARIABILITY_MAP.get(counter.getVariability()); return v == null ? Variability.INVALID : v; }
@Override public Units getUnits() { Units u = UNIT_MAP.get(counter.getUnits()); return u == null ? Units.INVALID : u; }
import sun.management.ManagementFactoryHelper; import sun.management.counter.Counter; import java.util.NoSuchElementException; public class Test { public static void main(String[] args) { System.out.println(getContendedLockAttempts()); } private static long getContendedLockAttempts() { for (Counter counter : ManagementFactoryHelper.getHotspotRuntimeMBean().getInternalRuntimeCounters()) { if ("sun.rt._sync_ContendedLockAttempts".equals(counter.getName())) { return (long) counter.getValue(); } } throw new NoSuchElementException(); } }
vmArgs = (String) perfCounters.get("java.rt.vmArgs").getValue(); } else { vmArgs = Formats.join(jmxClient.getRuntimeMXBean().getInputArguments(), " ");
@Override public String getName() { return counter.getName(); }
@Override @SuppressWarnings("unchecked") public T getValue() { return (T) counter.getValue(); }
SynchronizationStatistics(HotspotRuntimeMBean hsRuntime) { super(SYNCLOCKS_HEADER); this.hsRuntime = hsRuntime; int countOfCounters = 0; for (Counter counter : hsRuntime.getInternalRuntimeCounters()) { String counterName = counter.getName(); if (this.counters.contains(counterName)) countOfCounters++; } if (countOfCounters == 0) throw new RuntimeException("No sync locks counters found"); }