diff --git a/libsrc/core/python_ngcore_export.cpp b/libsrc/core/python_ngcore_export.cpp index 1aaf12b0..4f93168e 100644 --- a/libsrc/core/python_ngcore_export.cpp +++ b/libsrc/core/python_ngcore_export.cpp @@ -246,4 +246,25 @@ threads : int .def("__timing__", &TaskManager::Timing) ; + py::class_(m, "PajeTrace") + .def(py::init( [] (string filename, size_t size_mb, bool threads, bool thread_counter) + { + PajeTrace::SetMaxTracefileSize(size_mb*1014*1024); + PajeTrace::SetTraceThreads(threads); + PajeTrace::SetTraceThreadCounter(thread_counter); + trace = new PajeTrace(TaskManager::GetMaxThreads(), filename); + return trace; + }), py::arg("filename")="ng.trace", py::arg("size")=1000, + py::arg("threads")=true, py::arg("thread_counter")=false, + "size in Megabytes" + ) + .def("__enter__", [](PajeTrace & self) { }) + .def("__exit__", [](PajeTrace & self, py::args) { self.StopTracing(); }) + .def("__del__", [](PajeTrace & self) { trace = nullptr; }) + .def("SetTraceThreads", &PajeTrace::SetTraceThreads) + .def("SetTraceThreadCounter", &PajeTrace::SetTraceThreadCounter) + .def("SetMaxTracefileSize", &PajeTrace::SetMaxTracefileSize) + ; + + } diff --git a/libsrc/core/taskmanager.cpp b/libsrc/core/taskmanager.cpp index ef38a277..4a49adff 100644 --- a/libsrc/core/taskmanager.cpp +++ b/libsrc/core/taskmanager.cpp @@ -166,8 +166,11 @@ namespace ngcore TaskManager :: ~TaskManager () { - delete trace; - trace = nullptr; + if (use_paje_trace) + { + delete trace; + trace = nullptr; + } num_threads = 1; } @@ -335,7 +338,7 @@ namespace ngcore } - if (use_paje_trace) + if (trace) trace->StartJob(jobnr, afunc.target_type()); func = &afunc; @@ -406,7 +409,7 @@ namespace ngcore if (ex) throw Exception (*ex); - if (use_paje_trace) + if (trace) trace->StopJob(); }