()
| 151 | } |
| 152 | |
| 153 | async function cliMain(): Promise<void> { |
| 154 | let args: FlamegraphArgs | undefined; |
| 155 | |
| 156 | try { |
| 157 | args = resolveArgs(process.argv.slice(2)); |
| 158 | } catch (error) { |
| 159 | console.error(error instanceof Error ? error.message : String(error)); |
| 160 | process.exit(1); |
| 161 | } |
| 162 | |
| 163 | if (args === undefined) { |
| 164 | console.log(USAGE); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | if (args.subcommand === Subcommand.Fold && args.title !== undefined) { |
| 169 | console.error("--title is only supported by the render subcommand"); |
| 170 | process.exit(1); |
| 171 | } |
| 172 | |
| 173 | const samples = path.join(args.runDir, PERF_SCRIPT_OUTPUT_FILENAME); |
| 174 | |
| 175 | if (!existsSync(samples) && !existsSync(`${samples}.gz`)) { |
| 176 | console.error( |
| 177 | `No ${PERF_SCRIPT_OUTPUT_FILENAME}(.gz) in ${args.runDir} — was the ` + |
| 178 | "run profiled with --mode system?", |
| 179 | ); |
| 180 | process.exit(1); |
| 181 | } |
| 182 | |
| 183 | const { pipeline, outputPath } = buildFlamegraphPipeline(args); |
| 184 | |
| 185 | const requiredTools = ["inferno-collapse-perf"]; |
| 186 | |
| 187 | if (args.subcommand === Subcommand.Render) { |
| 188 | requiredTools.push("inferno-flamegraph"); |
| 189 | } |
| 190 | |
| 191 | const missing = requiredTools.filter((tool) => !toolAvailable(tool)); |
| 192 | |
| 193 | if (missing.length > 0) { |
| 194 | console.error( |
| 195 | `Missing tools on PATH: ${missing.join(", ")}. Install inferno ` + |
| 196 | "(cargo install inferno), or run this pipeline where it is available:", |
| 197 | ); |
| 198 | console.error(` ${pipeline}`); |
| 199 | process.exit(1); |
| 200 | } |
| 201 | |
| 202 | const result = spawnSync("bash", ["-c", pipeline], { stdio: "inherit" }); |
| 203 | |
| 204 | if (result.status !== 0) { |
| 205 | console.error(`Pipeline failed (exit ${String(result.status)}):`); |
| 206 | console.error(` ${pipeline}`); |
| 207 | process.exit(1); |
| 208 | } |
| 209 | |
| 210 | console.log(outputPath); |
no test coverage detected