@@ -18,6 +18,7 @@ struct region_handle
1818};
1919
2020static std::unordered_map<std::string, region_handle> regions;
21+ static std::unordered_map<std::string, region_handle> rewind_regions;
2122
2223void region_begin (std::string region_name, std::string module , std::string file_name,
2324 std::uint64_t line_number)
@@ -41,6 +42,29 @@ void region_end(std::string region_name)
4142 SCOREP_User_RegionEnd (handle.value );
4243}
4344
45+ void rewind_begin (std::string region_name, std::string file_name, std::uint64_t line_number)
46+ {
47+ auto pair = rewind_regions.emplace (make_pair (region_name, region_handle ()));
48+ bool inserted_new = pair.second ;
49+ auto & handle = pair.first ->second ;
50+ if (inserted_new)
51+ {
52+ SCOREP_User_RegionInit (&handle.value , NULL , &SCOREP_User_LastFileHandle,
53+ region_name.c_str (), SCOREP_USER_REGION_TYPE_FUNCTION,
54+ file_name.c_str (), line_number);
55+ }
56+ SCOREP_User_RewindRegionEnter (handle.value );
57+ }
58+
59+ void rewind_end (std::string region_name, bool value)
60+ {
61+ auto & handle = rewind_regions[region_name];
62+ /* don't call SCOREP_ExitRewindRegion, as
63+ * SCOREP_User_RewindRegionEnd does some additional magic
64+ * */
65+ SCOREP_User_RewindRegionEnd (handle.value , value);
66+ }
67+
4468void parameter_int (std::string name, int64_t value)
4569{
4670 static SCOREP_User_ParameterHandle scorep_param = SCOREP_USER_INVALID_PARAMETER;
@@ -140,6 +164,36 @@ extern "C"
140164 return Py_None;
141165 }
142166
167+ static PyObject* rewind_begin (PyObject* self, PyObject* args)
168+ {
169+ const char * region_name;
170+ const char * file_name;
171+ std::uint64_t line_number = 0 ;
172+
173+ if (!PyArg_ParseTuple (args, " ssK" , ®ion_name, &file_name, &line_number))
174+ return NULL ;
175+
176+ scorep::rewind_begin (region_name, file_name, line_number);
177+
178+ Py_INCREF (Py_None);
179+ return Py_None;
180+ }
181+
182+ static PyObject* rewind_end (PyObject* self, PyObject* args)
183+ {
184+ const char * region_name;
185+ PyObject* value; // false C-Style
186+
187+ if (!PyArg_ParseTuple (args, " sO" , ®ion_name, &value))
188+ return NULL ;
189+
190+ // TODO cover PyObject_IsTrue(value) == -1 (error case)
191+ scorep::rewind_end (region_name, PyObject_IsTrue (value) == 1 );
192+
193+ Py_INCREF (Py_None);
194+ return Py_None;
195+ }
196+
143197 static PyObject* oa_region_begin (PyObject* self, PyObject* args)
144198 {
145199 const char * region;
@@ -219,6 +273,8 @@ extern "C"
219273 static PyMethodDef ScorePMethods[] = {
220274 { " region_begin" , region_begin, METH_VARARGS, " enter a region." },
221275 { " region_end" , region_end, METH_VARARGS, " exit a region." },
276+ { " rewind_begin" , rewind_begin, METH_VARARGS, " rewind begin." },
277+ { " rewind_end" , rewind_end, METH_VARARGS, " rewind end." },
222278 { " oa_region_begin" , oa_region_begin, METH_VARARGS, " enter an online access region." },
223279 { " oa_region_end" , oa_region_end, METH_VARARGS, " exit an online access region." },
224280 { " enable_recording" , enable_recording, METH_VARARGS, " disable scorep recording." },
0 commit comments