@skillsmith/core 0.1.2 → 0.2.0
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/dist/.tsbuildinfo +1 -1
- package/dist/src/analysis/CodebaseAnalyzer.d.ts +4 -134
- package/dist/src/analysis/CodebaseAnalyzer.d.ts.map +1 -1
- package/dist/src/analysis/CodebaseAnalyzer.js +7 -315
- package/dist/src/analysis/CodebaseAnalyzer.js.map +1 -1
- package/dist/src/analysis/framework-detector.d.ts +47 -0
- package/dist/src/analysis/framework-detector.d.ts.map +1 -0
- package/dist/src/analysis/framework-detector.js +151 -0
- package/dist/src/analysis/framework-detector.js.map +1 -0
- package/dist/src/analysis/index.d.ts +6 -1
- package/dist/src/analysis/index.d.ts.map +1 -1
- package/dist/src/analysis/index.js +10 -1
- package/dist/src/analysis/index.js.map +1 -1
- package/dist/src/analysis/parsers.d.ts +43 -0
- package/dist/src/analysis/parsers.d.ts.map +1 -0
- package/dist/src/analysis/parsers.js +219 -0
- package/dist/src/analysis/parsers.js.map +1 -0
- package/dist/src/analysis/types.d.ts +138 -0
- package/dist/src/analysis/types.d.ts.map +1 -0
- package/dist/src/analysis/types.js +25 -0
- package/dist/src/analysis/types.js.map +1 -0
- package/dist/src/analytics/AnalyticsRepository.d.ts.map +1 -1
- package/dist/src/analytics/AnalyticsRepository.js +4 -4
- package/dist/src/analytics/AnalyticsRepository.js.map +1 -1
- package/dist/src/api/cache.d.ts +108 -0
- package/dist/src/api/cache.d.ts.map +1 -0
- package/dist/src/api/cache.js +216 -0
- package/dist/src/api/cache.js.map +1 -0
- package/dist/src/api/client.d.ts +152 -0
- package/dist/src/api/client.d.ts.map +1 -0
- package/dist/src/api/client.js +221 -0
- package/dist/src/api/client.js.map +1 -0
- package/dist/src/api/index.d.ts +10 -0
- package/dist/src/api/index.d.ts.map +1 -0
- package/dist/src/api/index.js +10 -0
- package/dist/src/api/index.js.map +1 -0
- package/dist/src/benchmarks/BenchmarkRunner.d.ts +6 -175
- package/dist/src/benchmarks/BenchmarkRunner.d.ts.map +1 -1
- package/dist/src/benchmarks/BenchmarkRunner.js +6 -123
- package/dist/src/benchmarks/BenchmarkRunner.js.map +1 -1
- package/dist/src/benchmarks/MemoryProfiler.d.ts +4 -262
- package/dist/src/benchmarks/MemoryProfiler.d.ts.map +1 -1
- package/dist/src/benchmarks/MemoryProfiler.js +4 -400
- package/dist/src/benchmarks/MemoryProfiler.js.map +1 -1
- package/dist/src/benchmarks/comparator.d.ts +38 -0
- package/dist/src/benchmarks/comparator.d.ts.map +1 -0
- package/dist/src/benchmarks/comparator.js +81 -0
- package/dist/src/benchmarks/comparator.js.map +1 -0
- package/dist/src/benchmarks/formatters.d.ts +30 -0
- package/dist/src/benchmarks/formatters.d.ts.map +1 -0
- package/dist/src/benchmarks/formatters.js +88 -0
- package/dist/src/benchmarks/formatters.js.map +1 -0
- package/dist/src/benchmarks/index.d.ts +5 -1
- package/dist/src/benchmarks/index.d.ts.map +1 -1
- package/dist/src/benchmarks/index.js +9 -2
- package/dist/src/benchmarks/index.js.map +1 -1
- package/dist/src/benchmarks/memory/MemoryProfiler.d.ts +165 -0
- package/dist/src/benchmarks/memory/MemoryProfiler.d.ts.map +1 -0
- package/dist/src/benchmarks/memory/MemoryProfiler.js +312 -0
- package/dist/src/benchmarks/memory/MemoryProfiler.js.map +1 -0
- package/dist/src/benchmarks/memory/baseline-manager.d.ts +64 -0
- package/dist/src/benchmarks/memory/baseline-manager.d.ts.map +1 -0
- package/dist/src/benchmarks/memory/baseline-manager.js +95 -0
- package/dist/src/benchmarks/memory/baseline-manager.js.map +1 -0
- package/dist/src/benchmarks/memory/index.d.ts +12 -0
- package/dist/src/benchmarks/memory/index.d.ts.map +1 -0
- package/dist/src/benchmarks/memory/index.js +12 -0
- package/dist/src/benchmarks/memory/index.js.map +1 -0
- package/dist/src/benchmarks/memory/leak-detector.d.ts +23 -0
- package/dist/src/benchmarks/memory/leak-detector.d.ts.map +1 -0
- package/dist/src/benchmarks/memory/leak-detector.js +46 -0
- package/dist/src/benchmarks/memory/leak-detector.js.map +1 -0
- package/dist/src/benchmarks/memory/regression-detector.d.ts +17 -0
- package/dist/src/benchmarks/memory/regression-detector.d.ts.map +1 -0
- package/dist/src/benchmarks/memory/regression-detector.js +56 -0
- package/dist/src/benchmarks/memory/regression-detector.js.map +1 -0
- package/dist/src/benchmarks/memory/types.d.ts +111 -0
- package/dist/src/benchmarks/memory/types.d.ts.map +1 -0
- package/dist/src/benchmarks/memory/types.js +7 -0
- package/dist/src/benchmarks/memory/types.js.map +1 -0
- package/dist/src/benchmarks/memory/utils.d.ts +17 -0
- package/dist/src/benchmarks/memory/utils.d.ts.map +1 -0
- package/dist/src/benchmarks/memory/utils.js +29 -0
- package/dist/src/benchmarks/memory/utils.js.map +1 -0
- package/dist/src/benchmarks/types.d.ts +175 -0
- package/dist/src/benchmarks/types.d.ts.map +1 -0
- package/dist/src/benchmarks/types.js +20 -0
- package/dist/src/benchmarks/types.js.map +1 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +7 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/repositories/QuarantineRepository.d.ts +4 -251
- package/dist/src/repositories/QuarantineRepository.d.ts.map +1 -1
- package/dist/src/repositories/QuarantineRepository.js +4 -441
- package/dist/src/repositories/QuarantineRepository.js.map +1 -1
- package/dist/src/repositories/quarantine/QuarantineRepository.d.ts +168 -0
- package/dist/src/repositories/quarantine/QuarantineRepository.d.ts.map +1 -0
- package/dist/src/repositories/quarantine/QuarantineRepository.js +341 -0
- package/dist/src/repositories/quarantine/QuarantineRepository.js.map +1 -0
- package/dist/src/repositories/quarantine/index.d.ts +10 -0
- package/dist/src/repositories/quarantine/index.d.ts.map +1 -0
- package/dist/src/repositories/quarantine/index.js +10 -0
- package/dist/src/repositories/quarantine/index.js.map +1 -0
- package/dist/src/repositories/quarantine/queries.d.ts +58 -0
- package/dist/src/repositories/quarantine/queries.d.ts.map +1 -0
- package/dist/src/repositories/quarantine/queries.js +88 -0
- package/dist/src/repositories/quarantine/queries.js.map +1 -0
- package/dist/src/repositories/quarantine/query-builder.d.ts +44 -0
- package/dist/src/repositories/quarantine/query-builder.d.ts.map +1 -0
- package/dist/src/repositories/quarantine/query-builder.js +87 -0
- package/dist/src/repositories/quarantine/query-builder.js.map +1 -0
- package/dist/src/repositories/quarantine/types.d.ts +155 -0
- package/dist/src/repositories/quarantine/types.d.ts.map +1 -0
- package/dist/src/repositories/quarantine/types.js +13 -0
- package/dist/src/repositories/quarantine/types.js.map +1 -0
- package/dist/src/scripts/__tests__/scan-imported-skills.test.d.ts +1 -0
- package/dist/src/scripts/__tests__/scan-imported-skills.test.d.ts.map +1 -1
- package/dist/src/scripts/__tests__/scan-imported-skills.test.js +7 -43
- package/dist/src/scripts/__tests__/scan-imported-skills.test.js.map +1 -1
- package/dist/src/scripts/github-import/checkpoint.d.ts +21 -0
- package/dist/src/scripts/github-import/checkpoint.d.ts.map +1 -0
- package/dist/src/scripts/github-import/checkpoint.js +52 -0
- package/dist/src/scripts/github-import/checkpoint.js.map +1 -0
- package/dist/src/scripts/github-import/deduplication.d.ts +15 -0
- package/dist/src/scripts/github-import/deduplication.d.ts.map +1 -0
- package/dist/src/scripts/github-import/deduplication.js +33 -0
- package/dist/src/scripts/github-import/deduplication.js.map +1 -0
- package/dist/src/scripts/github-import/github-client.d.ts +29 -0
- package/dist/src/scripts/github-import/github-client.d.ts.map +1 -0
- package/dist/src/scripts/github-import/github-client.js +184 -0
- package/dist/src/scripts/github-import/github-client.js.map +1 -0
- package/dist/src/scripts/github-import/index.d.ts +29 -0
- package/dist/src/scripts/github-import/index.d.ts.map +1 -0
- package/dist/src/scripts/github-import/index.js +198 -0
- package/dist/src/scripts/github-import/index.js.map +1 -0
- package/dist/src/scripts/github-import/output.d.ts +12 -0
- package/dist/src/scripts/github-import/output.d.ts.map +1 -0
- package/dist/src/scripts/github-import/output.js +34 -0
- package/dist/src/scripts/github-import/output.js.map +1 -0
- package/dist/src/scripts/github-import/types.d.ts +108 -0
- package/dist/src/scripts/github-import/types.d.ts.map +1 -0
- package/dist/src/scripts/github-import/types.js +44 -0
- package/dist/src/scripts/github-import/types.js.map +1 -0
- package/dist/src/scripts/github-import/utils.d.ts +13 -0
- package/dist/src/scripts/github-import/utils.d.ts.map +1 -0
- package/dist/src/scripts/github-import/utils.js +28 -0
- package/dist/src/scripts/github-import/utils.js.map +1 -0
- package/dist/src/scripts/import-github-skills.d.ts +3 -12
- package/dist/src/scripts/import-github-skills.d.ts.map +1 -1
- package/dist/src/scripts/import-github-skills.js +18 -398
- package/dist/src/scripts/import-github-skills.js.map +1 -1
- package/dist/src/scripts/scan-imported-skills.d.ts +7 -7
- package/dist/src/scripts/scan-imported-skills.d.ts.map +1 -1
- package/dist/src/scripts/scan-imported-skills.js +8 -397
- package/dist/src/scripts/scan-imported-skills.js.map +1 -1
- package/dist/src/scripts/skill-scanner/categorizer.d.ts +43 -0
- package/dist/src/scripts/skill-scanner/categorizer.d.ts.map +1 -0
- package/dist/src/scripts/skill-scanner/categorizer.js +61 -0
- package/dist/src/scripts/skill-scanner/categorizer.js.map +1 -0
- package/dist/src/scripts/skill-scanner/file-scanner.d.ts +43 -0
- package/dist/src/scripts/skill-scanner/file-scanner.d.ts.map +1 -0
- package/dist/src/scripts/skill-scanner/file-scanner.js +90 -0
- package/dist/src/scripts/skill-scanner/file-scanner.js.map +1 -0
- package/dist/src/scripts/skill-scanner/index.d.ts +22 -0
- package/dist/src/scripts/skill-scanner/index.d.ts.map +1 -0
- package/dist/src/scripts/skill-scanner/index.js +43 -0
- package/dist/src/scripts/skill-scanner/index.js.map +1 -0
- package/dist/src/scripts/skill-scanner/logger.d.ts +59 -0
- package/dist/src/scripts/skill-scanner/logger.d.ts.map +1 -0
- package/dist/src/scripts/skill-scanner/logger.js +104 -0
- package/dist/src/scripts/skill-scanner/logger.js.map +1 -0
- package/dist/src/scripts/skill-scanner/reporter.d.ts +56 -0
- package/dist/src/scripts/skill-scanner/reporter.d.ts.map +1 -0
- package/dist/src/scripts/skill-scanner/reporter.js +166 -0
- package/dist/src/scripts/skill-scanner/reporter.js.map +1 -0
- package/dist/src/scripts/skill-scanner/scanner.d.ts +44 -0
- package/dist/src/scripts/skill-scanner/scanner.d.ts.map +1 -0
- package/dist/src/scripts/skill-scanner/scanner.js +140 -0
- package/dist/src/scripts/skill-scanner/scanner.js.map +1 -0
- package/dist/src/scripts/skill-scanner/trust-scorer.d.ts +59 -0
- package/dist/src/scripts/skill-scanner/trust-scorer.d.ts.map +1 -0
- package/dist/src/scripts/skill-scanner/trust-scorer.js +62 -0
- package/dist/src/scripts/skill-scanner/trust-scorer.js.map +1 -0
- package/dist/src/scripts/skill-scanner/types.d.ts +98 -0
- package/dist/src/scripts/skill-scanner/types.d.ts.map +1 -0
- package/dist/src/scripts/skill-scanner/types.js +7 -0
- package/dist/src/scripts/skill-scanner/types.js.map +1 -0
- package/dist/src/scripts/validate-skills.d.ts +3 -172
- package/dist/src/scripts/validate-skills.d.ts.map +1 -1
- package/dist/src/scripts/validate-skills.js +6 -519
- package/dist/src/scripts/validate-skills.js.map +1 -1
- package/dist/src/scripts/validation/deduplication.d.ts +23 -0
- package/dist/src/scripts/validation/deduplication.d.ts.map +1 -0
- package/dist/src/scripts/validation/deduplication.js +127 -0
- package/dist/src/scripts/validation/deduplication.js.map +1 -0
- package/dist/src/scripts/validation/field-validators.d.ts +9 -0
- package/dist/src/scripts/validation/field-validators.d.ts.map +1 -0
- package/dist/src/scripts/validation/field-validators.js +135 -0
- package/dist/src/scripts/validation/field-validators.js.map +1 -0
- package/dist/src/scripts/validation/index.d.ts +29 -0
- package/dist/src/scripts/validation/index.d.ts.map +1 -0
- package/dist/src/scripts/validation/index.js +84 -0
- package/dist/src/scripts/validation/index.js.map +1 -0
- package/dist/src/scripts/validation/normalizers.d.ts +29 -0
- package/dist/src/scripts/validation/normalizers.d.ts.map +1 -0
- package/dist/src/scripts/validation/normalizers.js +79 -0
- package/dist/src/scripts/validation/normalizers.js.map +1 -0
- package/dist/src/scripts/validation/pipeline.d.ts +13 -0
- package/dist/src/scripts/validation/pipeline.d.ts.map +1 -0
- package/dist/src/scripts/validation/pipeline.js +126 -0
- package/dist/src/scripts/validation/pipeline.js.map +1 -0
- package/dist/src/scripts/validation/types.d.ts +128 -0
- package/dist/src/scripts/validation/types.d.ts.map +1 -0
- package/dist/src/scripts/validation/types.js +43 -0
- package/dist/src/scripts/validation/types.js.map +1 -0
- package/dist/src/security/index.d.ts +5 -4
- package/dist/src/security/index.d.ts.map +1 -1
- package/dist/src/security/index.js +8 -2
- package/dist/src/security/index.js.map +1 -1
- package/dist/src/security/rate-limiter/RateLimiter.d.ts +86 -0
- package/dist/src/security/rate-limiter/RateLimiter.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/RateLimiter.js +260 -0
- package/dist/src/security/rate-limiter/RateLimiter.js.map +1 -0
- package/dist/src/security/rate-limiter/constants.d.ts +15 -0
- package/dist/src/security/rate-limiter/constants.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/constants.js +15 -0
- package/dist/src/security/rate-limiter/constants.js.map +1 -0
- package/dist/src/security/rate-limiter/errors.d.ts +22 -0
- package/dist/src/security/rate-limiter/errors.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/errors.js +32 -0
- package/dist/src/security/rate-limiter/errors.js.map +1 -0
- package/dist/src/security/rate-limiter/index.d.ts +12 -0
- package/dist/src/security/rate-limiter/index.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/index.js +16 -0
- package/dist/src/security/rate-limiter/index.js.map +1 -0
- package/dist/src/security/rate-limiter/metrics-manager.d.ts +55 -0
- package/dist/src/security/rate-limiter/metrics-manager.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/metrics-manager.js +144 -0
- package/dist/src/security/rate-limiter/metrics-manager.js.map +1 -0
- package/dist/src/security/rate-limiter/presets.d.ts +52 -0
- package/dist/src/security/rate-limiter/presets.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/presets.js +53 -0
- package/dist/src/security/rate-limiter/presets.js.map +1 -0
- package/dist/src/security/rate-limiter/queue-manager.d.ts +59 -0
- package/dist/src/security/rate-limiter/queue-manager.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/queue-manager.js +189 -0
- package/dist/src/security/rate-limiter/queue-manager.js.map +1 -0
- package/dist/src/security/rate-limiter/storage.d.ts +34 -0
- package/dist/src/security/rate-limiter/storage.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/storage.js +80 -0
- package/dist/src/security/rate-limiter/storage.js.map +1 -0
- package/dist/src/security/rate-limiter/token-bucket.d.ts +44 -0
- package/dist/src/security/rate-limiter/token-bucket.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/token-bucket.js +99 -0
- package/dist/src/security/rate-limiter/token-bucket.js.map +1 -0
- package/dist/src/security/rate-limiter/types.d.ts +104 -0
- package/dist/src/security/rate-limiter/types.d.ts.map +1 -0
- package/dist/src/security/rate-limiter/types.js +7 -0
- package/dist/src/security/rate-limiter/types.js.map +1 -0
- package/dist/src/security/scanner/SecurityScanner.d.ts +94 -0
- package/dist/src/security/scanner/SecurityScanner.d.ts.map +1 -0
- package/dist/src/security/scanner/SecurityScanner.js +403 -0
- package/dist/src/security/scanner/SecurityScanner.js.map +1 -0
- package/dist/src/security/scanner/index.d.ts +11 -0
- package/dist/src/security/scanner/index.d.ts.map +1 -0
- package/dist/src/security/scanner/index.js +14 -0
- package/dist/src/security/scanner/index.js.map +1 -0
- package/dist/src/security/scanner/patterns.d.ts +14 -0
- package/dist/src/security/scanner/patterns.d.ts.map +1 -0
- package/dist/src/security/scanner/patterns.js +147 -0
- package/dist/src/security/scanner/patterns.js.map +1 -0
- package/dist/src/security/scanner/regex-utils.d.ts +33 -0
- package/dist/src/security/scanner/regex-utils.d.ts.map +1 -0
- package/dist/src/security/scanner/regex-utils.js +41 -0
- package/dist/src/security/scanner/regex-utils.js.map +1 -0
- package/dist/src/security/scanner/types.d.ts +63 -0
- package/dist/src/security/scanner/types.d.ts.map +1 -0
- package/dist/src/security/scanner/types.js +7 -0
- package/dist/src/security/scanner/types.js.map +1 -0
- package/dist/src/security/scanner/weights.d.ts +15 -0
- package/dist/src/security/scanner/weights.d.ts.map +1 -0
- package/dist/src/security/scanner/weights.js +28 -0
- package/dist/src/security/scanner/weights.js.map +1 -0
- package/dist/src/session/SessionHealthMonitor.d.ts +5 -168
- package/dist/src/session/SessionHealthMonitor.d.ts.map +1 -1
- package/dist/src/session/SessionHealthMonitor.js +22 -91
- package/dist/src/session/SessionHealthMonitor.js.map +1 -1
- package/dist/src/session/health-checks.d.ts +37 -0
- package/dist/src/session/health-checks.d.ts.map +1 -0
- package/dist/src/session/health-checks.js +64 -0
- package/dist/src/session/health-checks.js.map +1 -0
- package/dist/src/session/health-types.d.ts +78 -0
- package/dist/src/session/health-types.d.ts.map +1 -0
- package/dist/src/session/health-types.js +16 -0
- package/dist/src/session/health-types.js.map +1 -0
- package/dist/src/session/index.d.ts +5 -1
- package/dist/src/session/index.d.ts.map +1 -1
- package/dist/src/session/index.js +9 -0
- package/dist/src/session/index.js.map +1 -1
- package/dist/src/session/metrics-collector.d.ts +23 -0
- package/dist/src/session/metrics-collector.d.ts.map +1 -0
- package/dist/src/session/metrics-collector.js +44 -0
- package/dist/src/session/metrics-collector.js.map +1 -0
- package/dist/src/session/typed-event-emitter.d.ts +70 -0
- package/dist/src/session/typed-event-emitter.d.ts.map +1 -0
- package/dist/src/session/typed-event-emitter.js +79 -0
- package/dist/src/session/typed-event-emitter.js.map +1 -0
- package/dist/src/sources/BaseSourceAdapter.d.ts +1 -1
- package/dist/src/sources/BaseSourceAdapter.d.ts.map +1 -1
- package/dist/src/sources/BaseSourceAdapter.js +2 -2
- package/dist/src/sources/BaseSourceAdapter.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +1 -0
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/index.js +2 -0
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/posthog.d.ts +125 -0
- package/dist/src/telemetry/posthog.d.ts.map +1 -0
- package/dist/src/telemetry/posthog.js +198 -0
- package/dist/src/telemetry/posthog.js.map +1 -0
- package/dist/tests/RateLimiter.test.js +4 -4
- package/dist/tests/RateLimiter.test.js.map +1 -1
- package/dist/tests/e2e/security/security.e2e.test.js +3 -3
- package/dist/tests/e2e/security/security.e2e.test.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SMI-632: Benchmark Report Formatters
|
|
3
|
+
* SMI-689: Enhanced with memory profiling output
|
|
4
|
+
* SMI-1189: Extracted from BenchmarkRunner.ts
|
|
5
|
+
*
|
|
6
|
+
* Functions for formatting benchmark reports in various output formats.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Format bytes to human-readable string
|
|
10
|
+
*
|
|
11
|
+
* @param bytes - Number of bytes
|
|
12
|
+
* @returns Human-readable string (e.g., "1.5 MB")
|
|
13
|
+
*/
|
|
14
|
+
export function formatBytes(bytes) {
|
|
15
|
+
if (bytes === 0)
|
|
16
|
+
return '0 B';
|
|
17
|
+
const k = 1024;
|
|
18
|
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
|
19
|
+
const i = Math.floor(Math.log(Math.abs(bytes)) / Math.log(k));
|
|
20
|
+
const value = bytes / Math.pow(k, i);
|
|
21
|
+
return `${value.toFixed(1)} ${sizes[i]}`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Format a benchmark report as JSON for CI integration
|
|
25
|
+
*
|
|
26
|
+
* @param report - Benchmark report to format
|
|
27
|
+
* @returns JSON string
|
|
28
|
+
*/
|
|
29
|
+
export function formatReportAsJson(report) {
|
|
30
|
+
return JSON.stringify(report, null, 2);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Format a benchmark report as human-readable text
|
|
34
|
+
*
|
|
35
|
+
* @param report - Benchmark report to format
|
|
36
|
+
* @returns Formatted text string
|
|
37
|
+
*/
|
|
38
|
+
export function formatReportAsText(report) {
|
|
39
|
+
const lines = [
|
|
40
|
+
`Benchmark Report: ${report.suite}`,
|
|
41
|
+
`Timestamp: ${report.timestamp}`,
|
|
42
|
+
`Environment: Node ${report.environment.node} on ${report.environment.platform}/${report.environment.arch}`,
|
|
43
|
+
`Docker: ${report.environment.docker ? 'Yes' : 'No'}`,
|
|
44
|
+
'',
|
|
45
|
+
'Results:',
|
|
46
|
+
'-'.repeat(80),
|
|
47
|
+
];
|
|
48
|
+
for (const [name, stats] of Object.entries(report.results)) {
|
|
49
|
+
lines.push(` ${name}:`);
|
|
50
|
+
lines.push(` Iterations: ${stats.iterations}`);
|
|
51
|
+
lines.push(` p50: ${stats.p50_ms}ms, p95: ${stats.p95_ms}ms, p99: ${stats.p99_ms}ms`);
|
|
52
|
+
lines.push(` Mean: ${stats.mean_ms}ms, StdDev: ${stats.stddev_ms}ms`);
|
|
53
|
+
lines.push(` Min: ${stats.min_ms}ms, Max: ${stats.max_ms}ms`);
|
|
54
|
+
if (stats.memoryPeak_mb !== undefined) {
|
|
55
|
+
lines.push(` Memory Peak: ${stats.memoryPeak_mb}MB`);
|
|
56
|
+
}
|
|
57
|
+
// SMI-689: Add detailed memory profile if available
|
|
58
|
+
if (report.memoryProfile?.[name]) {
|
|
59
|
+
const mp = report.memoryProfile[name];
|
|
60
|
+
lines.push(` Memory Profile:`);
|
|
61
|
+
lines.push(` Heap Growth: ${formatBytes(mp.heapGrowth)} (${mp.heapGrowthPercent.toFixed(1)}%)`);
|
|
62
|
+
lines.push(` Peak Heap: ${formatBytes(mp.peakHeapSize)}`);
|
|
63
|
+
lines.push(` Samples: ${mp.sampleCount}`);
|
|
64
|
+
}
|
|
65
|
+
lines.push('');
|
|
66
|
+
}
|
|
67
|
+
lines.push('-'.repeat(80));
|
|
68
|
+
lines.push(`Summary:`);
|
|
69
|
+
lines.push(` Total Benchmarks: ${report.summary.totalBenchmarks}`);
|
|
70
|
+
lines.push(` Total Iterations: ${report.summary.totalIterations}`);
|
|
71
|
+
lines.push(` Total Duration: ${report.summary.totalDuration_ms}ms`);
|
|
72
|
+
// SMI-689: Add memory regression summary
|
|
73
|
+
if (report.memoryRegression) {
|
|
74
|
+
lines.push('');
|
|
75
|
+
lines.push('Memory Regression Check:');
|
|
76
|
+
if (report.memoryRegression.hasRegressions) {
|
|
77
|
+
lines.push(` WARNING: ${report.memoryRegression.regressions.length} regression(s) detected (threshold: ${report.memoryRegression.threshold}%)`);
|
|
78
|
+
for (const reg of report.memoryRegression.regressions) {
|
|
79
|
+
lines.push(` - ${reg.label}: ${reg.changePercent.toFixed(1)}% increase`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
lines.push(` No memory regressions detected (threshold: ${report.memoryRegression.threshold}%)`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return lines.join('\n');
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=formatters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.js","sourceRoot":"","sources":["../../../src/benchmarks/formatters.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,IAAI,KAAK,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAC7B,MAAM,CAAC,GAAG,IAAI,CAAA;IACd,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IACrC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7D,MAAM,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC,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B,EAAE,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAA;QACtC,IAAI,MAAM,CAAC,gBAAgB,CAAC,cAAc,EAAE,CAAC;YAC3C,KAAK,CAAC,IAAI,CACR,cAAc,MAAM,CAAC,gBAAgB,CAAC,WAAW,CAAC,MAAM,uCAAuC,MAAM,CAAC,gBAAgB,CAAC,SAAS,IAAI,CACrI,CAAA;YACD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,CAAC;gBACtD,KAAK,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC,KAAK,KAAK,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;YAC7E,CAAC;QACH,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CACR,gDAAgD,MAAM,CAAC,gBAAgB,CAAC,SAAS,IAAI,CACtF,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SMI-632: Benchmark module exports
|
|
3
3
|
* SMI-689: Enhanced with MemoryProfiler integration
|
|
4
|
+
* SMI-1189: Updated to export from split modules
|
|
4
5
|
*
|
|
5
6
|
* Provides performance benchmarking infrastructure for:
|
|
6
7
|
* - Search query latency
|
|
@@ -9,7 +10,10 @@
|
|
|
9
10
|
* - CI integration
|
|
10
11
|
* - Memory profiling and leak detection
|
|
11
12
|
*/
|
|
12
|
-
export { BenchmarkRunner, type BenchmarkConfig, type BenchmarkResult, type BenchmarkStats, type BenchmarkReport, type BenchmarkDefinition, type BenchmarkFn, type MemoryStats, type EnvironmentInfo, type ComparisonResult, type MetricComparison, type DetailedMemoryStats, type MemoryRegressionInfo, formatReportAsJson, formatReportAsText, compareReports, } from './BenchmarkRunner.js';
|
|
13
|
+
export { BenchmarkRunner, type BenchmarkConfig, type BenchmarkResult, type BenchmarkStats, type BenchmarkReport, type BenchmarkDefinition, type BenchmarkFn, type MemoryStats, type EnvironmentInfo, type ComparisonResult, type MetricComparison, type DetailedMemoryStats, type MemoryRegressionInfo, formatReportAsJson, formatReportAsText, formatBytes, compareReports, hasRegressions, getRegressedBenchmarks, getImprovedBenchmarks, } from './BenchmarkRunner.js';
|
|
14
|
+
export { DEFAULT_CONFIG } from './types.js';
|
|
15
|
+
export { formatBytes as formatBytesUtil } from './formatters.js';
|
|
16
|
+
export { hasRegressions as hasRegressionsUtil } from './comparator.js';
|
|
13
17
|
export { MemoryProfiler, defaultMemoryProfiler, type MemorySnapshot, type MemoryStats as ProfilerMemoryStats, type MemoryBaseline, type LeakDetectionResult, type MemoryRegressionResult, } from './MemoryProfiler.js';
|
|
14
18
|
export { SearchBenchmark, type SearchBenchmarkConfig, type ValidationResult, SEARCH_TARGETS, validateSearchResults, } from './SearchBenchmark.js';
|
|
15
19
|
export { IndexBenchmark, type IndexBenchmarkConfig, type ThroughputResult, type SizeImpactResult, type IndexValidationResult, INDEX_TARGETS, validateIndexResults, } from './IndexBenchmark.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/benchmarks/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/benchmarks/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EACL,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB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zB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,WAAW,CAAA;IAClD,2CAA2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,uCAAuC;IACvC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,sDAAsD;IACtD,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,kDAAkD;IAClD,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SMI-632: Benchmark module exports
|
|
3
3
|
* SMI-689: Enhanced with MemoryProfiler integration
|
|
4
|
+
* SMI-1189: Updated to export from split modules
|
|
4
5
|
*
|
|
5
6
|
* Provides performance benchmarking infrastructure for:
|
|
6
7
|
* - Search query latency
|
|
@@ -9,8 +10,14 @@
|
|
|
9
10
|
* - CI integration
|
|
10
11
|
* - Memory profiling and leak detection
|
|
11
12
|
*/
|
|
12
|
-
// Core benchmark runner
|
|
13
|
-
export { BenchmarkRunner, formatReportAsJson, formatReportAsText, compareReports, } from './BenchmarkRunner.js';
|
|
13
|
+
// Core benchmark runner (includes re-exports for backwards compatibility)
|
|
14
|
+
export { BenchmarkRunner, formatReportAsJson, formatReportAsText, formatBytes, compareReports, hasRegressions, getRegressedBenchmarks, getImprovedBenchmarks, } from './BenchmarkRunner.js';
|
|
15
|
+
// Types module (direct access)
|
|
16
|
+
export { DEFAULT_CONFIG } from './types.js';
|
|
17
|
+
// Formatters module (direct access)
|
|
18
|
+
export { formatBytes as formatBytesUtil } from './formatters.js';
|
|
19
|
+
// Comparator module (direct access)
|
|
20
|
+
export { hasRegressions as hasRegressionsUtil } from './comparator.js';
|
|
14
21
|
// SMI-689: Memory profiler
|
|
15
22
|
export { MemoryProfiler, defaultMemoryProfiler, } from './MemoryProfiler.js';
|
|
16
23
|
// Search benchmarks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/benchmarks/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/benchmarks/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,0EAA0E;AAC1E,OAAO,EACL,eAAe,EAaf,kBAAkB,EAClB,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,cAAc,EACd,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,sBAAsB,CAAA;AAE7B,+BAA+B;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAE3C,oCAAoC;AACpC,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEhE,oCAAoC;AACpC,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEtE,2BAA2B;AAC3B,OAAO,EACL,cAAc,EACd,qBAAqB,GAMtB,MAAM,qBAAqB,CAAA;AAE5B,oBAAoB;AACpB,OAAO,EACL,eAAe,EAGf,cAAc,EACd,qBAAqB,GACtB,MAAM,sBAAsB,CAAA;AAE7B,mBAAmB;AACnB,OAAO,EACL,cAAc,EAKd,aAAa,EACb,oBAAoB,GACrB,MAAM,qBAAqB,CAAA;AAE5B,4BAA4B;AAC5B,OAAO,EACL,cAAc,EAGd,aAAa,EACb,oBAAoB,GACrB,MAAM,qBAAqB,CAAA;AAE5B,gCAAgC;AAChC,OAAO,EACL,kBAAkB,EAGlB,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,yBAAyB,CAAA;AAEhC,wCAAwC;AACxC,OAAO,EACL,UAAU,EACV,IAAI,EACJ,YAAY,EACZ,qBAAqB,GAEtB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;GAWG;AACH,M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AAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AACtF,OAAO,EAEL,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,GACf,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SMI-689: MemoryProfiler - Memory profiling for benchmark infrastructure
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Track memory usage for labeled operations
|
|
6
|
+
* - Detect memory leaks over threshold
|
|
7
|
+
* - Get heap snapshots using V8 statistics
|
|
8
|
+
* - Generate human-readable memory reports
|
|
9
|
+
* - Baseline comparison for memory regression detection
|
|
10
|
+
*/
|
|
11
|
+
import type { MemorySnapshot, MemoryStats, MemoryBaseline, LeakDetectionResult, MemoryRegressionResult } from './types.js';
|
|
12
|
+
export type { MemorySnapshot, MemoryStats, MemoryBaseline, LeakDetectionResult, MemoryRegressionResult, } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* MemoryProfiler provides comprehensive memory tracking and leak detection
|
|
15
|
+
* for the benchmark infrastructure.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const profiler = new MemoryProfiler();
|
|
20
|
+
*
|
|
21
|
+
* profiler.trackMemory('heavy_operation');
|
|
22
|
+
* await heavyOperation();
|
|
23
|
+
* const stats = profiler.stopTracking('heavy_operation');
|
|
24
|
+
*
|
|
25
|
+
* console.log(`Heap grew by ${stats.heapGrowthPercent}%`);
|
|
26
|
+
*
|
|
27
|
+
* // Check for leaks
|
|
28
|
+
* const leakResult = profiler.detectLeaks(10);
|
|
29
|
+
* if (leakResult.hasLeaks) {
|
|
30
|
+
* console.error(leakResult.message);
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class MemoryProfiler {
|
|
35
|
+
private activeTracking;
|
|
36
|
+
private completedStats;
|
|
37
|
+
private baselineManager;
|
|
38
|
+
private samplingIntervalMs;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new MemoryProfiler instance
|
|
41
|
+
*
|
|
42
|
+
* @param samplingIntervalMs - Interval in ms for collecting memory samples (default: 100ms)
|
|
43
|
+
*/
|
|
44
|
+
constructor(samplingIntervalMs?: number);
|
|
45
|
+
/**
|
|
46
|
+
* Start tracking memory for a labeled operation
|
|
47
|
+
*
|
|
48
|
+
* @param label - Unique label to identify this tracking session
|
|
49
|
+
* @throws Error if label is already being tracked
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* profiler.trackMemory('database_query');
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
trackMemory(label: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Stop tracking memory for a labeled operation and return statistics
|
|
59
|
+
*
|
|
60
|
+
* @param label - Label of the tracking session to stop
|
|
61
|
+
* @returns Memory statistics for the tracked operation
|
|
62
|
+
* @throws Error if label is not being tracked
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const stats = profiler.stopTracking('database_query');
|
|
67
|
+
* console.log(`Heap growth: ${stats.heapGrowthPercent}%`);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
stopTracking(label: string): MemoryStats;
|
|
71
|
+
/**
|
|
72
|
+
* Get current heap statistics using V8
|
|
73
|
+
*
|
|
74
|
+
* @returns Current memory snapshot
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* const snapshot = profiler.getHeapSnapshot();
|
|
79
|
+
* console.log(`Used heap: ${snapshot.usedHeapSize / 1024 / 1024} MB`);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
getHeapSnapshot(): MemorySnapshot;
|
|
83
|
+
/**
|
|
84
|
+
* Detect potential memory leaks across all completed tracking sessions
|
|
85
|
+
*
|
|
86
|
+
* @param threshold - Heap growth percentage threshold to consider a leak (default: 10%)
|
|
87
|
+
* @returns Leak detection result
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const result = profiler.detectLeaks(15); // 15% threshold
|
|
92
|
+
* if (result.hasLeaks) {
|
|
93
|
+
* console.error(`Potential leak detected: ${result.message}`);
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
detectLeaks(threshold?: number): LeakDetectionResult;
|
|
98
|
+
/**
|
|
99
|
+
* Save a baseline for memory regression comparison
|
|
100
|
+
*
|
|
101
|
+
* @param label - Label to save as baseline
|
|
102
|
+
* @throws Error if no completed stats exist for the label
|
|
103
|
+
*/
|
|
104
|
+
saveBaseline(label: string): MemoryBaseline;
|
|
105
|
+
/**
|
|
106
|
+
* Load baselines from a JSON object
|
|
107
|
+
*
|
|
108
|
+
* @param baselines - Object mapping labels to baselines
|
|
109
|
+
*/
|
|
110
|
+
loadBaselines(baselines: Record<string, MemoryBaseline>): void;
|
|
111
|
+
/**
|
|
112
|
+
* Check for memory regression against baseline
|
|
113
|
+
*
|
|
114
|
+
* @param label - Label to check
|
|
115
|
+
* @param threshold - Regression threshold percentage (default: 10%)
|
|
116
|
+
* @returns Regression result
|
|
117
|
+
*/
|
|
118
|
+
checkRegression(label: string, threshold?: number): MemoryRegressionResult;
|
|
119
|
+
/**
|
|
120
|
+
* Generate a human-readable memory report
|
|
121
|
+
*
|
|
122
|
+
* @returns Formatted memory report string
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* profiler.trackMemory('op1');
|
|
127
|
+
* await operation1();
|
|
128
|
+
* profiler.stopTracking('op1');
|
|
129
|
+
*
|
|
130
|
+
* console.log(profiler.formatMemoryReport());
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
formatMemoryReport(): string;
|
|
134
|
+
/**
|
|
135
|
+
* Get all completed statistics
|
|
136
|
+
*
|
|
137
|
+
* @returns Map of label to MemoryStats
|
|
138
|
+
*/
|
|
139
|
+
getCompletedStats(): Map<string, MemoryStats>;
|
|
140
|
+
/**
|
|
141
|
+
* Get all baselines
|
|
142
|
+
*
|
|
143
|
+
* @returns Map of label to MemoryBaseline
|
|
144
|
+
*/
|
|
145
|
+
getBaselines(): Map<string, MemoryBaseline>;
|
|
146
|
+
/**
|
|
147
|
+
* Export baselines as JSON-serializable object
|
|
148
|
+
*
|
|
149
|
+
* @returns Object mapping labels to baselines
|
|
150
|
+
*/
|
|
151
|
+
exportBaselines(): Record<string, MemoryBaseline>;
|
|
152
|
+
/**
|
|
153
|
+
* Clear all tracking data
|
|
154
|
+
*/
|
|
155
|
+
clear(): void;
|
|
156
|
+
/**
|
|
157
|
+
* Clear baselines
|
|
158
|
+
*/
|
|
159
|
+
clearBaselines(): void;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Default memory profiler instance for convenience
|
|
163
|
+
*/
|
|
164
|
+
export declare const defaultMemoryProfiler: MemoryProfiler;
|
|
165
|
+
//# sourceMappingURL=MemoryProfiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MemoryProfiler.d.ts","sourceRoot":"","sources":["../../../../src/benchmarks/memory/MemoryProfiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EAEvB,MAAM,YAAY,CAAA;AAOnB,YAAY,EACV,cAAc,EACd,WAAW,EACX,cAAc,EACd,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,YAAY,CAAA;AAEnB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,cAAc,CAAwC;IAC9D,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,eAAe,CAAyC;IAChE,OAAO,CAAC,kBAAkB,CAAQ;IAElC;;;;OAIG;gBACS,kBAAkB,GAAE,MAAY;IAI5C;;;;;;;;;;OAUG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAyBhC;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW;IA+CxC;;;;;;;;;;OAUG;IACH,eAAe,IAAI,cAAc;IAiBjC;;;;;;;;;;;;;OAaG;IACH,WAAW,CAAC,SAAS,GAAE,MAAW,GAAG,mBAAmB;IAIxD;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc;IAQ3C;;;;OAIG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,GAAG,IAAI;IAI9D;;;;;;OAMG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,sBAAsB;IAS9E;;;;;;;;;;;;;OAaG;IACH,kBAAkB,IAAI,MAAM;IAkF5B;;;;OAIG;IACH,iBAAiB,IAAI,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC;IAI7C;;;;OAIG;IACH,YAAY,IAAI,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC;IAI3C;;;;OAIG;IACH,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC;IAIjD;;OAEG;IACH,KAAK,IAAI,IAAI;IAWb;;OAEG;IACH,cAAc,IAAI,IAAI;CAGvB;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,gBAAuB,CAAA"}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SMI-689: MemoryProfiler - Memory profiling for benchmark infrastructure
|
|
3
|
+
*
|
|
4
|
+
* Features:
|
|
5
|
+
* - Track memory usage for labeled operations
|
|
6
|
+
* - Detect memory leaks over threshold
|
|
7
|
+
* - Get heap snapshots using V8 statistics
|
|
8
|
+
* - Generate human-readable memory reports
|
|
9
|
+
* - Baseline comparison for memory regression detection
|
|
10
|
+
*/
|
|
11
|
+
import * as v8 from 'v8';
|
|
12
|
+
import { BaselineManager } from './baseline-manager.js';
|
|
13
|
+
import { detectLeaks } from './leak-detector.js';
|
|
14
|
+
import { checkRegression } from './regression-detector.js';
|
|
15
|
+
import { formatBytes, forceGC } from './utils.js';
|
|
16
|
+
/**
|
|
17
|
+
* MemoryProfiler provides comprehensive memory tracking and leak detection
|
|
18
|
+
* for the benchmark infrastructure.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const profiler = new MemoryProfiler();
|
|
23
|
+
*
|
|
24
|
+
* profiler.trackMemory('heavy_operation');
|
|
25
|
+
* await heavyOperation();
|
|
26
|
+
* const stats = profiler.stopTracking('heavy_operation');
|
|
27
|
+
*
|
|
28
|
+
* console.log(`Heap grew by ${stats.heapGrowthPercent}%`);
|
|
29
|
+
*
|
|
30
|
+
* // Check for leaks
|
|
31
|
+
* const leakResult = profiler.detectLeaks(10);
|
|
32
|
+
* if (leakResult.hasLeaks) {
|
|
33
|
+
* console.error(leakResult.message);
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export class MemoryProfiler {
|
|
38
|
+
activeTracking = new Map();
|
|
39
|
+
completedStats = new Map();
|
|
40
|
+
baselineManager = new BaselineManager();
|
|
41
|
+
samplingIntervalMs;
|
|
42
|
+
/**
|
|
43
|
+
* Create a new MemoryProfiler instance
|
|
44
|
+
*
|
|
45
|
+
* @param samplingIntervalMs - Interval in ms for collecting memory samples (default: 100ms)
|
|
46
|
+
*/
|
|
47
|
+
constructor(samplingIntervalMs = 100) {
|
|
48
|
+
this.samplingIntervalMs = samplingIntervalMs;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Start tracking memory for a labeled operation
|
|
52
|
+
*
|
|
53
|
+
* @param label - Unique label to identify this tracking session
|
|
54
|
+
* @throws Error if label is already being tracked
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* profiler.trackMemory('database_query');
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
trackMemory(label) {
|
|
62
|
+
if (this.activeTracking.has(label)) {
|
|
63
|
+
throw new Error(`Memory tracking already active for label: ${label}`);
|
|
64
|
+
}
|
|
65
|
+
// Force GC if available for more accurate starting point
|
|
66
|
+
forceGC();
|
|
67
|
+
const startSnapshot = this.getHeapSnapshot();
|
|
68
|
+
const entry = {
|
|
69
|
+
label,
|
|
70
|
+
startSnapshot,
|
|
71
|
+
startTime: performance.now(),
|
|
72
|
+
samples: [startSnapshot],
|
|
73
|
+
};
|
|
74
|
+
// Start periodic sampling
|
|
75
|
+
entry.samplingInterval = setInterval(() => {
|
|
76
|
+
const snapshot = this.getHeapSnapshot();
|
|
77
|
+
entry.samples.push(snapshot);
|
|
78
|
+
}, this.samplingIntervalMs);
|
|
79
|
+
this.activeTracking.set(label, entry);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Stop tracking memory for a labeled operation and return statistics
|
|
83
|
+
*
|
|
84
|
+
* @param label - Label of the tracking session to stop
|
|
85
|
+
* @returns Memory statistics for the tracked operation
|
|
86
|
+
* @throws Error if label is not being tracked
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const stats = profiler.stopTracking('database_query');
|
|
91
|
+
* console.log(`Heap growth: ${stats.heapGrowthPercent}%`);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
stopTracking(label) {
|
|
95
|
+
const entry = this.activeTracking.get(label);
|
|
96
|
+
if (!entry) {
|
|
97
|
+
throw new Error(`No active memory tracking for label: ${label}`);
|
|
98
|
+
}
|
|
99
|
+
// Stop sampling
|
|
100
|
+
if (entry.samplingInterval) {
|
|
101
|
+
clearInterval(entry.samplingInterval);
|
|
102
|
+
}
|
|
103
|
+
// Force GC for accurate end measurement
|
|
104
|
+
forceGC();
|
|
105
|
+
const endSnapshot = this.getHeapSnapshot();
|
|
106
|
+
const duration = performance.now() - entry.startTime;
|
|
107
|
+
// Calculate peak from samples
|
|
108
|
+
const peakHeapUsed = Math.max(entry.startSnapshot.usedHeapSize, ...entry.samples.map((s) => s.usedHeapSize), endSnapshot.usedHeapSize);
|
|
109
|
+
const heapGrowth = endSnapshot.usedHeapSize - entry.startSnapshot.usedHeapSize;
|
|
110
|
+
const heapGrowthPercent = entry.startSnapshot.usedHeapSize > 0
|
|
111
|
+
? (heapGrowth / entry.startSnapshot.usedHeapSize) * 100
|
|
112
|
+
: 0;
|
|
113
|
+
const stats = {
|
|
114
|
+
label,
|
|
115
|
+
startSnapshot: entry.startSnapshot,
|
|
116
|
+
endSnapshot,
|
|
117
|
+
duration,
|
|
118
|
+
heapGrowth,
|
|
119
|
+
heapGrowthPercent: Math.round(heapGrowthPercent * 100) / 100,
|
|
120
|
+
peakHeapUsed,
|
|
121
|
+
sampleCount: entry.samples.length + 1,
|
|
122
|
+
};
|
|
123
|
+
this.completedStats.set(label, stats);
|
|
124
|
+
this.activeTracking.delete(label);
|
|
125
|
+
return stats;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get current heap statistics using V8
|
|
129
|
+
*
|
|
130
|
+
* @returns Current memory snapshot
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const snapshot = profiler.getHeapSnapshot();
|
|
135
|
+
* console.log(`Used heap: ${snapshot.usedHeapSize / 1024 / 1024} MB`);
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
getHeapSnapshot() {
|
|
139
|
+
const heapStats = v8.getHeapStatistics();
|
|
140
|
+
const memUsage = process.memoryUsage();
|
|
141
|
+
return {
|
|
142
|
+
timestamp: Date.now(),
|
|
143
|
+
totalHeapSize: heapStats.total_heap_size,
|
|
144
|
+
usedHeapSize: heapStats.used_heap_size,
|
|
145
|
+
externalMemory: memUsage.external,
|
|
146
|
+
heapSizeLimit: heapStats.heap_size_limit,
|
|
147
|
+
totalPhysicalSize: heapStats.total_physical_size,
|
|
148
|
+
totalAvailableSize: heapStats.total_available_size,
|
|
149
|
+
mallocedMemory: heapStats.malloced_memory,
|
|
150
|
+
peakMallocedMemory: heapStats.peak_malloced_memory,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Detect potential memory leaks across all completed tracking sessions
|
|
155
|
+
*
|
|
156
|
+
* @param threshold - Heap growth percentage threshold to consider a leak (default: 10%)
|
|
157
|
+
* @returns Leak detection result
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const result = profiler.detectLeaks(15); // 15% threshold
|
|
162
|
+
* if (result.hasLeaks) {
|
|
163
|
+
* console.error(`Potential leak detected: ${result.message}`);
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
detectLeaks(threshold = 10) {
|
|
168
|
+
return detectLeaks(this.completedStats, threshold);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Save a baseline for memory regression comparison
|
|
172
|
+
*
|
|
173
|
+
* @param label - Label to save as baseline
|
|
174
|
+
* @throws Error if no completed stats exist for the label
|
|
175
|
+
*/
|
|
176
|
+
saveBaseline(label) {
|
|
177
|
+
const stats = this.completedStats.get(label);
|
|
178
|
+
if (!stats) {
|
|
179
|
+
throw new Error(`No completed stats for label: ${label}`);
|
|
180
|
+
}
|
|
181
|
+
return this.baselineManager.saveBaseline(label, stats);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Load baselines from a JSON object
|
|
185
|
+
*
|
|
186
|
+
* @param baselines - Object mapping labels to baselines
|
|
187
|
+
*/
|
|
188
|
+
loadBaselines(baselines) {
|
|
189
|
+
this.baselineManager.loadBaselines(baselines);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Check for memory regression against baseline
|
|
193
|
+
*
|
|
194
|
+
* @param label - Label to check
|
|
195
|
+
* @param threshold - Regression threshold percentage (default: 10%)
|
|
196
|
+
* @returns Regression result
|
|
197
|
+
*/
|
|
198
|
+
checkRegression(label, threshold = 10) {
|
|
199
|
+
return checkRegression(label, this.baselineManager.getBaseline(label), this.completedStats.get(label), threshold);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Generate a human-readable memory report
|
|
203
|
+
*
|
|
204
|
+
* @returns Formatted memory report string
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* profiler.trackMemory('op1');
|
|
209
|
+
* await operation1();
|
|
210
|
+
* profiler.stopTracking('op1');
|
|
211
|
+
*
|
|
212
|
+
* console.log(profiler.formatMemoryReport());
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
formatMemoryReport() {
|
|
216
|
+
const lines = [
|
|
217
|
+
'===================================================================================================',
|
|
218
|
+
' SMI-689: Memory Profiling Report ',
|
|
219
|
+
'===================================================================================================',
|
|
220
|
+
];
|
|
221
|
+
// Current heap snapshot
|
|
222
|
+
const current = this.getHeapSnapshot();
|
|
223
|
+
lines.push(' Current Heap Status: ');
|
|
224
|
+
lines.push(` Used Heap: ${formatBytes(current.usedHeapSize).padEnd(15)} | Total Heap: ${formatBytes(current.totalHeapSize).padEnd(15)} `);
|
|
225
|
+
lines.push(` Heap Limit: ${formatBytes(current.heapSizeLimit).padEnd(15)} | External: ${formatBytes(current.externalMemory).padEnd(15)} `);
|
|
226
|
+
lines.push(' ');
|
|
227
|
+
// Completed tracking stats
|
|
228
|
+
if (this.completedStats.size > 0) {
|
|
229
|
+
lines.push(' Tracked Operations: ');
|
|
230
|
+
lines.push('---------------------------------------------------------------------------------------------------');
|
|
231
|
+
for (const [label, stats] of this.completedStats) {
|
|
232
|
+
const growthColor = stats.heapGrowthPercent > 10 ? '!' : stats.heapGrowthPercent > 5 ? '~' : ' ';
|
|
233
|
+
lines.push(` ${growthColor} ${label.substring(0, 25).padEnd(25)} | Duration: ${stats.duration.toFixed(0).padStart(6)}ms | Growth: ${stats.heapGrowthPercent.toFixed(1).padStart(6)}% `);
|
|
234
|
+
lines.push(` Start: ${formatBytes(stats.startSnapshot.usedHeapSize).padEnd(10)} | End: ${formatBytes(stats.endSnapshot?.usedHeapSize ?? 0).padEnd(10)} | Peak: ${formatBytes(stats.peakHeapUsed).padEnd(10)} `);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
lines.push(' No tracked operations recorded. ');
|
|
239
|
+
}
|
|
240
|
+
// Active tracking
|
|
241
|
+
if (this.activeTracking.size > 0) {
|
|
242
|
+
lines.push(' ');
|
|
243
|
+
lines.push(' Active Tracking: ');
|
|
244
|
+
for (const [label, entry] of this.activeTracking) {
|
|
245
|
+
const elapsed = (performance.now() - entry.startTime).toFixed(0);
|
|
246
|
+
lines.push(` ${label.substring(0, 30).padEnd(30)} | Elapsed: ${elapsed.padStart(6)}ms | Samples: ${String(entry.samples.length).padStart(4)} `);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// Leak detection summary
|
|
250
|
+
const leakResult = this.detectLeaks(10);
|
|
251
|
+
lines.push(' ');
|
|
252
|
+
lines.push(' Leak Detection (10% threshold): ');
|
|
253
|
+
if (leakResult.hasLeaks) {
|
|
254
|
+
lines.push(` WARNING: POTENTIAL LEAKS DETECTED `);
|
|
255
|
+
lines.push(` Suspected: ${leakResult.suspectedLabels.slice(0, 3).join(', ').substring(0, 60).padEnd(60)} `);
|
|
256
|
+
lines.push(` Total leaked: ${formatBytes(leakResult.leakedBytes).padEnd(15)} | Max growth: ${leakResult.heapGrowthPercent.toFixed(1).padStart(6)}% `);
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
lines.push(` OK: No memory leaks detected `);
|
|
260
|
+
}
|
|
261
|
+
lines.push('===================================================================================================');
|
|
262
|
+
return lines.join('\n');
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Get all completed statistics
|
|
266
|
+
*
|
|
267
|
+
* @returns Map of label to MemoryStats
|
|
268
|
+
*/
|
|
269
|
+
getCompletedStats() {
|
|
270
|
+
return new Map(this.completedStats);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Get all baselines
|
|
274
|
+
*
|
|
275
|
+
* @returns Map of label to MemoryBaseline
|
|
276
|
+
*/
|
|
277
|
+
getBaselines() {
|
|
278
|
+
return this.baselineManager.getBaselines();
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Export baselines as JSON-serializable object
|
|
282
|
+
*
|
|
283
|
+
* @returns Object mapping labels to baselines
|
|
284
|
+
*/
|
|
285
|
+
exportBaselines() {
|
|
286
|
+
return this.baselineManager.exportBaselines();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Clear all tracking data
|
|
290
|
+
*/
|
|
291
|
+
clear() {
|
|
292
|
+
// Stop any active tracking
|
|
293
|
+
for (const entry of this.activeTracking.values()) {
|
|
294
|
+
if (entry.samplingInterval) {
|
|
295
|
+
clearInterval(entry.samplingInterval);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
this.activeTracking.clear();
|
|
299
|
+
this.completedStats.clear();
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Clear baselines
|
|
303
|
+
*/
|
|
304
|
+
clearBaselines() {
|
|
305
|
+
this.baselineManager.clear();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Default memory profiler instance for convenience
|
|
310
|
+
*/
|
|
311
|
+
export const defaultMemoryProfiler = new MemoryProfiler();
|
|
312
|
+
//# sourceMappingURL=MemoryProfiler.js.map
|