From 87623981a6c66df3d439ba951b64e9dc700361d6 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 19 Nov 2020 19:29:04 +0100 Subject: [PATCH] export PajeTrace.WriteMemoryChart() to python --- libsrc/core/paje_trace.cpp | 18 ++++++++++-------- libsrc/core/paje_trace.hpp | 3 ++- libsrc/core/python_ngcore_export.cpp | 7 ++++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/libsrc/core/paje_trace.cpp b/libsrc/core/paje_trace.cpp index 856e2214..4e5331e6 100644 --- a/libsrc/core/paje_trace.cpp +++ b/libsrc/core/paje_trace.cpp @@ -742,7 +742,8 @@ namespace ngcore } } } - WriteSunburstHTML(); + WriteTimingChart(); + WriteMemoryChart(""); paje.WriteEvents(); } @@ -929,8 +930,10 @@ namespace ngcore } - void WriteMemorySunburstHTML( std::vector & events, std::string filename ) + void PajeTrace::WriteMemoryChart( std::string fname ) { + if(fname=="") + fname = tracefile_name + "_memory"; size_t mem_allocated = 0; size_t max_mem_allocated = 0; size_t imax_mem_allocated = 0; @@ -944,9 +947,9 @@ namespace ngcore mem_allocated_id = 0; // Find point with maximum memory allocation, check for missing allocs/frees - for(auto i : IntRange(events.size())) + for(auto i : IntRange(memory_events.size())) { - const auto & ev = events[i]; + const auto & ev = memory_events[i]; if(ev.is_alloc) { @@ -974,7 +977,7 @@ namespace ngcore mem_allocated_id = 0; for(auto i : IntRange(imax_mem_allocated+1)) { - const auto & ev = events[i]; + const auto & ev = memory_events[i]; if(ev.is_alloc) mem_allocated_id[ev.id] += ev.size; @@ -1047,11 +1050,11 @@ namespace ngcore nodes[parents[i]]->size += nodes[i]->size; } - WriteSunburstHTML( root, filename, false ); + WriteSunburstHTML( root, fname, false ); } - void PajeTrace::WriteSunburstHTML( ) + void PajeTrace::WriteTimingChart( ) { std::vector events; @@ -1140,7 +1143,6 @@ namespace ngcore root.chart_size = 0.0; ngcore::WriteSunburstHTML( root, tracefile_name, true ); - WriteMemorySunburstHTML( memory_events, tracefile_name+"_memory" ); } } // namespace ngcore diff --git a/libsrc/core/paje_trace.hpp b/libsrc/core/paje_trace.hpp index 22fd0f50..421f866e 100644 --- a/libsrc/core/paje_trace.hpp +++ b/libsrc/core/paje_trace.hpp @@ -30,7 +30,8 @@ namespace ngcore int nthreads; public: - void WriteSunburstHTML(); + NGCORE_API void WriteTimingChart(); + NGCORE_API void WriteMemoryChart( std::string fname ); // Approximate number of events to trace. Tracing will // be stopped if any thread reaches this number of events diff --git a/libsrc/core/python_ngcore_export.cpp b/libsrc/core/python_ngcore_export.cpp index 08d41ef4..59d1a13f 100644 --- a/libsrc/core/python_ngcore_export.cpp +++ b/libsrc/core/python_ngcore_export.cpp @@ -263,9 +263,10 @@ threads : int .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) + .def_static("SetTraceThreads", &PajeTrace::SetTraceThreads) + .def_static("SetTraceThreadCounter", &PajeTrace::SetTraceThreadCounter) + .def_static("SetMaxTracefileSize", &PajeTrace::SetMaxTracefileSize) + .def_static("WriteMemoryChart", [](string filename){ if(trace) trace->WriteMemoryChart(filename); }, py::arg("filename")="memory" ) ;