public OperatorWrapper(int major, List<ImmutablePair<OperatorProfile, Integer>> ops, CoreOperatorTypeMetricsMap coreOperatorTypeMetricsMap) { Preconditions.checkArgument(ops.size() > 0); this.major = major; firstProfile = ops.get(0).getLeft(); operatorType = CoreOperatorType.valueOf(firstProfile.getOperatorType()); operatorName = operatorType == null ? "UNKNOWN_OPERATOR" : operatorType.toString(); this.coreOperatorTypeMetricsMap = Optional.ofNullable(coreOperatorTypeMetricsMap).orElse(OperatorMetricRegistry.getCoreOperatorTypeMetricsMap()); this.ops = ops; size = ops.size(); }
@SuppressWarnings("unused") public String getOperatorsJSON() { final StringBuilder sb = new StringBuilder("{"); String sep = ""; for (final CoreOperatorType op : CoreOperatorType.values()) { sb.append(String.format("%s\"%d\" : \"%s\"", sep, op.ordinal(), op)); sep = ", "; } return sb.append("}").toString(); }
public static CoreOperatorType valueOf( com.google.protobuf.Descriptors.EnumValueDescriptor desc) { if (desc.getType() != getDescriptor()) { throw new java.lang.IllegalArgumentException( "EnumValueDescriptor is not for this type."); } return VALUES[desc.getIndex()]; }
final CoreOperatorType operatorType = CoreOperatorType.valueOf(operatorProfile.getOperatorType());
final String[] metricNames = OperatorMetricRegistry.getMetricNames(operatorType.getNumber()); final Integer[] metricIds = OperatorMetricRegistry.getMetricIds(coreOperatorTypeMetricsMap, operatorType.getNumber()); int i = 1; for (final int metricId : metricIds) { Optional<MetricDef> metric = OperatorMetricRegistry.getMetricById(coreOperatorTypeMetricsMap, operatorType.getNumber(), metricId); assert metric.isPresent(); // Since metric id was retrieved from map, doing a reverse lookup shouldn't fail. metricIdToMetricTableColumnIndex.put(metricId, i - 1); final boolean isHashAgg = operatorType.getNumber() == CoreOperatorType.HASH_AGGREGATE_VALUE; final boolean toSkip = isHashAgg && renderingOldProfiles(op); final Number[] values = new Number[metricIds.length];
outputTable.addRow(String.format("Metrics for operator %s", CoreOperatorType.values()[operatorType], operatorId), String.format("id: %d.", operatorId)); outputTable.addRule(); outputTable.addRow("metric", "value");
@Test public void testGetMetricsTableHandlesNotRegisteredMetrics() { OperatorProfile op = OperatorProfile .newBuilder().addMetric( UserBitShared.MetricValue.newBuilder() .setMetricId(1) .setDoubleValue(200)) .addMetric( UserBitShared.MetricValue.newBuilder() .setMetricId(3) .setDoubleValue(21)) .setOperatorId(UserBitShared.CoreOperatorType.PARQUET_ROW_GROUP_SCAN.getNumber()) .build(); ImmutablePair<OperatorProfile, Integer> pair = new ImmutablePair<>(op, 1); OperatorWrapper ow = new OperatorWrapper(1, ImmutableList.of(pair), OperatorMetricRegistry.getCoreOperatorTypeMetricsMap()); String html = ow.getMetricsTable(); Pattern columnPattern = Pattern.compile("<td>.*?</td>"); Matcher matcher = columnPattern.matcher(html); int count = 0; while (matcher.find()){ count++; } // Unregistered metrics should not appear on profiles screen assertEquals(2, count); }
public final com.google.protobuf.Descriptors.EnumDescriptor getDescriptorForType() { return getDescriptor(); } public static final com.google.protobuf.Descriptors.EnumDescriptor
private void setSortSpillInfo(CoreOperatorType operatorType, OperatorProfile operatorProfile) { initSpillJobDetails(); final int operatorNumber = operatorType.getNumber(); Preconditions.checkState(operatorNumber == CoreOperatorType.EXTERNAL_SORT_VALUE); final List<UserBitShared.MetricValue> metricValues = operatorProfile.getMetricList(); for (UserBitShared.MetricValue metricValue : metricValues) { final int metricId = metricValue.getMetricId(); if (metricId == ExternalSortOperator.Metric.TOTAL_SPILLED_DATA_SIZE.ordinal() && metricValue.hasLongValue()) { spillJobDetails.setTotalBytesSpilledBySort(spillJobDetails.getTotalBytesSpilledBySort() + metricValue.getLongValue()); } } }
private void setAggSpillInfo(CoreOperatorType operatorType, OperatorProfile operatorProfile) { initSpillJobDetails(); final int operatorNumber = operatorType.getNumber(); Preconditions.checkState(operatorNumber == CoreOperatorType.HASH_AGGREGATE_VALUE); final List<UserBitShared.MetricValue> metricValues = operatorProfile.getMetricList(); for (UserBitShared.MetricValue metricValue : metricValues) { final int metricId = metricValue.getMetricId(); if (metricId == HashAggStats.Metric.TOTAL_SPILLED_DATA_SIZE.ordinal() && metricValue.hasLongValue()) { spillJobDetails.setTotalBytesSpilledByHashAgg(spillJobDetails.getTotalBytesSpilledByHashAgg() + metricValue.getLongValue()); } } }
public final com.google.protobuf.Descriptors.EnumValueDescriptor getValueDescriptor() { return getDescriptor().getValues().get(index); } public final com.google.protobuf.Descriptors.EnumDescriptor
private static CoreOperatorTypeMetricsMap.Builder getMapBuilder() { CoreOperatorTypeMetricsMap.Builder builder = CoreOperatorTypeMetricsMap.newBuilder(); for (int i = 0; i < CoreOperatorType.values().length; i++) { // Initalizing with metricsdef object with empty list => This can be modified later at the time of registration builder.addMetricsDef(MetricsDef.getDefaultInstance()); } return builder; }