diff --git a/libsrc/core/paje_trace.cpp b/libsrc/core/paje_trace.cpp index 844710d5..5349f3ae 100644 --- a/libsrc/core/paje_trace.cpp +++ b/libsrc/core/paje_trace.cpp @@ -98,7 +98,7 @@ namespace ngcore // return time in milliseconds as double // return std::chrono::duration(t-start_time).count()*1000.0; // return std::chrono::duration(t-start_time).count() / 2.7e3; - return (t-start_time) / 2.7e6; + return (t-start_time) / ticks_per_second; } enum PType @@ -393,7 +393,7 @@ namespace ngcore if(trace_threads) for (int i=0; i children; + double time; + std::string name; + }; + + void PrintNode (const TreeNode &n, int &level, std::ofstream & f); + void PrintNode (const TreeNode &n, int &level, std::ofstream & f) + { + f << "{ name: \"" + n.name + "\", size: " + ToString(n.time); + int size = n.children.size(); + if(size>0) + { + int i = 0; + f << ", children: ["; + for(auto & c : n.children) + { + PrintNode(c.second, level, f); + if(++i events; + + TreeNode root; + root.time=0; + root.name="all"; + TreeNode *current = &root; + + std::vector node_stack; + + node_stack.push_back(&root); + + TTimePoint stop_time = 0; + + for(auto & event : timer_events) + { + events.push_back(event); + stop_time = std::max(event.time, stop_time); + } + + std::map job_names; + for(auto & job : jobs) + { + events.push_back(TimerEvent{-1, job.start_time, true, job.job_id}); + events.push_back(TimerEvent{-1, job.stop_time, false, job.job_id}); + stop_time = std::max(job.stop_time, stop_time); + + if(job_names.count(job.job_id)==0) + job_names[job.job_id] = Demangle(job.type->name()); + } + + std::sort (events.begin(), events.end()); + + root.time = 1000.0*(stop_time-start_time)/ticks_per_second; + + for(auto & event : events) + { + if(event.is_start) + { + bool need_init = !current->children.count(event.timer_id); + node_stack.push_back(current); + current = ¤t->children[event.timer_id]; + + if(need_init) + { + if(event.timer_id==-1) + current->name = job_names[event.thread_id]; + else + current->name = NgProfiler::GetName(event.timer_id); + current->time = 0.0; + current->id = event.timer_id; + } + + current->time -= 1000.0*event.time/ticks_per_second; + } + else + { + current->time += 1000.0*event.time/ticks_per_second; + current = node_stack.back(); + node_stack.pop_back(); + } + } + + int level = 0; + std::ofstream f(tracefile_name+".html"); + f.precision(4); + f << R"CODE_( + + + + + + + +
+ + + +)CODE_" << std::endl; + } + } // namespace ngcore const char *header = diff --git a/libsrc/core/paje_trace.hpp b/libsrc/core/paje_trace.hpp index 96684285..1d656ca3 100644 --- a/libsrc/core/paje_trace.hpp +++ b/libsrc/core/paje_trace.hpp @@ -29,6 +29,7 @@ namespace ngcore int nthreads; public: + void WriteSunburstHTML(); // Approximate number of events to trace. Tracing will // be stopped if any thread reaches this number of events