侧边栏壁纸
  • 累计撰写 1,975 篇文章
  • 累计创建 73 个标签
  • 累计收到 20 条评论

目 录CONTENT

文章目录

JVisualVM监控面板基础使用--Jvm调优(三)

猿哥
2022-04-07 / 0 评论 / 0 点赞 / 778 阅读 / 0 字

JvisualVM启动之后即可以监控本地的java进程,是不需要配置参数的,直接打开就能够进行监控。首先我们需要在本地打开一个Java程序,例如我打开IDEA,这时在jvisualvm界面就可以看到与IDEA相关的Java进程了。

1、概况

点击一个进程,就可以看到该进程的概述信息,该进程的JVM参数以及系统属性等信息都能够查看到。

image

2、监视

点击 “监视” 就能够看到CPU、内存、类以及线程的活动状况,点击右上角的 “堆Dump” 就能够导出内存映像文件。

image

打开一段时间以后,我们可以看到内存使用量出现了波峰曲线,只要曲线出现了下降就表明经过了一次 GC,也就是 JVM 执行了垃圾回收。

可以注意到,内存面板其实相当于是 jstat -gc 或 jstat -gcutil 命令的图形化展示,它们的本质是一样的,都是通过采样的方式拿到JVM各个内存池的数据进行统计,并展示出来。其实图形界面存在一个问题,如果 GC 特别频繁,每秒钟执行了很多次 GC,实际上图表方式就很难反应出每一次的变化信息。

3、线程

点击 “线程” 就能够看到该进程内部的所有线程,以及线程的运行状况等信息。

如果点击右上角的 “线程Dump” 就会导出一个内容与jstack打印内容一致的文件。

image

4、抽样器

抽样,可以配合我们在性能压测的时候,看压测过程中,各个线程发生了什么、或者是分配了多少内存,每个类直接占用了多少内存等等。

点击 “抽样器--CPU ” 就可以动态的看到每个方法的执行时间,当我们的代码执行的比较慢了,就可以通过抽样器来查看是哪一个方法执行的比较慢。

image

而点击 “抽样器--内存” 的话,就可以实时的、动态的查看到每个类实例对象的数量以及这些实例所占用的内存大小。

image

5、分析器

使用 Profiler 时,需要先校准分析器, 然后可以像抽样器一样使用了。

在Profiler界面上,可以对CPU、内存进行性能分析,分析后会给出分析结果:

image

抽样器和分析器的区别,截取一段英文回答:

In general:

A profiler is running all the time, so it gives you the complete call stack; at any given point in time.

A sampler only takes "snapshots" at distinct point in times.

Thing is: when you "profile" everything, then that slows down your JVM significantly; and it creates *enormous** amounts of data within a few seconds. Think about: the profiler will write down *each and any* method invocation that takes place!*

So typically, you initially use a sampler, when you have "no idea" what is going on within your application. And then you just hope that the samples tell you something; like "hey, within our 10 000 samples, we are in that one method most of the time, why is that?" But as soon as you have a better understanding what you are "hunting" for, you would try to do a full profiler run in order to capture the whole call chain that leads into some method.

And then there is some "middle ground" - where you profile "everything" but exclude things. In other words: most profilers allow you to say "do *not** profile methods in classes in this or that package". But of course - excluding packages/hierarchies only makes sense when you already have a pretty good feeling which direction you intend to investigate。*

基本上就是sampler比profiler花费较少的时间计算每个方法的消耗,但是sampler没有profiler准确,通常情况下sampler就够用了。

0
博主关闭了所有页面的评论