Memory Profiler CLI
Contributed by f
Improved by Laravel Company · 2026-09-07
Improved prompt:
Design and implement a high-performance memory profiler in C for system-level analysis of process memory usage and allocation behavior. Your primary objective is to create a comprehensive tool that enables developers to identify memory leaks, optimize allocation patterns, and gain detailed insights into the memory dynamics of their applications.
Key requirements and constraints:
- The profiler must be capable of attaching to running processes without significant performance overhead, ensuring minimal impact on the target application's execution.
- Implement a robust heap analysis component that tracks memory allocations and deallocations, providing a clear picture of an application's memory usage patterns.
- Develop a state-of-the-art memory leak detection mechanism that captures stack traces associated with leaked memory objects, enabling precise root cause analysis.
- Create a memory usage visualization module that presents detailed statistics and visualizations in an easily consumable format, allowing developers to quickly identify areas for optimization.
- Implement custom allocator hooking functionality to enable detailed tracking of memory allocations made through custom allocators, ensuring comprehensive coverage.
- Develop a multi-format report generation system that allows the user to export analysis results in common formats such as JSON, HTML, and CSV for further processing and documentation.
- Include advanced filtering options to reduce noise and focus the analysis on relevant memory objects and allocation patterns, improving the signal-to-noise ratio.
- Implement a snapshot comparison feature that allows developers to analyze the memory usage differences between two snapshots, facilitating before-and-after comparisons and performance benchmarking.
- Create a versatile command-line interface with an interactive mode that provides an intuitive user experience for memory profiling tasks.
Please provide a detailed implementation plan, including code structure, algorithmic approaches, performance optimizations, and any trade-offs or challenges you anticipate in meeting the specified constraints.
Original prompt (before our improvements)
Develop a memory profiling tool in C for analyzing process memory usage. Implement process attachment with minimal performance impact. Add heap analysis with allocation tracking. Include memory leak detection with stack traces. Implement memory usage visualization with detailed statistics. Add custom allocator hooking for detailed tracking. Include report generation in multiple formats. Implement filtering options for noise reduction. Add comparison functionality between snapshots. Include command-line interface with interactive mode. Implement signal handling for clean detachment.