Beispiel #1
0
 // saves the current configuration (breakpoints, window sizes and positions...)
 private void saveConfig() {
   try {
     ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(idxName + ".config"));
     Breakpoints.save(out);
     Properties.save(out);
     out.close();
   } catch (IOException exc) {
     consoleFrame.echoInfo("Could not save settings: " + exc);
   }
 }
Beispiel #2
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);
    }
  }
Beispiel #3
0
 public void processItem(String key, String data) {
   if (!inWkld && showResultsItem.getState()) {
     consoleFrame.echoTuple(key + ": " + data);
   }
 }
Beispiel #4
0
  public void updateGuiState(int priorState, LibgistCommand cmd, boolean success) {
    switch (cmd.cmdType) {
      case LibgistCommand.CREATE:
      case LibgistCommand.OPEN:
        resetState();
        if (!success) return; // done
        setGuiState(IDXOPENSTATE);
        isOpen = true;
        idxName = cmd.indexName.toString();
        if (cmd.cmdType == LibgistCommand.CREATE) {
          resetConfig();
        } else {
          restoreConfig();
        }
        // setTitle("amdb: " + filename);
        setTree(idxName);
        try {
          treeView = new TreeView(desktop); // creates a display of the opened index
          desktop.add(treeView, JLayeredPane.PALETTE_LAYER);
        } catch (LibgistException e) {
          // what to do now?
          consoleFrame.echoInfo("new TreeView() failed");
        }
        break;

      case LibgistCommand.CLOSE:
        saveConfig();
        resetState();
        break;

      case LibgistCommand.OPENANL:
        resetState();
        if (!success) return; // done
        // enable menu items and open tree view
        setGuiState(ANLOPENSTATE);
        // setTitle("amdb: " + filename);
        setTree(idxName);
        try {
          treeView = new TreeView(desktop); // creates a display of the opened index
          desktop.add(treeView, JLayeredPane.PALETTE_LAYER);
        } catch (LibgistException e) {
          // what to do now?
          consoleFrame.echoInfo("new TreeView() failed");
        }

        // get ready to display dialogs
        if (analysisInfo.actualHasWkldStats) {
          wkldStatsDlg.init(treeView);
        }
        if (analysisInfo.actualHasSplitStats) {
          splitStatsDlg.init(treeView);
        }
        if (analysisInfo.actualHasPenaltyStats) {
          penaltyStatsDlg.init(treeView);
        }
        break;

      case LibgistCommand.CLOSEANL:
        treeView.dispose();
        treeView = null;
        setGuiState(INITSTATE);
        setTree("");
        break;

        // if these didn't work, we don't care
      case LibgistCommand.INSERT:
      case LibgistCommand.REMOVE:
      case LibgistCommand.FETCH:
      case LibgistCommand.FLUSH:
      case LibgistCommand.CREATEANL:
      case LibgistCommand.SCRIPT:
        setGuiState(priorState);
        break;
    }
  }
Beispiel #5
0
  public void echoCmd(LibgistCommand cmd) {
    if (!showCmdsItem.getState()) {
      return;
    }

    echoBuffer.setLength(0); // reset
    switch (cmd.cmdType) {
      case LibgistCommand.INSERT:
        echoBuffer.append("insert \"").append(cmd.key);
        echoBuffer.append("\" \"").append(cmd.data).append("\"");
        break;

      case LibgistCommand.REMOVE:
        echoBuffer.append("delete \"").append(cmd.qual);
        echoBuffer.append("\"");
        break;

      case LibgistCommand.FETCH:
        echoBuffer.append("select ");
        if (cmd.fetchLimit > 0) {
          echoBuffer.append(cmd.fetchLimit).append(" ");
        }
        echoBuffer.append("\"").append(cmd.qual).append("\"");
        break;

      case LibgistCommand.CREATE:
        echoBuffer.append("create ").append(cmd.indexName);
        echoBuffer.append(" ").append(cmd.extension);
        break;

      case LibgistCommand.OPEN:
        echoBuffer.append("open ").append(cmd.indexName);
        break;

      case LibgistCommand.CLOSE:
        echoBuffer.append("close");
        break;

      case LibgistCommand.FLUSH:
        echoBuffer.append("flush");
        break;

      case LibgistCommand.OPENANL:
        echoBuffer.append("openanl ").append(cmd.analysisFile.getPath());
        break;

      case LibgistCommand.CLOSEANL:
        echoBuffer.append("closeanl");
        break;

      case LibgistCommand.CREATEANL:
        echoBuffer.append("createanl");
        break;

      case LibgistCommand.SCRIPT:
        echoBuffer.append("executing script...");
        break;

      default:
        // something wrong here
    }
    consoleFrame.echoCmd(echoBuffer.toString());
  }
Beispiel #6
0
 // tiles treeView, globalView and consoleFrame
 public void tile() {
   if (treeView != null) treeView.tile();
   consoleFrame.tile();
 }
Beispiel #7
0
 private void setTree(String title) {
   consoleFrame.setTree(title);
 }