Skip to content

Commit 149fc92

Browse files
committed
refactor(ps)!: Adjust CreateProcess event process state attribution
1 parent d029fed commit 149fc92

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

pkg/ps/snapshotter_windows.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ package ps
2020

2121
import (
2222
"expvar"
23-
"github.com/rabbitstack/fibratus/pkg/sys"
24-
"github.com/rabbitstack/fibratus/pkg/util/va"
25-
"golang.org/x/sys/windows"
2623
"path/filepath"
2724
"strconv"
2825
"strings"
2926
"sync"
3027
"time"
3128

29+
"github.com/rabbitstack/fibratus/pkg/sys"
30+
"github.com/rabbitstack/fibratus/pkg/util/va"
31+
"golang.org/x/sys/windows"
32+
3233
"github.com/rabbitstack/fibratus/pkg/config"
3334
"github.com/rabbitstack/fibratus/pkg/event"
3435
"github.com/rabbitstack/fibratus/pkg/event/params"
@@ -195,18 +196,8 @@ func (s *snapshotter) Write(e *event.Event) error {
195196
s.procs[pid] = proc
196197
}
197198

198-
// adjust the process which is generating
199-
// the event. For `CreateProcess` events
200-
// the process context is scoped to the
201-
// parent/creator process. Otherwise, it
202-
// is a regular rundown event that doesn't
203-
// require consulting the process in the
204-
// snapshot state
205-
if e.IsProcessRundown() {
206-
e.PS = proc
207-
} else if !e.IsProcessRundownInternal() && !e.IsCreateProcessInternal() {
208-
e.PS = s.procs[e.PID]
209-
}
199+
// assign process state to the event
200+
e.PS = proc
210201

211202
return err
212203
}

pkg/ps/snapshotter_windows_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
package ps
2020

2121
import (
22+
"os"
23+
"path/filepath"
24+
"strings"
25+
"testing"
26+
"time"
27+
2228
"github.com/rabbitstack/fibratus/pkg/config"
2329
"github.com/rabbitstack/fibratus/pkg/event"
2430
"github.com/rabbitstack/fibratus/pkg/event/params"
@@ -31,11 +37,6 @@ import (
3137
"github.com/stretchr/testify/mock"
3238
"github.com/stretchr/testify/require"
3339
"golang.org/x/sys/windows"
34-
"os"
35-
"path/filepath"
36-
"strings"
37-
"testing"
38-
"time"
3940
)
4041

4142
func TestWrite(t *testing.T) {
@@ -175,11 +176,7 @@ func TestWrite(t *testing.T) {
175176
assert.True(t, (ps.Parent != nil) == (proc.Parent != nil))
176177
if found, _ := psnap.Find(evt.PID); found {
177178
assert.NotNil(t, evt.PS)
178-
if evt.IsProcessRundown() {
179-
assert.Equal(t, ps.PID, evt.PS.PID)
180-
} else {
181-
assert.Equal(t, ps.Ppid, evt.PS.PID)
182-
}
179+
assert.Equal(t, ps.PID, evt.PS.PID)
183180
}
184181
})
185182
}

0 commit comments

Comments
 (0)