@Override protected int[] initialValue() { return new int[MethodMetrics.getPercentiles().length]; } };
private static MethodMetrics reviseStatistic(MethodMetrics methodMetrics) { int[] tpArr = methodMetrics.getTpArr(); for (int i = 1; i < tpArr.length; ++i) { int last = tpArr[i - 1]; int cur = tpArr[i]; if (cur <= -1) { tpArr[i] = last; } } return methodMetrics; }
public static MethodMetrics getInstance(MethodTag methodTag, long startMillTime, long stopMillTime) { MethodMetrics result = new MethodMetrics(methodTag); result.setStartMillTime(startMillTime); result.setStopMillTime(stopMillTime); return result; }
@Override public String toString() { return "MethodMetrics{" + "methodTag=" + methodTag + ", RPS=" + getRPS() + ", TP50=" + getTP50() + ", TP90=" + getTP90() + ", TP95=" + getTP95() + ", TP99=" + getTP99() + ", TP999=" + getTP999() + ", TP9999=" + getTP9999() + ", TP99999=" + getTP99999() + ", TP100=" + getTP100() + ", minTime=" + minTime + ", avgTime=" + avgTime + ", maxTime=" + maxTime + ", stdDev=" + stdDev + ", totalCount=" + totalCount + '}'; }
private String createLineProtocol(JvmThreadMetrics metrics, long startNanos, StringBuilder sb) { sb.append("jvm_thread_metrics") .append(",AppName=").append(ProfilingConfig.getInstance().getAppName()) .append(" TotalStarted=").append(metrics.getTotalStarted()).append("i") .append(",Active=").append(metrics.getActive()).append("i") .append(",Peak=").append(metrics.getPeak()).append("i") .append(",Daemon=").append(metrics.getDaemon()).append("i") .append(",New=").append(metrics.getNews()).append("i") .append(",Runnable=").append(metrics.getRunnable()).append("i") .append(",Blocked=").append(metrics.getBlocked()).append("i") .append(",Waiting=").append(metrics.getWaiting()).append("i") .append(",TimedWaiting=").append(metrics.getTimedWaiting()).append("i") .append(",Terminated=").append(metrics.getTerminated()).append("i") .append(" ").append(startNanos); return sb.toString(); } }
private String createLineProtocol(JvmMemoryMetrics metrics, long startNanos, StringBuilder sb) { sb.append("jvm_memory_metrics") .append(",AppName=").append(ProfilingConfig.getInstance().getAppName()) .append(" NonHeapInit=").append(metrics.getNonHeapInit()) .append(",NonHeapUsed=").append(metrics.getNonHeapUsed()) .append(",NonHeapCommitted=").append(metrics.getNonHeapCommitted()) .append(",NonHeapMax=").append(metrics.getNonHeapMax()) .append(",HeapInit=").append(metrics.getHeapInit()) .append(",HeapUsed=").append(metrics.getHeapUsed()) .append(",HeapCommitted=").append(metrics.getHeapCommitted()) .append(",HeapMax=").append(metrics.getHeapMax()) .append(" ").append(startNanos); return sb.toString(); } }
private void processJVMThreadMetrics(long processId, long startMillis, long stopMillis) { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); threadMetricsProcessor.beforeProcess(processId, startMillis, stopMillis); try { threadMetricsProcessor.process(new JvmThreadMetrics(threadMXBean), processId, startMillis, stopMillis); } finally { threadMetricsProcessor.afterProcess(processId, startMillis, stopMillis); } } }
private void processJVMGCMetrics(long processId, long startMillis, long stopMillis) { gcMetricsProcessor.beforeProcess(processId, startMillis, stopMillis); try { List<GarbageCollectorMXBean> garbageCollectorMxBeans = ManagementFactory.getGarbageCollectorMXBeans(); for (GarbageCollectorMXBean bean : garbageCollectorMxBeans) { JvmGCMetrics gcMetrics = new JvmGCMetrics(bean); gcMetricsProcessor.process(gcMetrics, processId, startMillis, stopMillis); } } finally { gcMetricsProcessor.afterProcess(processId, startMillis, stopMillis); } }
private void processJVMClassMetrics(long processId, long startMillis, long stopMillis) { JvmClassMetrics classMetrics = new JvmClassMetrics(ManagementFactory.getClassLoadingMXBean()); classMetricsProcessor.beforeProcess(processId, startMillis, stopMillis); try { classMetricsProcessor.process(classMetrics, processId, startMillis, stopMillis); } finally { classMetricsProcessor.afterProcess(processId, startMillis, stopMillis); } }
private void processJVMBufferPoolMetrics(long processId, long startMillis, long stopMillis) { bufferPoolMetricsProcessor.beforeProcess(processId, startMillis, stopMillis); try { List<BufferPoolMXBean> pools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class); for (BufferPoolMXBean mxBean : pools) { bufferPoolMetricsProcessor.process(new JvmBufferPoolMetrics(mxBean), processId, startMillis, stopMillis); } } finally { bufferPoolMetricsProcessor.afterProcess(processId, startMillis, stopMillis); } }
private void processJVMMemoryMetrics(long processId, long startMillis, long stopMillis) { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage nonHeapMem = memoryMXBean.getNonHeapMemoryUsage(); MemoryUsage heapMem = memoryMXBean.getHeapMemoryUsage(); memoryMetricsProcessor.beforeProcess(processId, startMillis, stopMillis); try { memoryMetricsProcessor.process(new JvmMemoryMetrics(nonHeapMem, heapMem), processId, startMillis, stopMillis); } finally { memoryMetricsProcessor.afterProcess(processId, startMillis, stopMillis); } }
private String createLineProtocol(JvmBufferPoolMetrics metrics, long startNanos, StringBuilder sb) { sb.append("jvm_buffer_pool_metrics") .append(",AppName=").append(ProfilingConfig.getInstance().getAppName()) .append(",PoolName=").append(metrics.getName()) .append(" Count=").append(metrics.getCount()).append("i") .append(",MemoryUsed=").append(metrics.getMemoryUsed()).append("i") .append(",MemoryCapacity=").append(metrics.getMemoryCapacity()).append("i") .append(" ").append(startNanos); return sb.toString(); } }
private String createLineProtocol(JvmClassMetrics metrics, long startNanos, StringBuilder sb) { sb.append("jvm_class_metrics") .append(",AppName=").append(ProfilingConfig.getInstance().getAppName()) .append(" Total=").append(metrics.getTotal()).append("i") .append(",Loaded=").append(metrics.getLoaded()).append("i") .append(",Unloaded=").append(metrics.getUnloaded()).append("i") .append(" ").append(startNanos); return sb.toString(); }
private String createLineProtocol(JvmGCMetrics metrics, long startNanos, StringBuilder sb) { String gcName = LineProtocolUtils.processTagOrField(metrics.getGcName()); sb.append("jvm_gc_metrics") .append(",AppName=").append(ProfilingConfig.getInstance().getAppName()) .append(",GCName=").append(gcName) .append(" CollectCount=").append(metrics.getCollectCount()).append("i") .append(",CollectTime=").append(metrics.getCollectTime()).append("i") .append(" ").append(startNanos); return sb.toString(); } }
/** * @param methodMetricsList * @return : int[0]:max(api.length) */ private int[] getStatistics(List<MethodMetrics> methodMetricsList) { int[] result = {1}; for (int i = 0; i < methodMetricsList.size(); ++i) { MethodMetrics stats = methodMetricsList.get(i); if (stats == null || stats.getMethodTag() == null) { continue; } result[0] = Math.max(result[0], stats.getMethodTag().getSimpleDesc().length()); } return result; }
public static MethodMetrics getInstance(MethodTag methodTag) { return new MethodMetrics(methodTag); }
/** * @param metricsList * @return : int[0]:max(api.length) */ private int[] getStatistics(List<JvmGCMetrics> metricsList) { int[] result = {1}; for (int i = 0; i < metricsList.size(); ++i) { JvmGCMetrics metrics = metricsList.get(i); if (metrics == null) { continue; } result[0] = Math.max(result[0], metrics.getGcName().length()); } return result; } }
public static MethodMetrics calPerfStats(Recorder recorder, MethodTag methodTag, long startTime, long stopTime) { int[] sortedRecords = null; try { int effectiveCount = recorder.getEffectiveCount(); sortedRecords = ChunkPool.getInstance().getChunk(effectiveCount * 2); recorder.fillSortedRecords(sortedRecords); return calPerfStats(methodTag, startTime, stopTime, sortedRecords, effectiveCount); } catch (Exception e) { Logger.error("MethodMetricsCalculator.calPerfStats(" + recorder + ", " + methodTag + ", " + startTime + ", " + stopTime + ")", e); } finally { ChunkPool.getInstance().returnChunk(sortedRecords); } return MethodMetrics.getInstance(methodTag, startTime, stopTime); }
private static int[] getTopPercentileIndexArr(int totalCount) { int[] result = threadLocalIntArr.get(); double[] percentiles = MethodMetrics.getPercentiles(); for (int i = 0; i < percentiles.length; ++i) { result[i] = getIndex(totalCount, percentiles[i]); } return result; }
private int getSuitSize(MethodMetrics methodMetrics) { MethodTag methodTag = methodMetrics.getMethodTag(); return methodTag.getClassName().length() + 8 + methodTag.getSimpleDesc().length()//Method + 5 + 6 + 1//RPS + 5 + 7 //Avg + 5 + 3 + 1//Min + 5 + 5 + 1//Max + 8 + 7//StdDev + 7 + 8 + 1//Count + 6 + 5 + 1//TP50 + 6 + 5 + 1//TP90 + 6 + 5 + 1//TP95 + 6 + 5 + 1//TP99 + 7 + 5 + 1//TP999 + 8 + 5 + 1//TP9999 + 9 + 5 + 1//TP99999 + 7 + 5 + 1//TP100 + 1 + 21//startNanos ; }