2

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
joseph
  • 2,429
  • 1
  • 22
  • 43

2 Answers2

5

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" };
}
Tomas Hurka
  • 6,723
  • 29
  • 38
2

I was solving the same thing a few years before: https://vondrnotes.blogspot.com/2014/09/visualvm-oql-which-write-byte-into-file.html

I did it in With VisualVM in OQL:

//To get Id of object
//In VisualVM right click on instance of byte[] and select 'Copy ID'
var bytes = heap.findObject(0xe21b95d8);

var filePath = "c:/tmp/result.txt"
var fos = new java.io.FileOutputStream(filePath);
var len = bytes.length
for (var i=0; i<len; i++) {
  fos.write(bytes[i]);
}
fos.close();

"Bytes has been written into file '" + filePath+"'";
bugs_
  • 3,544
  • 4
  • 34
  • 39