DRILL-3341: Avoid recomputing stats in ProfileWrapper + Small optimizations and comments in OperatorWrapper and FragmentWrapper + Comparator renames for consistency + Move TableBuilder#toString logic to TableBuilder#build + Incorrect field names in profile page for failed queries
Project: http://git-wip-us.apache.org/repos/asf/drill/repo Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/891fa1aa Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/891fa1aa Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/891fa1aa Branch: refs/heads/master Commit: 891fa1aa819f486c1d488898e2bdd43f618d62ce Parents: 5cd9916 Author: Sudheesh Katkam <[email protected]> Authored: Mon Jul 13 16:04:26 2015 -0700 Committer: Jason Altekruse <[email protected]> Committed: Tue Aug 4 08:49:02 2015 -0700 ---------------------------------------------------------------------- .../exec/server/rest/profile/Comparators.java | 31 ++++--- .../server/rest/profile/FragmentWrapper.java | 77 +++++++++--------- .../server/rest/profile/OperatorWrapper.java | 82 ++++++++++--------- .../server/rest/profile/ProfileWrapper.java | 85 ++++++++++---------- .../exec/server/rest/profile/TableBuilder.java | 3 +- .../src/main/resources/rest/profile/profile.ftl | 6 +- 6 files changed, 148 insertions(+), 136 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/drill/blob/891fa1aa/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/Comparators.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/Comparators.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/Comparators.java index 20f76a2..fa2f43f 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/Comparators.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/Comparators.java @@ -24,80 +24,85 @@ import org.apache.drill.exec.proto.UserBitShared.MajorFragmentProfile; import org.apache.drill.exec.proto.UserBitShared.MinorFragmentProfile; import org.apache.drill.exec.proto.UserBitShared.OperatorProfile; +/** + * Collection of comparators for comparing data in major fragment profiles, minor fragment profiles and + * operator profiles. + */ interface Comparators { - final static Comparator<MajorFragmentProfile> majorIdCompare = new Comparator<MajorFragmentProfile>() { + + final static Comparator<MajorFragmentProfile> majorId = new Comparator<MajorFragmentProfile>() { public int compare(final MajorFragmentProfile o1, final MajorFragmentProfile o2) { return Long.compare(o1.getMajorFragmentId(), o2.getMajorFragmentId()); } }; - final static Comparator<MinorFragmentProfile> minorIdCompare = new Comparator<MinorFragmentProfile>() { + final static Comparator<MinorFragmentProfile> minorId = new Comparator<MinorFragmentProfile>() { public int compare(final MinorFragmentProfile o1, final MinorFragmentProfile o2) { return Long.compare(o1.getMinorFragmentId(), o2.getMinorFragmentId()); } }; - final static Comparator<MinorFragmentProfile> startTimeCompare = new Comparator<MinorFragmentProfile>() { + final static Comparator<MinorFragmentProfile> startTime = new Comparator<MinorFragmentProfile>() { public int compare(final MinorFragmentProfile o1, final MinorFragmentProfile o2) { return Long.compare(o1.getStartTime(), o2.getStartTime()); } }; - final static Comparator<MinorFragmentProfile> lastUpdateCompare = new Comparator<MinorFragmentProfile>() { + final static Comparator<MinorFragmentProfile> lastUpdate = new Comparator<MinorFragmentProfile>() { public int compare(final MinorFragmentProfile o1, final MinorFragmentProfile o2) { return Long.compare(o1.getLastUpdate(), o2.getLastUpdate()); } }; - final static Comparator<MinorFragmentProfile> lastProgressCompare = new Comparator<MinorFragmentProfile>() { + final static Comparator<MinorFragmentProfile> lastProgress = new Comparator<MinorFragmentProfile>() { public int compare(final MinorFragmentProfile o1, final MinorFragmentProfile o2) { return Long.compare(o1.getLastProgress(), o2.getLastProgress()); } }; - final static Comparator<MinorFragmentProfile> endTimeCompare = new Comparator<MinorFragmentProfile>() { + final static Comparator<MinorFragmentProfile> endTime = new Comparator<MinorFragmentProfile>() { public int compare(final MinorFragmentProfile o1, final MinorFragmentProfile o2) { return Long.compare(o1.getEndTime(), o2.getEndTime()); } }; - final static Comparator<MinorFragmentProfile> fragPeakMemAllocated = new Comparator<MinorFragmentProfile>() { + final static Comparator<MinorFragmentProfile> fragmentPeakMemory = new Comparator<MinorFragmentProfile>() { public int compare(final MinorFragmentProfile o1, final MinorFragmentProfile o2) { return Long.compare(o1.getMaxMemoryUsed(), o2.getMaxMemoryUsed()); } }; - final static Comparator<MinorFragmentProfile> runTimeCompare = new Comparator<MinorFragmentProfile>() { + final static Comparator<MinorFragmentProfile> runTime = new Comparator<MinorFragmentProfile>() { public int compare(final MinorFragmentProfile o1, final MinorFragmentProfile o2) { return Long.compare(o1.getEndTime() - o1.getStartTime(), o2.getEndTime() - o2.getStartTime()); } }; - final static Comparator<OperatorProfile> operatorIdCompare = new Comparator<OperatorProfile>() { + final static Comparator<OperatorProfile> operatorId = new Comparator<OperatorProfile>() { public int compare(final OperatorProfile o1, final OperatorProfile o2) { return Long.compare(o1.getOperatorId(), o2.getOperatorId()); } }; - final static Comparator<Pair<OperatorProfile, Integer>> setupTimeSort = new Comparator<Pair<OperatorProfile, Integer>>() { + final static Comparator<Pair<OperatorProfile, Integer>> setupTime = new Comparator<Pair<OperatorProfile, Integer>>() { public int compare(final Pair<OperatorProfile, Integer> o1, final Pair<OperatorProfile, Integer> o2) { return Long.compare(o1.getLeft().getSetupNanos(), o2.getLeft().getSetupNanos()); } }; - final static Comparator<Pair<OperatorProfile, Integer>> processTimeSort = new Comparator<Pair<OperatorProfile, Integer>>() { + final static Comparator<Pair<OperatorProfile, Integer>> processTime = new Comparator<Pair<OperatorProfile, Integer>>() { public int compare(final Pair<OperatorProfile, Integer> o1, final Pair<OperatorProfile, Integer> o2) { return Long.compare(o1.getLeft().getProcessNanos(), o2.getLeft().getProcessNanos()); } }; - final static Comparator<Pair<OperatorProfile, Integer>> waitTimeSort = new Comparator<Pair<OperatorProfile, Integer>>() { + final static Comparator<Pair<OperatorProfile, Integer>> waitTime = new Comparator<Pair<OperatorProfile, Integer>>() { public int compare(final Pair<OperatorProfile, Integer> o1, final Pair<OperatorProfile, Integer> o2) { return Long.compare(o1.getLeft().getWaitNanos(), o2.getLeft().getWaitNanos()); } }; - final static Comparator<Pair<OperatorProfile, Integer>> opPeakMem = new Comparator<Pair<OperatorProfile, Integer>>() { + final static Comparator<Pair<OperatorProfile, Integer>> operatorPeakMemory = new Comparator<Pair<OperatorProfile, Integer>>() { public int compare(final Pair<OperatorProfile, Integer> o1, final Pair<OperatorProfile, Integer> o2) { return Long.compare(o1.getLeft().getPeakLocalMemoryAllocated(), o2.getLeft().getPeakLocalMemoryAllocated()); } http://git-wip-us.apache.org/repos/asf/drill/blob/891fa1aa/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/FragmentWrapper.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/FragmentWrapper.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/FragmentWrapper.java index e395e3e..2a8b564 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/FragmentWrapper.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/FragmentWrapper.java @@ -19,6 +19,7 @@ package org.apache.drill.exec.server.rest.profile; import java.util.ArrayList; import java.util.Collections; +import java.util.List; import org.apache.drill.exec.proto.UserBitShared.MajorFragmentProfile; import org.apache.drill.exec.proto.UserBitShared.MinorFragmentProfile; @@ -28,6 +29,9 @@ import org.apache.drill.exec.proto.UserBitShared.StreamProfile; import com.google.common.base.Preconditions; import com.google.common.collect.Collections2; +/** + * Wrapper class for a major fragment profile. + */ public class FragmentWrapper { private final MajorFragmentProfile major; private final long start; @@ -54,78 +58,75 @@ public class FragmentWrapper { public void addSummary(TableBuilder tb) { final String fmt = " (%d)"; - final long t0 = start; - final ArrayList<MinorFragmentProfile> complete = new ArrayList<MinorFragmentProfile>( - Collections2.filter(major.getMinorFragmentProfileList(), Filters.hasOperatorsAndTimes)); + // Use only minor fragments that have complete profiles + // Complete iff the fragment profile has at least one operator profile, and start and end times. + final List<MinorFragmentProfile> complete = new ArrayList<>( + Collections2.filter(major.getMinorFragmentProfileList(), Filters.hasOperatorsAndTimes)); tb.appendCell(new OperatorPathBuilder().setMajor(major).build(), null); tb.appendCell(complete.size() + " / " + major.getMinorFragmentProfileCount(), null); + // If there are no stats to aggregate, create an empty row if (complete.size() < 1) { tb.appendRepeated("", null, NUM_NULLABLE_OVERVIEW_COLUMNS); return; } - final MinorFragmentProfile firstStart = Collections.min(complete, Comparators.startTimeCompare); - final MinorFragmentProfile lastStart = Collections.max(complete, Comparators.startTimeCompare); - tb.appendMillis(firstStart.getStartTime() - t0, String.format(fmt, firstStart.getMinorFragmentId())); - tb.appendMillis(lastStart.getStartTime() - t0, String.format(fmt, lastStart.getMinorFragmentId())); + final MinorFragmentProfile firstStart = Collections.min(complete, Comparators.startTime); + final MinorFragmentProfile lastStart = Collections.max(complete, Comparators.startTime); + tb.appendMillis(firstStart.getStartTime() - start, String.format(fmt, firstStart.getMinorFragmentId())); + tb.appendMillis(lastStart.getStartTime() - start, String.format(fmt, lastStart.getMinorFragmentId())); - final MinorFragmentProfile firstEnd = Collections.min(complete, Comparators.endTimeCompare); - final MinorFragmentProfile lastEnd = Collections.max(complete, Comparators.endTimeCompare); - tb.appendMillis(firstEnd.getEndTime() - t0, String.format(fmt, firstEnd.getMinorFragmentId())); - tb.appendMillis(lastEnd.getEndTime() - t0, String.format(fmt, lastEnd.getMinorFragmentId())); + final MinorFragmentProfile firstEnd = Collections.min(complete, Comparators.endTime); + final MinorFragmentProfile lastEnd = Collections.max(complete, Comparators.endTime); + tb.appendMillis(firstEnd.getEndTime() - start, String.format(fmt, firstEnd.getMinorFragmentId())); + tb.appendMillis(lastEnd.getEndTime() - start, String.format(fmt, lastEnd.getMinorFragmentId())); long total = 0; for (final MinorFragmentProfile p : complete) { total += p.getEndTime() - p.getStartTime(); } - final MinorFragmentProfile shortRun = Collections.min(complete, Comparators.endTimeCompare); - final MinorFragmentProfile longRun = Collections.max(complete, Comparators.endTimeCompare); - + final MinorFragmentProfile shortRun = Collections.min(complete, Comparators.runTime); + final MinorFragmentProfile longRun = Collections.max(complete, Comparators.runTime); tb.appendMillis(shortRun.getEndTime() - shortRun.getStartTime(), String.format(fmt, shortRun.getMinorFragmentId())); - tb.appendMillis((long) (total / complete.size()), null); + tb.appendMillis(total / complete.size(), null); tb.appendMillis(longRun.getEndTime() - longRun.getStartTime(), String.format(fmt, longRun.getMinorFragmentId())); - final MinorFragmentProfile lastUpdate = Collections.max(complete, Comparators.lastUpdateCompare); + final MinorFragmentProfile lastUpdate = Collections.max(complete, Comparators.lastUpdate); tb.appendTime(lastUpdate.getLastUpdate(), null); - final MinorFragmentProfile lastProgress = Collections.max(complete, Comparators.lastProgressCompare); + final MinorFragmentProfile lastProgress = Collections.max(complete, Comparators.lastProgress); tb.appendTime(lastProgress.getLastProgress(), null); - final MinorFragmentProfile maxMem = Collections.max(complete, Comparators.fragPeakMemAllocated); + // TODO(DRILL-3494): Names (maxMem, getMaxMemoryUsed) are misleading; the value is peak memory allocated to fragment + final MinorFragmentProfile maxMem = Collections.max(complete, Comparators.fragmentPeakMemory); tb.appendBytes(maxMem.getMaxMemoryUsed(), null); } - public String getContent() { - return majorFragmentTimingProfile(major); - } - public static final String[] FRAGMENT_COLUMNS = {"Minor Fragment ID", "Host Name", "Start", "End", "Runtime", "Max Records", "Max Batches", "Last Update", "Last Progress", "Peak Memory", "State"}; // Not including minor fragment ID private static final int NUM_NULLABLE_FRAGMENTS_COLUMNS = FRAGMENT_COLUMNS.length - 1; - public String majorFragmentTimingProfile(final MajorFragmentProfile major) { + public String getContent() { final TableBuilder builder = new TableBuilder(FRAGMENT_COLUMNS); - ArrayList<MinorFragmentProfile> complete, incomplete; - complete = new ArrayList<MinorFragmentProfile>(Collections2.filter( - major.getMinorFragmentProfileList(), Filters.hasOperatorsAndTimes)); - incomplete = new ArrayList<MinorFragmentProfile>(Collections2.filter( - major.getMinorFragmentProfileList(), Filters.missingOperatorsOrTimes)); + // Use only minor fragments that have complete profiles + // Complete iff the fragment profile has at least one operator profile, and start and end times. + final List<MinorFragmentProfile> complete = new ArrayList<>( + Collections2.filter(major.getMinorFragmentProfileList(), Filters.hasOperatorsAndTimes)); + final List<MinorFragmentProfile> incomplete = new ArrayList<>( + Collections2.filter(major.getMinorFragmentProfileList(), Filters.missingOperatorsOrTimes)); - Collections.sort(complete, Comparators.minorIdCompare); + Collections.sort(complete, Comparators.minorId); for (final MinorFragmentProfile minor : complete) { - final ArrayList<OperatorProfile> ops = new ArrayList<OperatorProfile>(minor.getOperatorProfileList()); + final ArrayList<OperatorProfile> ops = new ArrayList<>(minor.getOperatorProfileList()); - final long t0 = start; long biggestIncomingRecords = 0; long biggestBatches = 0; - for (final OperatorProfile op : ops) { long incomingRecords = 0; long batches = 0; @@ -139,8 +140,8 @@ public class FragmentWrapper { builder.appendCell(new OperatorPathBuilder().setMajor(major).setMinor(minor).build(), null); builder.appendCell(minor.getEndpoint().getAddress(), null); - builder.appendMillis(minor.getStartTime() - t0, null); - builder.appendMillis(minor.getEndTime() - t0, null); + builder.appendMillis(minor.getStartTime() - start, null); + builder.appendMillis(minor.getEndTime() - start, null); builder.appendMillis(minor.getEndTime() - minor.getStartTime(), null); builder.appendFormattedInteger(biggestIncomingRecords, null); @@ -148,15 +149,15 @@ public class FragmentWrapper { builder.appendTime(minor.getLastUpdate(), null); builder.appendTime(minor.getLastProgress(), null); + builder.appendBytes(minor.getMaxMemoryUsed(), null); builder.appendCell(minor.getState().name(), null); } + for (final MinorFragmentProfile m : incomplete) { - builder.appendCell( - major.getMajorFragmentId() + "-" - + m.getMinorFragmentId(), null); + builder.appendCell(major.getMajorFragmentId() + "-" + m.getMinorFragmentId(), null); builder.appendRepeated(m.getState().toString(), null, NUM_NULLABLE_FRAGMENTS_COLUMNS); } - return builder.toString(); + return builder.build(); } } http://git-wip-us.apache.org/repos/asf/drill/blob/891fa1aa/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/OperatorWrapper.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/OperatorWrapper.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/OperatorWrapper.java index 403a23f..2e972b0 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/OperatorWrapper.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/OperatorWrapper.java @@ -20,26 +20,36 @@ package org.apache.drill.exec.server.rest.profile; import java.util.Collections; import java.util.List; +import com.google.common.base.Preconditions; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.drill.exec.proto.UserBitShared.CoreOperatorType; import org.apache.drill.exec.proto.UserBitShared.OperatorProfile; import org.apache.drill.exec.proto.UserBitShared.StreamProfile; +/** + * Wrapper class for profiles of ALL operator instances of the same operator type within a major fragment. + */ public class OperatorWrapper { + private static final String format = " (%s)"; + private final int major; - private List<ImmutablePair<OperatorProfile, Integer>> ops; + private final List<ImmutablePair<OperatorProfile, Integer>> ops; + private final OperatorProfile firstProfile; + private final CoreOperatorType operatorType; + private final int size; public OperatorWrapper(int major, List<ImmutablePair<OperatorProfile, Integer>> ops) { - assert ops.size() > 0; + Preconditions.checkArgument(ops.size() > 0); this.major = major; + firstProfile = ops.get(0).getLeft(); + operatorType = CoreOperatorType.valueOf(firstProfile.getOperatorType()); this.ops = ops; + size = ops.size(); } public String getDisplayName() { - OperatorProfile op = ops.get(0).getLeft(); - String path = new OperatorPathBuilder().setMajor(major).setOperator(op).build(); - CoreOperatorType operatorType = CoreOperatorType.valueOf(op.getOperatorType()); - return String.format("%s - %s", path, operatorType == null ? "UKNOWN_OPERATOR" : operatorType.toString()); + final String path = new OperatorPathBuilder().setMajor(major).setOperator(firstProfile).build(); + return String.format("%s - %s", path, operatorType == null ? "UNKNOWN_OPERATOR" : operatorType.toString()); } public String getId() { @@ -73,7 +83,7 @@ public class OperatorWrapper { builder.appendFormattedInteger(maxRecords, null); builder.appendBytes(op.getPeakLocalMemoryAllocated(), null); } - return builder.toString(); + return builder.build(); } public static final String[] OPERATORS_OVERVIEW_COLUMNS = {"Operator ID", "Type", "Min Setup Time", "Avg Setup Time", @@ -81,45 +91,43 @@ public class OperatorWrapper { "Max Wait Time", "Avg Peak Memory", "Max Peak Memory"}; public void addSummary(TableBuilder tb) { - OperatorProfile op = ops.get(0).getLeft(); - String path = new OperatorPathBuilder().setMajor(major).setOperator(op).build(); + + String path = new OperatorPathBuilder().setMajor(major).setOperator(firstProfile).build(); tb.appendCell(path, null); - CoreOperatorType operatorType = CoreOperatorType.valueOf(ops.get(0).getLeft().getOperatorType()); tb.appendCell(operatorType == null ? "UNKNOWN_OPERATOR" : operatorType.toString(), null); - String fmt = " (%s)"; - double setupSum = 0.0; double processSum = 0.0; double waitSum = 0.0; double memSum = 0.0; for (ImmutablePair<OperatorProfile, Integer> ip : ops) { - setupSum += ip.getLeft().getSetupNanos(); - processSum += ip.getLeft().getProcessNanos(); - waitSum += ip.getLeft().getWaitNanos(); - memSum += ip.getLeft().getPeakLocalMemoryAllocated(); + OperatorProfile profile = ip.getLeft(); + setupSum += profile.getSetupNanos(); + processSum += profile.getProcessNanos(); + waitSum += profile.getWaitNanos(); + memSum += profile.getPeakLocalMemoryAllocated(); } - final ImmutablePair<OperatorProfile, Integer> shortSetup = Collections.min(ops, Comparators.setupTimeSort); - final ImmutablePair<OperatorProfile, Integer> longSetup = Collections.max(ops, Comparators.setupTimeSort); - tb.appendNanos(shortSetup.getLeft().getSetupNanos(), String.format(fmt, shortSetup.getRight())); - tb.appendNanos((long) (setupSum / ops.size()), null); - tb.appendNanos(longSetup.getLeft().getSetupNanos(), String.format(fmt, longSetup.getRight())); - - final ImmutablePair<OperatorProfile, Integer> shortProcess = Collections.min(ops, Comparators.processTimeSort); - final ImmutablePair<OperatorProfile, Integer> longProcess = Collections.max(ops, Comparators.processTimeSort); - tb.appendNanos(shortProcess.getLeft().getProcessNanos(), String.format(fmt, shortProcess.getRight())); - tb.appendNanos((long) (processSum / ops.size()), null); - tb.appendNanos(longProcess.getLeft().getProcessNanos(), String.format(fmt, longProcess.getRight())); - - final ImmutablePair<OperatorProfile, Integer> shortWait = Collections.min(ops, Comparators.waitTimeSort); - final ImmutablePair<OperatorProfile, Integer> longWait = Collections.max(ops, Comparators.waitTimeSort); - tb.appendNanos(shortWait.getLeft().getWaitNanos(), String.format(fmt, shortWait.getRight())); - tb.appendNanos((long) (waitSum / ops.size()), null); - tb.appendNanos(longWait.getLeft().getWaitNanos(), String.format(fmt, longWait.getRight())); - - final ImmutablePair<OperatorProfile, Integer> peakMem = Collections.max(ops, Comparators.opPeakMem); - tb.appendBytes(Math.round(memSum / ops.size()), null); + final ImmutablePair<OperatorProfile, Integer> shortSetup = Collections.min(ops, Comparators.setupTime); + final ImmutablePair<OperatorProfile, Integer> longSetup = Collections.max(ops, Comparators.setupTime); + tb.appendNanos(shortSetup.getLeft().getSetupNanos(), String.format(format, shortSetup.getRight())); + tb.appendNanos(Math.round(setupSum / size), null); + tb.appendNanos(longSetup.getLeft().getSetupNanos(), String.format(format, longSetup.getRight())); + + final ImmutablePair<OperatorProfile, Integer> shortProcess = Collections.min(ops, Comparators.processTime); + final ImmutablePair<OperatorProfile, Integer> longProcess = Collections.max(ops, Comparators.processTime); + tb.appendNanos(shortProcess.getLeft().getProcessNanos(), String.format(format, shortProcess.getRight())); + tb.appendNanos(Math.round(processSum / size), null); + tb.appendNanos(longProcess.getLeft().getProcessNanos(), String.format(format, longProcess.getRight())); + + final ImmutablePair<OperatorProfile, Integer> shortWait = Collections.min(ops, Comparators.waitTime); + final ImmutablePair<OperatorProfile, Integer> longWait = Collections.max(ops, Comparators.waitTime); + tb.appendNanos(shortWait.getLeft().getWaitNanos(), String.format(format, shortWait.getRight())); + tb.appendNanos(Math.round(waitSum / size), null); + tb.appendNanos(longWait.getLeft().getWaitNanos(), String.format(format, longWait.getRight())); + + final ImmutablePair<OperatorProfile, Integer> peakMem = Collections.max(ops, Comparators.operatorPeakMemory); + tb.appendBytes(Math.round(memSum / size), null); tb.appendBytes(peakMem.getLeft().getPeakLocalMemoryAllocated(), null); } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/drill/blob/891fa1aa/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java index dd26a76..7de05c1 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/ProfileWrapper.java @@ -19,6 +19,7 @@ package org.apache.drill.exec.server.rest.profile; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,55 +31,50 @@ import org.apache.drill.exec.proto.UserBitShared.OperatorProfile; import org.apache.drill.exec.proto.UserBitShared.QueryProfile; import org.apache.drill.exec.proto.helper.QueryIdHelper; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - +/** + * This class contains information presented in the query profile web UI. + */ public class ProfileWrapper { +// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ProfileWrapper.class); - public QueryProfile profile; - public String id; + private QueryProfile profile; + private String id; + private final List<FragmentWrapper> fragmentProfiles; + private final List<OperatorWrapper> operatorProfiles; public ProfileWrapper(final QueryProfile profile) { this.profile = profile; this.id = QueryIdHelper.getQueryId(profile.getId()); - } - - public boolean hasError() { - return profile.hasError() && profile.getError() != null; - } - public QueryProfile getProfile() { - return profile; - } + final List<FragmentWrapper> fragmentProfiles = new ArrayList<>(); - public String getId() { - return id; - } + final List<MajorFragmentProfile> majors = new ArrayList<>(profile.getFragmentProfileList()); + Collections.sort(majors, Comparators.majorId); - public String getQueryId() { - return QueryIdHelper.getQueryId(profile.getId()); - } + for (final MajorFragmentProfile major : majors) { + fragmentProfiles.add(new FragmentWrapper(major, profile.getStart())); + } + this.fragmentProfiles = fragmentProfiles; - public List<OperatorWrapper> getOperatorProfiles() { - final List<OperatorWrapper> ows = Lists.newArrayList(); - final Map<ImmutablePair<Integer, Integer>, List<ImmutablePair<OperatorProfile, Integer>>> opmap = Maps.newHashMap(); + final List<OperatorWrapper> ows = new ArrayList<>(); + // temporary map to store (major_id, operator_id) -> [(op_profile, minor_id)] + final Map<ImmutablePair<Integer, Integer>, List<ImmutablePair<OperatorProfile, Integer>>> opmap = new HashMap<>(); - final List<MajorFragmentProfile> majors = new ArrayList<>(profile.getFragmentProfileList()); - Collections.sort(majors, Comparators.majorIdCompare); + Collections.sort(majors, Comparators.majorId); for (final MajorFragmentProfile major : majors) { final List<MinorFragmentProfile> minors = new ArrayList<>(major.getMinorFragmentProfileList()); - Collections.sort(minors, Comparators.minorIdCompare); + Collections.sort(minors, Comparators.minorId); for (final MinorFragmentProfile minor : minors) { final List<OperatorProfile> ops = new ArrayList<>(minor.getOperatorProfileList()); - Collections.sort(ops, Comparators.operatorIdCompare); + Collections.sort(ops, Comparators.operatorId); for (final OperatorProfile op : ops) { final ImmutablePair<Integer, Integer> ip = new ImmutablePair<>( major.getMajorFragmentId(), op.getOperatorId()); if (!opmap.containsKey(ip)) { - final List<ImmutablePair<OperatorProfile, Integer>> l = Lists.newArrayList(); + final List<ImmutablePair<OperatorProfile, Integer>> l = new ArrayList<>(); opmap.put(ip, l); } opmap.get(ip).add(new ImmutablePair<>(op, minor.getMinorFragmentId())); @@ -92,38 +88,43 @@ public class ProfileWrapper { for (final ImmutablePair<Integer, Integer> ip : keys) { ows.add(new OperatorWrapper(ip.getLeft(), opmap.get(ip))); } + this.operatorProfiles = ows; + } - return ows; + public boolean hasError() { + return profile.hasError() && profile.getError() != null; } - public List<FragmentWrapper> getFragmentProfiles() { - final List<FragmentWrapper> fws = Lists.newArrayList(); + public QueryProfile getProfile() { + return profile; + } - final List<MajorFragmentProfile> majors = new ArrayList<>(profile.getFragmentProfileList()); - Collections.sort(majors, Comparators.majorIdCompare); - for (final MajorFragmentProfile major : majors) { - fws.add(new FragmentWrapper(major, profile.getStart())); - } + public String getQueryId() { + return id; + } - return fws; + public List<FragmentWrapper> getFragmentProfiles() { + return fragmentProfiles; } public String getFragmentsOverview() { TableBuilder tb = new TableBuilder(FragmentWrapper.FRAGMENT_OVERVIEW_COLUMNS); - for (final FragmentWrapper fw : getFragmentProfiles()) { + for (final FragmentWrapper fw : fragmentProfiles) { fw.addSummary(tb); } - return tb.toString(); + return tb.build(); } - + public List<OperatorWrapper> getOperatorProfiles() { + return operatorProfiles; + } public String getOperatorsOverview() { final TableBuilder tb = new TableBuilder(OperatorWrapper.OPERATORS_OVERVIEW_COLUMNS); - for (final OperatorWrapper ow : getOperatorProfiles()) { + for (final OperatorWrapper ow : operatorProfiles) { ow.addSummary(tb); } - return tb.toString(); + return tb.build(); } public String getOperatorsJSON() { @@ -135,6 +136,4 @@ public class ProfileWrapper { } return sb.append("}").toString(); } - - } http://git-wip-us.apache.org/repos/asf/drill/blob/891fa1aa/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/TableBuilder.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/TableBuilder.java b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/TableBuilder.java index 8616820..bcc67f2 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/TableBuilder.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/profile/TableBuilder.java @@ -149,8 +149,7 @@ class TableBuilder { return "-"; } - @Override - public String toString() { + public String build() { String rv; rv = sb.append("\n</table>").toString(); sb = null; http://git-wip-us.apache.org/repos/asf/drill/blob/891fa1aa/exec/java-exec/src/main/resources/rest/profile/profile.ftl ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/resources/rest/profile/profile.ftl b/exec/java-exec/src/main/resources/rest/profile/profile.ftl index 46cdc83..47c7e06 100644 --- a/exec/java-exec/src/main/resources/rest/profile/profile.ftl +++ b/exec/java-exec/src/main/resources/rest/profile/profile.ftl @@ -71,7 +71,7 @@ </div> <button type="submit" class="btn btn-default">Re-run query</button> </form> - <form action="/profiles/cancel/${model.id}" method="GET"> + <form action="/profiles/cancel/${model.queryId}" method="GET"> <button type="link" class="btn btn-default">Cancel query</button> </form> </div> @@ -82,8 +82,8 @@ ${model.getProfile().error?trim} </pre> </p> - <p>ErrorId: ${model.getProfile().errorNode}</p> - <p>Failure node: ${model.getProfile().errorId}</p> + <p>Failure node: ${model.getProfile().errorNode}</p> + <p>Error ID: ${model.getProfile().errorId}</p> <h3 class="panel-title"> <a data-toggle="collapse" href="#error-verbose">
