Skip to content

Commit 417ca39

Browse files
author
epriestley
committed
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
1 parent a69f217 commit 417ca39

File tree

10 files changed

+57
-103
lines changed

10 files changed

+57
-103
lines changed

scripts/repository/parse_one_commit.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@
7676
$workers[] = new PhabricatorRepositoryCommitHeraldWorker($spec);
7777
}
7878

79-
ExecFuture::pushEchoMode(true);
80-
8179
foreach ($workers as $worker) {
8280
echo "Running ".get_class($worker)."...\n";
8381
$worker->doWork();

src/__phutil_library_map__.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109
'DarkConsolePlugin' => 'aphront/console/plugin/base',
110110
'DarkConsoleRequestPlugin' => 'aphront/console/plugin/request',
111111
'DarkConsoleServicesPlugin' => 'aphront/console/plugin/services',
112-
'DarkConsoleServicesPluginAPI' => 'aphront/console/plugin/services/api',
113112
'DarkConsoleXHProfPlugin' => 'aphront/console/plugin/xhprof',
114113
'DarkConsoleXHProfPluginAPI' => 'aphront/console/plugin/xhprof/api',
115114
'DatabaseConfigurationProvider' => 'applications/base/storage/configuration',

src/aphront/console/plugin/services/DarkConsoleServicesPlugin.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function getDescription() {
2929
}
3030

3131
public function generateData() {
32-
return DarkConsoleServicesPluginAPI::getEvents();
32+
return PhutilServiceProfiler::getInstance()->getServiceCallLog();
3333
}
3434

3535
public function render() {
@@ -38,24 +38,31 @@ public function render() {
3838
$rows = array();
3939
foreach ($data as $row) {
4040

41-
switch ($row['event']) {
42-
case DarkConsoleServicesPluginAPI::EVENT_QUERY:
41+
switch ($row['type']) {
42+
case 'query':
4343
$info = $row['query'];
4444
$info = phutil_escape_html($info);
4545
break;
46-
case DarkConsoleServicesPluginAPI::EVENT_CONNECT:
46+
case 'connect':
4747
$info = $row['host'].':'.$row['database'];
4848
$info = phutil_escape_html($info);
49-
49+
break;
50+
case 'exec':
51+
$info = $row['command'];
52+
$info = phutil_escape_html($info);
53+
break;
54+
case 'conduit':
55+
$info = $row['method'];
56+
$info = phutil_escape_html($info);
5057
break;
5158
default:
5259
$info = '-';
5360
break;
5461
}
5562

5663
$rows[] = array(
57-
$row['event'],
58-
number_format(1000000 * ($row['end'] - $row['start'])).' us',
64+
phutil_escape_html($row['type']),
65+
number_format(1000000 * $row['duration']).' us',
5966
$info,
6067
);
6168
}

src/aphront/console/plugin/services/__init__.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88

99
phutil_require_module('phabricator', 'aphront/console/plugin/base');
10-
phutil_require_module('phabricator', 'aphront/console/plugin/services/api');
1110
phutil_require_module('phabricator', 'view/control/table');
1211

1312
phutil_require_module('phutil', 'markup');
13+
phutil_require_module('phutil', 'serviceprofiler');
1414

1515

1616
phutil_require_source('DarkConsoleServicesPlugin.php');

src/aphront/console/plugin/services/api/DarkConsoleServicesPluginAPI.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/aphront/console/plugin/services/api/__init__.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/infrastructure/daemon/base/PhabricatorDaemon.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ abstract class PhabricatorDaemon extends PhutilDaemon {
2121
protected function willRun() {
2222
parent::willRun();
2323

24-
// Both of these store unbounded amounts of log data; make them discard it
25-
// instead so that daemons do not require unbounded amounts of memory.
26-
DarkConsoleServicesPluginAPI::enableDiscardMode();
24+
// This stores unbounded amounts of log data; make it discard instead so
25+
// that daemons do not require unbounded amounts of memory.
2726
DarkConsoleErrorLogPluginAPI::enableDiscardMode();
2827

2928
$phabricator = phutil_get_library_root('phabricator');

src/infrastructure/daemon/base/__init__.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
phutil_require_module('phabricator', 'aphront/console/plugin/errorlog/api');
10-
phutil_require_module('phabricator', 'aphront/console/plugin/services/api');
1110

1211
phutil_require_module('phutil', 'daemon/base');
1312
phutil_require_module('phutil', 'moduleutils');

src/storage/connection/mysql/AphrontMySQLDatabaseConnection.php

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -129,39 +129,43 @@ private function establishConnection() {
129129
"available!");
130130
}
131131

132-
$conn = @mysql_connect(
133-
$host,
134-
$user,
135-
$this->getConfiguration('pass'),
136-
$new_link = true,
137-
$flags = 0);
138-
139-
if (!$conn) {
140-
$errno = mysql_errno();
141-
$error = mysql_error();
142-
throw new AphrontQueryConnectionException(
143-
"Attempt to connect to {$user}@{$host} failed with error #{$errno}: ".
144-
"{$error}.");
145-
}
146-
147-
if ($database !== null) {
148-
$ret = @mysql_select_db($database, $conn);
149-
if (!$ret) {
150-
$this->throwQueryException($conn);
151-
}
152-
}
153-
154-
$end = microtime(true);
155-
156-
DarkConsoleServicesPluginAPI::addEvent(
132+
$profiler = PhutilServiceProfiler::getInstance();
133+
$call_id = $profiler->beginServiceCall(
157134
array(
158-
'event' => DarkConsoleServicesPluginAPI::EVENT_CONNECT,
135+
'type' => 'connect',
159136
'host' => $host,
160137
'database' => $database,
161-
'start' => $start,
162-
'end' => $end,
163138
));
164139

140+
try {
141+
$conn = @mysql_connect(
142+
$host,
143+
$user,
144+
$this->getConfiguration('pass'),
145+
$new_link = true,
146+
$flags = 0);
147+
148+
if (!$conn) {
149+
$errno = mysql_errno();
150+
$error = mysql_error();
151+
throw new AphrontQueryConnectionException(
152+
"Attempt to connect to {$user}@{$host} failed with error #{$errno}: ".
153+
"{$error}.");
154+
}
155+
156+
if ($database !== null) {
157+
$ret = @mysql_select_db($database, $conn);
158+
if (!$ret) {
159+
$this->throwQueryException($conn);
160+
}
161+
}
162+
163+
$profiler->endServiceCall($call_id, array());
164+
} catch (Exception $ex) {
165+
$profiler->endServiceCall($call_id, array());
166+
throw $ex;
167+
}
168+
165169
self::$connectionCache[$key] = $conn;
166170
$this->connection = $conn;
167171
}
@@ -205,17 +209,18 @@ public function executeRawQuery($raw_query) {
205209
$this->requireConnection();
206210

207211
$start = microtime(true);
208-
$result = @mysql_query($raw_query, $this->connection);
209-
$end = microtime(true);
210212

211-
DarkConsoleServicesPluginAPI::addEvent(
213+
$profiler = PhutilServiceProfiler::getInstance();
214+
$call_id = $profiler->beginServiceCall(
212215
array(
213-
'event' => DarkConsoleServicesPluginAPI::EVENT_QUERY,
216+
'type' => 'query',
214217
'query' => $raw_query,
215-
'start' => $start,
216-
'end' => $end,
217218
));
218219

220+
$result = @mysql_query($raw_query, $this->connection);
221+
222+
$profiler->endServiceCall($call_id, array());
223+
219224
if ($result) {
220225
$this->lastResult = $result;
221226
break;

src/storage/connection/mysql/__init__.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88

9-
phutil_require_module('phabricator', 'aphront/console/plugin/services/api');
109
phutil_require_module('phabricator', 'storage/connection/base');
1110
phutil_require_module('phabricator', 'storage/exception/accessdenied');
1211
phutil_require_module('phabricator', 'storage/exception/base');
@@ -15,6 +14,7 @@
1514
phutil_require_module('phabricator', 'storage/exception/duplicatekey');
1615
phutil_require_module('phabricator', 'storage/exception/recoverable');
1716

17+
phutil_require_module('phutil', 'serviceprofiler');
1818
phutil_require_module('phutil', 'utils');
1919

2020

0 commit comments

Comments
 (0)