Skip to content
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
patch
  • Loading branch information
Jongy committed Feb 1, 2022
commit 95fac2db6e51d3088e076b38eed1d072c8d2d43d
58 changes: 54 additions & 4 deletions examples/cpp/pyperf/PyOffsets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ There are a couple of exceptions:
3. PyThreadState.thread - this field's name is "thread_id" in some Python versions.
*/

#if defined(__x86_64__)
extern const struct struct_offsets kPy27OffsetConfig = {
.PyObject = {
.ob_type = 8
Expand Down Expand Up @@ -229,19 +230,68 @@ extern const struct struct_offsets kPy310OffsetConfig = {
},
};

#elif defined(__aarch64__)

extern const struct struct_offsets kPy37OffsetConfig = {
.PyObject = {
.ob_type = 8
},
.String = {
.data = 48, // offsetof(PyStringObject, ob_sval)
.size = -1, // offsetof(PyVarObject, ob_size)
},
.PyTypeObject = {
.tp_name = 24
},
.PyThreadState = {
.next = 8,
.interp = 16,
.frame = 24,
.thread = 176,
},
.PyInterpreterState = {
.tstate_head = 8,
},
.PyRuntimeState = {
.interp_main = 32, // N/A
},
.PyFrameObject = {
.f_back = 24,
.f_code = 32,
.f_lineno = 108,
.f_localsplus = 360,
},
.PyCodeObject = {
.co_nlocals = 24,
.co_filename = 96,
.co_name = 104,
.co_varnames = 64,
.co_firstlineno = 36,
},
.PyTupleObject = {
.ob_item = 24
},
.PyCellObject = {
.ob_ref = 16
}
};

#endif

// List of mappings from Python 3 minor versions to offsets. `get_offsets` depends on this list
// being sorted in ascending order when it searches through it.
const std::vector<std::pair<version, struct_offsets>> python3Versions = {
{{3,6,0}, kPy36OffsetConfig},
// {{3,6,0}, kPy36OffsetConfig},
{{3,7,0}, kPy37OffsetConfig},
{{3,8,0}, kPy38OffsetConfig},
// {{3,8,0}, kPy38OffsetConfig},
// TODO check on aarch64
// 3.9 is same as 3.8
{{3,10,0}, kPy310OffsetConfig},
// {{3,10,0}, kPy310OffsetConfig},
};

const struct_offsets& get_offsets(version& version) {
if (version.major == 2) {
return kPy27OffsetConfig;
return kPy37OffsetConfig;
}
else {
// Find offsets for Python 3 version:
Expand Down