java 8 内存分析,工具ps, jstat, jcmd,pmap

释放双眼,带上耳机,听听看~!

查看jvm进程id


1
2
3
4
5
6
7
8
9
1[yeqiang@localhost ~]$ jps
28353 Launcher
313301 Jps
48581 Main
57528 RemoteMavenServer
68363 App
74301 Main
8
9

查看操作系统内存占用


1
2
3
4
1[yeqiang@localhost ~]$ ps aux | egrep "MEM|8363"
2USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
3yeqiang   8363  2.3  2.8 4121404 473348 pts/0  Sl   10:10   1:41 /usr/local/jdk1.8.0_161/bin/java -Xmx400m -javaagent:/home/yeqiang/program/idea-IC-171.4694.70/lib/idea_rt.jar=43137:/home/yeqiang/program/idea-IC-171.4694.70/bin -Dfile.encoding=UTF-8
4

内存使用状态快速求和方法


1
2
3
4
1[yeqiang@localhost ~]$ jstat -gc 8363| grep -v S0C | awk '{s=$3+$4+$6+$8+$10+$12} END {print s}'
2203272
3
4

堆内存(S0U+S1U+EU+OU)+元数据内存(MU)+已编译class占用内存(CSSU)
共203272KB 大约200MB

 

jstat 查看堆,元数据,编译class内存占用情况:

 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
1[yeqiang@localhost ~]$ jstat -gc 8363
2    S0C    S1C    S0U    S1U      EC       EU        OC         OU       MC     MU    CCSC   CCSU   YGC     YGCT    FGC    FGCT     GCT  
3   35328.0 36352.0  0.0   1504.0 63488.0  56313.1   273408.0   39001.0   121176.0 118360.5 10840.0 10150.4     31    0.327   8      0.520    0.848
4
5
6   [yeqiang@localhost ~]$ man jstat
7   -gc option
8          Garbage-collected heap statistics.
9
10         S0C: Current survivor space 0 capacity (kB).
11
12         S1C: Current survivor space 1 capacity (kB).
13
14         S0U: Survivor space 0 utilization (kB).
15
16         S1U: Survivor space 1 utilization (kB).
17
18         EC: Current eden space capacity (kB).
19
20         EU: Eden space utilization (kB).
21
22         OC: Current old space capacity (kB).
23
24         OU: Old space utilization (kB).
25
26         MC: Metaspace capacity (kB).
27
28         MU: Metacspace utilization (kB).
29
30         CCSC: Compressed class space capacity (kB).
31
32         CCSU: Compressed class space used (kB).
33
34         YGC: Number of young generation garbage collection events.
35
36         YGCT: Young generation garbage collection time.
37
38         FGC: Number of full GC events.
39
40         FGCT: Full garbage collection time.
41
42         GCT: Total garbage collection time.
43

 

jvm 内存相关内存参数


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
1-Xmnsize
2           Sets the initial and maximum size (in bytes) of the heap for the young generation (nursery). Append the letter k or K to indicate kilobytes, m or M to indicate megabytes, g or G to indicate
3           gigabytes.
4
5           The young generation region of the heap is used for new objects. GC is performed in this region more often than in other regions. If the size for the young generation is too small, then a lot of
6           minor garbage collections will be performed. If the size is too large, then only full garbage collections will be performed, which can take a long time to complete. Oracle recommends that you
7           keep the size for the young generation between a half and a quarter of the overall heap size.
8
9-Xmssize
10           Sets the initial size (in bytes) of the heap. This value must be a
11           multiple of 1024 and greater than 1 MB. Append the letter k or K to
12           indicate kilobytes, m or M to indicate megabytes, g or G to
13           indicate gigabytes.
14-Xmxsize
15           Specifies the maximum size (in bytes) of the memory allocation pool
16           in bytes. This value must be a multiple of 1024 and greater than 2
17           MB. Append the letter k or K to indicate kilobytes, m or M to
18           indicate megabytes, g or G to indicate gigabytes. The default value
19           is chosen at runtime based on system configuration. For server
20           deployments, -Xms and -Xmx are often set to the same value. See the
21           section "Ergonomics" in Java SE HotSpot Virtual Machine Garbage
22           Collection Tuning Guide at
23           http://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/index.html.
24
25
26-XX:+PrintGC
27           Enables printing of messages at every GC. By default, this option is disabled.
28
29-XX:+PrintGCDetails
30           Enables printing of detailed messages at every GC. By default, this option is disabled.
31
32-XX:NativeMemoryTracking=mode
33           Specifies the mode for tracking JVM native memory usage. Possible mode arguments for this option include the following:
34
35           off
36               Do not track JVM native memory usage. This is the default behavior if you do not specify the -XX:NativeMemoryTracking option.
37
38           summary
39               Only track memory usage by JVM subsystems, such as Java heap, class, code, and thread.
40
41           detail
42               In addition to tracking memory usage by JVM subsystems, track memory usage by individual CallSite, individual virtual memory region and its committed regions.
43
44-XX:NativeMemoryTracking=detail -XX:+PrintGC -XX:+PrintGCDetails -Xmn100m -Xms200m -Xmx200m
45

 

jcmd


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
1[yeqiang@localhost webapp2]$ jcmd 17108 VM.native_memory
217108:
3
4Native Memory Tracking:
5
6Total: reserved=2589996KB, committed=1291028KB
7-                 Java Heap (reserved=204800KB, committed=204800KB)
8                            (mmap: reserved=204800KB, committed=204800KB)
9
10-                     Class (reserved=1062080KB, committed=10176KB)
11                            (classes #532)
12                            (malloc=5312KB #1296)
13                            (mmap: reserved=1056768KB, committed=4864KB)
14
15-                    Thread (reserved=1048963KB, committed=1048963KB)
16                            (thread #1017)
17                            (stack: reserved=1044408KB, committed=1044408KB)
18                            (malloc=3363KB #5086)
19                            (arena=1192KB #2033)
20
21-                      Code (reserved=249712KB, committed=2648KB)
22                            (malloc=112KB #451)
23                            (mmap: reserved=249600KB, committed=2536KB)
24
25-                        GC (reserved=13191KB, committed=13191KB)
26                            (malloc=5771KB #119)
27                            (mmap: reserved=7420KB, committed=7420KB)
28
29-                  Compiler (reserved=133KB, committed=133KB)
30                            (malloc=2KB #29)
31                            (arena=131KB #3)
32
33-                  Internal (reserved=8809KB, committed=8809KB)
34                            (malloc=8777KB #13536)
35                            (mmap: reserved=32KB, committed=32KB)
36
37-                    Symbol (reserved=1512KB, committed=1512KB)
38                            (malloc=961KB #178)
39                            (arena=552KB #1)
40
41-    Native Memory Tracking (reserved=590KB, committed=590KB)
42                            (malloc=194KB #2585)
43                            (tracking overhead=396KB)
44
45-               Arena Chunk (reserved=206KB, committed=206KB)
46                            (malloc=206KB)
47

 

给TA打赏
共{{data.count}}人
人已打赏
安全技术

bootstrap栅格系统自定义列

2021-12-21 16:36:11

安全技术

从零搭建自己的SpringBoot后台框架(二十三)

2022-1-12 12:36:11

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索