Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ The profiler contains 2 types of entities: a profile and sections.
A profile contains a name (usually the http path called or the cli), the point in time the profile started, the status (succeeded, failed or pending) and an exit message.

A section is a part of a profile. By default there are 9 sections:

- Http: the request and response (if the app didn't crash) the app received
- Exception: the stack trace represented as graph (see [`innmind/stack-trace`](https://packagist.org/packages/innmind/stack-trace))
- App graph: the object graph representing the application (see [`innmind/object-graph`](https://packagist.org/packages/innmind/object-graph))
- Call graph: a flamechart
- Environment: the list of environment variables
- Processes: the list of commands run on the machine
- Remote / Http: all the http requests issued by the application
- Remote / Processes: all the commands run on a distant machine
- Remote / Sql: all the SQL queries issued to a database
- Remote
- Http: all the http requests issued by the application
- Processes: all the commands run on a distant machine
- Sql: all the SQL queries issued to a database

![](overview/index.png)
![](overview/http.png)
Expand Down
5 changes: 3 additions & 2 deletions docs/in-app.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Add the profiler to an existing app

For this use cas you must [`innmind/framework`](https://packagist.org/packages/innmind/framework).
For this use case you must use [`innmind/framework`](https://packagist.org/packages/innmind/framework).

```php
use Innmind\Framework\{
Expand All @@ -20,4 +20,5 @@ new class extends Http {

This example will expose the profiler under the `/_profiler/` route and the profiles will be stored in the `/tmp/` folder. Using the tmp folder means the profiles will be lost when rebooting your machine, you can use a local folder if you want to keep them.

> **Note** this example add the middleware in the entrypoint of your app but you can add it in your own middleware.
> [!NOTE]
> This example add the middleware in the entrypoint of your app but you can add it in your own middleware.
65 changes: 35 additions & 30 deletions docs/record.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ The examples show how to record data when the profiler is [in the current app](i
use Innmind\Framework\{
Application,
Middleware,
Http\RequestHandler,
};
use Innmind\Profiler\{
Web\Kernel,
Web\Services,
Profiler,
Profiler\Mutation,
Profile\Id,
};
use Innmind\Http\Message\{
use Innmind\DI\Container;
use Innmind\Route\Component;
use Innmind\Http\{
ServerRequest,
Response,
};
Expand All @@ -26,36 +30,37 @@ final class YourApp implements Middleware
{
return $app
->map(Kernel::inApp(Path::of('/tmp/')))
->mapRequestHandler(
static fn($handler, $get) => new class($handler, $get('innmind/profiler')) implements RequestHandler {
public function __construct(
private RequestHandler $inner,
private Profiler $profiler,
) {
}
->mapRoute(
static fn(
Component $route,
Container $get,
) => Component::of(static function(ServerRequest $request, mixed $input) use ($route, $get) {
$profiler = $get(Services::profiler());

public function __invoke(ServerRequest $request): Response
{
$profile = $this->profiler->start($request->url()->path()->toString());
$this->profiler->mutate(
$profile,
static function($mutation) {
$mutation->sections(); // call any method here to record sections data
},
return $profiler
->start($request->url()->path()->toString())
->flatMap(
static fn(Id $profile) => $profiler
->mutate(
$profile,
static fn(Mutation $mutation) => $mutation
->http()
->received($request->body()),
)
->flatMap(static fn() => $route($request, $input))
->flatMap(
static fn(Response $response) => $profiler
->mutate(
$profile,
static fn(Mutation $mutation) => match ($response->statusCode()->successful()) {
true => $mutation->succeed($response->statusCode()->toString()),
false => $mutation->fail($response->statusCode()->toString()),
},
)
->map(static fn() => $response),
),
);

$response = ($this->inner)($request);
$this->profiler->mutate(
$profile,
static fn($mutation) => match ($response->statusCode()->successful()) {
true => $mutation->succeed($response->statusCode()->toString()),
false => $mutation->fail($response->statusCode()->toString()),
},
);

return $response;
}
},
}),
);
}
}
Expand Down
Loading