BitBabit Developer Tools is a comprehensive development and debugging suite for Magento 2 that provides real-time performance monitoring, database query profiling, and advanced debugging capabilities. It features a modern, interactive web-based toolbar similar to Symfony's DebugBar or Laravel Debugbar.
- Real-time SQL query monitoring with execution times
- Slow query detection and highlighting
- Query parameter binding visualization
- Query type analysis (SELECT, INSERT, UPDATE, DELETE)
- Comprehensive query statistics
- Application execution time tracking
- Memory usage monitoring (current, peak, real usage)
- Bootstrap time measurement
- Server load monitoring
- OPcache status and statistics
- API key-based authentication system
- Secure header validation (
X-Debug-Api-Key
) - Developer mode restrictions
- Cookie-based session management
- HTTP request/response monitoring
- Header inspection
- Parameter analysis (GET, POST, FILES)
- Session data examination
- AJAX request interception
- PHP version and configuration
- Server software details
- Operating system information
- PHP extensions listing
- Timezone and locale settings
- Multi-level debug logging (info, warning, error, debug)
- Contextual debug messages
- Interactive JSON tree visualization
- Real-time message collection
- Modern, responsive toolbar widget
- Real-time data updates
- Collapsible panels
- Multi-request tracking
- Mobile-friendly design
composer require bitbabit/magento2-dev-tools
bin/magento module:enable BitBabit_DeveloperTools
bin/magento setup:upgrade
php bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
If the package is not yet published to Packagist, you can install with explicit version:
composer require bitbabit/magento2-dev-tools:^1.2.0
bin/magento module:enable BitBabit_DeveloperTools
bin/magento setup:upgrade
php bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
- Download the module files
- Extract to
app/code/BitBabit/DeveloperTools/
- Run the following commands:
bin/magento module:enable BitBabit_DeveloperTools
bin/magento setup:upgrade
php bin/magento setup:di:compile
bin/magento setup:static-content:deploy -f
After installation, follow these steps to get started:
# Enable the profiler
bin/magento bitbabit:profiler:enable
# Generate API key for frontend widget
bin/magento bitbabit:devtools:generate-api-key
# Copy the generated API key for frontend widget usage
# Clear cache
bin/magento cache:flush
To enable the profiler widget and save the API key to cookies for persistent profiling:
https://YOUR_FRONTEND_URL?api_key=YOUR_GENERATED_API_KEY
This will:
- Enable the profiler widget on your frontend
- Save the API key to cookies for automatic profiling on subsequent requests
- Allow you to see the profiler widget on all pages
Note: Boot time and memory management features are currently under development, so data may not be 100% accurate.
Navigate to Stores → Configuration → BitBabit → Developer Tools
- Enable Developer Tools: Master toggle for the entire module
- Profiler Header Key: HTTP header to trigger profiling (default:
X-Debug-Mode
) - Enable HTML Output: Show profiler data for web requests
- Enable JSON Injection: Inject profiler data into API responses
- Developer Mode Only: Restrict profiling to developer mode
- Slow Query Threshold: Highlight queries exceeding this time (ms)
- Toolbar Widget: Enable/disable the floating toolbar
- Memory Limit: Auto-disable threshold to prevent memory issues
- Enable API Key Validation: Require API key for access
- API Key: Encrypted storage of the authentication key
# Enable profiler
bin/magento bitbabit:profiler:enable
# Disable profiler
bin/magento bitbabit:profiler:disable
# Check status
bin/magento bitbabit:profiler:status
# Generate new API key
bin/magento bitbabit:devtools:generate-api-key
# Regenerate existing API key
bin/magento bitbabit:devtools:generate-api-key --regenerate
- Enable the module in admin configuration
- Generate an API key using the console command
- Configure your browser to send the debug header:
- Header:
X-Debug-Api-Key
- Value: Your generated API key
- Header:
- Visit any frontend page to see the toolbar
The module is designed to work with browser extensions that can inject custom headers:
// Example browser extension configuration
headers: {
'X-Debug-Mode': '1',
'X-Debug-Api-Key': 'your-generated-api-key'
}
<?php
use BitBabit\DeveloperTools\Helper\Debug;
// Basic logging
Debug::info('Processing order', ['order_id' => 123]);
Debug::warning('Low stock detected', ['product_id' => 456]);
Debug::error('Payment failed', ['error' => $exception->getMessage()]);
// Variable dumping
Debug::dump($complexArray, 'Order Data');
// Timer usage (legacy methods)
Debug::startTimer('product-load');
// ... your code ...
Debug::endTimer('product-load', 'Product loading completed');
For AJAX requests, profiler data is automatically injected into JSON responses:
// AJAX response with profiler data
{
"data": { /* your response data */ },
"_profiler": {
"database": { /* query information */ },
"performance": { /* timing data */ },
"memory": { /* memory usage */ }
}
}
ProfilerConfigInterface
: Main configuration contract defining all settings and validation methods
ProfilerConfig
: Configuration implementation with scope integrationDebugInfo
: Singleton for collecting debug messages
ComprehensiveProfilerService
: Main profiling engine collecting all dataApiKeyCookieManagerService
: Secure API key management with cookie support
EnableCommand
: Enable profiler via CLIDisableCommand
: Disable profiler via CLIStatusCommand
: Show current profiler statusGenerateApiKeyCommand
: API key generation and management
ResponseObserver
: Injects profiler data into responsesHttpLaunchPlugin
: Initializes profiling for each request
profiler-widget.js
: Interactive JavaScript toolbarprofiler-widget.css
: Responsive styling
- Request Initialization:
HttpLaunchPlugin
checks if profiling should be enabled - Data Collection:
ComprehensiveProfilerService
gathers metrics throughout request - Response Injection:
ResponseObserver
adds profiler data to output - Frontend Display: JavaScript widget renders interactive toolbar
- API Key Authentication: Secure access control
- Timing-Safe Comparison: Prevents timing attacks
- Developer Mode Restriction: Production safety
- Cookie Security: Secure, HTTP-only cookie handling
{
"overview": {
"status": "good|warning|error",
"total_queries": 25,
"total_time": "1.234s"
},
"database": {
"total_queries": 25,
"total_time_formatted": "145.67ms",
"slow_query_threshold": "100ms",
"queries": [
{
"query": "SELECT * FROM catalog_product_entity WHERE ...",
"time": 45.67,
"time_formatted": "45.67ms",
"type": "SELECT",
"is_slow": false,
"params": ["value1", "value2"]
}
],
"queries_by_type": {
"SELECT": 20,
"INSERT": 3,
"UPDATE": 2
}
},
"performance": {
"application_time": "1.234s",
"bootstrap_time": "0.123s",
"php_version": "8.3.0",
"magento_mode": "developer",
"server_load": [0.5, 0.7, 0.9],
"opcache": {
"enabled": true,
"hit_rate": 95.5,
"memory_usage": {
"used_memory": 67108864,
"free_memory": 33554432,
"wasted_memory": 1048576
}
}
},
"memory": {
"current_usage": 16777216,
"current_usage_formatted": "16.0 MB",
"peak_usage": 20971520,
"peak_usage_formatted": "20.0 MB",
"real_usage_formatted": "18.5 MB",
"limit": "512M"
},
"request": {
"method": "GET",
"uri": "/catalog/product/view/id/123",
"url": "https://example.com/catalog/product/view/id/123",
"ip": "192.168.1.100",
"content_type": "text/html",
"user_agent": "Mozilla/5.0...",
"headers": {
"Host": "example.com",
"X-Debug-Mode": "1"
},
"parameters": {
"GET": {"id": "123"},
"POST": {},
"FILES": {}
},
"session": {
"session_id": "abc123",
"customer_id": null
}
},
"environment": {
"php_version": "8.3.0",
"server_software": "nginx/1.20.0",
"operating_system": "Linux",
"max_execution_time": 30,
"timezone": "UTC",
"locale": "en_US.UTF-8",
"extensions": ["json", "mysqli", "gd", "curl"]
},
"metadata": {
"generated_at": "2024-01-15 10:30:45",
"request_id": "req_123456789",
"profiler_version": "1.2.0",
"memory_limit_exceeded": false,
"timestamp": 1705315845
},
"debug_info": {
"messages": [
{
"message": "Order processing started",
"level": "info",
"context": {"order_id": 123},
"timestamp": 1705315845.123
}
]
},
"timers": {
"product-load": {
"duration": 45.67,
"duration_formatted": "45.67ms",
"started_at": "10:30:45.123",
"ended_at": "10:30:45.169"
}
}
}
- Database Queries: SQL query analysis with parameters and timing
- Performance: Execution times, server load, OPcache status
- Memory: Current, peak, and real memory usage statistics
- Request: HTTP request details, headers, parameters, session
- Environment: PHP info, server details, extensions
- OPcache: Cache statistics and memory usage
- Debug: Custom debug messages with context data
- Collapsible panels for organized data viewing
- Multi-request tracking for AJAX monitoring
- Real-time updates without page refresh
- JSON tree visualization for complex data
- Responsive design for mobile debugging
- Request selector to switch between tracked requests
// manifest.json permissions
"permissions": [
"webRequest",
"webRequestBlocking",
"*://*/*"
]
// Background script example
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
details.requestHeaders.push({
name: 'X-Debug-Mode',
value: '1'
});
details.requestHeaders.push({
name: 'X-Debug-Api-Key',
value: localStorage.getItem('debug_api_key')
});
return {requestHeaders: details.requestHeaders};
},
{urls: ["*://*/*"]},
["blocking", "requestHeaders"]
);
- Automatic profiler disable when memory limit exceeded
- Configurable memory thresholds
- Efficient data structure usage
- Storage cleanup on page refresh
- IndexedDB: Primary storage (highest capacity)
- localStorage: Fallback option
- Cookies: Minimal fallback for basic functionality
- Minimal performance overhead
- Optional profiling activation
- Selective data collection
- Efficient query parameter handling
- Cryptographically secure key generation
- Timing-safe string comparison
- Secure cookie attributes
- URL parameter cleanup
- Developer mode restrictions
- API key authentication
- Request header validation
- Limited sensitive data collection (session data capped at 10 items)
- Configurable data exposure levels
- Secure transmission headers
- Memory usage limits to prevent resource exhaustion
- Check if module is enabled:
bin/magento module:status BitBabit_DeveloperTools
- Verify API key configuration
- Ensure correct headers are sent
- Check browser console for JavaScript errors
- Increase memory limits
- Disable in production environments
- Reduce slow query threshold
- Monitor server resources
- Regenerate API key:
bin/magento bitbabit:devtools:generate-api-key --regenerate
- Clear browser storage
- Verify header transmission
- Check admin configuration
Enable debug logging in the JavaScript widget:
// In browser console
DevProfiler.isDebugEnabled = true;
Check Magento logs for profiler-related issues:
var/log/developer_tools.log
var/log/system.log
var/log/exception.log
<?php
// Custom data collector
class CustomDataCollector
{
public function collect(): array
{
return [
'custom_metric' => $this->calculateMetric(),
'additional_data' => $this->gatherData()
];
}
}
// Extend the profiler widget
class ExtendedProfilerWidget extends ProfilerWidget {
getCustomPanel(data) {
return `<div class="custom-panel">${data}</div>`;
}
}
Run the included PHPUnit tests:
cd DeveloperTools
../../../vendor/bin/phpunit
Test coverage includes:
- Configuration management
- Console commands
- API key generation
- Debug info collection
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
- Documentation: This README and inline code comments
- Issues: GitHub Issues tracker
- Email: babitkumar6@gmail.com
- Initial public release
- Complete profiling suite
- API key authentication
- Interactive web interface
- Console command integration
- Comprehensive test coverage