Skip to content

Commit 78f3dc4

Browse files
committed
Allow dumping stacks via ETW capture state
Signed-off-by: Kevin Parsons <[email protected]>
1 parent 05dd66b commit 78f3dc4

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

cmd/containerd/command/main_windows.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import (
2424
"unsafe"
2525

2626
winio "github.com/Microsoft/go-winio"
27+
"github.com/Microsoft/go-winio/pkg/etw"
2728
"github.com/Microsoft/go-winio/pkg/etwlogrus"
29+
"github.com/Microsoft/go-winio/pkg/guid"
2830
"github.com/containerd/containerd/log"
2931
"github.com/containerd/containerd/services/server"
3032
"github.com/sirupsen/logrus"
@@ -91,11 +93,25 @@ func setupDumpStacks() {
9193
}()
9294
}
9395

96+
func etwCallback(sourceID *guid.GUID, state etw.ProviderState, level etw.Level, matchAnyKeyword uint64, matchAllKeyword uint64, filterData uintptr) {
97+
if state == etw.ProviderStateCaptureState {
98+
dumpStacks()
99+
}
100+
}
101+
94102
func init() {
95-
// Provider ID: {2acb92c0-eb9b-571a-69cf-8f3410f383ad}
96-
// Hook isn't closed explicitly, as it will exist until process exit.
97-
// GUID is generated based on name - see Microsoft/go-winio/tools/etw-provider-gen.
98-
if hook, err := etwlogrus.NewHook("ContainerD"); err == nil {
99-
logrus.AddHook(hook)
103+
// Provider ID: 2acb92c0-eb9b-571a-69cf-8f3410f383ad
104+
// Provider and hook aren't closed explicitly, as they will exist until
105+
// process exit. GUID is generated based on name - see
106+
// Microsoft/go-winio/tools/etw-provider-gen.
107+
provider, err := etw.NewProvider("ContainerD", etwCallback)
108+
if err != nil {
109+
logrus.Error(err)
110+
} else {
111+
if hook, err := etwlogrus.NewHookFromProvider(provider); err == nil {
112+
logrus.AddHook(hook)
113+
} else {
114+
logrus.Error(err)
115+
}
100116
}
101117
}

0 commit comments

Comments
 (0)