memory tracing - handle multiple consecutive tracers correctly

This commit is contained in:
Matthias Hochsteger 2020-11-24 19:20:21 +01:00
parent efdc57885a
commit b55264e0ee
2 changed files with 29 additions and 7 deletions

View File

@ -29,6 +29,8 @@ namespace ngcore
#endif // PARALLEL #endif // PARALLEL
} }
std::vector<PajeTrace::MemoryEvent> PajeTrace::memory_events;
// Produce no traces by default // Produce no traces by default
size_t PajeTrace::max_tracefile_size = 0; size_t PajeTrace::max_tracefile_size = 0;
@ -75,6 +77,7 @@ namespace ngcore
start_time = GetTimeCounter(); start_time = GetTimeCounter();
tracing_enabled = true; tracing_enabled = true;
mem_tracing_enabled = true; mem_tracing_enabled = true;
n_memory_events_at_start = memory_events.size();
} }
PajeTrace :: ~PajeTrace() PajeTrace :: ~PajeTrace()
@ -97,8 +100,8 @@ namespace ngcore
for(auto & link : llink) for(auto & link : llink)
link.time -= start_time; link.time -= start_time;
for(auto & m : memory_events) for(auto i : IntRange(n_memory_events_at_start, memory_events.size()))
m.time -= start_time; memory_events[i].time -= start_time;
NgMPI_Comm comm(MPI_COMM_WORLD); NgMPI_Comm comm(MPI_COMM_WORLD);
@ -451,7 +454,6 @@ namespace ngcore
if(mem_tracing_enabled) if(mem_tracing_enabled)
{ {
variable_type_memory = paje.DefineVariableType( container_type_task_manager, "Memory [MB]" ); variable_type_memory = paje.DefineVariableType( container_type_task_manager, "Memory [MB]" );
paje.SetVariable( 0, variable_type_memory, container_memory, 0.0 );
} }
@ -524,8 +526,23 @@ namespace ngcore
paje.PopState( j.stop_time, state_type_job, container_jobs ); paje.PopState( j.stop_time, state_type_job, container_jobs );
} }
for(const auto & m : memory_events) size_t memory_at_start = 0;
for(const auto & i : IntRange(0, n_memory_events_at_start))
{ {
if(memory_events[i].is_alloc)
memory_at_start += memory_events[i].size;
else
memory_at_start -= memory_events[i].size;
}
paje.SetVariable( 0, variable_type_memory, container_memory, 1.0*memory_at_start/(1024*1024));
for(const auto & i : IntRange(n_memory_events_at_start, memory_events.size()))
{
auto & m = memory_events[i];
if(m.size==0)
continue;
double size = 1.0*m.size/(1024*1024); double size = 1.0*m.size/(1024*1024);
if(m.is_alloc) if(m.is_alloc)
paje.AddVariable( m.time, variable_type_memory, container_memory, size); paje.AddVariable( m.time, variable_type_memory, container_memory, size);
@ -958,7 +975,7 @@ namespace ngcore
{ {
mem_allocated += ev.size; mem_allocated += ev.size;
mem_allocated_id[ev.id] += ev.size; mem_allocated_id[ev.id] += ev.size;
if(mem_allocated > max_mem_allocated) if(mem_allocated > max_mem_allocated && i>=n_memory_events_at_start)
{ {
imax_mem_allocated = i; imax_mem_allocated = i;
max_mem_allocated = mem_allocated; max_mem_allocated = mem_allocated;
@ -1006,6 +1023,7 @@ namespace ngcore
Array<TreeNode*> nodes; Array<TreeNode*> nodes;
nodes.SetSize(N); nodes.SetSize(N);
nodes = nullptr; nodes = nullptr;
nodes[0] = &root;
Array<Array<int>> children(N); Array<Array<int>> children(N);
Array<size_t> sorting; // topological sorting (parents before children) Array<size_t> sorting; // topological sorting (parents before children)
@ -1033,7 +1051,10 @@ namespace ngcore
for(auto i : sorting) for(auto i : sorting)
{ {
TreeNode * parent = (parents[i]==-1) ? &root : nodes[parents[i]]; if(i==0)
continue;
TreeNode * parent = nodes[parents[i]];
auto & node = parent->children[i]; auto & node = parent->children[i];
nodes[i] = &node; nodes[i] = &node;

View File

@ -28,6 +28,7 @@ namespace ngcore
bool tracing_enabled; bool tracing_enabled;
TTimePoint start_time; TTimePoint start_time;
int nthreads; int nthreads;
size_t n_memory_events_at_start;
public: public:
NGCORE_API void WriteTimingChart(); NGCORE_API void WriteTimingChart();
@ -119,7 +120,7 @@ namespace ngcore
std::vector<Job> jobs; std::vector<Job> jobs;
std::vector<TimerEvent> timer_events; std::vector<TimerEvent> timer_events;
std::vector<std::vector<ThreadLink> > links; std::vector<std::vector<ThreadLink> > links;
std::vector<MemoryEvent> memory_events; NGCORE_API static std::vector<MemoryEvent> memory_events;
public: public:
NGCORE_API void StopTracing(); NGCORE_API void StopTracing();