Esempio n. 1
0
  /**
   * Build an XML element with the task profile information
   *
   * @param taskProfile the task profile
   * @param doc the XML document
   * @param name the name of the element
   * @return the XML element
   */
  private Element buildTaskProfileElement(MRTaskProfile taskProfile, Document doc, String name) {

    // Add the task attributes
    Element task = doc.createElement(name);
    task.setAttribute(ID, taskProfile.getTaskId());
    task.setAttribute(NUM_TASKS, Integer.toString(taskProfile.getNumTasks()));

    // Add the task enum maps
    task.appendChild(buildEnumMapElement(taskProfile.getCounters(), doc, COUNTERS, COUNTER));
    task.appendChild(buildEnumMapElement(taskProfile.getStatistics(), doc, STATS, STAT));
    task.appendChild(buildEnumMapElement(taskProfile.getCostFactors(), doc, FACTORS, FACTOR));
    task.appendChild(buildEnumMapElement(taskProfile.getTimings(), doc, TIMINGS, TIMING));

    // Add the task auxiliary counters map
    if (taskProfile.containsAuxCounters()) {
      Element counters = doc.createElement(AUX_COUNTERS);
      for (Entry<String, Long> e : taskProfile.getAuxCounters().entrySet()) {
        Element counter = doc.createElement(AUX_COUNTER);
        counters.appendChild(counter);
        counter.setAttribute(KEY, e.getKey());
        counter.setAttribute(VALUE, e.getValue().toString());
      }
      task.appendChild(counters);
    }

    return task;
  }
Esempio n. 2
0
 /**
  * Load the task profile timings from the XML element to the profile
  *
  * @param taskProf the task profile
  * @param task the task XML element
  */
 private void loadTaskProfileTimings(MRTaskProfile taskProf, Element task) {
   Element timings = (Element) task.getElementsByTagName(TIMINGS).item(0);
   NodeList timingList = timings.getElementsByTagName(TIMING);
   for (int j = 0; j < timingList.getLength(); ++j) {
     Element timing = (Element) timingList.item(j);
     taskProf.addTiming(
         MRTaskPhase.valueOf(timing.getAttribute(KEY)),
         Double.parseDouble(timing.getAttribute(VALUE)));
   }
 }
Esempio n. 3
0
 /**
  * Load the task profile cost factor from the XML element to the profile
  *
  * @param taskProf the task profile
  * @param task the task XML element
  */
 private void loadTaskProfileCostFactors(MRTaskProfile taskProf, Element task) {
   Element factors = (Element) task.getElementsByTagName(FACTORS).item(0);
   NodeList factorList = factors.getElementsByTagName(FACTOR);
   for (int j = 0; j < factorList.getLength(); ++j) {
     Element factor = (Element) factorList.item(j);
     taskProf.addCostFactor(
         MRCostFactors.valueOf(factor.getAttribute(KEY)),
         Double.parseDouble(factor.getAttribute(VALUE)));
   }
 }
Esempio n. 4
0
 /**
  * Load the task profile statistics from the XML element to the profile
  *
  * @param taskProf the task profile
  * @param task the task XML element
  */
 private void loadTaskProfileStatistics(MRTaskProfile taskProf, Element task) {
   Element stats = (Element) task.getElementsByTagName(STATS).item(0);
   NodeList statList = stats.getElementsByTagName(STAT);
   for (int j = 0; j < statList.getLength(); ++j) {
     Element stat = (Element) statList.item(j);
     taskProf.addStatistic(
         MRStatistics.valueOf(stat.getAttribute(KEY)),
         Double.parseDouble(stat.getAttribute(VALUE)));
   }
 }
Esempio n. 5
0
 /**
  * Load the task profile counters from the XML element to the profile
  *
  * @param taskProf the task profile
  * @param task the task XML element
  */
 private void loadTaskProfileCounters(MRTaskProfile taskProf, Element task) {
   Element counters = (Element) task.getElementsByTagName(COUNTERS).item(0);
   NodeList counterList = counters.getElementsByTagName(COUNTER);
   for (int j = 0; j < counterList.getLength(); ++j) {
     Element counter = (Element) counterList.item(j);
     taskProf.addCounter(
         MRCounter.valueOf(counter.getAttribute(KEY)),
         Long.parseLong(counter.getAttribute(VALUE)));
   }
 }
  /**
   * Load the execution profile
   *
   * @param profile the task profile to load
   * @return true if the loading was successful
   */
  public boolean loadExecutionProfile(MRTaskProfile profile) {

    if (!this.profile.getTaskId().equalsIgnoreCase(profile.getTaskId())) {
      return false;
    } else if (loaded && this.profile == profile) {
      return true;
    }

    // Load the profile
    this.profile = profile;
    loaded = true;

    try {
      if (parseProfileFile()) {
        return loadExecutionProfile();
      } else {
        return false;
      }
    } catch (ProfileFormatException e) {
      System.err.println(e.getMessage());
      e.printStackTrace();
      return false;
    }
  }