From e94ae502ff9faaa2b7b066dcc5ba628053a0ef68 Mon Sep 17 00:00:00 2001 From: sji Date: Mon, 20 Nov 2023 06:30:27 +0900 Subject: [PATCH] Some minor fixes for the output of the memory reader command --- src/Command/Inspector/MemoryCommand.php | 4 ++-- .../ObjectClassAnalyzer/ObjectClassAnalyzer.php | 4 ++++ .../PhpMemoryReader/RegionAnalyzer/RegionAnalyzer.php | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Command/Inspector/MemoryCommand.php b/src/Command/Inspector/MemoryCommand.php index c472c7bb..06f53ebf 100644 --- a/src/Command/Inspector/MemoryCommand.php +++ b/src/Command/Inspector/MemoryCommand.php @@ -135,8 +135,8 @@ public function execute(InputInterface $input, OutputInterface $output): int echo json_encode( [ 'summary' => $summary, - "per_type_analysis" => $heap_location_type_summary->per_type_usage, - 'per_class_analysis' => $object_class_summary->per_class_usage, + "location_types_summary" => $heap_location_type_summary->per_type_usage, + 'class_objects_summary' => $object_class_summary->per_class_usage, 'context' => $analyzed_context, ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE, diff --git a/src/Lib/PhpProcessReader/PhpMemoryReader/ObjectClassAnalyzer/ObjectClassAnalyzer.php b/src/Lib/PhpProcessReader/PhpMemoryReader/ObjectClassAnalyzer/ObjectClassAnalyzer.php index c8af754c..972567f7 100644 --- a/src/Lib/PhpProcessReader/PhpMemoryReader/ObjectClassAnalyzer/ObjectClassAnalyzer.php +++ b/src/Lib/PhpProcessReader/PhpMemoryReader/ObjectClassAnalyzer/ObjectClassAnalyzer.php @@ -36,6 +36,10 @@ public function analyze(MemoryLocations $memory_locations): ObjectClassAnalyzerR $per_class_usage[$class_name]['memory_usage'] += $memory_location->size; } } + uasort( + $per_class_usage, + fn ($a, $b) => $b['memory_usage'] <=> $a['memory_usage'] + ); return new ObjectClassAnalyzerResult($per_class_usage); } } diff --git a/src/Lib/PhpProcessReader/PhpMemoryReader/RegionAnalyzer/RegionAnalyzer.php b/src/Lib/PhpProcessReader/PhpMemoryReader/RegionAnalyzer/RegionAnalyzer.php index 9c915701..9e103c14 100644 --- a/src/Lib/PhpProcessReader/PhpMemoryReader/RegionAnalyzer/RegionAnalyzer.php +++ b/src/Lib/PhpProcessReader/PhpMemoryReader/RegionAnalyzer/RegionAnalyzer.php @@ -127,7 +127,7 @@ public function analyze(MemoryLocations $memory_locations): RegionAnalyzerResult uasort( $per_class_objects, - fn (array $a, array $b) => $b['count'] <=> $a['count'] + fn (array $a, array $b) => $b['total_size'] <=> $a['total_size'] ); $heap_memory_usage += $possible_allocation_overhead_total;