通过 jvisualvm dump文件 oql 查看springboot加载的数据库连接参数

首先贴出application.properties的内容
在这里插入图片描述

如果想要查看这些参数在jvm加载的值是什么。可以通过 jvisualvm 的oql语句。

首先要知道springboot通过是哪个类进行加载这些数据库连接池的参数的。如果忘记了类名,就到spring-boot-autoconfigure.jar的META-INF/spring.factories
在这里插入图片描述

org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

顺藤摸瓜

@ConfigurationProperties(prefix = "spring.datasource")

org.springframework.boot.autoconfigure.jdbc.DataSourceProperties

这个类就是我们要用的,在oql中填写

select x from org.springframework.boot.autoconfigure.jdbc.DataSourceProperties x

在这里插入图片描述

现在看到我们熟悉的用户名和密码了吧。

查询包含key=dataSourceDW.minIdle 的 Map实例

select s from java.util.HashMap s where contains(s.table, function(it) {
    if (it && it.key && it.key.value && it.key.value.toString() == 'dataSourceDW.minIdle') {
        return true;
    }
    return false;
})

查询包含key=dataSourceDW.minIdle 的 Map实例并且过滤出的dataSourceDW.minIdle

select filter(s.table,function(it){
   if (it && it.key && it.key.value && it.key.value.toString() == 'dataSourceDW.minIdle') {
        return true;
    }
    return false;
     } ) from java.util.HashMap s where contains(s.table, function(it) {
    if (it && it.key && it.key.value && it.key.value.toString() == 'dataSourceDW.minIdle') {
        return true;
    }
    return false;
})

Visual VM的OQL语言是对HeapDump进行查询,类似于SQL的查询语言,它的基本语法如下:

select <JavaScript expression to select> 

[ from [instanceof] <class name> <identifier> 

[ where <JavaScript boolean expression to filter> ] ]

OQL由3个部分组成:select子句、from子句和where子句。select子句指定查询结果要显示的内容。from子句指定查询范围,可指定类名,如java.lang.String、char[]、[Ljava.io.File;(File数组)。where子句用于指定查询条件。

1.字符串的长度大于 50 小于 60的 实例

select s from java.lang.String s where s.value.length>50 && s.value.length<60

在这里插入图片描述

2.显示所有文件对象的文件路径

select file.path.value.toString()  from java.io.File file

在这里插入图片描述

3.显示所有ClassLoader的类名

select classof(cl).name from instanceof java.lang.ClassLoader cl

4.查找包含内容最多的List

这个应该是查找内存泄露的好语句

select map(top(heap.objects('java.util.ArrayList'), 'rhs.size - lhs.size', 5),"toHtml(it)+'='+it.size")

5.通过引用查询对象

select o from instanceof 0xd404d404 o

6.heap 对象

heap.findClass(class name) – 找到类

select heap.findClass("java.lang.String").superclass

7.找到对象
heap.findObject(object id) – 找到对象

select heap.findObject("0xd404d404")

8.所有类的枚举
heap.classes

select heap.classes

9.所有对象的枚举
heap.objects

select heap.objects("java.lang.String")

10.等待垃圾收集的java对象的枚举
heap.finalizables

select heap.finalizables

11.某一对象存活路径
heap.livepaths

select heap.livepaths(s) from java.lang.String s

12.辨识对象的函数

12.1.返回java对象的类对象
classof(class name)

select classof(cl).name from instanceof java.lang.ClassLoader cl

12.2 返回是否两个对象是同一个实例
identical(object1,object2) -

select identical(heap.findClass("java.lang.String").name, heap.findClass("java.lang.String").name)

12.3 返回对象的id
objectid(object)

select objectid(s) from java.lang.String s

12.4 返回可从对象可到达的对象
reachables
12.4.1 查询从Properties对象可到达的对象

select reachables(p) from java.util.Properties p  

12.4.2查询从URL对象可到达的对象,但不包括从URL.handler可到达的对象

select reachables(u, "java.net.URL.handler") from java.net.URL u 

12.5.1 返回引用某一对象的对象
referrers(object)

select referrers(s) from java.lang.String s where s.count > 100

12.5.2 返回是否第一个对象引用第二个对象
refers(object1,object2)

select refers(heap.findObject("0xd4d4d4d4"),heap.findObject("0xe4e4e4e4"))

12.6 返回是否对象是根集的成员
root(object)

select root(heap.findObject("0xd4d4d4d4"))

12.7 返回对象的大小
sizeof(object)
12.8 返回对象的html格式

select "<b>" + toHtml(o) + "</b>" from java.lang.Object o

12.9 选择多值

select {name:t.name?t.name.toString():"null",thread:t} from instanceof java.lang.Thread t

13 数组、迭代器等函数
13.1 将数组或枚举进行连接
concat(enumeration1,enumeration2)

select concat(referrers(p),referrers(p)) from java.util.Properties p

13.2 数组中元素是否满足某表达式
contains(array, expression) –

13.3 返回由java.lang.Class引用的java.util.Properties对象

select p from java.util.Properties where contains(referres(p), "classof(it).name == 'java.lang.Class'") 

built-in变量

it – 当前的迭代元素

index – 当前迭代元素的索引

array – 被迭代的数组

count(array, expression) – 满足某一条件的元素的数量

select count(heap.classes(), "/java.io./(it.name)")

filter(array, expression) – 过滤出满足某一条件的元素

select filter(heap.classes(), "/java.io./(it.name)")

length(array) – 返回数组长度

select length(heap.classes())

map(array,expression) – 根据表达式对数组中的元素进行转换映射

select map(heap.classes(),"index + '-->' + toHtml(it)")

max(array,expression) – 最大值, min(array,expression)

select max(heap.objects("java.lang.String"),"lhs.count>rhs.count") 

built-in变量

lhs – 左边元素

rhs – 右边元素

sort(array,expression) – 排序

select sort(heap.objects('[C'),'sizeof(lhs)-sizeof(rhs)')

sum(array,expression) – 求和

select sum(heap.objects('[C'),'sizeof(it)')

toArray(array) – 返回数组

unique(array) – 唯一化数组

猜你喜欢

转载自blog.csdn.net/hepei120/article/details/85264407
今日推荐