Files
michaelschiemer/resources/js/modules/performance-profiler/index.js
Michael Schiemer fc3d7e6357 feat(Production): Complete production deployment infrastructure
- Add comprehensive health check system with multiple endpoints
- Add Prometheus metrics endpoint
- Add production logging configurations (5 strategies)
- Add complete deployment documentation suite:
  * QUICKSTART.md - 30-minute deployment guide
  * DEPLOYMENT_CHECKLIST.md - Printable verification checklist
  * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle
  * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference
  * production-logging.md - Logging configuration guide
  * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation
  * README.md - Navigation hub
  * DEPLOYMENT_SUMMARY.md - Executive summary
- Add deployment scripts and automation
- Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment
- Update README with production-ready features

All production infrastructure is now complete and ready for deployment.
2025-10-25 19:18:37 +02:00

182 lines
5.6 KiB
JavaScript

/**
* Performance Profiler Module
*
* Provides performance profiling with flamegraph and timeline visualization
* for LiveComponents and general application performance analysis.
*
* @module performance-profiler
*/
import { PerformanceProfiler, LiveComponentsProfiler } from './profiler.js';
import { FlamegraphVisualizer, TimelineVisualizer } from './visualizer.js';
export const definition = {
name: 'performance-profiler',
version: '1.0.0',
dependencies: [],
provides: ['performance-profiling', 'flamegraph', 'timeline'],
priority: 0
};
let globalProfiler = null;
let flamegraphViz = null;
let timelineViz = null;
/**
* Initialize performance profiler module
* @param {Object} config - Module configuration
* @param {Object} state - Module state manager
*/
export async function init(config = {}, state) {
console.log('[PerformanceProfiler] Initializing performance profiler module');
const enabled = config.enabled ?? false;
// Create global profiler instance
globalProfiler = new PerformanceProfiler({
enabled,
maxSamples: config.maxSamples ?? 1000,
samplingInterval: config.samplingInterval ?? 10,
autoStart: config.autoStart ?? false
});
// Initialize visualizers if containers exist
if (config.flamegraphContainer) {
const container = document.querySelector(config.flamegraphContainer);
if (container) {
flamegraphViz = new FlamegraphVisualizer(container, config.flamegraph ?? {});
console.log('[PerformanceProfiler] Flamegraph visualizer initialized');
}
}
if (config.timelineContainer) {
const container = document.querySelector(config.timelineContainer);
if (container) {
timelineViz = new TimelineVisualizer(container, config.timeline ?? {});
console.log('[PerformanceProfiler] Timeline visualizer initialized');
}
}
// Expose global API
if (typeof window !== 'undefined') {
window.PerformanceProfiler = {
profiler: globalProfiler,
flamegraph: flamegraphViz,
timeline: timelineViz,
// Convenience methods
start: () => globalProfiler.start(),
stop: () => {
const results = globalProfiler.stop();
if (results) {
console.log('[PerformanceProfiler] Profiling results:', results);
// Auto-render visualizations if available
if (flamegraphViz) {
const flamegraphData = globalProfiler.generateFlamegraph();
flamegraphViz.render(flamegraphData);
}
if (timelineViz) {
const timelineData = globalProfiler.generateTimeline();
timelineViz.render(timelineData);
}
}
return results;
},
mark: (name, metadata) => globalProfiler.mark(name, metadata),
measure: (name, start, end) => globalProfiler.measure(name, start, end),
exportChromeTrace: () => globalProfiler.exportToChromeTrace(),
createComponentProfiler: (component, options) => {
return new LiveComponentsProfiler(component, {
...options,
enabled: enabled || options?.enabled
});
}
};
console.log('[PerformanceProfiler] Global API available at window.PerformanceProfiler');
}
// Auto-instrument LiveComponents if available
if (typeof window !== 'undefined' && window.LiveComponents && config.autoInstrument !== false) {
instrumentLiveComponents();
}
console.log('[PerformanceProfiler] Module initialized');
}
/**
* Auto-instrument all LiveComponents
* @private
*/
function instrumentLiveComponents() {
const liveComponents = window.LiveComponents;
if (!liveComponents || !liveComponents.registry) {
console.warn('[PerformanceProfiler] LiveComponents not available for instrumentation');
return;
}
// Instrument existing components
for (const [id, component] of liveComponents.registry.entries()) {
const profiler = new LiveComponentsProfiler(component, {
enabled: true
});
// Store profiler reference
component._profiler = profiler;
console.log(`[PerformanceProfiler] Instrumented component: ${id}`);
}
// Instrument future components
const originalRegister = liveComponents.register.bind(liveComponents);
liveComponents.register = (id, component) => {
const result = originalRegister(id, component);
const profiler = new LiveComponentsProfiler(component, {
enabled: true
});
component._profiler = profiler;
console.log(`[PerformanceProfiler] Instrumented component: ${id}`);
return result;
};
console.log('[PerformanceProfiler] LiveComponents instrumentation enabled');
}
/**
* Destroy performance profiler module
*/
export function destroy() {
if (globalProfiler) {
globalProfiler.clear();
}
if (flamegraphViz) {
flamegraphViz.clear();
}
if (timelineViz) {
timelineViz.clear();
}
if (typeof window !== 'undefined') {
delete window.PerformanceProfiler;
}
console.log('[PerformanceProfiler] Module destroyed');
}
// Export classes for advanced usage
export { PerformanceProfiler, LiveComponentsProfiler, FlamegraphVisualizer, TimelineVisualizer };
export default { init, destroy, definition };