MCPcopy
hub / github.com/formatjs/formatjs / main

Function main

packages/intl-durationformat/benchmark/analyze-profile.ts:103–149  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101}
102
103function 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
151main()

Callers 1

analyze-profile.tsFile · 0.70

Calls 3

errorMethod · 0.80
logMethod · 0.80
analyzeProfileFunction · 0.70

Tested by

no test coverage detected