Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions tsc/internal/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,15 @@ func traceThreadKeyFromArgs(args map[string]any) (traceThreadKey, bool) {
}

for _, key := range traceThreadArgKeys {
if value, ok := args[key]; ok {
if path, ok := value.(string); ok && path != "" {
return traceThreadKey{kind: traceThreadKindFile, text: path}, true
}
var path string
switch value := args[key].(type) {
case string:
path = value
case tspath.RootedFilePath:
path = value.AsString()
}
if path != "" {
return traceThreadKey{kind: traceThreadKindFile, text: path}, true
}
}

Expand Down
57 changes: 57 additions & 0 deletions tsc/internal/tracing/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,63 @@ func TestThreadIDsAreStableAcrossFirstSeenOrder(t *testing.T) {
assert.DeepEqual(t, first, second)
}

func TestTypedEmitPathsUseFileThreads(t *testing.T) {
t.Parallel()

for _, test := range []struct {
name string
key string
ext string
}{
{name: "emitJsFileOrBundle", key: "jsFilePath", ext: ".js"},
{name: "emitDeclarationFileOrBundle", key: "declarationFilePath", ext: ".d.ts"},
} {
t.Run(test.name, func(t *testing.T) {
t.Parallel()

fsys := vfstest.FromMap(fstest.MapFS{
"/trace": &fstest.MapFile{Mode: fs.ModeDir},
}, tspath.CaseSensitive)
tr, err := StartTracing(fsys, "/trace", "", true /*deterministic*/)
assert.NilError(t, err)

a := "/a" + test.ext
b := "/b" + test.ext
aPath := tspath.RootedFilePathFromAbsolute(a)
bPath := tspath.RootedFilePathFromAbsolute(b)
endA := tr.Push(PhaseEmit, test.name, map[string]any{test.key: aPath}, true)
endB := tr.Push(PhaseEmit, test.name, map[string]any{test.key: bPath}, true)
endA()
endB()
tr.Instant(PhaseEmit, "stringPath", map[string]any{"path": a})
tr.Instant(PhaseEmit, "emptyPath", map[string]any{"path": tspath.RootedFilePath(""), test.key: aPath})
tr.Instant(PhaseEmit, "noPath", nil)
assert.NilError(t, tr.StopTracing())

traceText, ok := fsys.ReadFile("/trace/trace.json")
assert.Assert(t, ok)
var events []traceEvent
assert.NilError(t, json.Unmarshal([]byte(traceText), &events))

aBegin := findEvent(t, events, "B", test.name, test.key, a)
aEnd := findEvent(t, events, "E", test.name, test.key, a)
bBegin := findEvent(t, events, "B", test.name, test.key, b)
bEnd := findEvent(t, events, "E", test.name, test.key, b)
assert.Equal(t, aBegin.TID, aEnd.TID)
assert.Equal(t, bBegin.TID, bEnd.TID)
assert.Assert(t, aBegin.TID != bBegin.TID)
assertThreadName(t, events, aBegin.TID, "file:"+a)
assertThreadName(t, events, bBegin.TID, "file:"+b)
assert.Equal(t, aBegin.TID, findEvent(t, events, "I", "stringPath", "path", a).TID)
assert.Equal(t, aBegin.TID, findEvent(t, events, "I", "emptyPath", "path", "").TID)
noPath := findEvent(t, events, "I", "noPath", "", nil)
assert.Assert(t, aBegin.TID != noPath.TID)
assertThreadName(t, events, noPath.TID, "Main")
assertDurationEventsAreWellNestedByThread(t, events)
})
}
}

func traceThreadIDsForPaths(t *testing.T, paths []string) map[string]int {
t.Helper()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ export declare const w: {
{"pid":1,"tid":1,"ph":"E","cat":"check","ts":21,"name":"checkSourceFiles"},
{"pid":1,"tid":1,"ph":"B","cat":"emit","ts":22,"name":"emit"},
{"pid":1,"tid":100209852,"ph":"B","cat":"emit","ts":23,"name":"emit","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":1,"ph":"B","cat":"emit","ts":24,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":1,"ph":"E","cat":"emit","ts":25,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":887537909,"ph":"M","cat":"__metadata","ts":1,"name":"thread_name","args":{"name":"file:/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":887537909,"ph":"B","cat":"emit","ts":24,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":887537909,"ph":"E","cat":"emit","ts":25,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":100209852,"ph":"E","cat":"emit","ts":26,"name":"emit","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":100209852,"ph":"B","cat":"emit","ts":27,"name":"emitPrint","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":100209852,"ph":"E","cat":"emit","ts":28,"name":"emitPrint","args":{"path":"/home/src/workspaces/project/main.ts"}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ export declare const w: {
{"pid":1,"tid":1,"ph":"E","cat":"check","ts":21,"name":"checkSourceFiles"},
{"pid":1,"tid":1,"ph":"B","cat":"emit","ts":22,"name":"emit"},
{"pid":1,"tid":100209852,"ph":"B","cat":"emit","ts":23,"name":"emit","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":1,"ph":"B","cat":"emit","ts":24,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":1,"ph":"E","cat":"emit","ts":25,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":887537909,"ph":"M","cat":"__metadata","ts":1,"name":"thread_name","args":{"name":"file:/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":887537909,"ph":"B","cat":"emit","ts":24,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":887537909,"ph":"E","cat":"emit","ts":25,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":100209852,"ph":"E","cat":"emit","ts":26,"name":"emit","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":100209852,"ph":"B","cat":"emit","ts":27,"name":"emitPrint","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":100209852,"ph":"E","cat":"emit","ts":28,"name":"emitPrint","args":{"path":"/home/src/workspaces/project/main.ts"}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,9 @@ export declare const widget: import("./gadget").Gadget;
{"pid":1,"tid":1,"ph":"E","cat":"check","ts":133,"name":"checkSourceFiles"},
{"pid":1,"tid":1,"ph":"B","cat":"emit","ts":134,"name":"emit"},
{"pid":1,"tid":100209852,"ph":"B","cat":"emit","ts":135,"name":"emit","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":1,"ph":"B","cat":"emit","ts":136,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":1,"ph":"E","cat":"emit","ts":137,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":887537909,"ph":"M","cat":"__metadata","ts":1,"name":"thread_name","args":{"name":"file:/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":887537909,"ph":"B","cat":"emit","ts":136,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":887537909,"ph":"E","cat":"emit","ts":137,"name":"emitDeclarationFileOrBundle","args":{"declarationFilePath":"/home/src/workspaces/project/out/main.d.ts"}},
{"pid":1,"tid":100209852,"ph":"E","cat":"emit","ts":138,"name":"emit","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":100209852,"ph":"B","cat":"emit","ts":139,"name":"emitPrint","args":{"path":"/home/src/workspaces/project/main.ts"}},
{"pid":1,"tid":100209852,"ph":"E","cat":"emit","ts":140,"name":"emitPrint","args":{"path":"/home/src/workspaces/project/main.ts"}},
Expand Down
Loading