Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increasing the max size of jvisualVM OQL resultset

I have a memory dump file which has nearly 5000 instances of a particular object. These objects are to be written into a DB, and the way i am doing this is to write an OQL query in jvisualvm to generate a string that will serve as an SQL insert for example

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

When i run this via OQL, i get a result set like this -

<code>
insert into trades (id, tradeNumber) values (1,12345); 
insert into trades (id, tradeNumber) values (2,123456);
insert into trades (id, tradeNumber) values (3,123457); </code>

etc

However, since the total number of instances is large (around 5000) JvisualVM only shows about 100 of them. and then errors out with a message "Too many results. Please, refine your query."

I cannot refine the query as i have to parse all instances this way. Is there a way in which i can ask JvisualVM to show me all instances and not restrict the number of results?

I also see that Jvisual vm shows the first 100 instances without any filters, is it possible to get the next 100 instances and so on via OQL query?

Thanks

like image 800
Mukul Jain Avatar asked Jun 11 '14 15:06

Mukul Jain


2 Answers

Open visualvm.conf file:

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

add to a string started with

visualvm_default_options="....

a property with your desirable limit value

-J-DOQLController.limitResults=999
like image 86
Yura Avatar answered Nov 06 '22 22:11

Yura


I couldn't find any settings in jvisualVm to increase the size of resultset. May be its not possible that way. It looks like a hard coded limit in Jvisualvm code base. Ref: http://visualvm.sourcearchive.com/documentation/1.3/OQLController_8java-source.html

find below snippets there:

final AtomicInteger counter = new AtomicInteger(100);

and

 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
 }

Now the interesting part, the workaround for your problem.

Consider the class below :

 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;
        }
    }

now say I have 105 objects in memory for this class, kept in a list like :

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

and I need to achieve what you are doing.

Now to show these 105 objects instead of listing all the result sets, i would rather iterate over all the objects and create one single string containing all the SQL queries separated by new line. For this you need to invoke similar OQL script in Query Editor.

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"));

and the result in Query Results tab will be:

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);

just modify the OQL script to suit your requirement.

NOTE: in class Xyz the field idXyz was intentionally not set as id, as in that case itr.id will return object id associated with that instance.

for more on OQL methods ref: http://visualvm.java.net/oqlhelp.html#toHtml

like image 8
Shail016 Avatar answered Nov 06 '22 22:11

Shail016