Skip to content

Commit 5b92e1c

Browse files
authored
Merge pull request #96 from phpDocumentor/feature/blackfire
Profiling
2 parents aa06ba3 + c13fc87 commit 5b92e1c

File tree

8 files changed

+27519
-20
lines changed

8 files changed

+27519
-20
lines changed

.github/workflows/push.yml

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,7 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@master
12-
- name: Restore/cache vendor folder
13-
uses: actions/cache@v1
14-
with:
15-
path: vendor
16-
key: all-build-${{ hashFiles('**/composer.lock') }}
17-
restore-keys: |
18-
all-build-${{ hashFiles('**/composer.lock') }}
19-
all-build-
12+
2013
- name: Restore/cache tools folder
2114
uses: actions/cache@v1
2215
with:
@@ -25,20 +18,24 @@ jobs:
2518
restore-keys: |
2619
all-tools-${{ github.sha }}-
2720
all-tools-
21+
2822
- name: composer
2923
uses: docker://composer
3024
env:
3125
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3226
with:
3327
args: install --no-interaction --prefer-dist --optimize-autoloader
28+
3429
- name: composer-require-checker
3530
uses: docker://phpga/composer-require-checker-ga
3631
env:
3732
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3833
with:
3934
args: check --config-file ./composer-require-config.json composer.json
35+
4036
- name: Install phive
4137
run: make install-phive
38+
4239
- name: Install PHAR dependencies
4340
run: tools/phive.phar --no-progress install --copy --trust-gpg-keys 4AA394086372C20A,8A03EA3B385DBAA1 --force-accept-unsigned
4441

@@ -222,3 +219,52 @@ jobs:
222219
all-build-
223220
- name: Roave BC Check
224221
uses: docker://nyholm/roave-bc-check-ga
222+
223+
profile:
224+
runs-on: ubuntu-latest
225+
name: profile
226+
needs: [setup, phpunit]
227+
services:
228+
blackfire:
229+
image: blackfire/blackfire
230+
ports:
231+
- 8707:8707
232+
env:
233+
BLACKFIRE_SERVER_ID: "517a7aa6-1ec8-4d29-bff8-dddecf4333de"
234+
BLACKFIRE_SERVER_TOKEN: "21795bdce7c0b5d24f0ccbb42e2a7518feb5359840752b163652899f927cbf2b"
235+
236+
steps:
237+
- uses: actions/checkout@master
238+
239+
- name: Setup PHP
240+
uses: shivammathur/setup-php@v2
241+
with:
242+
php-version: 7.2
243+
extensions: blackfire
244+
ini-values: memory_limit=2G, display_errors=On, error_reporting=-1, blackfire.agent_socket=tcp://localhost:8707
245+
coverage: none
246+
247+
- name: Get Composer Cache Directory
248+
id: composer-cache
249+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
250+
251+
- name: Cache dependencies
252+
uses: actions/cache@v1
253+
with:
254+
path: ${{ steps.composer-cache.outputs.dir }}
255+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
256+
restore-keys: ${{ runner.os }}-composer-
257+
258+
- name: Install dependencies
259+
run: composer install --prefer-dist --no-progress --no-suggest
260+
261+
- name: Install phpbench
262+
run: |
263+
composer global require jaapio/phpbench-blackfire:1.x-dev@dev && \
264+
sudo ln -sf "$(composer -q global config home)"/vendor/bin/phpbench /usr/local/bin/phpbench
265+
266+
- name: Run phpbench
267+
run: phpbench run -l blackfire --revs=1 --tag="Build_PR_${{ github.event.number }}"
268+
env:
269+
BLACKFIRE_CLIENT_ID: ${{ secrets.BLACKFIRE_CLIENT_ID }}
270+
BLACKFIRE_CLIENT_TOKEN: ${{ secrets.BLACKFIRE_CLIENT_TOKEN }}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"autoload-dev": {
2626
"psr-4": {
27-
"phpDocumentor\\Reflection\\": "tests/unit"
27+
"phpDocumentor\\Reflection\\": ["tests/unit", "tests/benchmark"]
2828
}
2929
},
3030
"extra": {

phpbench.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"bootstrap": "vendor/autoload.php",
3+
"path": "tests/benchmark",
4+
"extensions": [
5+
"Jaapio\\Blackfire\\Extension"
6+
],
7+
"blackfire" : {
8+
"env": "c12030d0-c177-47e2-b466-4994c40dc993"
9+
}
10+
}

src/Types/ContextFactory.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Reflector;
2424
use RuntimeException;
2525
use UnexpectedValueException;
26-
use function array_merge;
2726
use function file_exists;
2827
use function file_get_contents;
2928
use function get_class;
@@ -166,7 +165,8 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
166165
$tokens = new ArrayIterator(token_get_all($fileContents));
167166

168167
while ($tokens->valid()) {
169-
switch ($tokens->current()[0]) {
168+
$currentToken = $tokens->current();
169+
switch ($currentToken[0]) {
170170
case T_NAMESPACE:
171171
$currentNamespace = $this->parseNamespace($tokens);
172172
break;
@@ -177,17 +177,18 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
177177
$braceLevel = 0;
178178
$firstBraceFound = false;
179179
while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) {
180-
if ($tokens->current() === '{'
181-
|| $tokens->current()[0] === T_CURLY_OPEN
182-
|| $tokens->current()[0] === T_DOLLAR_OPEN_CURLY_BRACES) {
180+
$currentToken = $tokens->current();
181+
if ($currentToken === '{'
182+
|| $currentToken[0] === T_CURLY_OPEN
183+
|| $currentToken[0] === T_DOLLAR_OPEN_CURLY_BRACES) {
183184
if (!$firstBraceFound) {
184185
$firstBraceFound = true;
185186
}
186187

187188
++$braceLevel;
188189
}
189190

190-
if ($tokens->current() === '}') {
191+
if ($currentToken === '}') {
191192
--$braceLevel;
192193
}
193194

@@ -197,7 +198,7 @@ public function createForNamespace(string $namespace, string $fileContents) : Co
197198
break;
198199
case T_USE:
199200
if ($currentNamespace === $namespace) {
200-
$useStatements = array_merge($useStatements, $this->parseUseStatement($tokens));
201+
$useStatements += $this->parseUseStatement($tokens);
201202
}
202203

203204
break;
@@ -243,12 +244,13 @@ private function parseUseStatement(ArrayIterator $tokens) : array
243244
while (true) {
244245
$this->skipToNextStringOrNamespaceSeparator($tokens);
245246

246-
$uses = array_merge($uses, $this->extractUseStatements($tokens));
247-
if ($tokens->current()[0] === self::T_LITERAL_END_OF_USE) {
247+
$uses += $this->extractUseStatements($tokens);
248+
$currentToken = $tokens->current();
249+
if ($currentToken[0] === self::T_LITERAL_END_OF_USE) {
248250
return $uses;
249251
}
250252

251-
if ($tokens->current() === false) {
253+
if ($currentToken === false) {
252254
break;
253255
}
254256
}
@@ -263,7 +265,12 @@ private function parseUseStatement(ArrayIterator $tokens) : array
263265
*/
264266
private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : void
265267
{
266-
while ($tokens->valid() && ($tokens->current()[0] !== T_STRING) && ($tokens->current()[0] !== T_NS_SEPARATOR)) {
268+
while ($tokens->valid()) {
269+
$currentToken = $tokens->current();
270+
if ($currentToken[0] === T_STRING || $currentToken[0] === T_NS_SEPARATOR) {
271+
break;
272+
}
273+
267274
$tokens->next();
268275
}
269276
}

0 commit comments

Comments
 (0)