PipelineStats.java
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.operator;
import com.facebook.airlift.stats.Distribution.DistributionSnapshot;
import com.facebook.drift.annotations.ThriftConstructor;
import com.facebook.drift.annotations.ThriftField;
import com.facebook.drift.annotations.ThriftStruct;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import java.util.List;
import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
@Immutable
@ThriftStruct
public class PipelineStats
{
private final int pipelineId;
private final long firstStartTimeInMillis;
private final long lastStartTimeInMillis;
private final long lastEndTimeInMillis;
private final boolean inputPipeline;
private final boolean outputPipeline;
private final int totalDrivers;
private final int queuedDrivers;
private final int queuedPartitionedDrivers;
private final long queuedPartitionedSplitsWeight;
private final int runningDrivers;
private final int runningPartitionedDrivers;
private final long runningPartitionedSplitsWeight;
private final int blockedDrivers;
private final int completedDrivers;
private final long userMemoryReservationInBytes;
private final long revocableMemoryReservationInBytes;
private final long systemMemoryReservationInBytes;
private final DistributionSnapshot queuedTime;
private final DistributionSnapshot elapsedTime;
private final long totalScheduledTimeInNanos;
private final long totalCpuTimeInNanos;
private final long totalBlockedTimeInNanos;
private final boolean fullyBlocked;
private final Set<BlockedReason> blockedReasons;
private final long totalAllocationInBytes;
private final long rawInputDataSizeInBytes;
private final long rawInputPositions;
private final long processedInputDataSizeInBytes;
private final long processedInputPositions;
private final long outputDataSizeInBytes;
private final long outputPositions;
private final long physicalWrittenDataSizeInBytes;
private final List<OperatorStats> operatorSummaries;
private final List<DriverStats> drivers;
@JsonCreator
@ThriftConstructor
public PipelineStats(
@JsonProperty("pipelineId") int pipelineId,
@JsonProperty("firstStartTimeInMillis") long firstStartTimeInMillis,
@JsonProperty("lastStartTimeInMillis") long lastStartTimeInMillis,
@JsonProperty("lastEndTimeInMillis") long lastEndTimeInMillis,
@JsonProperty("inputPipeline") boolean inputPipeline,
@JsonProperty("outputPipeline") boolean outputPipeline,
@JsonProperty("totalDrivers") int totalDrivers,
@JsonProperty("queuedDrivers") int queuedDrivers,
@JsonProperty("queuedPartitionedDrivers") int queuedPartitionedDrivers,
@JsonProperty("queuedPartitionedSplitsWeight") long queuedPartitionedSplitsWeight,
@JsonProperty("runningDrivers") int runningDrivers,
@JsonProperty("runningPartitionedDrivers") int runningPartitionedDrivers,
@JsonProperty("runningPartitionedSplitsWeight") long runningPartitionedSplitsWeight,
@JsonProperty("blockedDrivers") int blockedDrivers,
@JsonProperty("completedDrivers") int completedDrivers,
@JsonProperty("userMemoryReservationInBytes") long userMemoryReservationInBytes,
@JsonProperty("revocableMemoryReservationInBytes") long revocableMemoryReservationInBytes,
@JsonProperty("systemMemoryReservationInBytes") long systemMemoryReservationInBytes,
@JsonProperty("queuedTime") DistributionSnapshot queuedTime,
@JsonProperty("elapsedTime") DistributionSnapshot elapsedTime,
@JsonProperty("totalScheduledTimeInNanos") long totalScheduledTimeInNanos,
@JsonProperty("totalCpuTimeInNanos") long totalCpuTimeInNanos,
@JsonProperty("totalBlockedTimeInNanos") long totalBlockedTimeInNanos,
@JsonProperty("fullyBlocked") boolean fullyBlocked,
@JsonProperty("blockedReasons") Set<BlockedReason> blockedReasons,
@JsonProperty("totalAllocationInBytes") long totalAllocationInBytes,
@JsonProperty("rawInputDataSizeInBytes") long rawInputDataSizeInBytes,
@JsonProperty("rawInputPositions") long rawInputPositions,
@JsonProperty("processedInputDataSizeInBytes") long processedInputDataSizeInBytes,
@JsonProperty("processedInputPositions") long processedInputPositions,
@JsonProperty("outputDataSizeInBytes") long outputDataSizeInBytes,
@JsonProperty("outputPositions") long outputPositions,
@JsonProperty("physicalWrittenDataSizeInBytes") long physicalWrittenDataSizeInBytes,
@JsonProperty("operatorSummaries") List<OperatorStats> operatorSummaries,
@JsonProperty("drivers") List<DriverStats> drivers)
{
this.pipelineId = pipelineId;
this.firstStartTimeInMillis = firstStartTimeInMillis;
this.lastStartTimeInMillis = lastStartTimeInMillis;
this.lastEndTimeInMillis = lastEndTimeInMillis;
this.inputPipeline = inputPipeline;
this.outputPipeline = outputPipeline;
checkArgument(totalDrivers >= 0, "totalDrivers is negative");
this.totalDrivers = totalDrivers;
checkArgument(queuedDrivers >= 0, "queuedDrivers is negative");
this.queuedDrivers = queuedDrivers;
checkArgument(queuedPartitionedDrivers >= 0, "queuedPartitionedDrivers is negative");
this.queuedPartitionedDrivers = queuedPartitionedDrivers;
checkArgument(queuedPartitionedSplitsWeight >= 0, "queuedPartitionedSplitsWeight must be non-negative");
this.queuedPartitionedSplitsWeight = queuedPartitionedSplitsWeight;
checkArgument(runningDrivers >= 0, "runningDrivers is negative");
this.runningDrivers = runningDrivers;
checkArgument(runningPartitionedDrivers >= 0, "runningPartitionedDrivers is negative");
this.runningPartitionedDrivers = runningPartitionedDrivers;
checkArgument(runningPartitionedSplitsWeight >= 0, "runningPartitionedSplitsWeight must be non-negative");
this.runningPartitionedSplitsWeight = runningPartitionedSplitsWeight;
checkArgument(blockedDrivers >= 0, "blockedDrivers is negative");
this.blockedDrivers = blockedDrivers;
checkArgument(completedDrivers >= 0, "completedDrivers is negative");
this.completedDrivers = completedDrivers;
this.userMemoryReservationInBytes = userMemoryReservationInBytes;
this.revocableMemoryReservationInBytes = revocableMemoryReservationInBytes;
this.systemMemoryReservationInBytes = systemMemoryReservationInBytes;
this.queuedTime = requireNonNull(queuedTime, "queuedTime is null");
this.elapsedTime = requireNonNull(elapsedTime, "elapsedTime is null");
this.totalScheduledTimeInNanos = totalScheduledTimeInNanos;
this.totalCpuTimeInNanos = totalCpuTimeInNanos;
this.totalBlockedTimeInNanos = totalBlockedTimeInNanos;
this.fullyBlocked = fullyBlocked;
this.blockedReasons = ImmutableSet.copyOf(requireNonNull(blockedReasons, "blockedReasons is null"));
this.totalAllocationInBytes = totalAllocationInBytes;
this.rawInputDataSizeInBytes = rawInputDataSizeInBytes;
checkArgument(rawInputPositions >= 0, "rawInputPositions is negative");
this.rawInputPositions = rawInputPositions;
this.processedInputDataSizeInBytes = processedInputDataSizeInBytes;
checkArgument(processedInputPositions >= 0, "processedInputPositions is negative");
this.processedInputPositions = processedInputPositions;
this.outputDataSizeInBytes = outputDataSizeInBytes;
checkArgument(outputPositions >= 0, "outputPositions is negative");
this.outputPositions = outputPositions;
this.physicalWrittenDataSizeInBytes = physicalWrittenDataSizeInBytes;
this.operatorSummaries = ImmutableList.copyOf(requireNonNull(operatorSummaries, "operatorSummaries is null"));
this.drivers = ImmutableList.copyOf(requireNonNull(drivers, "drivers is null"));
}
@JsonProperty
@ThriftField(1)
public int getPipelineId()
{
return pipelineId;
}
@Nullable
@JsonProperty
@ThriftField(2)
public long getFirstStartTimeInMillis()
{
return firstStartTimeInMillis;
}
@Nullable
@JsonProperty
@ThriftField(3)
public long getLastStartTimeInMillis()
{
return lastStartTimeInMillis;
}
@Nullable
@JsonProperty
@ThriftField(4)
public long getLastEndTimeInMillis()
{
return lastEndTimeInMillis;
}
@JsonProperty
@ThriftField(5)
public boolean isInputPipeline()
{
return inputPipeline;
}
@JsonProperty
@ThriftField(6)
public boolean isOutputPipeline()
{
return outputPipeline;
}
@JsonProperty
@ThriftField(7)
public int getTotalDrivers()
{
return totalDrivers;
}
@JsonProperty
@ThriftField(8)
public int getQueuedDrivers()
{
return queuedDrivers;
}
@JsonProperty
@ThriftField(9)
public int getQueuedPartitionedDrivers()
{
return queuedPartitionedDrivers;
}
@JsonProperty
@ThriftField(10)
public long getQueuedPartitionedSplitsWeight()
{
return queuedPartitionedSplitsWeight;
}
@JsonProperty
@ThriftField(11)
public int getRunningDrivers()
{
return runningDrivers;
}
@JsonProperty
@ThriftField(12)
public int getRunningPartitionedDrivers()
{
return runningPartitionedDrivers;
}
@JsonProperty
@ThriftField(13)
public long getRunningPartitionedSplitsWeight()
{
return runningPartitionedSplitsWeight;
}
@JsonProperty
@ThriftField(14)
public int getBlockedDrivers()
{
return blockedDrivers;
}
@JsonProperty
@ThriftField(15)
public int getCompletedDrivers()
{
return completedDrivers;
}
@JsonProperty
@ThriftField(16)
public long getUserMemoryReservationInBytes()
{
return userMemoryReservationInBytes;
}
@JsonProperty
@ThriftField(17)
public long getRevocableMemoryReservationInBytes()
{
return revocableMemoryReservationInBytes;
}
@JsonProperty
@ThriftField(18)
public long getSystemMemoryReservationInBytes()
{
return systemMemoryReservationInBytes;
}
@JsonProperty
@ThriftField(19)
public DistributionSnapshot getQueuedTime()
{
return queuedTime;
}
@JsonProperty
@ThriftField(20)
public DistributionSnapshot getElapsedTime()
{
return elapsedTime;
}
@JsonProperty
@ThriftField(21)
public long getTotalScheduledTimeInNanos()
{
return totalScheduledTimeInNanos;
}
@JsonProperty
@ThriftField(22)
public long getTotalCpuTimeInNanos()
{
return totalCpuTimeInNanos;
}
@JsonProperty
@ThriftField(23)
public long getTotalBlockedTimeInNanos()
{
return totalBlockedTimeInNanos;
}
@JsonProperty
@ThriftField(24)
public boolean isFullyBlocked()
{
return fullyBlocked;
}
@JsonProperty
@ThriftField(25)
public Set<BlockedReason> getBlockedReasons()
{
return blockedReasons;
}
@JsonProperty
@ThriftField(26)
public long getTotalAllocationInBytes()
{
return totalAllocationInBytes;
}
@JsonProperty
@ThriftField(27)
public long getRawInputDataSizeInBytes()
{
return rawInputDataSizeInBytes;
}
@JsonProperty
@ThriftField(28)
public long getRawInputPositions()
{
return rawInputPositions;
}
@JsonProperty
@ThriftField(29)
public long getProcessedInputDataSizeInBytes()
{
return processedInputDataSizeInBytes;
}
@JsonProperty
@ThriftField(30)
public long getProcessedInputPositions()
{
return processedInputPositions;
}
@JsonProperty
@ThriftField(31)
public long getOutputDataSizeInBytes()
{
return outputDataSizeInBytes;
}
@JsonProperty
@ThriftField(32)
public long getOutputPositions()
{
return outputPositions;
}
@JsonProperty
@ThriftField(33)
public long getPhysicalWrittenDataSizeInBytes()
{
return physicalWrittenDataSizeInBytes;
}
@JsonProperty
@ThriftField(34)
public List<OperatorStats> getOperatorSummaries()
{
return operatorSummaries;
}
@JsonProperty
@ThriftField(35)
public List<DriverStats> getDrivers()
{
return drivers;
}
public PipelineStats summarize()
{
return new PipelineStats(
pipelineId,
firstStartTimeInMillis,
lastStartTimeInMillis,
lastEndTimeInMillis,
inputPipeline,
outputPipeline,
totalDrivers,
queuedDrivers,
queuedPartitionedDrivers,
queuedPartitionedSplitsWeight,
runningDrivers,
runningPartitionedDrivers,
runningPartitionedSplitsWeight,
blockedDrivers,
completedDrivers,
userMemoryReservationInBytes,
revocableMemoryReservationInBytes,
systemMemoryReservationInBytes,
queuedTime,
elapsedTime,
totalScheduledTimeInNanos,
totalCpuTimeInNanos,
totalBlockedTimeInNanos,
fullyBlocked,
blockedReasons,
totalAllocationInBytes,
rawInputDataSizeInBytes,
rawInputPositions,
processedInputDataSizeInBytes,
processedInputPositions,
outputDataSizeInBytes,
outputPositions,
physicalWrittenDataSizeInBytes,
summarizeOperatorStats(operatorSummaries),
ImmutableList.of());
}
private static List<OperatorStats> summarizeOperatorStats(List<OperatorStats> operatorSummaries)
{
// Use an exact size ImmutableList builder to avoid a redundant copy in the PipelineStats constructor
ImmutableList.Builder<OperatorStats> results = ImmutableList.builderWithExpectedSize(operatorSummaries.size());
for (OperatorStats operatorStats : operatorSummaries) {
results.add(operatorStats.summarize());
}
return results.build();
}
}