增加jvisualVM OQL结果集的最大大小

时间:2014-06-11 15:01:28

标签: java jvisualvm heap-dump oql

我有一个内存转储文件,它有近5000个特定对象的实例。这些对象将被写入数据库,我这样做的方法是在jvisualvm中编写一个OQL查询,以生成一个字符串,用作SQL插入,例如

select "insert into trades (id, tradeNumber) values ("+ x.id+ ", " + x.tradeNumber +");" from com.test.application.TradeObject x;

select "insert into trades (id, tradeNumber) values ("+ x.id+ ", " + x.tradeNumber +");" from com.test.application.TradeObject x; 当我通过OQL运行时,我得到一个像这样的结果集 -

但是,由于实例总数很大(大约5000),JvisualVM只显示其中的大约100个。然后出现错误消息“结果太多。请改进您的查询。”

我无法优化查询,因为我必须以这种方式解析所有实例。 有没有办法可以让JvisualVM向我显示所有实例而不限制结果数量?

我还看到Jvisual vm显示前100个没有任何过滤器的实例,是否可以通过OQL查询获得接下来的100个实例等等?

由于

3 个答案:

答案 0 :(得分:9)

打开visualvm.conf文件:

%JDK_HOME%\lib\visualvm\etc\visualvm.conf

添加到以

开头的字符串
visualvm_default_options="....

具有所需限制值的属性

-J-DOQLController.limitResults=999

答案 1 :(得分:7)

我无法在jvisualVm中找到任何设置来增加结果集的大小。也许不可能那样。 它看起来像Jvisualvm代码库中的硬编码限制。参考:http://visualvm.sourcearchive.com/documentation/1.3/OQLController_8java-source.html

在下面找到以下片段:

final AtomicInteger counter = new AtomicInteger(100);

 if (counter.get() == 0) {
 sb.append("<tr><td><h4>Too many results. Please, refine your query.</h4></td></tr>" );
 } else if (counter.get() == 100) {
 sb.append("<tr><td><h4>"); // NOI18N
 sb.append(NbBundle.getMessage(OQLController.class, "OQL_NO_RESULTS_MSG")); // NOI18N
 sb.append("</h4></td></tr>" ); // NOI18N
 }

现在是有趣的部分,解决问题的方法。

考虑下面的课程:

 package com.demo.test; 
 class Xyz {
        int idXyz;// intentionally not set as id
        String value;

        public Xyz(int idXyz, String value) {
            this.idXyz = idXyz;
            this.value = value;
        }
    }

现在说我在这个类的内存中有105个对象,保存在如下列表中:

       static List<Xyz> lst = new ArrayList<>();
        for (int i = 0; i < 105; i++) {
            lst.add(new Xyz( i,"xyz value-" + i));
        }

我需要实现你正在做的事情。

现在要显示这105个对象而不是列出所有结果集,我宁愿遍历所有对象并创建一个包含由新行分隔的所有SQL查询的单个字符串。为此,您需要在Query Editor中调用类似的OQL脚本。

function fun(objEnumeration){
var res =" ";
while (objEnumeration.hasMoreElements()) {
  var itr = objEnumeration.nextElement();
  var v = "insert into table_Xyz (idXyz, value) values ("+ itr.idXyz.toString()+ ", " + itr.value.toString() +");\n"
  res = res + v;
}
return res;
}

fun(heap.objects("com.demo.test.Xyz"));

Query Results标签中的结果为:

insert into table_Xyz (idXyz, value) values (104, xyz value-104);
insert into table_Xyz (idXyz, value) values (103, xyz value-103);
insert into table_Xyz (idXyz, value) values (102, xyz value-102);
insert into table_Xyz (idXyz, value) values (101, xyz value-101);
insert into table_Xyz (idXyz, value) values (100, xyz value-100);
insert into table_Xyz (idXyz, value) values (99, xyz value-99);
insert into table_Xyz (idXyz, value) values (98, xyz value-98);
insert into table_Xyz (idXyz, value) values (97, xyz value-97);
insert into table_Xyz (idXyz, value) values (96, xyz value-96);
insert into table_Xyz (idXyz, value) values (95, xyz value-95);
insert into table_Xyz (idXyz, value) values (94, xyz value-94);
insert into table_Xyz (idXyz, value) values (93, xyz value-93);
insert into table_Xyz (idXyz, value) values (92, xyz value-92);
insert into table_Xyz (idXyz, value) values (91, xyz value-91);
insert into table_Xyz (idXyz, value) values (90, xyz value-90);
insert into table_Xyz (idXyz, value) values (89, xyz value-89);
insert into table_Xyz (idXyz, value) values (88, xyz value-88);
insert into table_Xyz (idXyz, value) values (87, xyz value-87);
insert into table_Xyz (idXyz, value) values (86, xyz value-86);
insert into table_Xyz (idXyz, value) values (85, xyz value-85);
insert into table_Xyz (idXyz, value) values (84, xyz value-84);
insert into table_Xyz (idXyz, value) values (83, xyz value-83);
insert into table_Xyz (idXyz, value) values (82, xyz value-82);
insert into table_Xyz (idXyz, value) values (81, xyz value-81);
insert into table_Xyz (idXyz, value) values (80, xyz value-80);
insert into table_Xyz (idXyz, value) values (79, xyz value-79);
insert into table_Xyz (idXyz, value) values (78, xyz value-78);
insert into table_Xyz (idXyz, value) values (77, xyz value-77);
insert into table_Xyz (idXyz, value) values (76, xyz value-76);
insert into table_Xyz (idXyz, value) values (75, xyz value-75);
insert into table_Xyz (idXyz, value) values (74, xyz value-74);
insert into table_Xyz (idXyz, value) values (73, xyz value-73);
insert into table_Xyz (idXyz, value) values (72, xyz value-72);
insert into table_Xyz (idXyz, value) values (71, xyz value-71);
insert into table_Xyz (idXyz, value) values (70, xyz value-70);
insert into table_Xyz (idXyz, value) values (69, xyz value-69);
insert into table_Xyz (idXyz, value) values (68, xyz value-68);
insert into table_Xyz (idXyz, value) values (67, xyz value-67);
insert into table_Xyz (idXyz, value) values (66, xyz value-66);
insert into table_Xyz (idXyz, value) values (65, xyz value-65);
insert into table_Xyz (idXyz, value) values (64, xyz value-64);
insert into table_Xyz (idXyz, value) values (63, xyz value-63);
insert into table_Xyz (idXyz, value) values (62, xyz value-62);
insert into table_Xyz (idXyz, value) values (61, xyz value-61);
insert into table_Xyz (idXyz, value) values (60, xyz value-60);
insert into table_Xyz (idXyz, value) values (59, xyz value-59);
insert into table_Xyz (idXyz, value) values (58, xyz value-58);
insert into table_Xyz (idXyz, value) values (57, xyz value-57);
insert into table_Xyz (idXyz, value) values (56, xyz value-56);
insert into table_Xyz (idXyz, value) values (55, xyz value-55);
insert into table_Xyz (idXyz, value) values (54, xyz value-54);
insert into table_Xyz (idXyz, value) values (53, xyz value-53);
insert into table_Xyz (idXyz, value) values (52, xyz value-52);
insert into table_Xyz (idXyz, value) values (51, xyz value-51);
insert into table_Xyz (idXyz, value) values (50, xyz value-50);
insert into table_Xyz (idXyz, value) values (49, xyz value-49);
insert into table_Xyz (idXyz, value) values (48, xyz value-48);
insert into table_Xyz (idXyz, value) values (47, xyz value-47);
insert into table_Xyz (idXyz, value) values (46, xyz value-46);
insert into table_Xyz (idXyz, value) values (45, xyz value-45);
insert into table_Xyz (idXyz, value) values (44, xyz value-44);
insert into table_Xyz (idXyz, value) values (43, xyz value-43);
insert into table_Xyz (idXyz, value) values (42, xyz value-42);
insert into table_Xyz (idXyz, value) values (41, xyz value-41);
insert into table_Xyz (idXyz, value) values (40, xyz value-40);
insert into table_Xyz (idXyz, value) values (39, xyz value-39);
insert into table_Xyz (idXyz, value) values (38, xyz value-38);
insert into table_Xyz (idXyz, value) values (37, xyz value-37);
insert into table_Xyz (idXyz, value) values (36, xyz value-36);
insert into table_Xyz (idXyz, value) values (35, xyz value-35);
insert into table_Xyz (idXyz, value) values (34, xyz value-34);
insert into table_Xyz (idXyz, value) values (33, xyz value-33);
insert into table_Xyz (idXyz, value) values (32, xyz value-32);
insert into table_Xyz (idXyz, value) values (31, xyz value-31);
insert into table_Xyz (idXyz, value) values (30, xyz value-30);
insert into table_Xyz (idXyz, value) values (29, xyz value-29);
insert into table_Xyz (idXyz, value) values (28, xyz value-28);
insert into table_Xyz (idXyz, value) values (27, xyz value-27);
insert into table_Xyz (idXyz, value) values (26, xyz value-26);
insert into table_Xyz (idXyz, value) values (25, xyz value-25);
insert into table_Xyz (idXyz, value) values (24, xyz value-24);
insert into table_Xyz (idXyz, value) values (23, xyz value-23);
insert into table_Xyz (idXyz, value) values (22, xyz value-22);
insert into table_Xyz (idXyz, value) values (21, xyz value-21);
insert into table_Xyz (idXyz, value) values (20, xyz value-20);
insert into table_Xyz (idXyz, value) values (19, xyz value-19);
insert into table_Xyz (idXyz, value) values (18, xyz value-18);
insert into table_Xyz (idXyz, value) values (17, xyz value-17);
insert into table_Xyz (idXyz, value) values (16, xyz value-16);
insert into table_Xyz (idXyz, value) values (15, xyz value-15);
insert into table_Xyz (idXyz, value) values (14, xyz value-14);
insert into table_Xyz (idXyz, value) values (13, xyz value-13);
insert into table_Xyz (idXyz, value) values (12, xyz value-12);
insert into table_Xyz (idXyz, value) values (11, xyz value-11);
insert into table_Xyz (idXyz, value) values (10, xyz value-10);
insert into table_Xyz (idXyz, value) values (9, xyz value-9);
insert into table_Xyz (idXyz, value) values (8, xyz value-8);
insert into table_Xyz (idXyz, value) values (7, xyz value-7);
insert into table_Xyz (idXyz, value) values (6, xyz value-6);
insert into table_Xyz (idXyz, value) values (5, xyz value-5);
insert into table_Xyz (idXyz, value) values (4, xyz value-4);
insert into table_Xyz (idXyz, value) values (3, xyz value-3);
insert into table_Xyz (idXyz, value) values (2, xyz value-2);
insert into table_Xyz (idXyz, value) values (1, xyz value-1);
insert into table_Xyz (idXyz, value) values (0, xyz value-0);

只需修改OQL脚本以满足您的要求。

注意:在类Xyz中,字段idXyz为intentionally not set as id,因为在这种情况下itr.id将返回与该实例关联的对象ID。

有关OQL方法的更多信息,请参阅参考:http://visualvm.java.net/oqlhelp.html#toHtml

答案 2 :(得分:1)

现在有可能(v 1.7),来自netbeans/profiler.heapwalker/src/org/netbeans/modules/profiler/heapwalk/OQLController.java

private static final int RESULTS_LIMIT = \
  Integer.parseInt(System.getProperty("OQLController.limitResults", "100")); // NOI18N

我的帮助代码(如果你跳过limit - 然后无限制):

function loop1(iter, limit) {
  if (!iter.hasNext())
    return "<b>Nothing found!</b>";
  var count = 0;
  var html = "";
  while (true) {
    if (count >= limit)
      return "<b>First </b>" + limit + "<b> objects (not all):</b><br>" + html;
    if (!iter.hasNext())
      return "<b>Total </b>" + count + "<b> objects:</b><br>" + html;
    html += toHtml(iter.next()) + "<br>";
    count += 1;
  }
}
function loop2(iter, limit) {
  if (!iter.hasMoreElements())
    return "<b>Nothing found!</b>";
  var count = 0;
  var html = "";
  while (true) {
    if (count >= limit)
      return "<b>First </b>" + limit + "<b> objects (not all):</b><br>" + html;
    if (!iter.hasMoreElements())
      return "<b>Total </b>" + count + "<b> objects:</b><br>" + html;
    html += toHtml(iter.nextElement()) + '<br>';
    count += 1;
  }
}
function loop(iter, limit) {
   if ('hasMoreElements' in iter)
     return loop2(iter, limit);
   return loop1(iter, limit);
}

loop(filter(heap.classes(), "/javax.mail./(it.name)"), 1000)  // loop1
loop(heap.objects('java.lang.ClassLoader'))                   // loop2

UPDATE 我发现的另一个技巧是为变量赋值:

x = filter(heap.objects("java.lang.String"), "/hibernate\\.ejb/(it.toString())")
x

结果对象具有查看器使用的界面next() / hasNext()。默认情况下,它显示100个条目。但接下来只打电话:

x

显示接下来的100个条目,等等......!