2015-08-17 36 views
1

由於是從任何Java虛擬機中的詳細GC日誌(可以是任何XML,所以不能用java標記):Xidel:解析屬性新的目標

<?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> 

所以,我想創建一個新對象,每個垃圾回收週期都會重複使用時間戳和使用的字節(總計減去空閒)。計算工作得很好,但輸出沒有。這是我excpect獲得:

[ 
    { 
    "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:[email protected]})" gc.log --output-format=json-wrapped 

輸出看起來是這樣的:

[ 
    { 
    "timestamp": [null], 
    "used": [8.41172624E8, 8.41615896E8] 
    } 
] 

顯然不是我所指出的。

回答

1

實際上,你可以寫在提取表達整個JSON結構,不需要輸出格式:

xidel --input-format=xml -e "[ //af/tenured[1]/{'used':(@totalbytes - @freebytes),'timestamp':../@timestamp} ]" gc.log 
+0

這正是我一直在尋找!非常感謝你。如果你認爲這個問題很有用,我會很高興得到upvote。 :-) – Ben

0

正確的想法是不將對象分配給變量(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 
     }, 
    ] 
] 

它給出了一個額外的數組,但我可以忍受的。至少它是一個穩定的輸出和可解析的。