visualvmoql

How to save the VisualVM OQL result directly into file?


My query results in millions of rows. I have already modified visualvm.conf

-J-DOQLController.limitResults=1000000

Currently, as a workaround I run the query, and copy and paste the result to a file. However, the result puts a lot of strain on my memory. Is there anyway to skip displaying the result to the UI, and just stream the result directly to a file?

My query looks like:

select { obj1: busObj.obj1, ... , objN: busObj.objN }
  from com.my.BusinessObject busObj

Solution

  • You can try something like:

    writeToFile()
    
    function writeToFile() {
        var objects = heap.objects("com.my.BusinessObject", false);
        var FileWriterClass=Java.type("java.io.FileWriter");
        var writer = new FileWriterClass("/tmp/out.txt");
    
        while (objects.hasMoreElements()) {
            var busObj = objects.nextElement();
    
            writer.write("obj1: "+busObj.obj1+", obj2: "+busObj.obj2+"\n");
        }
        writer.close();
        return { Result: "done" };
    }