Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions velox/exec/Task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,11 @@ ContinueFuture Task::terminate(TaskState terminalState) {
if (taskStats_.executionEndTimeMs == 0) {
taskStats_.executionEndTimeMs = getCurrentTimeMs();
}
if (taskStats_.terminationTimeMs == 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add unit test for this new timestamp? thanks!

// In case terminate gets called multiple times somehow,
// this represents the first time.
taskStats_.terminationTimeMs = getCurrentTimeMs();
}
if (not isRunningLocked()) {
return makeFinishFutureLocked("Task::terminate");
}
Expand Down Expand Up @@ -1944,6 +1949,14 @@ uint64_t Task::timeSinceEndMs() const {
return getCurrentTimeMs() - taskStats_.executionEndTimeMs;
}

uint64_t Task::timeSinceTerminationMs() const {
std::lock_guard<std::mutex> l(mutex_);
if (taskStats_.terminationTimeMs == 0UL) {
return 0UL;
}
return getCurrentTimeMs() - taskStats_.terminationTimeMs;
}

void Task::onTaskCompletion() {
listeners().withRLock([&](auto& listeners) {
if (listeners.empty()) {
Expand Down
4 changes: 4 additions & 0 deletions velox/exec/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ class Task : public std::enable_shared_from_this<Task> {
/// Returns time (ms) since the task execution ended or zero, if not finished.
uint64_t timeSinceEndMs() const;

/// Returns time (ms) since the task was terminated or zero, if not terminated
/// yet.
uint64_t timeSinceTerminationMs() const;

/// Returns the total number of drivers in the output pipeline, e.g. the
/// pipeline that produces the results.
uint32_t numOutputDrivers() const {
Expand Down
5 changes: 5 additions & 0 deletions velox/exec/TaskStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ struct TaskStats {
/// and results have been consumed.
uint64_t endTimeMs{0};

/// Epoch time (ms) when the task was terminated, i.e. its terminal state
/// has been set, whether by finishing successfully or with an error, or
/// being cancelled or aborted.
uint64_t terminationTimeMs{0};

/// Total number of drivers.
uint64_t numTotalDrivers{0};
/// The number of completed drivers (which slots are null in Task 'drivers_'
Expand Down