给出的是来自任何Java虚拟机的详细GC日志(可以是任何xml,所以不使用java标记):
<?xml version="1.0" ?>
<verbosegc version="versioninformation">
<af type="nursery" id="49383" timestamp="Jan 01 01:34:54 2015" intervalms="33.821">
<tenured freebytes="769243504" totalbytes="1610416128" percent="47" >
<soa freebytes="198858272" totalbytes="805208064" percent="24" />
<loa freebytes="570385232" totalbytes="805208064" percent="70" />
</tenured>
<gc></gc>
<tenured freebytes="768800232" totalbytes="1610416128" percent="47" >
<soa freebytes="198415" totalbytes="805208064" percent="24" />
<loa freebytes="570385232" totalbytes="805208064" percent="70" />
</tenured>
</af>
<af type="nursery" id="49384" timestamp="Jan 01 01:35:54 2015" intervalms="40.877">
<tenured freebytes="768800232" totalbytes="1610416128" percent="47" >
<soa freebytes="198415" totalbytes="805208064" percent="24" />
<loa freebytes="570385232" totalbytes="805208064" percent="70" />
</tenured>
<gc></gc>
<tenured freebytes="768320928" totalbytes="1610416128" percent="47" >
<soa freebytes="197935696" totalbytes="805208064" percent="24" />
<loa freebytes="570385232" totalbytes="805208064" percent="70" />
</tenured>
</af>因此,我想创建一个新的对象,这个对象在每个垃圾回收循环中都会被重复使用时间戳和使用的字节(总计减去空闲)。计算工作正常,但输出不工作。这就是我想要得到的:
[
{
"timestamp": "Jan 01 01:34:54 2015",
"used": 8.41172624E8
},
{
"timestamp": "Jan 01 01:35:54 2015",
"used": 8.41615896E8
},
]我尝试了这个命令行,它不幸地创建了一个空时间戳和堆信息的长列表:
xidel --input-format=xml -e "//af/tenured[1]/(heap:={used:=(@totalbytes - @freebytes):timestamp:=@timestamp})" gc.log --output-format=json-wrapped输出如下所示:
[
{
"timestamp": [null],
"used": [8.41172624E8, 8.41615896E8]
}
]显然不是我切除的东西。
发布于 2015-08-18 22:26:14
实际上,您可以在提取表达式中编写整个JSON结构,并且不需要输出格式:
xidel --input-format=xml -e "[ //af/tenured[1]/{'used':(@totalbytes - @freebytes),'timestamp':../@timestamp} ]" gc.log 发布于 2015-08-18 07:42:50
正确的想法不是将对象赋值给变量(heap:={}),而是在xpath中直接使用json表示法。第三,时间戳是一个高于终身的水平,所以我把../放在前面。
所以这个方法很有效:
xidel --input-format=xml -e "//af/tenured[1]/('used':(@totalbytes - @freebytes),'timestamp':../@timestamp)" gc.log --output-format=json-wrapped输出:
[
[
{
"timestamp": "Jan 01 01:34:54 2015",
"used": 841172624.0
},
{
"timestamp": "Jan 01 01:35:54 2015",
"used": 841615896.0
},
]
]它提供了一个额外的数组,但我可以接受。至少这是一个稳定的输出和可解析的。
https://stackoverflow.com/questions/32050521
复制相似问题