Xidel:将属性解析为新对象
Xidel: Parse attributes into new object
给出的是来自任何 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]
}
]
显然不是我所期望的。
正确的想法是不将对象分配给变量(heap:={}
),而是直接在 xpath 中使用 json 表示法。第三,timestamp是tenured之上的一个级别,所以我把../
放在前面。
所以这个有效:
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
},
]
]
它提供了一个额外的数组,但我可以接受。至少它是一个稳定的输出和可解析的。
您实际上可以在提取表达式中写入整个 JSON 结构,不需要输出格式:
xidel --input-format=xml -e "[ //af/tenured[1]/{'used':(@totalbytes - @freebytes),'timestamp':../@timestamp} ]" gc.log
给出的是来自任何 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]
}
]
显然不是我所期望的。
正确的想法是不将对象分配给变量(heap:={}
),而是直接在 xpath 中使用 json 表示法。第三,timestamp是tenured之上的一个级别,所以我把../
放在前面。
所以这个有效:
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
},
]
]
它提供了一个额外的数组,但我可以接受。至少它是一个稳定的输出和可解析的。
您实际上可以在提取表达式中写入整个 JSON 结构,不需要输出格式:
xidel --input-format=xml -e "[ //af/tenured[1]/{'used':(@totalbytes - @freebytes),'timestamp':../@timestamp} ]" gc.log