Skip to content

Commit cc73dc3

Browse files
author
John Howard
authored
Merge pull request #3217 from kevpar/etw-capture-state
Enable dumping Goroutine stacks via ETW capture state
2 parents 396eba1 + 78f3dc4 commit cc73dc3

10 files changed

Lines changed: 496 additions & 259 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
}

vendor.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ github.com/opencontainers/image-spec v1.0.1
3333
golang.org/x/sync 42b317875d0fa942474b76e1b46a6060d720ae6e
3434
github.com/BurntSushi/toml v0.3.1
3535
github.com/grpc-ecosystem/go-grpc-prometheus 6b7015e65d366bf3f19b2b2a000a831940f0f7e0
36-
github.com/Microsoft/go-winio c599b533b43b1363d7d7c6cfda5ede70ed73ff13
36+
github.com/Microsoft/go-winio 84b4ab48a50763fe7b3abcef38e5205c12027fac
3737
github.com/Microsoft/hcsshim 8abdbb8205e4192c68b5f84c31197156f31be517
3838
google.golang.org/genproto d80a6e20e776b0b17a324d0ba1ab50a39c8e8944
3939
golang.org/x/text 19e51611da83d6be54ddafce4a4af510cb3e9ea4

vendor/github.com/Microsoft/go-winio/pipe.go

Lines changed: 160 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)