88using namespace chimbuko ;
99
1010ADEvent::ADEvent (bool verbose)
11- : m_funcMap(nullptr ), m_eventType(nullptr ), m_counterMap(nullptr ), m_verbose(verbose)
11+ : m_funcMap(nullptr ), m_eventType(nullptr ), m_counterMap(nullptr ), m_verbose(verbose),
12+ m_eidx_func_entry(-1 ), m_eidx_func_exit(-1 ), m_eidx_comm_send(-1 ), m_eidx_comm_recv(-1 )
1213{
1314
1415}
@@ -123,31 +124,49 @@ CallListIterator_t ADEvent::addCall(const ExecData_t &exec){
123124
124125
125126EventError ADEvent::addFunc (const Event_t& event) {
127+ // Determine the event type. Use the known event indices if previously determined, otherwise find them
126128 if (m_eventType == nullptr ) {
127129 std::cerr << " Uninitialized eventType\n " ;
128130 return EventError::UnknownEvent;
129131 }
130-
131- std::string eventType;
132132 int eid = static_cast <int >(event.eid ());
133- if (m_eventType->count (eid) == 0 ) {
134- std::cerr << " Unknown event in eventType: " << eid << std::endl;
135- return EventError::UnknownEvent;
133+
134+ bool is_entry (false ), is_exit (false );
135+
136+ if (eid == m_eidx_func_entry){
137+ is_entry = true ;
138+ }else if (eid == m_eidx_func_exit){
139+ is_exit = true ;
140+ }else {
141+ // Event might be an unknown type *or* the m_eidx* members have not yet been set
142+ auto it = m_eventType->find (eid);
143+ if (it == m_eventType->end ()){ // event index is not in the map??
144+ std::cerr << " Unknown event in eventType: " << eid << std::endl;
145+ return EventError::UnknownEvent;
146+ }
147+ if (m_eidx_func_entry == -1 && it->second == " ENTRY" ){
148+ m_eidx_func_entry = eid;
149+ is_entry = true ;
150+ }else if (m_eidx_func_exit == -1 && it->second == " EXIT" ){
151+ m_eidx_func_exit = eid;
152+ is_exit = true ;
153+ }
136154 }
137155
156+ // Get the iterator to the function name
138157 if (m_funcMap == nullptr ) {
139158 std::cerr << " Uninitialized function map\n " ;
140159 return EventError::UnknownEvent;
141160 }
142-
143- if (m_funcMap->count (event.fid ()) == 0 ) {
161+ auto func_name_it = m_funcMap->find (event.fid ());
162+
163+ if (func_name_it == m_funcMap->end ()){
144164 std::cerr << " Unknown function event\n " ;
145165 return EventError::UnknownFunc;
146166 }
167+ const std::string &func_name = func_name_it->second ;
147168
148- eventType = m_eventType->find (eid)->second ;
149-
150- if (eventType.compare (" ENTRY" ) == 0 ){
169+ if (is_entry){
151170 // Create a new ExecData_t object with function entry information and push onto the call list
152171 CallList_t& cl = m_callList[event.pid ()][event.rid ()][event.tid ()];
153172
@@ -159,20 +178,20 @@ EventError ADEvent::addFunc(const Event_t& event) {
159178 it->set_parent (cs.top ()->get_id ());
160179 cs.top ()->inc_n_children ();
161180 }
162- it->set_funcname (m_funcMap-> find (event. fid ())-> second );
181+ it->set_funcname (func_name );
163182 cs.push (it);
164183
165184 // Add the new call to the map of call index string
166185 m_callIDMap[it->get_id ()] = it;
167186
168187 return EventError::OK;
169- }else if (eventType. compare ( " EXIT " ) == 0 ){
188+ }else if (is_exit ){
170189 CallStack_t& cs = m_callStack[event.pid ()][event.rid ()][event.tid ()];
171190 if (cs.size () == 0 ) { // Expect to have at least one entry; that created when the ENTRY was encountered
172191 std::stringstream ss;
173192 ss << " \n ***** Empty call stack! *****" << std::endl
174193 << " Event information: " << event.get_json ().dump () << std::endl
175- << " Event type: " << m_eventType-> find (event. eid ())-> second << " Function name: " << m_funcMap-> find (event. fid ())-> second << std::endl;
194+ << " Event type: EXIT Function name: " << func_name << std::endl;
176195 recoverable_error (ss.str ());
177196 return EventError::EmptyCallStack;
178197 }
@@ -183,13 +202,8 @@ EventError ADEvent::addFunc(const Event_t& event) {
183202 std::stringstream ss;
184203 ss << " \n ***** Invalid EXIT event! *****" << std::endl
185204 << " Event information: " << event.get_json ().dump () << std::endl
186- << " Event type: " << m_eventType-> find (event. eid ())-> second << " Function name: " << m_funcMap-> find (event. fid ())-> second << std::endl;
205+ << " Event type: EXIT Function name: " << func_name << std::endl;
187206 recoverable_error (ss.str ());
188-
189- // while (!cs.empty()) {
190- // std::cerr << *cs.top() << std::endl;
191- // cs.pop();
192- // }
193207 return EventError::CallStackViolation;
194208 }
195209 // Remove the object from the stack (it still lives in the CallList)
@@ -249,22 +263,41 @@ EventError ADEvent::addFunc(const Event_t& event) {
249263}
250264
251265EventError ADEvent::addComm (const Event_t& event) {
252- if (m_eventType == nullptr )
266+ if (m_eventType == nullptr ) {
267+ std::cerr << " Uninitialized eventType\n " ;
253268 return EventError::UnknownEvent;
254-
269+ }
255270 int eid = static_cast <int >(event.eid ());
256- if (m_eventType->count (eid) == 0 )
257- return EventError::UnknownEvent;
258271
259- std::string eventType = m_eventType->find (eid)->second ;
272+ bool is_send (false ), is_recv (false );
273+
274+ if (eid == m_eidx_comm_send){
275+ is_send = true ;
276+ }else if (eid == m_eidx_comm_recv){
277+ is_recv = true ;
278+ }else {
279+ // Event might be an unknown type *or* the m_eidx* members have not yet been set
280+ auto it = m_eventType->find (eid);
281+ if (it == m_eventType->end ()){ // event index is not in the map??
282+ std::cerr << " Unknown event in eventType: " << eid << std::endl;
283+ return EventError::UnknownEvent;
284+ }
285+ if (m_eidx_comm_send == -1 && it->second == " SEND" ){
286+ m_eidx_comm_send = eid;
287+ is_send = true ;
288+ }else if (m_eidx_comm_recv == -1 && it->second == " RECV" ){
289+ m_eidx_comm_recv = eid;
290+ is_recv = true ;
291+ }
292+ }
260293
261- if (eventType. compare ( " SEND " ) == 0 || eventType. compare ( " RECV " ) == 0 ) {
294+ if (is_send || is_recv ) {
262295 CommStack_t& cs = m_commStack[event.pid ()][event.rid ()][event.tid ()];
263- cs.push (CommData_t (event, eventType));
296+ cs.push (CommData_t (event, is_send ? " SEND" : " RECV" ));
297+ return EventError::OK;
264298 }
265- else return EventError::UnknownEvent;
266-
267- return EventError::OK;
299+
300+ return EventError::UnknownEvent;
268301}
269302
270303EventError ADEvent::addCounter (const Event_t& event){
@@ -278,7 +311,7 @@ EventError ADEvent::addCounter(const Event_t& event){
278311 if (it == m_counterMap->end ())
279312 return EventError::UnknownEvent;
280313
281- std::string counterName = it->second ;
314+ const std::string & counterName = it->second ;
282315 CounterStack_t &cs = m_counterStack[event.pid ()][event.rid ()][event.tid ()];
283316 cs.push (CounterData_t (event, counterName));
284317
0 commit comments