How to check heap usage of a running JVM from the command line?

前端 未结 4 1296
忘了有多久
忘了有多久 2020-12-12 21:34

Can I check heap usage of a running JVM from the commandline, I mean the actual usage rather than the max amount allocated with Xmx.

I need it to be commandline beca

4条回答
  •  独厮守ぢ
    2020-12-12 21:54

    For Java 8 you can use the following command line to get the heap space utilization in kB:

    jstat -gc  | tail -n 1 | awk '{split($0,a," "); sum=a[3]+a[4]+a[6]+a[8]; print sum}'
    

    The command basically sums up:

    • S0U: Survivor space 0 utilization (kB).
    • S1U: Survivor space 1 utilization (kB).
    • EU: Eden space utilization (kB).
    • OU: Old space utilization (kB).

    You may also want to include the metaspace and the compressed class space utilization. In this case you have to add a[10] and a[12] to the awk sum.

提交回复
热议问题