()
| 101 | } |
| 102 | |
| 103 | function main(): void { |
| 104 | const argv = minimist(process.argv.slice(2), { |
| 105 | string: ['profile', 'p'], |
| 106 | alias: {p: 'profile'}, |
| 107 | default: { |
| 108 | profile: '/tmp/CPU.*.cpuprofile', |
| 109 | }, |
| 110 | }) |
| 111 | |
| 112 | const profilePath = argv.profile || argv._[0] |
| 113 | |
| 114 | if (!profilePath) { |
| 115 | console.error('Error: No profile path specified') |
| 116 | console.error('\nUsage:') |
| 117 | console.error(' analyze-profile <path-to-profile.cpuprofile>') |
| 118 | console.error(' analyze-profile --profile <path-to-profile.cpuprofile>') |
| 119 | console.error(' analyze-profile -p <path-to-profile.cpuprofile>') |
| 120 | process.exit(1) |
| 121 | } |
| 122 | |
| 123 | // Handle glob pattern for /tmp/CPU.*.cpuprofile |
| 124 | if (profilePath.includes('*')) { |
| 125 | const dir = profilePath.substring(0, profilePath.lastIndexOf('/')) |
| 126 | const pattern = profilePath.substring(profilePath.lastIndexOf('/') + 1) |
| 127 | const files = readdirSync(dir) |
| 128 | .filter(f => f.match(pattern.replace('*', '.*'))) |
| 129 | .sort() |
| 130 | .reverse() // Get most recent first |
| 131 | |
| 132 | if (files.length === 0) { |
| 133 | console.error(`Error: No profile files found matching ${profilePath}`) |
| 134 | process.exit(1) |
| 135 | } |
| 136 | |
| 137 | const latestProfile = `${dir}/${files[0]}` |
| 138 | console.log(`Using most recent profile: ${latestProfile}\n`) |
| 139 | analyzeProfile(latestProfile) |
| 140 | return |
| 141 | } |
| 142 | |
| 143 | if (!existsSync(profilePath)) { |
| 144 | console.error(`Error: Profile file not found: ${profilePath}`) |
| 145 | process.exit(1) |
| 146 | } |
| 147 | |
| 148 | analyzeProfile(profilePath) |
| 149 | } |
| 150 | |
| 151 | main() |
no test coverage detected