Example #1
0
  private void enableAnalysis() {
    setAllEnabled(false);
    analysisMenu.setEnabled(true);

    // get info on state of analysis
    String scriptFile;
    Libgist.getAnalysisInfo(analysisInfo);

    // newAnalysisItem not enabled: can't create new profile, we just closed the index
    newAnalysisItem.setEnabled(false);
    openAnalysisItem.setEnabled(true);
    completeAnalysisItem.setEnabled(true);

    wkldStatsItem.setEnabled(analysisInfo.actualHasWkldStats);
    splitStatsItem.setEnabled(analysisInfo.actualHasSplitStats);
    penaltyStatsItem.setEnabled(analysisInfo.actualHasPenaltyStats);

    // general tree statistics are okay
    treeStatsMenu.setEnabled(true);
    utilItem.setEnabled(true);
    predSzItem.setEnabled(true);
    slotCntItem.setEnabled(true);

    // can always select another index or exit
    fileMenu.setEnabled(true);
    newItem.setEnabled(true);
    openItem.setEnabled(true);
    exitItem.setEnabled(true);
  }
Example #2
0
 public void windowClosing(WindowEvent e) {
   try {
     Libgist.close();
   } catch (LibgistException exc) {
     // can't do very much at this point
     System.err.println("Could not close " + exc);
   }
   opThread.stopNow();
   System.exit(0);
 }
Example #3
0
  public static void main(String[] argv) {
    MainWindow win;

    DbgOutput.toStdout();
    win = new MainWindow();
    // process cmd line arguments
    int i;
    for (i = 0; i < argv.length; i++) {
      if (argv[i].equals("-D")) {
        i++;
        // try to interpret the next argument as the debug level
        int dbgLvl = 1; // basic debug level
        if (i >= argv.length) {
          // no more arguments, we stick with debug level 1
          break;
        }
        try {
          dbgLvl = Integer.parseInt(argv[i]);
        } catch (NumberFormatException e) {
          dbgLvl = 1; // didn't work, this is probably a filename
          win.open(argv[i]);
        }
        DbgOutput.setDbgLevel(dbgLvl);
        Libgist.setDbgLevel(dbgLvl);

      } else if (argv[i].equals("-h")) {
        // print help message and exit
        System.out.println("Usage: amdb [-D <dbglevel> | -h] [index]");
        System.exit(0);

      } else {
        // this is a name of an index, open it
        // System.out.println("open " + argv[i]);
        win.open(argv[i]);
      }
    }
    win.setTitle("amdb");
    win.setSize(800, 600);
    win.setLocation(50, 50);
    win.setVisible(true);
  }
Example #4
0
  public MainWindow() {
    JMenuItem showTextItem, showContentItem, showStatsItem;
    JMenuItem consoleWinItem, treeWinItem, traceWinItem;

    // our libgist execution thread
    opThread = new OpThread(this);
    Libgist.setBreakHandler(opThread);
    opThread.start();
    cmd = new LibgistCommand();

    menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    // create toolbar and console window with text area

    getContentPane().removeAll();
    getContentPane().setLayout(new BorderLayout());
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    // desktop pane + console frame
    desktop = new JDesktopPane();
    desktop.setOpaque(true);
    desktop.setBackground(Color.lightGray);
    consoleFrame = new ConsoleWindow(200, desktop);
    desktop.add(consoleFrame, JLayeredPane.PALETTE_LAYER);

    // debugging actions for toolbar:
    // notify opThread of what to do when it hits a breakpoint
    stepAction =
        new AbstractAction("Step") {
          public void actionPerformed(ActionEvent e) {
            opThread.step();
          }
        };
    cancelAction =
        new AbstractAction("Cancel") {
          public void actionPerformed(ActionEvent e) {
            scriptWasCancelled = true; // don't call it after next line!
            opThread.cancel();
          }
        };
    nextAction =
        new AbstractAction("Next") {
          public void actionPerformed(ActionEvent e) {
            opThread.next();
          }
        };
    contAction =
        new AbstractAction("Continue") {
          public void actionPerformed(ActionEvent e) {
            opThread.cont();
          }
        };

    // opThread is currently executing a script and we want it to stop:
    // tell libgist directly to suspend execution once opThread is done
    // with the current operation
    stopAction =
        new AbstractAction("Stop") {
          public void actionPerformed(ActionEvent e) {
            Libgist.singleStep();
          }
        };

    // toolbar
    JToolBar toolbar = new JToolBar();
    toolbar.add(stepAction).setText("Step");
    toolbar.add(nextAction).setText("Next");
    toolbar.add(contAction).setText("Continue");
    toolbar.add(stopAction).setText("Stop");
    toolbar.add(cancelAction).setText("Cancel");

    panel.add(toolbar, BorderLayout.NORTH);
    panel.add(desktop, BorderLayout.CENTER);
    getContentPane().add(panel);

    createFileMenu();
    createOpsMenu();
    createDebugMenu();
    createTreeStatsMenu();
    createAnalysisMenu();
    createWindowsMenu();

    setGuiState(INITSTATE); // nothing opened yet

    // addWindowListener(this); // So we do the right thing on window closing.
  }
Example #5
0
  // create a new profile: read the script and possibly execute the queries,
  // save the stats (if 'import' == true, we assume the profile already exists
  // and don't run the queries)
  public void createWkld(String name, String scriptFile, boolean runQueries) {
    System.gc();
    Workload wkld = new Workload(name);

    if (showCmdsItem.getState()) {
      consoleFrame.echoCmd((!runQueries ? "importprof " : "newwkld ") + name + " " + scriptFile);
    }

    // construct the Workload object from the script;
    // first, check if the file exists
    try {
      FileReader reader = new FileReader(scriptFile);
      reader.close();
    } catch (FileNotFoundException e) {
      System.out.println("couldn't open " + scriptFile);
      return;
    } catch (IOException e) {
      System.out.println("couldn't close " + scriptFile);
    }

    // now, check if it contains only queries
    int scriptId = 0;
    try {
      scriptId = Libgist.openScript(scriptFile);
    } catch (LibgistException e) {
      System.out.println("couldn't open (C) " + scriptFile);
      return;
    }
    char[] arg1 = new char[64 * 1024];
    StringBuffer arg1Buf = new StringBuffer();
    char[] arg2 = new char[64 * 1024];
    StringBuffer arg2Buf = new StringBuffer();
    // for (;;) {
    // int cmd = Libgist.getCommand(scriptId, arg1, arg2);
    // if (cmd == Libgist.EOF) break;
    // if (cmd != Libgist.FETCH) {
    // there should only be queries
    // System.out.println("Script file contains non-SELECT command");
    // return;
    // }
    // }

    if (runQueries) {
      // turn profiling on and execute queries
      // Libgist.setProfilingEnabled(true);
      Libgist.disableBps(true); // we don't want to stop at breakpoints

      // rescan queries
      try {
        scriptId = Libgist.openScript(scriptFile);
      } catch (LibgistException e) {
        System.out.println("couldn't open (C) " + scriptFile);
        return;
      }
      int cnt = 1;
      // for (;;) {
      // int cmd = Libgist.getCommand(scriptId, arg1, arg2);
      // if (cmd == Libgist.EOF) break;
      // arg1Buf.setLength(0);
      // arg1Buf.append(arg1, 0, strlen(arg1));
      // arg2Buf.setLength(0);
      // arg2Buf.append(arg2, 0, strlen(arg2));
      // OpThread.execCmd(LibgistCommand.FETCH, arg1Buf.toString(),
      // arg2Buf.toString(), false);
      // System.out.print(cnt + " ");
      // System.out.println(cnt + ": execute " + arg2Buf.toString() + " "
      // + arg1Buf.toString());
      // cnt++;
      // }
      System.out.println();

      Libgist.disableBps(false);
      // compute optimal clustering and some more statistics
      // Libgist.computeMetrics(wkld.filename);
    }

    // save profile
    try {
      // we're saving Java and C++ data in separate files (filename and filename.prof)
      // the profile object only contains the filename, the queries will be
      // read in from the file when the profile is opened (faster that way)
      ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(wkld.filename));
      out.writeObject(wkld);
      out.close();
      System.out.println("copy query file");
      Runtime.getRuntime().exec("cp " + scriptFile + " " + wkld.filename + ".queries");
      System.out.println("saving tree and profile");
      Libgist.saveToFile(wkld.filename + ".idx");
      if (runQueries) {
        // Libgist.saveProfile(wkld.filename + ".prof");
      }
    } catch (Exception e) {
      System.out.println("Error saving profile: " + e);
      return;
    }

    if (runQueries) {
      // turn profiling off (after the metrics were computed and
      // the profile saved)
      // Libgist.setProfilingEnabled(false);
    }
  }