Skip to content

Commit

Permalink
Merge pull request #44 from parca-dev/add_frame_owner
Browse files Browse the repository at this point in the history
python: Add frame owner
  • Loading branch information
kakkoyun authored Feb 26, 2024
2 parents 6adb051 + e8d9576 commit faf52d0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
21 changes: 21 additions & 0 deletions pkg/python/datamap.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func (p python27) Layout() runtimedata.RuntimeData {
PyTupleObject: PyTupleObject{
ObItem: p.PyTupleObjectObItem,
},
PyInterpreterFrame: PyInterpreterFrame{
Owner: doesNotExist,
},
}
}

Expand Down Expand Up @@ -163,6 +166,9 @@ func (p python33_39) Layout() runtimedata.RuntimeData {
PyTupleObject: PyTupleObject{
ObItem: p.PyTupleObjectObItem,
},
PyInterpreterFrame: PyInterpreterFrame{
Owner: doesNotExist,
},
}
}

Expand Down Expand Up @@ -231,6 +237,9 @@ func (p python310) Layout() runtimedata.RuntimeData {
PyTupleObject: PyTupleObject{
ObItem: p.PyTupleObjectObItem,
},
PyInterpreterFrame: PyInterpreterFrame{
Owner: doesNotExist,
},
}
}

Expand All @@ -251,6 +260,7 @@ type python311 struct {
PyFrameObjectFBack int64 `offsetof:"_PyInterpreterFrame.previous"`
PyFrameObjectFCode int64 `offsetof:"_PyInterpreterFrame.f_code"`
PyFrameObjectFLocalsplus int64 `offsetof:"_PyInterpreterFrame.localsplus"`
PyInterpreterFrameOwner int64 `offsetof:"_PyInterpreterFrame.owner"`
PyCodeObjectCoFilename int64 `offsetof:"PyCodeObject.co_filename"`
PyCodeObjectCoName int64 `offsetof:"PyCodeObject.co_name"`
PyCodeObjectCoVarNames int64 `offsetof:"PyCodeObject.co_localsplusnames"`
Expand Down Expand Up @@ -302,6 +312,9 @@ func (p python311) Layout() runtimedata.RuntimeData {
PyTupleObject: PyTupleObject{
ObItem: p.PyTupleObjectObItem,
},
PyInterpreterFrame: PyInterpreterFrame{
Owner: p.PyInterpreterFrameOwner,
},
}
}

Expand All @@ -321,6 +334,7 @@ type python312 struct {
PyFrameObjectFBack int64 `offsetof:"_PyInterpreterFrame.previous"`
PyFrameObjectFCode int64 `offsetof:"_PyInterpreterFrame.f_code"`
PyFrameObjectFLocalsplus int64 `offsetof:"_PyInterpreterFrame.localsplus"`
PyInterpreterFrameOwner int64 `offsetof:"_PyInterpreterFrame.owner"`
PyCodeObjectCoFilename int64 `offsetof:"PyCodeObject.co_filename"`
PyCodeObjectCoName int64 `offsetof:"PyCodeObject.co_name"`
PyCodeObjectCoVarNames int64 `offsetof:"PyCodeObject.co_varnames"`
Expand Down Expand Up @@ -372,6 +386,9 @@ func (p python312) Layout() runtimedata.RuntimeData {
PyTupleObject: PyTupleObject{
ObItem: p.PyTupleObjectObItem,
},
PyInterpreterFrame: PyInterpreterFrame{
Owner: p.PyInterpreterFrameOwner,
},
}
}

Expand All @@ -391,6 +408,7 @@ type python313 struct {
PyFrameObjectFBack int64 `offsetof:"_PyInterpreterFrame.previous"`
PyFrameObjectFExecutable int64 `offsetof:"_PyInterpreterFrame.f_executable"`
PyFrameObjectFLocalsplus int64 `offsetof:"_PyInterpreterFrame.localsplus"`
PyInterpreterFrameOwner int64 `offsetof:"_PyInterpreterFrame.owner"`
PyCodeObjectCoFilename int64 `offsetof:"PyCodeObject.co_filename"`
PyCodeObjectCoName int64 `offsetof:"PyCodeObject.co_name"`
PyCodeObjectCoFirstlineno int64 `offsetof:"PyCodeObject.co_firstlineno"`
Expand Down Expand Up @@ -442,5 +460,8 @@ func (p python313) Layout() runtimedata.RuntimeData {
PyTupleObject: PyTupleObject{
ObItem: p.PyTupleObjectObItem,
},
PyInterpreterFrame: PyInterpreterFrame{
Owner: p.PyInterpreterFrameOwner,
},
}
}
6 changes: 6 additions & 0 deletions pkg/python/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ type PyFrameObject struct {
FLocalsplus int64 `yaml:"f_localsplus"`
}

// PyInterpreterFrame
type PyInterpreterFrame struct {
Owner int64 `yaml:"owner"`
}

type Layout struct {
PyCFrame PyCFrame `yaml:"py_cframe"`
PyCodeObject PyCodeObject `yaml:"py_code_object"`
Expand All @@ -93,6 +98,7 @@ type Layout struct {
PyThreadState PyThreadState `yaml:"py_thread_state"`
PyTupleObject PyTupleObject `yaml:"py_tuple_object"`
PyTypeObject PyTypeObject `yaml:"py_type_object"`
PyInterpreterFrame PyInterpreterFrame `yaml:"py_interpreter_frame"`
}

func (pvo Layout) Data() ([]byte, error) {
Expand Down
16 changes: 12 additions & 4 deletions pkg/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ func TestGetLayout(t *testing.T) {
NativeThreadID: -1,
CFrame: -1,
},
PyTupleObject: PyTupleObject{ObItem: 24},
PyTypeObject: PyTypeObject{TPName: 24},
PyTupleObject: PyTupleObject{ObItem: 24},
PyTypeObject: PyTypeObject{TPName: 24},
PyInterpreterFrame: PyInterpreterFrame{Owner: -1},
},
},
{
Expand Down Expand Up @@ -100,8 +101,9 @@ func TestGetLayout(t *testing.T) {
NativeThreadID: -1,
CFrame: -1,
},
PyTupleObject: PyTupleObject{ObItem: 24},
PyTypeObject: PyTypeObject{TPName: 24},
PyTupleObject: PyTupleObject{ObItem: 24},
PyTypeObject: PyTypeObject{TPName: 24},
PyInterpreterFrame: PyInterpreterFrame{Owner: -1},
},
},
{
Expand Down Expand Up @@ -150,6 +152,9 @@ func TestGetLayout(t *testing.T) {
PyTupleObject: PyTupleObject{
ObItem: 24,
},
PyInterpreterFrame: PyInterpreterFrame{
Owner: 69,
},
},
},
{
Expand Down Expand Up @@ -198,6 +203,9 @@ func TestGetLayout(t *testing.T) {
PyTupleObject: PyTupleObject{
ObItem: 24,
},
PyInterpreterFrame: PyInterpreterFrame{
Owner: 70,
},
},
},
}
Expand Down

0 comments on commit faf52d0

Please sign in to comment.