1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-28 00:10:57 +01:00

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
This commit is contained in:
epriestley 2011-05-16 16:18:33 -07:00
parent a69f217f98
commit 417ca39703
10 changed files with 57 additions and 103 deletions

View file

@ -76,8 +76,6 @@ if (isset($argv[2]) && $argv[2] == '--herald') {
$workers[] = new PhabricatorRepositoryCommitHeraldWorker($spec); $workers[] = new PhabricatorRepositoryCommitHeraldWorker($spec);
} }
ExecFuture::pushEchoMode(true);
foreach ($workers as $worker) { foreach ($workers as $worker) {
echo "Running ".get_class($worker)."...\n"; echo "Running ".get_class($worker)."...\n";
$worker->doWork(); $worker->doWork();

View file

@ -109,7 +109,6 @@ phutil_register_library_map(array(
'DarkConsolePlugin' => 'aphront/console/plugin/base', 'DarkConsolePlugin' => 'aphront/console/plugin/base',
'DarkConsoleRequestPlugin' => 'aphront/console/plugin/request', 'DarkConsoleRequestPlugin' => 'aphront/console/plugin/request',
'DarkConsoleServicesPlugin' => 'aphront/console/plugin/services', 'DarkConsoleServicesPlugin' => 'aphront/console/plugin/services',
'DarkConsoleServicesPluginAPI' => 'aphront/console/plugin/services/api',
'DarkConsoleXHProfPlugin' => 'aphront/console/plugin/xhprof', 'DarkConsoleXHProfPlugin' => 'aphront/console/plugin/xhprof',
'DarkConsoleXHProfPluginAPI' => 'aphront/console/plugin/xhprof/api', 'DarkConsoleXHProfPluginAPI' => 'aphront/console/plugin/xhprof/api',
'DatabaseConfigurationProvider' => 'applications/base/storage/configuration', 'DatabaseConfigurationProvider' => 'applications/base/storage/configuration',

View file

@ -29,7 +29,7 @@ class DarkConsoleServicesPlugin extends DarkConsolePlugin {
} }
public function generateData() { public function generateData() {
return DarkConsoleServicesPluginAPI::getEvents(); return PhutilServiceProfiler::getInstance()->getServiceCallLog();
} }
public function render() { public function render() {
@ -38,15 +38,22 @@ class DarkConsoleServicesPlugin extends DarkConsolePlugin {
$rows = array(); $rows = array();
foreach ($data as $row) { foreach ($data as $row) {
switch ($row['event']) { switch ($row['type']) {
case DarkConsoleServicesPluginAPI::EVENT_QUERY: case 'query':
$info = $row['query']; $info = $row['query'];
$info = phutil_escape_html($info); $info = phutil_escape_html($info);
break; break;
case DarkConsoleServicesPluginAPI::EVENT_CONNECT: case 'connect':
$info = $row['host'].':'.$row['database']; $info = $row['host'].':'.$row['database'];
$info = phutil_escape_html($info); $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; break;
default: default:
$info = '-'; $info = '-';
@ -54,8 +61,8 @@ class DarkConsoleServicesPlugin extends DarkConsolePlugin {
} }
$rows[] = array( $rows[] = array(
$row['event'], phutil_escape_html($row['type']),
number_format(1000000 * ($row['end'] - $row['start'])).' us', number_format(1000000 * $row['duration']).' us',
$info, $info,
); );
} }

View file

@ -7,10 +7,10 @@
phutil_require_module('phabricator', 'aphront/console/plugin/base'); 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('phabricator', 'view/control/table');
phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'markup');
phutil_require_module('phutil', 'serviceprofiler');
phutil_require_source('DarkConsoleServicesPlugin.php'); phutil_require_source('DarkConsoleServicesPlugin.php');

View file

@ -1,43 +0,0 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
*
* 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.
*/
class DarkConsoleServicesPluginAPI {
const EVENT_QUERY = 'query';
const EVENT_CONNECT = 'connect';
private static $events = array();
private static $discardMode = false;
public static function enableDiscardMode() {
self::$discardMode = true;
}
public static function addEvent(array $event) {
if (!self::$discardMode) {
self::$events[] = $event;
}
}
public static function getEvents() {
return self::$events;
}
}

View file

@ -1,10 +0,0 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_source('DarkConsoleServicesPluginAPI.php');

View file

@ -21,9 +21,8 @@ abstract class PhabricatorDaemon extends PhutilDaemon {
protected function willRun() { protected function willRun() {
parent::willRun(); parent::willRun();
// Both of these store unbounded amounts of log data; make them discard it // This stores unbounded amounts of log data; make it discard instead so
// instead so that daemons do not require unbounded amounts of memory. // that daemons do not require unbounded amounts of memory.
DarkConsoleServicesPluginAPI::enableDiscardMode();
DarkConsoleErrorLogPluginAPI::enableDiscardMode(); DarkConsoleErrorLogPluginAPI::enableDiscardMode();
$phabricator = phutil_get_library_root('phabricator'); $phabricator = phutil_get_library_root('phabricator');

View file

@ -7,7 +7,6 @@
phutil_require_module('phabricator', 'aphront/console/plugin/errorlog/api'); phutil_require_module('phabricator', 'aphront/console/plugin/errorlog/api');
phutil_require_module('phabricator', 'aphront/console/plugin/services/api');
phutil_require_module('phutil', 'daemon/base'); phutil_require_module('phutil', 'daemon/base');
phutil_require_module('phutil', 'moduleutils'); phutil_require_module('phutil', 'moduleutils');

View file

@ -129,39 +129,43 @@ class AphrontMySQLDatabaseConnection extends AphrontDatabaseConnection {
"available!"); "available!");
} }
$conn = @mysql_connect( $profiler = PhutilServiceProfiler::getInstance();
$host, $call_id = $profiler->beginServiceCall(
$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);
}
}
$end = microtime(true);
DarkConsoleServicesPluginAPI::addEvent(
array( array(
'event' => DarkConsoleServicesPluginAPI::EVENT_CONNECT, 'type' => 'connect',
'host' => $host, 'host' => $host,
'database' => $database, '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; self::$connectionCache[$key] = $conn;
$this->connection = $conn; $this->connection = $conn;
} }
@ -205,17 +209,18 @@ class AphrontMySQLDatabaseConnection extends AphrontDatabaseConnection {
$this->requireConnection(); $this->requireConnection();
$start = microtime(true); $start = microtime(true);
$result = @mysql_query($raw_query, $this->connection);
$end = microtime(true);
DarkConsoleServicesPluginAPI::addEvent( $profiler = PhutilServiceProfiler::getInstance();
$call_id = $profiler->beginServiceCall(
array( array(
'event' => DarkConsoleServicesPluginAPI::EVENT_QUERY, 'type' => 'query',
'query' => $raw_query, 'query' => $raw_query,
'start' => $start,
'end' => $end,
)); ));
$result = @mysql_query($raw_query, $this->connection);
$profiler->endServiceCall($call_id, array());
if ($result) { if ($result) {
$this->lastResult = $result; $this->lastResult = $result;
break; break;

View file

@ -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/connection/base');
phutil_require_module('phabricator', 'storage/exception/accessdenied'); phutil_require_module('phabricator', 'storage/exception/accessdenied');
phutil_require_module('phabricator', 'storage/exception/base'); 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/duplicatekey');
phutil_require_module('phabricator', 'storage/exception/recoverable'); phutil_require_module('phabricator', 'storage/exception/recoverable');
phutil_require_module('phutil', 'serviceprofiler');
phutil_require_module('phutil', 'utils'); phutil_require_module('phutil', 'utils');