Skip to content

Commit

Permalink
#900 trace- unify reporting to rank 0
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
pnstickne committed Jun 30, 2020
1 parent 7f9532b commit 7cfaf41
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
58 changes: 23 additions & 35 deletions src/vt/trace/trace_user_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,56 +75,44 @@ UserEventIDType UserEventRegistry::createEvent(
UserEventIDType UserEventRegistry::hash(std::string const& in_event_name) {
auto id_hash = static_cast<uint16_t>(std::hash<std::string>{}(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<NewUserEventMsg>(false, id, in_event_name);
theMsg()->sendMsg<NewUserEventMsg,newEventHan>(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<NewUserEventMsg>(false, id, in_event_name);
theMsg()->sendMsg<NewUserEventMsg,newEventHan>(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<NewUserEventMsg>(true, id, in_event_name);
theMsg()->sendMsg<NewUserEventMsg,newEventHan>(0, msg.get());
}
return id;
const bool report_up = true;
return newEventImpl(true, false, in_event_name, seq, false, report_up);
}

std::tuple<UserEventIDType, bool> 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<NewUserEventMsg>(user, event, in_event);
theMsg()->sendMsg<NewUserEventMsg,newEventHan>(0, msg.get());
}

return event;
}

bool UserEventRegistry::insertEvent(
Expand Down
4 changes: 2 additions & 2 deletions src/vt/trace/trace_user_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ struct UserEventRegistry {
friend void insertNewUserEvent(UserEventIDType event, std::string const& name);

private:
std::tuple<UserEventIDType, bool> 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);
Expand Down

0 comments on commit 7cfaf41

Please sign in to comment.