@coherent.js/profiler 1.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Coherent.js Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @coherent.js/profiler
2
+
3
+ Advanced performance monitoring and profiling tools for Coherent.js applications.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @coherent.js/profiler
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Profiling
14
+
15
+ ```js
16
+ import { PerformanceProfiler } from '@coherent.js/profiler';
17
+
18
+ const profiler = new PerformanceProfiler();
19
+
20
+ const profileId = profiler.startProfile('render-component');
21
+ profiler.mark(profileId, 'start-render');
22
+ // ... your code
23
+ profiler.mark(profileId, 'end-render');
24
+ const report = profiler.endProfile(profileId);
25
+ ```
26
+
27
+ ### Metrics Collection
28
+
29
+ ```js
30
+ import { MetricsCollector } from '@coherent.js/performance-profiler';
31
+
32
+ const collector = new MetricsCollector();
33
+ collector.recordMetric('render-time', 16.5);
34
+ ```
35
+
36
+ ### Performance Dashboard
37
+
38
+ ```js
39
+ import { createDashboard } from '@coherent.js/performance-profiler';
40
+
41
+ const dashboard = createDashboard(profiler);
42
+ const dashboardHTML = dashboard.render();
43
+ ```
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@coherent.js/profiler",
3
+ "version": "1.0.0-beta.3",
4
+ "description": "Performance profiling and monitoring tools for Coherent.js applications",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "types": "./types/index.d.ts",
8
+ "exports": {
9
+ ".": "./src/index.js",
10
+ "./profiler": "./src/profiler.js",
11
+ "./server": "./src/server.js",
12
+ "./dashboard": "./src/dashboard/index.js"
13
+ },
14
+ "files": [
15
+ "src/",
16
+ "types/",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "keywords": [
21
+ "performance",
22
+ "profiling",
23
+ "monitoring",
24
+ "coherent",
25
+ "ssr"
26
+ ],
27
+ "author": "Coherent.js Team",
28
+ "license": "MIT",
29
+ "devDependencies": {
30
+ "vitest": "^3.2.4"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/Tomdrouv1/coherent.js.git"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "node build.mjs",
41
+ "test": "vitest",
42
+ "dev": "node src/server.js"
43
+ }
44
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Metrics Collector for Performance Profiler
3
+ */
4
+
5
+ export class MetricsCollector {
6
+ constructor(options = {}) {
7
+ this.options = options;
8
+ this.collectors = new Map();
9
+ }
10
+
11
+ addCollector(name, collector) {
12
+ this.collectors.set(name, collector);
13
+ }
14
+
15
+ async collect() {
16
+ const results = {};
17
+ for (const [name, collector] of this.collectors) {
18
+ try {
19
+ results[name] = await collector.collect();
20
+ } catch (error) {
21
+ results[name] = { error: error.message };
22
+ }
23
+ }
24
+ return results;
25
+ }
26
+
27
+ createRenderingCollector() {
28
+ return {
29
+ collect: () => ({
30
+ renderCount: 0,
31
+ averageRenderTime: 0,
32
+ slowestRender: 0
33
+ })
34
+ };
35
+ }
36
+ }
@@ -0,0 +1,37 @@
1
+ export function createDashboard(profiler, _options = {}) {
2
+ return {
3
+ render() {
4
+ const metrics = profiler.getMetrics();
5
+ return {
6
+ div: {
7
+ className: 'performance-dashboard',
8
+ children: [
9
+ {
10
+ h2: {
11
+ text: 'Performance Dashboard',
12
+ className: 'dashboard-title'
13
+ }
14
+ },
15
+ {
16
+ div: {
17
+ className: 'metrics-grid',
18
+ children: Object.entries(metrics).map(([name, metric]) => ({
19
+ div: {
20
+ className: 'metric-card',
21
+ children: [
22
+ { h3: { text: name } },
23
+ { p: { text: `Count: ${metric.count}` } },
24
+ { p: { text: `Average: ${metric.average?.toFixed(2)}ms` } },
25
+ { p: { text: `Min: ${metric.min}ms` } },
26
+ { p: { text: `Max: ${metric.max}ms` } }
27
+ ]
28
+ }
29
+ }))
30
+ }
31
+ }
32
+ ]
33
+ }
34
+ };
35
+ }
36
+ };
37
+ }
package/src/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Coherent.js Performance Profiler
3
+ * Advanced performance monitoring and profiling tools
4
+ */
5
+
6
+ export { PerformanceProfiler } from './profiler.js';
7
+ export { MetricsCollector } from './collectors/metrics-collector.js';
8
+ export { createProfilerServer } from './server.js';
9
+ export { createDashboard } from './dashboard/index.js';
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Performance Profiler for Coherent.js
3
+ */
4
+
5
+ export class PerformanceProfiler {
6
+ constructor(options = {}) {
7
+ this.options = {
8
+ enableMetrics: true,
9
+ enableTracing: true,
10
+ sampleRate: 1.0,
11
+ ...options
12
+ };
13
+ this.metrics = new Map();
14
+ this.traces = [];
15
+ }
16
+
17
+ startProfiling(name) {
18
+ const start = performance.now();
19
+ return {
20
+ end: () => {
21
+ const duration = performance.now() - start;
22
+ this.recordMetric(name, duration);
23
+ return duration;
24
+ }
25
+ };
26
+ }
27
+
28
+ recordMetric(name, value, tags = {}) {
29
+ if (!this.metrics.has(name)) {
30
+ this.metrics.set(name, []);
31
+ }
32
+ this.metrics.get(name).push({
33
+ value,
34
+ timestamp: Date.now(),
35
+ tags
36
+ });
37
+ }
38
+
39
+ getMetrics() {
40
+ return Object.fromEntries(this.metrics);
41
+ }
42
+
43
+ reset() {
44
+ this.metrics.clear();
45
+ this.traces = [];
46
+ }
47
+ }
package/src/server.js ADDED
@@ -0,0 +1,14 @@
1
+ export function createProfilerServer(profiler, options = {}) {
2
+ const port = options.port || 3001;
3
+
4
+ return {
5
+ start() {
6
+ console.log(`Performance profiler server would start on port ${port}`);
7
+ return Promise.resolve();
8
+ },
9
+ stop() {
10
+ console.log('Performance profiler server stopped');
11
+ return Promise.resolve();
12
+ }
13
+ };
14
+ }