/** * PerformanceDashboard Component * * A development tool for monitoring video streaming performance. * Only shown in development mode. */ import React, { useState, useEffect } from 'react'; import { performanceMonitor, thumbnailCache } from '../utils'; interface PerformanceDashboardProps { className?: string; } export const PerformanceDashboard: React.FC = ({ className = '', }) => { const [isOpen, setIsOpen] = useState(false); const [stats, setStats] = useState(null); const [cacheStats, setCacheStats] = useState(null); useEffect(() => { if (isOpen) { const updateStats = () => { setStats({ overall: performanceMonitor.getStats(), getVideos: performanceMonitor.getStats('get_videos'), getThumbnail: performanceMonitor.getStats('get_thumbnail'), recentMetrics: performanceMonitor.getRecentMetrics(5), }); setCacheStats(thumbnailCache.getStats()); }; updateStats(); const interval = setInterval(updateStats, 2000); return () => clearInterval(interval); } }, [isOpen]); // Only show in development if (process.env.NODE_ENV !== 'development') { return null; } if (!isOpen) { return ( ); } return (

Performance

{stats && (
{/* Overall Stats */}

Overall

Operations: {stats.overall.totalOperations}
Success: {(stats.overall.successRate * 100).toFixed(1)}%
Avg: {stats.overall.averageDuration.toFixed(0)}ms
Max: {stats.overall.maxDuration.toFixed(0)}ms
{/* Video Loading Stats */} {stats.getVideos.totalOperations > 0 && (

Video Loading

Calls: {stats.getVideos.totalOperations}
Success: {(stats.getVideos.successRate * 100).toFixed(1)}%
Avg: {stats.getVideos.averageDuration.toFixed(0)}ms
Max: {stats.getVideos.maxDuration.toFixed(0)}ms
)} {/* Thumbnail Stats */} {stats.getThumbnail.totalOperations > 0 && (

Thumbnails

Calls: {stats.getThumbnail.totalOperations}
Success: {(stats.getThumbnail.successRate * 100).toFixed(1)}%
Avg: {stats.getThumbnail.averageDuration.toFixed(0)}ms
Max: {stats.getThumbnail.maxDuration.toFixed(0)}ms
)} {/* Cache Stats */} {cacheStats && (

Cache

Cached: {cacheStats.size}
Memory: {(cacheStats.totalMemory / 1024 / 1024).toFixed(1)}MB
Hits: {cacheStats.totalAccess}
Avg Size: {(cacheStats.averageSize / 1024).toFixed(0)}KB
)} {/* Recent Operations */} {stats.recentMetrics.length > 0 && (

Recent

{stats.recentMetrics.map((metric: any, index: number) => (
{metric.operation} {metric.duration?.toFixed(0)}ms
))}
)} {/* Actions */}
)}
); };