From 417ca39703c825dd43f41740d075e69576bac9ac Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 May 2011 16:18:33 -0700 Subject: [PATCH] Update Phabricator to new PhutilServiceProfiler APIs Summary: Get rid of the Phabricator-level DarkConsole-specific API and use the more general Phutil-level one. Test Plan: Loaded DarkConsole services plugin, viewed Diffusion, got execs in the trace. Reviewed By: aran Reviewers: aran, jungejason, tuomaspelkonen CC: aran Differential Revision: 293 --- scripts/repository/parse_one_commit.php | 2 - src/__phutil_library_map__.php | 1 - .../services/DarkConsoleServicesPlugin.php | 21 ++++-- .../console/plugin/services/__init__.php | 2 +- .../api/DarkConsoleServicesPluginAPI.php | 43 ----------- .../console/plugin/services/api/__init__.php | 10 --- .../daemon/base/PhabricatorDaemon.php | 5 +- src/infrastructure/daemon/base/__init__.php | 1 - .../mysql/AphrontMySQLDatabaseConnection.php | 73 ++++++++++--------- src/storage/connection/mysql/__init__.php | 2 +- 10 files changed, 57 insertions(+), 103 deletions(-) delete mode 100644 src/aphront/console/plugin/services/api/DarkConsoleServicesPluginAPI.php delete mode 100644 src/aphront/console/plugin/services/api/__init__.php diff --git a/scripts/repository/parse_one_commit.php b/scripts/repository/parse_one_commit.php index a98586d4dd..750d4507c1 100755 --- a/scripts/repository/parse_one_commit.php +++ b/scripts/repository/parse_one_commit.php @@ -76,8 +76,6 @@ if (isset($argv[2]) && $argv[2] == '--herald') { $workers[] = new PhabricatorRepositoryCommitHeraldWorker($spec); } -ExecFuture::pushEchoMode(true); - foreach ($workers as $worker) { echo "Running ".get_class($worker)."...\n"; $worker->doWork(); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e5cf6a1c2a..8eb1a8db8e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -109,7 +109,6 @@ phutil_register_library_map(array( 'DarkConsolePlugin' => 'aphront/console/plugin/base', 'DarkConsoleRequestPlugin' => 'aphront/console/plugin/request', 'DarkConsoleServicesPlugin' => 'aphront/console/plugin/services', - 'DarkConsoleServicesPluginAPI' => 'aphront/console/plugin/services/api', 'DarkConsoleXHProfPlugin' => 'aphront/console/plugin/xhprof', 'DarkConsoleXHProfPluginAPI' => 'aphront/console/plugin/xhprof/api', 'DatabaseConfigurationProvider' => 'applications/base/storage/configuration', diff --git a/src/aphront/console/plugin/services/DarkConsoleServicesPlugin.php b/src/aphront/console/plugin/services/DarkConsoleServicesPlugin.php index 8c21dfbf55..91da2d5f01 100644 --- a/src/aphront/console/plugin/services/DarkConsoleServicesPlugin.php +++ b/src/aphront/console/plugin/services/DarkConsoleServicesPlugin.php @@ -29,7 +29,7 @@ class DarkConsoleServicesPlugin extends DarkConsolePlugin { } public function generateData() { - return DarkConsoleServicesPluginAPI::getEvents(); + return PhutilServiceProfiler::getInstance()->getServiceCallLog(); } public function render() { @@ -38,15 +38,22 @@ class DarkConsoleServicesPlugin extends DarkConsolePlugin { $rows = array(); foreach ($data as $row) { - switch ($row['event']) { - case DarkConsoleServicesPluginAPI::EVENT_QUERY: + switch ($row['type']) { + case 'query': $info = $row['query']; $info = phutil_escape_html($info); break; - case DarkConsoleServicesPluginAPI::EVENT_CONNECT: + case 'connect': $info = $row['host'].':'.$row['database']; $info = phutil_escape_html($info); - + break; + case 'exec': + $info = $row['command']; + $info = phutil_escape_html($info); + break; + case 'conduit': + $info = $row['method']; + $info = phutil_escape_html($info); break; default: $info = '-'; @@ -54,8 +61,8 @@ class DarkConsoleServicesPlugin extends DarkConsolePlugin { } $rows[] = array( - $row['event'], - number_format(1000000 * ($row['end'] - $row['start'])).' us', + phutil_escape_html($row['type']), + number_format(1000000 * $row['duration']).' us', $info, ); } diff --git a/src/aphront/console/plugin/services/__init__.php b/src/aphront/console/plugin/services/__init__.php index 3952c2ebd4..00234db119 100644 --- a/src/aphront/console/plugin/services/__init__.php +++ b/src/aphront/console/plugin/services/__init__.php @@ -7,10 +7,10 @@ phutil_require_module('phabricator', 'aphront/console/plugin/base'); -phutil_require_module('phabricator', 'aphront/console/plugin/services/api'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phutil', 'markup'); +phutil_require_module('phutil', 'serviceprofiler'); phutil_require_source('DarkConsoleServicesPlugin.php'); diff --git a/src/aphront/console/plugin/services/api/DarkConsoleServicesPluginAPI.php b/src/aphront/console/plugin/services/api/DarkConsoleServicesPluginAPI.php deleted file mode 100644 index 23163081a2..0000000000 --- a/src/aphront/console/plugin/services/api/DarkConsoleServicesPluginAPI.php +++ /dev/null @@ -1,43 +0,0 @@ -getConfiguration('pass'), - $new_link = true, - $flags = 0); - - if (!$conn) { - $errno = mysql_errno(); - $error = mysql_error(); - throw new AphrontQueryConnectionException( - "Attempt to connect to {$user}@{$host} failed with error #{$errno}: ". - "{$error}."); - } - - if ($database !== null) { - $ret = @mysql_select_db($database, $conn); - if (!$ret) { - $this->throwQueryException($conn); - } - } - - $end = microtime(true); - - DarkConsoleServicesPluginAPI::addEvent( + $profiler = PhutilServiceProfiler::getInstance(); + $call_id = $profiler->beginServiceCall( array( - 'event' => DarkConsoleServicesPluginAPI::EVENT_CONNECT, + 'type' => 'connect', 'host' => $host, 'database' => $database, - 'start' => $start, - 'end' => $end, )); + try { + $conn = @mysql_connect( + $host, + $user, + $this->getConfiguration('pass'), + $new_link = true, + $flags = 0); + + if (!$conn) { + $errno = mysql_errno(); + $error = mysql_error(); + throw new AphrontQueryConnectionException( + "Attempt to connect to {$user}@{$host} failed with error #{$errno}: ". + "{$error}."); + } + + if ($database !== null) { + $ret = @mysql_select_db($database, $conn); + if (!$ret) { + $this->throwQueryException($conn); + } + } + + $profiler->endServiceCall($call_id, array()); + } catch (Exception $ex) { + $profiler->endServiceCall($call_id, array()); + throw $ex; + } + self::$connectionCache[$key] = $conn; $this->connection = $conn; } @@ -205,17 +209,18 @@ class AphrontMySQLDatabaseConnection extends AphrontDatabaseConnection { $this->requireConnection(); $start = microtime(true); - $result = @mysql_query($raw_query, $this->connection); - $end = microtime(true); - DarkConsoleServicesPluginAPI::addEvent( + $profiler = PhutilServiceProfiler::getInstance(); + $call_id = $profiler->beginServiceCall( array( - 'event' => DarkConsoleServicesPluginAPI::EVENT_QUERY, + 'type' => 'query', 'query' => $raw_query, - 'start' => $start, - 'end' => $end, )); + $result = @mysql_query($raw_query, $this->connection); + + $profiler->endServiceCall($call_id, array()); + if ($result) { $this->lastResult = $result; break; diff --git a/src/storage/connection/mysql/__init__.php b/src/storage/connection/mysql/__init__.php index ae66d4b178..f1ec809cb5 100644 --- a/src/storage/connection/mysql/__init__.php +++ b/src/storage/connection/mysql/__init__.php @@ -6,7 +6,6 @@ -phutil_require_module('phabricator', 'aphront/console/plugin/services/api'); phutil_require_module('phabricator', 'storage/connection/base'); phutil_require_module('phabricator', 'storage/exception/accessdenied'); phutil_require_module('phabricator', 'storage/exception/base'); @@ -15,6 +14,7 @@ phutil_require_module('phabricator', 'storage/exception/connectionlost'); phutil_require_module('phabricator', 'storage/exception/duplicatekey'); phutil_require_module('phabricator', 'storage/exception/recoverable'); +phutil_require_module('phutil', 'serviceprofiler'); phutil_require_module('phutil', 'utils');