Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

61
LINES

< > TinyBrain | #1006326 - jInjectionsTable

JavaX fragment (include)

static int jInjectionsTable_updateInterval = 3000;

static JTable jInjectionsTable() {
  final JTable tbl = sexyTable();
  
  tablePopupMenu(tbl, voidfunc(JPopupMenu menu, final int row) {
    final int port = parseIntOpt(str(getTableLineAsMap(tbl, row).get("VM")));
    if (port != 0) {
      addMenuItem(menu, "Kill VM", r { killVM(port) });
      addMenuItem(menu, "Restart Program", r { restartVM(port) });
      addMenuItem(menu, "Show VM Output", r {
        thread "Show VM Output" {
          showText("Output of VM " + port, unquote(sendToLocalBot(port, "get output")));
        }
      });
      addMenuItem(menu, "Dump heap...", r {
        inputFilePath("Dump heap to where?", new File(javaxCachesDir(), "heap.bin"), voidfunc(File f) {
          pcall-messagebox {
            assertOK(send(port, "dump heap to *", f2s(f)));
            infoBox("Heap dumped to " + fileNamePlusMSize(f));
            if (confirmOKCancel("Start jhat (heap analysis server running on localhost:7000)?")) {
              nohupJavax("#1007494 " + f2s(f));
              infoBox("Tried to start jhat.");
            }
          }
        });
      });
    }
  });
  
  awtCalcRegularly(tbl, jInjectionsTable_updateInterval, 0, r {
    long time = sysNow();
    new L l;
    for (DialogIO vm : talkToAllVMs()) {
      pcall {
        int vmPort = vm.getPort();
        S x = vm.ask("get injections");
        S mem = dropUntilColon(vm.ask("how much memory are you consuming"));
        //print("VM " + vmPort + " injections: " + x);
        L injections = cast safeUnstructure(x);

        for (O inj : injections) pcall{
          S progID = formatSnippetID((S) get(inj, "progID"));
          l.add(litorderedmap(
            "Program name", getSnippetTitle(progID),
            "Program ID", progID,
            "VM Size (Java)", mem,
            "VM", vmPort,
            "More info", isTrue(get(inj, "mainDone")) ? "main done" : "main running",
            "Injection ID", get(inj, "injectionID")));
        }
      }
      vm.close();
    }
    done2(time, "Scanned " + n(l, "VMs"));
    
    dataToTable(tbl, l);
  });
  ret tbl;
}

Author comment

Began life as a copy of #1001744

download  show line numbers  debug dex   

Travelled to 1 computer(s): sawdedvomwva

No comments. add comment

Snippet ID: #1006326
Snippet name: jInjectionsTable
Eternal ID of this version: #1006326/16
Text MD5: 4235cca2217b7c3a9182317db734b7e3
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-23 15:22:18
Source code size: 2187 bytes / 61 lines
Pitched / IR pitched: No / No
Views / Downloads: 51 / 3
Version history: 15 change(s)
Referenced in: [show]