From 7cfaf41b45692e30c4949e1b6bbaa8851f7dfdb2 Mon Sep 17 00:00:00 2001 From: Paul Nathan Stickney Date: Tue, 30 Jun 2020 01:57:30 -0700 Subject: [PATCH] #900 trace- unify reporting to rank 0 - When a trace user ID is registered it is (often) reported up to rank 0 so it can be added to the STS definition. Unify the logic in one place to support future changes. Also fixes an edge-case where it may be possible for the same registration to be sent multiple times, which is wasteful. --- src/vt/trace/trace_user_event.cc | 58 +++++++++++++------------------- src/vt/trace/trace_user_event.h | 4 +-- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/vt/trace/trace_user_event.cc b/src/vt/trace/trace_user_event.cc index f207d04fd4..c717638549 100644 --- a/src/vt/trace/trace_user_event.cc +++ b/src/vt/trace/trace_user_event.cc @@ -75,56 +75,44 @@ UserEventIDType UserEventRegistry::createEvent( UserEventIDType UserEventRegistry::hash(std::string const& in_event_name) { auto id_hash = static_cast(std::hash{}(in_event_name)); id_hash = id_hash & 0x0FFF; - auto ret = newEventImpl(false, false, in_event_name, id_hash, true); - auto id = std::get<0>(ret); - auto inserted = std::get<1>(ret); - if (inserted) { - auto const node = theContext()->getNode(); - if (node != 0) { - auto msg = makeMessage(false, id, in_event_name); - theMsg()->sendMsg(0, msg.get()); - } - } - return id; + const bool report_up = true; + return newEventImpl(false, false, in_event_name, id_hash, true, report_up); } UserEventIDType UserEventRegistry::collective(std::string const& in_event_name) { - auto ret = newEventImpl(false, false, in_event_name, cur_coll_event_++); - return std::get<0>(ret); + const bool report_up = false; + const int seq = cur_coll_event_++; + return newEventImpl(false, false, in_event_name, seq, false, report_up); } UserEventIDType UserEventRegistry::rooted(std::string const& in_event_name) { - auto ret = newEventImpl(false, true, in_event_name, cur_root_event_++); - auto id = std::get<0>(ret); - auto const node = theContext()->getNode(); - if (node != 0) { - auto msg = makeMessage(false, id, in_event_name); - theMsg()->sendMsg(0, msg.get()); - } - return id; + const bool report_up = true; + const int seq = cur_root_event_++; + return newEventImpl(false, true, in_event_name, seq, false, report_up); } UserEventIDType UserEventRegistry::user( std::string const& in_event_name, UserSpecEventIDType seq ) { - auto ret = newEventImpl(true, false, in_event_name, seq); - auto id = std::get<0>(ret); - auto const node = theContext()->getNode(); - if (node != 0) { - auto msg = makeMessage(true, id, in_event_name); - theMsg()->sendMsg(0, msg.get()); - } - return id; + const bool report_up = true; + return newEventImpl(true, false, in_event_name, seq, false, report_up); } -std::tuple UserEventRegistry::newEventImpl( +UserEventIDType UserEventRegistry::newEventImpl( bool user, bool rooted, std::string const& in_event, UserSpecEventIDType id, - bool hash + bool hash, bool report_up ) { - auto const node = theContext()->getNode(); - auto const event = createEvent(user, rooted, node, id, hash); - auto const inserted = insertEvent(event, in_event); - return std::make_tuple(event, inserted); + const NodeType node = theContext()->getNode(); + const UserEventIDType event = createEvent(user, rooted, node, id, hash); + const bool inserted = insertEvent(event, in_event); + + // Ensure newly inserted events are passed to rank 0 if requested. + if (inserted and report_up and node not_eq 0) { + auto msg = makeMessage(user, event, in_event); + theMsg()->sendMsg(0, msg.get()); + } + + return event; } bool UserEventRegistry::insertEvent( diff --git a/src/vt/trace/trace_user_event.h b/src/vt/trace/trace_user_event.h index 589596d8eb..d91ce07064 100644 --- a/src/vt/trace/trace_user_event.h +++ b/src/vt/trace/trace_user_event.h @@ -117,9 +117,9 @@ struct UserEventRegistry { friend void insertNewUserEvent(UserEventIDType event, std::string const& name); private: - std::tuple newEventImpl( + UserEventIDType newEventImpl( bool user, bool rooted, std::string const& in_event, UserSpecEventIDType id, - bool hash = false + bool hash, bool report_up ); bool insertEvent(UserEventIDType event, std::string const& name);