Skip to content

Analytics

Brenda Willams edited this page Oct 21, 2025 · 2 revisions

πŸ“Š Analytics & Performance Monitoring

Arsenal Lab provides comprehensive analytics and performance monitoring capabilities to help you understand and optimize your Bun applications.

Real-time Memory Tracking Hardware Detection

πŸ“‹ Table of Contents

πŸ“Š Real-Time Performance Metrics

FPS Monitoring

Track frames-per-second in real-time across all components:

import { usePerformanceMonitor } from '@bun/performance-arsenal';

function MyComponent() {
  const { fps, memoryUsage } = usePerformanceMonitor();

  return (
    <div>
      <p>FPS: {fps}</p>
      <p>Memory: {memoryUsage} MB</p>
    </div>
  );
}

Memory Usage Tracking

Monitor memory consumption with detailed breakdowns:

  • Heap usage
  • External memory
  • Array buffers
  • WebAssembly memory

Hardware Detection

Automatic hardware profiling:

  • CPU cores and architecture
  • Available memory
  • GPU capabilities
  • Network connectivity

πŸ” Benchmark Analytics

Comparative Analysis

Run side-by-side benchmarks between Bun and Node.js:

// Performance comparison results
{
  "postMessage": {
    "bun": 1250,    // operations per second
    "node": 890,
    "speedup": 1.4
  },
  "crypto": {
    "bun": 4500,
    "node": 3200,
    "speedup": 1.4
  }
}

Historical Tracking

  • Benchmark result history
  • Performance trend analysis
  • Regression detection
  • Optimization impact measurement

πŸ“ˆ Analytics Dashboard

Live Metrics Display

Real-time performance dashboard showing:

  • Current FPS
  • Memory usage graphs
  • CPU utilization
  • Network latency

Custom Analytics Events

Track custom performance events:

import { trackBenchmark, trackInteraction } from '@bun/performance-arsenal';

// Track benchmark completion
trackBenchmark('crypto-hash', {
  algorithm: 'SHA-256',
  inputSize: '1MB',
  duration: 45,
  throughput: '22.2 MB/s'
});

// Track user interactions
trackInteraction('build-config-change', {
  tab: 'optimization',
  setting: 'minify',
  value: true
});

🎯 Performance Thresholds

Warning Systems

Automatic alerts for performance issues:

  • FPS drops below 30
  • Memory usage exceeds 500MB
  • Long-running operations (>5s)

Hardware Compatibility

Intelligent hardware detection and recommendations:

  • Minimum requirements checking
  • Performance optimization suggestions
  • Hardware-specific optimizations

πŸ“Š Data Export

JSON Export

Export analytics data for external analysis:

const analytics = await exportAnalytics();
// Returns structured performance data
{
  "session": "2025-01-21T10:30:00Z",
  "benchmarks": [...],
  "metrics": {
    "avgFps": 58.3,
    "peakMemory": 234,
    "totalBenchmarks": 15
  }
}

CSV Reports

Generate performance reports for documentation:

await exportPerformanceReport('performance-report.csv', {
  includeBenchmarks: true,
  includeMetrics: true,
  dateRange: 'last-7-days'
});

πŸ”§ Configuration

Analytics Settings

Control analytics collection:

// Enable/disable analytics
setAnalyticsEnabled(true);

// Configure data retention
setAnalyticsRetention('30-days');

// Set custom tracking endpoints
setAnalyticsEndpoint('https://analytics.example.com/collect');

Privacy Controls

Respect user privacy preferences:

  • Opt-in analytics collection
  • Data minimization
  • Local storage only (no external tracking)
  • Clear data controls

πŸš€ Performance Optimization Tips

Memory Management

  • Use Bun.gc() for manual garbage collection
  • Monitor memory leaks with heap snapshots
  • Optimize large object allocations

CPU Optimization

  • Leverage Bun's native performance
  • Use Web Workers for heavy computations
  • Implement efficient algorithms

Network Performance

  • Use Bun's fast HTTP client
  • Implement proper caching strategies
  • Optimize bundle sizes with code splitting

πŸ“± Cross-Platform Analytics

Browser Compatibility

  • Chrome DevTools integration
  • Firefox performance tools
  • Safari Web Inspector support

Platform-Specific Metrics

  • macOS: Activity Monitor integration
  • Windows: Performance Monitor
  • Linux: System monitoring tools

πŸ” Troubleshooting

Common Issues

  • Low FPS: Check hardware requirements, reduce visual complexity
  • High memory usage: Look for memory leaks, optimize data structures
  • Slow benchmarks: Ensure clean system state, close background applications

Debug Mode

Enable detailed analytics logging:

// Enable debug analytics
setAnalyticsDebug(true);

// View detailed performance logs
console.log(getAnalyticsLogs());

πŸ“š API Reference

Performance Monitor Hook

const { fps, memoryUsage, analyticsEnabled, toggleAnalytics } = usePerformanceMonitor();

Analytics Functions

  • trackBenchmark(name, data) - Track benchmark results
  • trackInteraction(event, data) - Track user interactions
  • exportAnalytics() - Export analytics data
  • clearAnalytics() - Clear stored analytics data

πŸ“š Related Documentation

Document Description
🏠 Wiki Home Overview and getting started
πŸ”§ API Reference Technical component documentation
πŸ—„οΈ Database Guide Database integration patterns
πŸ“ SQL Examples Query patterns and examples

πŸ“ž Support & Community


Built with ❀️ for the Bun ecosystem β€’ Last updated: October 21, 2025

Clone this wiki locally