使用分析GC日志
gc日志是一种结构化的日志 ,就是一种固定的格式,不同的gc,不同 的jdk版本生产的日志格式数据是不一样的,但是只要是同一个gc参数和同一个版本,gc日志是固定的。
所以以下的分析方法也适用于不同的gc日志格式数据。
awk背景知识
awk是一种文本文件分析工具,结合正则表达式、内置函数、分隔符、甚至内置的条件循环等语法,可以分析算杂的文本数据,远远超出日常作为列分析工具的范筹。
这里简单介绍一些简单的awk使用方法,以便进行gc日志的分析甚至数据统计等。
演示的文本文件为gc.log,内容如下:
2020-07-28T01:23:35.309+0800: [GC (Allocation Failure) [PSYoungGen: 65536K->1480K(76288K)] 65536K->1488K(251392K), 0.0048826 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:23:35.344+0800: [GC (Allocation Failure) [PSYoungGen: 67016K->1448K(141824K)] 67024K->1464K(316928K), 0.0038402 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:23:35.441+0800: [GC (Allocation Failure) [PSYoungGen: 132520K->1480K(141824K)] 132536K->1496K(316928K), 0.0046722 secs] [Times: user=0.13 sys=0.00, real=0.00 secs]
2020-07-28T01:23:35.482+0800: [GC (Allocation Failure) [PSYoungGen: 132552K->1416K(272896K)] 132568K->1432K(448000K), 0.0037451 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
- 基本用法
$ awk '{print $1}' gc.log
2020-07-28T01:23:35.309+0800:
2020-07-28T01:23:35.344+0800:
2020-07-28T01:23:35.441+0800:
2020-07-28T01:23:35.482+0800:
这里是常用的用法,就是对gc.log这个文件进行过滤:
其中,每一行只显示第一列,用"print $1",另外$0表示第一行的全部数据,$2、$3表示第2列,第3列数据
每一列使用空格作为分隔符,
- 分隔符
$ awk -F ":" '{print $1}' gc.log
2020-07-28T01
2020-07-28T01
2020-07-28T01
2020-07-28T01
这里与上面比较只是指定了分隔符,这里为":",
- 多显示
$ awk '{print $1","$2}' gc.log
2020-07-28T01:23:35.309+0800:,[GC
2020-07-28T01:23:35.344+0800:,[GC
2020-07-28T01:23:35.441+0800:,[GC
2020-07-28T01:23:35.482+0800:,[GC
显示第1列与第2列,同时用“,”来隔开,如果没有“,”时第一列与第二列之前相当于合并在一起。
- 条件语句
$ awk '{if(match($1, "482")){print $0}}' gc.log
2020-07-28T01:23:35.482+0800: [GC (Allocation Failure) [PSYoungGen: 132552K->1416K(272896K)] 132568K->1432K(448000K), 0.0037451 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
这里表示只显示第1列中包含482字符串的行,
这里可以使用类似c语言的if语句,match函数是内置函数,match($1,"482")表示第一列包含age
- 变量使用
$ awk 'BEGIN{count=0}{count++;}END{print "count="count}' gc.log
count=4
- 循环语句
$ awk '{
for(i=1;i1480K(76288K)]@@65536K->1488K(251392K),@@0.0048826@@secs]@@[Times:@@user=0.00@@sys=0.00,@@real=0.00@@
2020-07-28T01:23:35.344+0800:@@[GC@@(Allocation@@Failure)@@[PSYoungGen:@@67016K->1448K(141824K)]@@67024K->1464K(316928K),@@0.0038402@@secs]@@[Times:@@user=0.00@@sys=0.00,@@real=0.00@@
2020-07-28T01:23:35.441+0800:@@[GC@@(Allocation@@Failure)@@[PSYoungGen:@@132520K->1480K(141824K)]@@132536K->1496K(316928K),@@0.0046722@@secs]@@[Times:@@user=0.13@@sys=0.00,@@real=0.00@@
2020-07-28T01:23:35.482+0800:@@[GC@@(Allocation@@Failure)@@[PSYoungGen:@@132552K->1416K(272896K)]@@132568K->1432K(448000K),@@0.0037451@@secs]@@[Times:@@user=0.00@@sys=0.00,@@real=0.00@@
print有换行,printf不换行 , NF表示当前行的列数
分析GC日志
日志数据如下,保存为gc.log
2020-07-28T01:45:24.619+0800: 0.727: [GC (Allocation Failure) [PSYoungGen: 65536K->1496K(76288K)] 65536K->1504K(251392K), 0.0042882 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:24.653+0800: 0.763: [GC (Allocation Failure) [PSYoungGen: 67032K->1448K(76288K)] 67040K->1456K(251392K), 0.0042457 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2020-07-28T01:45:24.679+0800: 0.786: [GC (Allocation Failure) [PSYoungGen: 66984K->1432K(76288K)] 66992K->1440K(251392K), 0.0033243 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:24.701+0800: 0.808: [GC (Allocation Failure) [PSYoungGen: 66968K->1384K(141824K)] 66976K->1392K(316928K), 0.0035944 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:24.810+0800: 0.918: [GC (Allocation Failure) [PSYoungGen: 132456K->1400K(141824K)] 132464K->1408K(316928K), 0.0043860 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2020-07-28T01:45:24.852+0800: 0.959: [GC (Allocation Failure) [PSYoungGen: 132472K->1384K(263680K)] 132480K->1392K(438784K), 0.0035378 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:25.054+0800: 1.162: [GC (Allocation Failure) [PSYoungGen: 263528K->0K(263680K)] 263536K->1340K(438784K), 0.0055308 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2020-07-28T01:45:25.135+0800: 1.242: [GC (Allocation Failure) [PSYoungGen: 262144K->0K(526336K)] 263484K->1340K(701440K), 0.0009377 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:25.515+0800: 1.623: [GC (Allocation Failure) [PSYoungGen: 524288K->0K(526336K)] 525628K->1340K(701440K), 0.0030435 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:25.651+0800: 1.758: [GC (Allocation Failure) [PSYoungGen: 524288K->800K(840704K)] 525628K->2140K(1015808K), 0.0042685 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:26.178+0800: 2.285: [GC (Allocation Failure) [PSYoungGen: 839968K->0K(841216K)] 841308K->2004K(1016320K), 0.0072233 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2020-07-28T01:45:26.419+0800: 2.526: [GC (Allocation Failure) [PSYoungGen: 839168K->0K(1345536K)] 841172K->2004K(1520640K), 0.0008589 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:27.240+0800: 3.348: [GC (Allocation Failure) [PSYoungGen: 1342976K->768K(1345536K)] 1344980K->2772K(1520640K), 0.0044832 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:27.589+0800: 3.696: [GC (Allocation Failure) [PSYoungGen: 1343744K->608K(1385472K)] 1345748K->2836K(1560576K), 0.0042988 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:27.995+0800: 4.102: [GC (Allocation Failure) [PSYoungGen: 1384032K->288K(1385472K)] 1386260K->3044K(1560576K), 0.0041383 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:28.365+0800: 4.472: [GC (Allocation Failure) [PSYoungGen: 1383712K->0K(1386496K)] 1386468K->2932K(1561600K), 0.0024757 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:28.729+0800: 4.837: [GC (Allocation Failure) [PSYoungGen: 1384448K->768K(1386496K)] 1387380K->3700K(1561600K), 0.0046646 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:29.101+0800: 5.208: [GC (Allocation Failure) [PSYoungGen: 1385216K->0K(1386496K)] 1388148K->3604K(1561600K), 0.0047139 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:29.472+0800: 5.580: [GC (Allocation Failure) [PSYoungGen: 1384448K->0K(1386496K)] 1388052K->3604K(1561600K), 0.0011109 secs] [Times: user=0.03 sys=0.00, real=0.00 secs]
2020-07-28T01:45:29.836+0800: 5.944: [GC (Allocation Failure) [PSYoungGen: 1384448K->768K(1386496K)] 1388052K->4372K(1561600K), 0.0045448 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2020-07-28T01:45:30.207+0800: 6.315: [GC (Allocation Failure) [PSYoungGen: 1385216K->0K(1386496K)] 1388820K->4276K(1561600K), 0.0046372 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:30.584+0800: 6.691: [GC (Allocation Failure) [PSYoungGen: 1384448K->288K(1318912K)] 1388724K->4564K(1494016K), 0.0022933 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:30.944+0800: 7.051: [GC (Allocation Failure) [PSYoungGen: 1318688K->640K(1257984K)] 1322964K->5140K(1433088K), 0.0036924 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:31.284+0800: 7.391: [GC (Allocation Failure) [PSYoungGen: 1256576K->0K(1197056K)] 1261076K->4988K(1372160K), 0.0034112 secs] [Times: user=0.13 sys=0.00, real=0.00 secs]
2020-07-28T01:45:31.596+0800: 7.703: [GC (Allocation Failure) [PSYoungGen: 1196544K->544K(1383936K)] 1201532K->5532K(1559040K), 0.0038690 secs] [Times: user=0.13 sys=0.00, real=0.00 secs]
2020-07-28T01:45:31.970+0800: 8.078: [GC (Allocation Failure) [PSYoungGen: 1382944K->320K(1387008K)] 1387932K->5788K(1562112K), 0.0045615 secs] [Times: user=0.11 sys=0.02, real=0.00 secs]
2020-07-28T01:45:32.340+0800: 8.447: [GC (Allocation Failure) [PSYoungGen: 1385792K->0K(1319936K)] 1391260K->5692K(1495040K), 0.0021098 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:32.686+0800: 8.794: [GC (Allocation Failure) [PSYoungGen: 1319424K->800K(1257984K)] 1325116K->6492K(1433088K), 0.0042386 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:33.031+0800: 9.138: [GC (Allocation Failure) [PSYoungGen: 1257760K->0K(1385472K)] 1263452K->6364K(1560576K), 0.0046622 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
2020-07-28T01:45:33.400+0800: 9.508: [GC (Allocation Failure) [PSYoungGen: 1383936K->0K(1318400K)] 1390300K->6364K(1493504K), 0.0014439 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:33.754+0800: 9.862: [GC (Allocation Failure) [PSYoungGen: 1317888K->832K(1256960K)] 1324252K->7196K(1432064K), 0.0042319 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:34.086+0800: 10.194: [GC (Allocation Failure) [PSYoungGen: 1256256K->0K(1385984K)] 1262620K->7036K(1561088K), 0.0044440 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2020-07-28T01:45:34.456+0800: 10.564: [GC (Allocation Failure) [PSYoungGen: 1384448K->0K(1318912K)] 1391484K->7036K(1494016K), 0.0008067 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]
2020-07-28T01:45:34.802+0800: 10.910: [GC (Allocation Failure) [PSYoungGen: 1318400K->800K(1256960K)] 1325436K->7836K(1432064K), 0.0047808 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:35.142+0800: 11.249: [GC (Allocation Failure) [PSYoungGen: 1256736K->0K(1384448K)] 1263772K->7708K(1559552K), 0.0040559 secs] [Times: user=0.13 sys=0.00, real=0.00 secs]
2020-07-28T01:45:35.515+0800: 11.622: [GC (Allocation Failure) [PSYoungGen: 1382912K->0K(1317888K)] 1390620K->7708K(1492992K), 0.0010345 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:35.867+0800: 11.975: [GC (Allocation Failure) [PSYoungGen: 1317376K->768K(1256448K)] 1325084K->8476K(1431552K), 0.0034270 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:36.210+0800: 12.318: [GC (Allocation Failure) [PSYoungGen: 1255680K->0K(1196032K)] 1263388K->8380K(1371136K), 0.0039587 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:36.533+0800: 12.641: [GC (Allocation Failure) [PSYoungGen: 1195520K->0K(1140736K)] 1203900K->8380K(1315840K), 0.0010645 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:36.841+0800: 12.949: [GC (Allocation Failure) [PSYoungGen: 1139200K->800K(1086464K)] 1147580K->9180K(1261568K), 0.0036930 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:37.153+0800: 13.261: [GC (Allocation Failure) [PSYoungGen: 1086240K->0K(1325056K)] 1094620K->9052K(1500160K), 0.0047955 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:37.508+0800: 13.615: [GC (Allocation Failure) [PSYoungGen: 1324544K->0K(1262080K)] 1333596K->9052K(1437184K), 0.0010161 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:37.897+0800: 14.004: [GC (Allocation Failure) [PSYoungGen: 1261568K->832K(1203200K)] 1270620K->9884K(1378304K), 0.0038449 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:38.240+0800: 14.347: [GC (Allocation Failure) [PSYoungGen: 1202496K->0K(1145344K)] 1211548K->9740K(1320448K), 0.0048670 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:38.559+0800: 14.666: [GC (Allocation Failure) [PSYoungGen: 1144832K->0K(1092608K)] 1154572K->9740K(1267712K), 0.0012054 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:38.859+0800: 14.966: [GC (Allocation Failure) [PSYoungGen: 1091072K->672K(1040896K)] 1100812K->10412K(1216000K), 0.0035737 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:39.146+0800: 15.253: [GC (Allocation Failure) [PSYoungGen: 1040544K->0K(1269248K)] 1050284K->10412K(1444352K), 0.0078338 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2020-07-28T01:45:39.504+0800: 15.611: [GC (Allocation Failure) [PSYoungGen: 1268736K->0K(1380864K)] 1279148K->10412K(1555968K), 0.0025550 secs] [Times: user=0.03 sys=0.00, real=0.00 secs]
2020-07-28T01:45:39.902+0800: 16.010: [GC (Allocation Failure) [PSYoungGen: 1379328K->736K(1380864K)] 1389740K->11148K(1555968K), 0.0036041 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:40.282+0800: 16.389: [GC (Allocation Failure) [PSYoungGen: 1380064K->0K(1387008K)] 1390476K->11084K(1562112K), 0.0047973 secs] [Times: user=0.13 sys=0.00, real=0.00 secs]
2020-07-28T01:45:40.676+0800: 16.783: [GC (Allocation Failure) [PSYoungGen: 1385472K->768K(1387008K)] 1396556K->11852K(1562112K), 0.0044042 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
2020-07-28T01:45:41.051+0800: 17.158: [GC (Allocation Failure) [PSYoungGen: 1386240K->0K(1387008K)] 1397324K->11756K(1562112K), 0.0042475 secs] [Times: user=0.13 sys=0.00, real=0.00 secs]
2020-07-28T01:45:41.428+0800: 17.535: [GC (Allocation Failure) [PSYoungGen: 1385472K->0K(1319936K)] 1397228K->11756K(1495040K), 0.0007525 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:41.792+0800: 17.899: [GC (Allocation Failure) [PSYoungGen: 1319424K->768K(1257984K)] 1331180K->12524K(1433088K), 0.0044829 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:42.171+0800: 18.279: [GC (Allocation Failure) [PSYoungGen: 1257728K->0K(1385472K)] 1269484K->12444K(1560576K), 0.0047608 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
2020-07-28T01:45:42.563+0800: 18.675: [GC (Allocation Failure) [PSYoungGen: 1383936K->0K(1318400K)] 1396380K->12444K(1493504K), 0.0007516 secs] [Times: user=0.02 sys=0.00, real=0.01 secs]
2020-07-28T01:45:42.914+0800: 19.021: [GC (Allocation Failure) [PSYoungGen: 1317888K->768K(1256960K)] 1330332K->13212K(1432064K), 0.0042181 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:43.256+0800: 19.363: [GC (Allocation Failure) [PSYoungGen: 1256192K->0K(1196544K)] 1268636K->13116K(1371648K), 0.0042273 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:43.577+0800: 19.684: [GC (Allocation Failure) [PSYoungGen: 1196032K->0K(1141248K)] 1209148K->13116K(1316352K), 0.0010647 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:43.885+0800: 19.993: [GC (Allocation Failure) [PSYoungGen: 1139712K->800K(1086976K)] 1152828K->13916K(1262080K), 0.0044039 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2020-07-28T01:45:44.182+0800: 20.289: [GC (Allocation Failure) [PSYoungGen: 1086752K->0K(1304064K)] 1099868K->13796K(1479168K), 0.0047595 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
2020-07-28T01:45:44.542+0800: 20.650: [GC (Allocation Failure) [PSYoungGen: 1303552K->0K(1242112K)] 1317348K->13796K(1417216K), 0.0014079 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:44.885+0800: 20.993: [GC (Allocation Failure) [PSYoungGen: 1241600K->768K(1184256K)] 1255396K->14564K(1359360K), 0.0039656 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:45.224+0800: 21.332: [GC (Allocation Failure) [PSYoungGen: 1183488K->0K(1127424K)] 1197284K->14468K(1302528K), 0.0035375 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:45.540+0800: 21.647: [GC (Allocation Failure) [PSYoungGen: 1126912K->0K(1075200K)] 1141380K->14468K(1250304K), 0.0012474 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2020-07-28T01:45:45.845+0800: 21.952: [GC (Allocation Failure) [PSYoungGen: 1073664K->768K(1024512K)] 1088132K->15236K(1199616K), 0.0038977 secs] [Times: user=0.03 sys=0.03, real=0.00 secs]
- 统计gc时间间隔(分布)
其中第二列就是时间,所以主要求出两行之差就可以算出,直接写代码
awk '{print $2}' gc.txt |
awk -F ":" '{print $1}'|
awk 'BEGIN{temp=0;count=0}{
if(count != 0){
diff = $1 - temp;
print diff
}
temp = $1
count++;
}'
结果如下:
0.036
0.023
0.022
0.11
0.041
0.203
0.08
0.381
0.135
0.527
0.241
0.822
0.348
0.406
0.37
0.365
0.371
0.372
0.364
...
这样就可以得到gc的两次gc的间隔了,然后再统计gc的间隔分布就容易了,就可以分析出gc的频繁,为gc调优做准备
- 求每次gc的晋升量(晋升速度、分布)
晋升量就是younggc后老年代的变化量
awk '{
if(match($0, "PSYoungGen")){
print $7","$8
}
}' gc.txt|
awk -F "->" '{print $1","$2","$3}'|
awk -F "K[(]" '{print $1","$2","$3}'|
awk -F "K[)]]" '{print $1$2}'|
awk -F "K[)]" '{print $1}'|
awk -F "K" '{print $1$2$3}'|
awk -F "," '{
temp =$5 - $2;
print temp;
}'|
awk 'BEGIN{temp=0;count=0}{
if(count != 0){
diff = $1 - temp;
print diff
}
temp = $1
count++;
}'
结果如下:
0
0
0
0
0
1332
0
0
0
664
0
0
224
528
176
0
672
0
0
672
0
224
488
0
480
224
0
...
- 求每次gc的时间(gc时间的分布等)
awk '{
if(match($0, "PSYoungGen")){
print $7","$8$9
}
}' gc.txt|
awk -F "->" '{print $1","$2","$3}'|
awk -F "K[(]" '{print $1","$2","$3}'|
awk -F "K[)]]" '{print $1$2}'|
awk -F "K[)]" '{print $1$2}'|
awk -F "K" '{print $1$2$3}'|
awk -F "," '{print $6}'
结果如下:
0.0042882
0.0042457
0.0033243
0.0035944
0.0043860
0.0035378
0.0055308
0.0009377
0.0030435
0.0042685
0.0072233
0.0008589
0.0044832
0.0042988
0.0041383
0.0024757
这里再弄细一点,时间分布:0ms - 200ms,步长为10ms
awk '{
if(match($0, "PSYoungGen")){
print $7","$8$9
}
}' gc.txt|
awk -F "->" '{print $1","$2","$3}'|
awk -F "K[(]" '{print $1","$2","$3}'|
awk -F "K[)]]" '{print $1$2}'|
awk -F "K[)]" '{print $1$2}'|
awk -F "K" '{print $1$2$3}'|
awk -F "," '{print $7}'|
awk 'BEGIN{
count[0]=0;
for(i=0;i<21;i++){
count[i]=0;
}
total=0;
}{
for(i=0;i<21;i++){
if($1*1000 < (i+1)*10){
count[i]++;
break;
}
if(i >=20){
count[20]++;
}
}
total++;
}END{
for(i=0;i<21;i++){
if(i != 20){
print (i*10)"ms~"((i+1)*10)"ms:"(count[i]/total*100.0)"%"
}else{
print (i*10)"ms+:"(count[i]/total*100.0)"%"
}
}
}'
结果如下:
0ms~10ms:100%
10ms~20ms:0%
20ms~30ms:0%
30ms~40ms:0%
40ms~50ms:0%
50ms~60ms:0%
60ms~70ms:0%
70ms~80ms:0%
80ms~90ms:0%
90ms~100ms:0%
100ms~110ms:0%
110ms~120ms:0%
120ms~130ms:0%
130ms~140ms:0%
140ms~150ms:0%
150ms~160ms:0%
160ms~170ms:0%
170ms~180ms:0%
180ms~190ms:0%
190ms~200ms:0%
200ms+:0%
总结
当然还有很的信息可以挖掘,
对调参、优化程序的性能状态提供比较好的统计数据,同时结合其他一些日志或者jvm信息,甚至可以直接优化代码。