6
6
"flag"
7
7
"fmt"
8
8
"os"
9
- "path/filepath"
10
9
"runtime"
11
- "runtime/pprof"
12
10
"slices"
13
11
"strconv"
14
12
"strings"
@@ -21,6 +19,7 @@ import (
21
19
"github.com/microsoft/typescript-go/internal/core"
22
20
"github.com/microsoft/typescript-go/internal/diagnosticwriter"
23
21
"github.com/microsoft/typescript-go/internal/execute"
22
+ "github.com/microsoft/typescript-go/internal/pprof"
24
23
"github.com/microsoft/typescript-go/internal/scanner"
25
24
"github.com/microsoft/typescript-go/internal/tspath"
26
25
"github.com/microsoft/typescript-go/internal/vfs/osvfs"
@@ -135,8 +134,8 @@ func main() {
135
134
opts := parseArgs ()
136
135
137
136
if opts .devel .pprofDir != "" {
138
- profileSession := beginProfiling (opts .devel .pprofDir )
139
- defer profileSession .stop ()
137
+ profileSession := pprof . BeginProfiling (opts .devel .pprofDir , os . Stdout )
138
+ defer profileSession .Stop ()
140
139
}
141
140
142
141
startTime := time .Now ()
@@ -221,7 +220,7 @@ func main() {
221
220
var emitTime time.Duration
222
221
if compilerOptions .NoEmit .IsFalseOrUnknown () {
223
222
emitStart := time .Now ()
224
- result := program .Emit (& ts.EmitOptions {})
223
+ result := program .Emit (ts.EmitOptions {})
225
224
diagnostics = append (diagnostics , result .Diagnostics ... )
226
225
emitTime = time .Since (emitStart )
227
226
}
@@ -238,15 +237,8 @@ func main() {
238
237
printDiagnostics (ts .SortAndDeduplicateDiagnostics (diagnostics ), host , compilerOptions )
239
238
}
240
239
241
- var unsupportedExtensions []string
242
- for _ , file := range program .SourceFiles () {
243
- extension := tspath .TryGetExtensionFromPath (file .FileName ())
244
- if extension == tspath .ExtensionTsx || slices .Contains (tspath .SupportedJSExtensionsFlat , extension ) {
245
- unsupportedExtensions = core .AppendIfUnique (unsupportedExtensions , extension )
246
- }
247
- }
248
- if len (unsupportedExtensions ) != 0 {
249
- fmt .Fprintf (os .Stderr , "Warning: The project contains unsupported file types (%s), which are currently not fully type-checked.\n " , strings .Join (unsupportedExtensions , ", " ))
240
+ if exts := program .UnsupportedExtensions (); len (exts ) != 0 {
241
+ fmt .Fprintf (os .Stderr , "Warning: The project contains unsupported file types (%s), which are currently not fully type-checked.\n " , strings .Join (exts , ", " ))
250
242
}
251
243
252
244
if compilerOptions .ListFiles .IsTrue () {
@@ -335,54 +327,3 @@ func printDiagnostics(diagnostics []*ast.Diagnostic, host ts.CompilerHost, compi
335
327
}
336
328
}
337
329
}
338
-
339
- type profileSession struct {
340
- cpuFilePath string
341
- memFilePath string
342
- cpuFile * os.File
343
- memFile * os.File
344
- }
345
-
346
- func beginProfiling (profileDir string ) * profileSession {
347
- if err := os .MkdirAll (profileDir , 0o755 ); err != nil {
348
- panic (err )
349
- }
350
-
351
- pid := os .Getpid ()
352
-
353
- cpuProfilePath := filepath .Join (profileDir , fmt .Sprintf ("%d-cpuprofile.pb.gz" , pid ))
354
- memProfilePath := filepath .Join (profileDir , fmt .Sprintf ("%d-memprofile.pb.gz" , pid ))
355
- cpuFile , err := os .Create (cpuProfilePath )
356
- if err != nil {
357
- panic (err )
358
- }
359
- memFile , err := os .Create (memProfilePath )
360
- if err != nil {
361
- panic (err )
362
- }
363
-
364
- if err := pprof .StartCPUProfile (cpuFile ); err != nil {
365
- panic (err )
366
- }
367
-
368
- return & profileSession {
369
- cpuFilePath : cpuProfilePath ,
370
- memFilePath : memProfilePath ,
371
- cpuFile : cpuFile ,
372
- memFile : memFile ,
373
- }
374
- }
375
-
376
- func (p * profileSession ) stop () {
377
- pprof .StopCPUProfile ()
378
- err := pprof .Lookup ("allocs" ).WriteTo (p .memFile , 0 )
379
- if err != nil {
380
- panic (err )
381
- }
382
-
383
- p .cpuFile .Close ()
384
- p .memFile .Close ()
385
-
386
- fmt .Printf ("CPU profile: %v\n " , p .cpuFilePath )
387
- fmt .Printf ("Memory profile: %v\n " , p .memFilePath )
388
- }
0 commit comments