{"record":{"id":"d3ed8c662337dee3","repo":"BabylonJS/Babylon.js","slug":"performance-trace-is-not-running-run-start-perf-t","errorCode":null,"errorMessage":"Performance trace is not running. Run start-perf-trace first.","messagePattern":"Performance trace is not running\\. Run start-perf-trace first\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/inspector-v2/src/services/cli/perfTraceCommandService.ts","lineNumber":47,"sourceCode":"                    return \"Performance trace is already running.\";\r\n                }\r\n\r\n                perfCollector = scene.getPerfCollector();\r\n                perfCollector.stop();\r\n                perfCollector.clear(false);\r\n                perfCollector.addCollectionStrategies(...DefaultPerfStrategies);\r\n                perfCollector.start(true);\r\n\r\n                return \"Performance trace started.\";\r\n            },\r\n        });\r\n\r\n        const stopReg = commandRegistry.addCommand({\r\n            id: \"stop-perf-trace\",\r\n            description: \"Stop collecting performance trace data and return the results as JSON.\",\r\n            executeAsync: async () => {\r\n                if (!perfCollector || !perfCollector.isStarted) {\r\n                    throw new Error(\"Performance trace is not running. Run start-perf-trace first.\");\r\n                }\r\n\r\n                perfCollector.stop();\r\n\r\n                const datasets = perfCollector.datasets;\r\n                const ids = datasets.ids;\r\n                const rawData = datasets.data.subarray(0, datasets.data.itemLength);\r\n                const sliceSize = ids.length + PerformanceViewerCollector.SliceDataOffset;\r\n\r\n                const samples: Record<string, unknown>[] = [];\r\n                for (let i = 0; i < rawData.length; i += sliceSize) {\r\n                    const timestamp = rawData[i];\r\n                    const sample: Record<string, unknown> = { timestamp };\r\n                    for (let j = 0; j < ids.length; j++) {\r\n                        sample[ids[j]] = rawData[i + PerformanceViewerCollector.SliceDataOffset + j];\r\n                    }\r\n                    samples.push(sample);\r\n                }\r","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/services/cli/perfTraceCommandService.ts#L29-L65","documentation":"Thrown by the 'stop-perf-trace' command when perfCollector is null or its isStarted flag is false, i.e. stop was called without a prior successful start. The command exists to stop collection and return datasets as JSON; without a running collector there is nothing to stop or report.","triggerScenarios":"Executing 'stop-perf-trace' before 'start-perf-trace'; after a previous stop already ran; or when start failed earlier (e.g. 'No active scene.') leaving perfCollector unset or not started.","commonSituations":"A scripted start/stop pair where the start step failed silently earlier; calling stop twice at the end of a profiling session; the collector auto-stopped on scene teardown and the user calls stop again.","solutions":["Run 'start-perf-trace' first and confirm it returns success before calling stop.","Make the stop call idempotent in your script: only stop when start reported that tracing is running.","If start failed, fix the underlying cause (e.g. no active scene) rather than retrying stop."],"exampleFix":"// before\nawait execute(\"stop-perf-trace\", {}); // never started\n// after\nconst res = await execute(\"start-perf-trace\", {});\nif (!res.includes(\"already running\")) {\n  const data = await execute(\"stop-perf-trace\", {});\n}","handlingStrategy":"validation","validationCode":"if (!perfCollector?.isStarted) return; // nothing to stop; skip or start first","typeGuard":"function isTraceRunning(c: { isStarted: boolean } | null | undefined): boolean { return !!c && c.isStarted; }","tryCatchPattern":"try {\n  await stopPerfTrace();\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Performance trace is not running\")) {\n    // treat as no-op or start-then-stop\n  } else throw e;\n}","preventionTips":["Pair start/stop calls in try/finally so stop only runs after a successful start.","Track collector state in your script instead of calling stop unconditionally.","Remember start may have failed (e.g. no scene) — check its return message."],"tags":["cli","state-error","performance"],"backgroundTag":"operation-not-started","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}