@Override public long getOldGcCpu() { return gc1 == null ? 0 : gc1.getNanos(); } }
@Override public long getSafePointCount() { return safePointCount == null ? 0 : safePointCount.getLong(); }
public PerfCounterSafePointMonitor(long pid) { JStatData jd = JStatData.connect(pid); safePointCount = (LongCounter) jd.getAllCounters().get("sun.rt.safepoints"); safePointTime = (TickCounter) jd.getAllCounters().get("sun.rt.safepointTime"); safePointSyncTime = (TickCounter) jd.getAllCounters().get("sun.rt.safepointSyncTime"); }
LongCounter youngGcCnt = null; try { JStatData jsd = JStatData.connect(pid); youngGcCnt = (LongCounter) jsd.getAllCounters().get("sun.gc.collector.0.invocations"); ygc = youngGcCnt == null ? 0 : youngGcCnt.getLong(); if (ygc != youngGcCnt.getLong()) { System.out.println("Warning: one or more young collections have occured during sampling."); System.out.println("Use --sample-depth option to reduce time to sample if needed.");
public static void main(String[] args) { JStatData jStatData = JStatData.connect(SigarUtil.getCurrentProcessId()); System.out.println(jStatData.getAllCounters().get("sun.gc.collector.0.name").getValue()); System.out.println(jStatData.getAllCounters().get("sun.gc.collector.1.name").getValue()); } }
void emit(ServiceEmitter emitter, Map<String, String[]> dimensions) { final ServiceMetricEvent.Builder builder = builder(); MonitorUtils.addDimensionsToBuilder(builder, dimensions); long newInvocations = invocationsCounter.getLong(); emitter.emit(builder.build("jvm/gc/count", newInvocations - lastInvocations)); lastInvocations = newInvocations; long newCpuNanos = cpuCounter.getNanos(); emitter.emit(builder.build("jvm/gc/cpu", newCpuNanos - lastCpuNanos)); lastCpuNanos = newCpuNanos; }
GcGenerationCollector(Map<String, JStatData.Counter<?>> jStatCounters, long genIndex) { String collectorKeyPrefix = StringUtils.format("sun.gc.collector.%d", genIndex); String nameKey = StringUtils.format("%s.name", collectorKeyPrefix); StringCounter nameCounter = (StringCounter) jStatCounters.get(nameKey); name = getReadableName(nameCounter.getString()); invocationsCounter = (LongCounter) jStatCounters.get(StringUtils.format("%s.invocations", collectorKeyPrefix)); cpuCounter = (TickCounter) jStatCounters.get(StringUtils.format("%s.time", collectorKeyPrefix)); }
@Override public long getNanos() { return (long)(tick * getLong()); } }
public PerfCounterGcCpuUsageMonitor(long pid) { JStatData jd = JStatData.connect(pid); gc0 = (TickCounter) jd.getAllCounters().get("sun.gc.collector.0.time"); gc1 = (TickCounter) jd.getAllCounters().get("sun.gc.collector.1.time"); }
LongCounter youngGcCnt = null; try { JStatData jsd = JStatData.connect(pid); youngGcCnt = (LongCounter) jsd.getAllCounters().get("sun.gc.collector.0.invocations"); ygc = youngGcCnt == null ? 0 : youngGcCnt.getLong(); if (ygc != youngGcCnt.getLong()) { System.out.println("Warning: one or more young collections have occured during sampling."); System.out.println("Use --sample-depth option to reduce time to sample if needed.");
@Override public long getYoungGcCpu() { return gc0 == null ? 0 : gc0.getNanos(); }
void emit(ServiceEmitter emitter, Map<String, String[]> dimensions) { final ServiceMetricEvent.Builder builder = builder(); MonitorUtils.addDimensionsToBuilder(builder, dimensions); builder.setDimension("gcGenSpaceName", name); emitter.emit(builder.build("jvm/gc/mem/max", maxCounter.getLong())); emitter.emit(builder.build("jvm/gc/mem/capacity", capacityCounter.getLong())); emitter.emit(builder.build("jvm/gc/mem/used", usedCounter.getLong())); emitter.emit(builder.build("jvm/gc/mem/init", initCounter.getLong())); } }
GcCounters() { // connect to itself final JStatData jStatData = JStatData.connect(pid); final Map<String, JStatData.Counter<?>> jStatCounters = jStatData.getAllCounters(); generations.add(new GcGeneration(jStatCounters, 0, "young")); generations.add(new GcGeneration(jStatCounters, 1, "old")); // Removed in Java 8 but still actual for previous Java versions if (jStatCounters.containsKey("sun.gc.generation.2.name")) { generations.add(new GcGeneration(jStatCounters, 2, "perm")); } }
@Override public long getSafePointTime() { return safePointTime == null ? 0 : safePointTime.getNanos(); }
GcGeneration(Map<String, JStatData.Counter<?>> jStatCounters, long genIndex, String name) { this.name = StringUtils.toLowerCase(name); long spacesCount = ((JStatData.LongCounter) jStatCounters.get( StringUtils.format("sun.gc.generation.%d.spaces", genIndex) )).getLong(); for (long spaceIndex = 0; spaceIndex < spacesCount; spaceIndex++) { spaces.add(new GcGenerationSpace(jStatCounters, genIndex, spaceIndex)); } if (jStatCounters.containsKey(StringUtils.format("sun.gc.collector.%d.name", genIndex))) { collector = new GcGenerationCollector(jStatCounters, genIndex); } else { collector = null; } }
@Override public void run() { if (!(dumpVmFlags | dumpSysProps | dumpAgentProps | dumpPerfCounters)) { host.failAndPrintUsage("No dump option specified"); } JavaProcessDetails jpd = AttachManager.getDetails(Long.parseLong(pid)); if (dumpVmFlags) { System.out.println(jpd.getVmFlag(null)); } if (dumpSysProps) { dumpProps(jpd.getSystemProperties()); } if (dumpAgentProps) { dumpProps(jpd.getAgentProperties()); } if (dumpPerfCounters) { JStatData jsd = JStatData.connect(Long.parseLong(pid)); dumpPerf(jsd.getAllCounters()); } }
@Override public long getSafePointSyncTime() { return safePointSyncTime == null ? 0 : safePointSyncTime.getNanos(); } }
private void dumpPerf(Map<String, Counter<?>> allCounters) { for(String key: allCounters.keySet()) { Counter<?> c = allCounters.get(key); if (c instanceof TickCounter) { String val = c.toString(); String suffix = ""; if (val.lastIndexOf('[') >= 0) { suffix = " " + val.substring(val.lastIndexOf('[')); } System.out.println(key + ": " + ((TickCounter)c).getNanos() + " ns" + suffix); } else { System.out.println(allCounters.get(key)); } } }
@Override public long getSafePointSyncTime() { return safePointSyncTime == null ? 0 : safePointSyncTime.getNanos(); } }
@Override public long getYoungGcCpu() { return gc0 == null ? 0 : gc0.getNanos(); }