export PajeTrace to Python (with context manager api)

This commit is contained in:
Matthias Hochsteger 2020-08-07 15:34:47 +02:00
parent f9ff1db7c3
commit b272614a51
2 changed files with 28 additions and 4 deletions

View File

@ -246,4 +246,25 @@ threads : int
.def("__timing__", &TaskManager::Timing)
;
py::class_<PajeTrace>(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)
;
}

View File

@ -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();
}