Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Apr 16, 2024
1 parent 2321f16 commit df472bc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
21 changes: 13 additions & 8 deletions src/Proto/Frame/Profiler/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ private function __construct(
$this->metadata['type'] = $type->value;
}

/**
* @param PayloadType $type
* @param Metadata $metadata
* @param \Closure(): Calls $callsProvider
*/
public static function new(
PayloadType $type,
array $metadata,
\Closure $callsProvider,
): self {
return new static($type, $metadata, $callsProvider);
}

public static function fromArray(array $data, ?Type $type = null): static
{
$metadata = $data;
Expand All @@ -48,14 +61,6 @@ public static function fromArray(array $data, ?Type $type = null): static
);
}

public static function fromFile(FileInfo $fileInfo): static
{
// todo
// $metadata = $data;
// unset($metadata['edges'], $metadata['peaks']);
// return new static(PayloadType::from($data['type']), $metadata, fn(): array => $data);
}

/**
* @return Calls
*/
Expand Down
27 changes: 14 additions & 13 deletions src/Service/FilesObserver/Filter/XHProf.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ public function validate(FileInfo $file): bool
public function convert(FileInfo $file): \Traversable
{
try {
// todo read in a stream
$content = \file_get_contents($file->path);

$data = \unserialize($content, ['allowed_classes' => false]);

$payload = $this->dataToPayload($data);
$payload['date'] = $file->mtime;
$payload['hostname'] = \explode('.', $file->getName(), 2)[0];
$payload['filename'] = $file->getName();
$metadata = [
'date' => $file->mtime,
'hostname' => \explode('.', $file->getName(), 2)[0],
'filename' => $file->getName(),
];

yield new ProfilerFrame(
ProfilerFrame\Payload::fromArray($payload, ProfilerFrame\Type::XHProf),
ProfilerFrame\Payload::new(
type: ProfilerFrame\Type::XHProf,
metadata: $metadata,
callsProvider: function () use ($file): array {
$content = \file_get_contents($file->path);
$data = \unserialize($content, ['allowed_classes' => false]);
return $this->dataToPayload($data);
},
),
);
// yield new ProfilerFrame(
// ProfilerFrame\Payload::fromFile($file),
// );
} catch (\Throwable $e) {
// todo log
var_dump($e->getMessage());
Expand Down

0 comments on commit df472bc

Please sign in to comment.