mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 04:50:34 +05:00
add UserEvents to PajeTrace
This commit is contained in:
parent
c0f57369e5
commit
618b81286a
@ -96,6 +96,12 @@ namespace ngcore
|
||||
for(auto & event : timer_events)
|
||||
event.time -= start_time;
|
||||
|
||||
for(auto & event : user_events)
|
||||
{
|
||||
event.t_start -= start_time;
|
||||
event.t_end -= start_time;
|
||||
}
|
||||
|
||||
for(auto & event : gpu_events)
|
||||
event.time -= start_time;
|
||||
|
||||
@ -192,6 +198,10 @@ namespace ngcore
|
||||
: time(atime), event_type(aevent_type), type(atype), container(acontainer), value(avalue), id(aid), value_is_alias(avalue_is_alias)
|
||||
{ }
|
||||
|
||||
PajeEvent( int aevent_type, double atime, int atype, int acontainer, std::string as_value, int aid = 0 )
|
||||
: time(atime), event_type(aevent_type), type(atype), container(acontainer), id(aid), s_value(as_value), value_is_alias(false), value_is_int(false)
|
||||
{ }
|
||||
|
||||
PajeEvent( int aevent_type, double atime, int atype, int acontainer, int avalue, int astart_container, int akey )
|
||||
: time(atime), event_type(aevent_type), type(atype), container(acontainer), value(avalue), start_container(astart_container), id(akey)
|
||||
{ }
|
||||
@ -201,10 +211,12 @@ namespace ngcore
|
||||
int event_type;
|
||||
int type;
|
||||
int container;
|
||||
std::string s_value = "";
|
||||
int value = 0;
|
||||
int start_container = 0;
|
||||
int id = 0;
|
||||
bool value_is_alias = true;
|
||||
bool value_is_int = true;
|
||||
|
||||
bool operator < (const PajeEvent & other) const {
|
||||
// Same start and stop times can occur for very small tasks -> take "starting" events first (eg. PajePushState before PajePopState)
|
||||
@ -228,8 +240,10 @@ namespace ngcore
|
||||
case PajePushState:
|
||||
if(value_is_alias)
|
||||
return fprintf( stream, "%d\t%.15g\ta%d\ta%d\ta%d\t%d\n", PajePushState, time, type, container, value, id); // NOLINT
|
||||
else
|
||||
else if(value_is_int)
|
||||
return fprintf( stream, "%d\t%.15g\ta%d\ta%d\t%d\t%d\n", PajePushState, time, type, container, value, id); // NOLINT
|
||||
else
|
||||
return fprintf( stream, "%d\t%.15g\ta%d\ta%d\t\"%s\"\t%d\n", PajePushState, time, type, container, s_value.c_str(), id); // NOLINT
|
||||
case PajePopState:
|
||||
return fprintf( stream, "%d\t%.15g\ta%d\ta%d\n", PajePopState, time, type, container ); // NOLINT
|
||||
case PajeStartLink:
|
||||
@ -354,6 +368,11 @@ namespace ngcore
|
||||
events.emplace_back( PajeEvent( PajePushState, ConvertTime(time), type, container, value, id, value_is_alias) );
|
||||
}
|
||||
|
||||
void PushState ( TTimePoint time, int type, int container, std::string value, int id = 0)
|
||||
{
|
||||
events.emplace_back( PajeEvent( PajePushState, ConvertTime(time), type, container, value, id) );
|
||||
}
|
||||
|
||||
void PopState ( TTimePoint time, int type, int container )
|
||||
{
|
||||
events.emplace_back( PajeEvent( PajePopState, ConvertTime(time), type, container ) );
|
||||
@ -645,6 +664,30 @@ namespace ngcore
|
||||
}
|
||||
}
|
||||
|
||||
if(user_events.size())
|
||||
{
|
||||
std::sort (user_events.begin(), user_events.end());
|
||||
|
||||
std::map<int, int> containers;
|
||||
|
||||
for(auto ev : user_events)
|
||||
if(containers[ev.container]==0)
|
||||
containers[ev.container] = paje.CreateContainer( container_type_timer, container_task_manager, "User " + ToString(ev.container) );
|
||||
|
||||
int i_start = 0;
|
||||
for(auto i : Range(user_events.size()))
|
||||
{
|
||||
auto & event = user_events[i];
|
||||
while(i_start < user_events.size() && user_events[i_start].t_start < event.t_end)
|
||||
{
|
||||
auto & ev = user_events[i_start];
|
||||
paje.PushState( ev.t_start, state_type_timer, containers[ev.container], ev.data, ev.id );
|
||||
i_start++;
|
||||
}
|
||||
paje.PopState( event.t_end, state_type_timer, containers[event.container]);
|
||||
}
|
||||
}
|
||||
|
||||
for(auto & vtasks : tasks)
|
||||
{
|
||||
for (Task & t : vtasks) {
|
||||
|
@ -97,6 +97,16 @@ namespace ngcore
|
||||
bool operator < (const TimerEvent & other) const { return time < other.time; }
|
||||
};
|
||||
|
||||
struct UserEvent
|
||||
{
|
||||
TTimePoint t_start, t_end;
|
||||
std::string data;
|
||||
int container = 0;
|
||||
int id = 0;
|
||||
|
||||
bool operator < (const UserEvent & other) const { return t_start < other.t_start; }
|
||||
};
|
||||
|
||||
struct ThreadLink
|
||||
{
|
||||
int thread_id;
|
||||
@ -119,6 +129,7 @@ namespace ngcore
|
||||
std::vector<std::vector<Task> > tasks;
|
||||
std::vector<Job> jobs;
|
||||
std::vector<TimerEvent> timer_events;
|
||||
std::vector<UserEvent> user_events;
|
||||
std::vector<TimerEvent> gpu_events;
|
||||
std::vector<std::vector<ThreadLink> > links;
|
||||
NGCORE_API static std::vector<MemoryEvent> memory_events;
|
||||
@ -135,6 +146,11 @@ namespace ngcore
|
||||
void operator=(const PajeTrace &) = delete;
|
||||
void operator=(PajeTrace &&) = delete;
|
||||
|
||||
void AddUserEvent(TTimePoint t_start, TTimePoint t_end, const std::string & data, int container = 0, int id=0 )
|
||||
{
|
||||
if(!tracing_enabled) return;
|
||||
user_events.push_back(UserEvent{t_start, t_end, data, container, id});
|
||||
}
|
||||
void StartGPU(int timer_id = 0)
|
||||
{
|
||||
if(!tracing_enabled) return;
|
||||
|
Loading…
Reference in New Issue
Block a user