| 2317 | } |
| 2318 | |
| 2319 | TaskStats Task::taskStats() const { |
| 2320 | std::lock_guard<std::timed_mutex> l(mutex_); |
| 2321 | |
| 2322 | // 'taskStats_' contains task stats plus stats for the completed drivers |
| 2323 | // (their operators). |
| 2324 | TaskStats taskStats = taskStats_; |
| 2325 | |
| 2326 | taskStats.numTotalDrivers = drivers_.size(); |
| 2327 | |
| 2328 | // Add stats of the drivers (their operators) that are still running. |
| 2329 | for (const auto& driver : drivers_) { |
| 2330 | // Driver can be null. |
| 2331 | if (driver == nullptr) { |
| 2332 | ++taskStats.numCompletedDrivers; |
| 2333 | continue; |
| 2334 | } |
| 2335 | |
| 2336 | for (auto& op : driver->operators()) { |
| 2337 | auto statsCopy = op->stats(false); |
| 2338 | aggregateOperatorRuntimeStats(statsCopy.runtimeStats); |
| 2339 | addRunningTimeOperatorMetrics(statsCopy); |
| 2340 | taskStats.pipelineStats[statsCopy.pipelineId] |
| 2341 | .operatorStats[statsCopy.operatorId] |
| 2342 | .add(statsCopy); |
| 2343 | } |
| 2344 | if (driver->isOnThread()) { |
| 2345 | ++taskStats.numRunningDrivers; |
| 2346 | } else if (driver->isTerminated()) { |
| 2347 | ++taskStats.numTerminatedDrivers; |
| 2348 | } else { |
| 2349 | ++taskStats.numBlockedDrivers[driver->blockingReason()]; |
| 2350 | } |
| 2351 | // Find the longest running operator. |
| 2352 | auto ocs = driver->opCallStatus(); |
| 2353 | if (!ocs.empty()) { |
| 2354 | const auto callDuration = ocs.callDuration(); |
| 2355 | if (callDuration > taskStats.longestRunningOpCallMs) { |
| 2356 | taskStats.longestRunningOpCall = |
| 2357 | ocs.formatCall(driver->findOperatorNoThrow(ocs.opId), ocs.method); |
| 2358 | taskStats.longestRunningOpCallMs = callDuration; |
| 2359 | } |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | // Don't bother with operator calls running under 30 seconds. |
| 2364 | if (taskStats.longestRunningOpCallMs < 30000) { |
| 2365 | taskStats.longestRunningOpCall.clear(); |
| 2366 | taskStats.longestRunningOpCallMs = 0; |
| 2367 | } |
| 2368 | |
| 2369 | auto bufferManager = bufferManager_.lock(); |
| 2370 | taskStats.outputBufferUtilization = bufferManager->getUtilization(taskId_); |
| 2371 | taskStats.outputBufferOverutilized = bufferManager->isOverutilized(taskId_); |
| 2372 | taskStats.outputBufferStats = bufferManager->stats(taskId_); |
| 2373 | return taskStats; |
| 2374 | } |
| 2375 | |
| 2376 | bool Task::getLongRunningOpCalls( |