Skip to content

Commit

Permalink
Merge pull request #44 from sj-i/opcode
Browse files Browse the repository at this point in the history
add opcode tracer
  • Loading branch information
sj-i committed Aug 9, 2021
2 parents 31e8950 + 7718713 commit a7c06d5
Show file tree
Hide file tree
Showing 14 changed files with 3,767 additions and 6 deletions.
19 changes: 19 additions & 0 deletions resources/templates/phpspy_with_opcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* This file is part of the sj-i/php-profiler package.
*
* (c) sji <sji@sj-i.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

use PhpProfiler\Lib\PhpProcessReader\CallTrace;
/** @var CallTrace $call_trace */
?>
<?php foreach ($call_trace->call_frames as $depth => $frame): ?>
<?= $depth ?> <?= $frame->getFullyQualifiedFunctionName() ?> <?= $frame->file_name ?>:<?= $frame->getLineno() ?>:<?= $frame->getOpcodeName() , "\n" ?>
<?php endforeach ?>
20 changes: 20 additions & 0 deletions src/Lib/PhpInternals/Opcodes/Opcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* This file is part of the sj-i/php-profiler package.
*
* (c) sji <sji@sj-i.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace PhpProfiler\Lib\PhpInternals\Opcodes;

/** @psalm-immutable */
interface Opcode
{
public function getName(): string;
}
50 changes: 50 additions & 0 deletions src/Lib/PhpInternals/Opcodes/OpcodeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* This file is part of the sj-i/php-profiler package.
*
* (c) sji <sji@sj-i.dev>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace PhpProfiler\Lib\PhpInternals\Opcodes;

final class OpcodeFactory
{
/** @var array<string, class-string<Opcode>> */
private const VERSION_MAP = [
'v70' => OpcodeV70::class,
'v71' => OpcodeV71::class,
'v72' => OpcodeV72::class,
'v73' => OpcodeV73::class,
'v74' => OpcodeV74::class,
'v80' => OpcodeV80::class,
];

/**
* @template TVersion of key-of<self::VERSION_MAP>
* @param TVersion $version
* @return (
* TVersion is 'v70' ? OpcodeV70 :
* TVersion is 'v71' ? OpcodeV71 :
* TVersion is 'v72' ? OpcodeV72 :
* TVersion is 'v73' ? OpcodeV73 :
* TVersion is 'v74' ? OpcodeV74 :
* OpcodeV80
* )
*/
public function create(string $version, int $opcode): Opcode
{
return match ($version) {
'v71' => new OpcodeV71($opcode),
'v72' => new OpcodeV72($opcode),
'v73' => new OpcodeV73($opcode),
'v74' => new OpcodeV74($opcode),
'v80' => new OpcodeV80($opcode),
};
}
}
Loading

0 comments on commit a7c06d5

Please sign in to comment.