Differential D20200 Diff 48235 src/applications/daemon/controller/PhabricatorDaemonConsoleController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/daemon/controller/PhabricatorDaemonConsoleController.php
Show All 25 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$completed_info = array(); | $completed_info = array(); | ||||
foreach ($completed as $completed_task) { | foreach ($completed as $completed_task) { | ||||
$class = $completed_task->getTaskClass(); | $class = $completed_task->getTaskClass(); | ||||
if (empty($completed_info[$class])) { | if (empty($completed_info[$class])) { | ||||
$completed_info[$class] = array( | $completed_info[$class] = array( | ||||
'n' => 0, | 'n' => 0, | ||||
'duration' => 0, | 'duration' => 0, | ||||
'queueTime' => 0, | |||||
); | ); | ||||
} | } | ||||
$completed_info[$class]['n']++; | $completed_info[$class]['n']++; | ||||
$duration = $completed_task->getDuration(); | $duration = $completed_task->getDuration(); | ||||
$completed_info[$class]['duration'] += $duration; | $completed_info[$class]['duration'] += $duration; | ||||
// NOTE: Duration is in microseconds, but we're just using seconds to | // NOTE: Duration is in microseconds, but we're just using seconds to | ||||
// compute utilization. | // compute utilization. | ||||
$usage_total += $lease_overhead + ($duration / 1000000); | $usage_total += $lease_overhead + ($duration / 1000000); | ||||
$usage_start = min($usage_start, $completed_task->getDateModified()); | $usage_start = min($usage_start, $completed_task->getDateModified()); | ||||
$date_archived = $completed_task->getArchivedEpoch(); | |||||
$queue_seconds = $date_archived - $completed_task->getDateCreated(); | |||||
// Don't measure queue time for tasks that completed in the same | |||||
// epoch-second they were created in. | |||||
if ($queue_seconds > 0) { | |||||
$sec_in_us = phutil_units('1 second in microseconds'); | |||||
epriestley: (This needs a `libphutil/` patch too, right?) | |||||
Done Inline ActionsYep, D20201 just landed. amckinley: Yep, D20201 just landed. | |||||
$queue_us = $queue_seconds * $sec_in_us; | |||||
$queue_exclusive_us = $queue_us - $duration; | |||||
$queue_exclusive_seconds = $queue_exclusive_us / $sec_in_us; | |||||
$rounded = floor($queue_exclusive_seconds); | |||||
$completed_info[$class]['queueTime'] += $rounded; | |||||
} | |||||
} | } | ||||
$completed_info = isort($completed_info, 'n'); | $completed_info = isort($completed_info, 'n'); | ||||
$rows = array(); | $rows = array(); | ||||
foreach ($completed_info as $class => $info) { | foreach ($completed_info as $class => $info) { | ||||
$duration_avg = new PhutilNumber((int)($info['duration'] / $info['n'])); | |||||
$queue_avg = new PhutilNumber((int)($info['queueTime'] / $info['n'])); | |||||
$rows[] = array( | $rows[] = array( | ||||
$class, | $class, | ||||
number_format($info['n']), | number_format($info['n']), | ||||
pht('%s us', new PhutilNumber((int)($info['duration'] / $info['n']))), | pht('%s us', $duration_avg), | ||||
pht('%s s', $queue_avg), | |||||
); | ); | ||||
} | } | ||||
if ($failed) { | if ($failed) { | ||||
// Add the time it takes to restart the daemons. This includes a guess | // Add the time it takes to restart the daemons. This includes a guess | ||||
// about other overhead of 2X. | // about other overhead of 2X. | ||||
$restart_delay = PhutilDaemonHandle::getWaitBeforeRestart(); | $restart_delay = PhutilDaemonHandle::getWaitBeforeRestart(); | ||||
$usage_total += $restart_delay * count($failed) * 2; | $usage_total += $restart_delay * count($failed) * 2; | ||||
Show All 31 Lines | if ($taskmasters && $usage_total) { | ||||
// Percentage of those wall-time seconds we can account for, which the | // Percentage of those wall-time seconds we can account for, which the | ||||
// daemons spent doing work: | // daemons spent doing work: | ||||
$used_time = ($usage_total / $available_time); | $used_time = ($usage_total / $available_time); | ||||
$rows[] = array( | $rows[] = array( | ||||
phutil_tag('em', array(), pht('Queue Utilization (Approximate)')), | phutil_tag('em', array(), pht('Queue Utilization (Approximate)')), | ||||
sprintf('%.1f%%', 100 * $used_time), | sprintf('%.1f%%', 100 * $used_time), | ||||
null, | null, | ||||
null, | |||||
); | ); | ||||
} | } | ||||
$completed_table = new AphrontTableView($rows); | $completed_table = new AphrontTableView($rows); | ||||
$completed_table->setNoDataString( | $completed_table->setNoDataString( | ||||
pht('No tasks have completed in the last 15 minutes.')); | pht('No tasks have completed in the last 15 minutes.')); | ||||
$completed_table->setHeaders( | $completed_table->setHeaders( | ||||
array( | array( | ||||
pht('Class'), | pht('Class'), | ||||
pht('Count'), | pht('Count'), | ||||
pht('Avg'), | pht('Average Duration'), | ||||
pht('Average Queue Time'), | |||||
)); | )); | ||||
$completed_table->setColumnClasses( | $completed_table->setColumnClasses( | ||||
array( | array( | ||||
'wide', | 'wide', | ||||
'n', | 'n', | ||||
'n', | 'n', | ||||
'n', | |||||
)); | )); | ||||
$completed_panel = id(new PHUIObjectBoxView()) | $completed_panel = id(new PHUIObjectBoxView()) | ||||
->setHeaderText(pht('Recently Completed Tasks (Last 15m)')) | ->setHeaderText(pht('Recently Completed Tasks (Last 15m)')) | ||||
->setTable($completed_table); | ->setTable($completed_table); | ||||
$daemon_table = id(new PhabricatorDaemonLogListView()) | $daemon_table = id(new PhabricatorDaemonLogListView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |
(This needs a libphutil/ patch too, right?)