|
15 | 15 | #include <pybind11/pytypes.h> |
16 | 16 | #endif |
17 | 17 |
|
| 18 | +#ifdef SUPPORT_VALGRIND |
| 19 | +#include <valgrind/valgrind.h> |
| 20 | +#endif |
| 21 | + |
18 | 22 | //------------------------------------------------------------------------------------------------------- |
19 | 23 | // Description : List of libyt C extension python methods built using Pybind11 API |
20 | 24 | // |
@@ -514,6 +518,16 @@ pybind11::object GetParticleRemote(const pybind11::dict& py_ptf, |
514 | 518 | #endif // #ifndef SERIAL_MODE |
515 | 519 | } |
516 | 520 |
|
| 521 | +#ifdef SUPPORT_VALGRIND |
| 522 | +pybind11::object DumpValgrindDetailedSnapshot(const char* filename) { |
| 523 | + std::string valgrind_cmd = "detailed_snapshot "; |
| 524 | + valgrind_cmd += filename; |
| 525 | + |
| 526 | + VALGRIND_MONITOR_COMMAND(valgrind_cmd.c_str()); |
| 527 | + return pybind11::none(); |
| 528 | +} |
| 529 | +#endif |
| 530 | + |
517 | 531 | PYBIND11_EMBEDDED_MODULE(libyt, m) { |
518 | 532 | SET_TIMER(__PRETTY_FUNCTION__); |
519 | 533 |
|
@@ -561,6 +575,11 @@ PYBIND11_EMBEDDED_MODULE(libyt, m) { |
561 | 575 | m.def("get_particle_remote", |
562 | 576 | &GetParticleRemote, |
563 | 577 | pybind11::return_value_policy::take_ownership); |
| 578 | +#ifdef SUPPORT_VALGRIND |
| 579 | + m.def("dump_valgrind_detailed_snapshot", |
| 580 | + &DumpValgrindDetailedSnapshot, |
| 581 | + pybind11::return_value_policy::take_ownership); |
| 582 | +#endif |
564 | 583 | } |
565 | 584 |
|
566 | 585 | #else // #ifdef USE_PYBIND11 |
@@ -1120,6 +1139,25 @@ static PyObject* LibytParticleGetParticleRemote(PyObject* self, PyObject* args) |
1120 | 1139 | #endif // #ifndef SERIAL_MODE |
1121 | 1140 | } |
1122 | 1141 |
|
| 1142 | +#ifdef SUPPORT_VALGRIND |
| 1143 | +static PyObject* LibytDumpValgrindDetailedSnapshot(PyObject* self, PyObject* args) { |
| 1144 | + char* filename; |
| 1145 | + if (!PyArg_ParseTuple(args, "s", &filename)) { |
| 1146 | + PyErr_SetString( |
| 1147 | + PyExc_TypeError, |
| 1148 | + "Wrong input type, expect to be libyt.dump_valgrind_detailed_snapshot(str)."); |
| 1149 | + return NULL; |
| 1150 | + } |
| 1151 | + |
| 1152 | + std::string valgrind_cmd = "detailed_snapshot "; |
| 1153 | + valgrind_cmd += filename; |
| 1154 | + |
| 1155 | + VALGRIND_MONITOR_COMMAND(valgrind_cmd.c_str()); |
| 1156 | + |
| 1157 | + Py_RETURN_NONE; |
| 1158 | +} |
| 1159 | +#endif |
| 1160 | + |
1123 | 1161 | //------------------------------------------------------------------------------------------------------- |
1124 | 1162 | // Description : Preparation for creating libyt python module |
1125 | 1163 | // |
@@ -1152,6 +1190,12 @@ static PyMethodDef libyt_method_list[] = { |
1152 | 1190 | LibytParticleGetParticleRemote, |
1153 | 1191 | METH_VARARGS, |
1154 | 1192 | "Get remote particle attribute data."}, |
| 1193 | +#ifdef SUPPORT_VALGRIND |
| 1194 | + {"dump_valgrind_detailed_snapshot", |
| 1195 | + LibytDumpValgrindDetailedSnapshot, |
| 1196 | + METH_VARARGS, |
| 1197 | + "Dump valgrind detailed snapshot."}, |
| 1198 | +#endif |
1155 | 1199 | {NULL, NULL, 0, NULL} // sentinel |
1156 | 1200 | }; |
1157 | 1201 |
|
|
0 commit comments