Skip to content

Commit

Permalink
Make phase timers and text log work for set()
Browse files Browse the repository at this point in the history
  • Loading branch information
daboehme committed Nov 4, 2015
1 parent fc090fd commit d7565dc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/common/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class Entry
return value(attr.id());
}

bool is_empty() const {
return m_node == 0 && m_attr_id == CALI_INV_ID;
}

// int extract(cali_id_t attr, int n, Variant buf[]) const;

static const Entry empty;
Expand Down
9 changes: 8 additions & 1 deletion src/services/textlog/TextLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ TriggerAttributeMap trigger_attr_map;

std::vector<std::string> trigger_attr_names;

Attribute set_event_attr { Attribute::invalid };
Attribute end_event_attr { Attribute::invalid };
Attribute phase_duration_attr { Attribute::invalid };

Expand All @@ -63,7 +64,8 @@ void create_attribute_cb(Caliper* c, const Attribute& attr)
void process_snapshot_cb(Caliper* c, const Entry* trigger_info, const Snapshot* snapshot)
{
// operate only on cali.snapshot.event.end attributes for now
if (!trigger_info || trigger_info->attribute() != end_event_attr.id())
if (!trigger_info &&
!(trigger_info->attribute() == end_event_attr.id() || trigger_info->attribute() == set_event_attr.id()))
return;

Attribute trigger_attr { Attribute::invalid };
Expand All @@ -84,6 +86,9 @@ void process_snapshot_cb(Caliper* c, const Entry* trigger_info, const Snapshot*
Entry time_entry = snapshot->get(phase_duration_attr);
Entry attr_entry = snapshot->get(trigger_attr);

if (time_entry.is_empty())
return;

// add hierarchy entries if this is a node, make string in reverse order

std::vector<Variant> attr_v;
Expand Down Expand Up @@ -122,10 +127,12 @@ void process_snapshot_cb(Caliper* c, const Entry* trigger_info, const Snapshot*

void post_init_cb(Caliper* c)
{
set_event_attr = c->get_attribute("cali.snapshot.event.set");
end_event_attr = c->get_attribute("cali.snapshot.event.end");
phase_duration_attr = c->get_attribute("time.phase.duration");

if (end_event_attr == Attribute::invalid ||
set_event_attr == Attribute::invalid ||
phase_duration_attr == Attribute::invalid)
Log(1).stream() << "Warning: \"event\" service with snapshot info\n"
" and \"timestamp\" service with phase duration recording\n"
Expand Down
29 changes: 18 additions & 11 deletions src/services/timestamp/Timestamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bool record_duration;
bool record_phases;

Attribute begin_evt_attr { Attribute::invalid };
Attribute set_evt_attr { Attribute::invalid };
Attribute end_evt_attr { Attribute::invalid };
Attribute lvl_attr { Attribute::invalid };

Expand Down Expand Up @@ -155,25 +156,29 @@ void snapshot_cb(Caliper* c, int scope, const Entry* trigger_info, Snapshot* sbu
}

if (record_phases && trigger_info) {
cali_id_t evt_attr_id = trigger_info->value().to_id();
Variant v_level = trigger_info->value(lvl_attr);

if (evt_attr_id == CALI_INV_ID || v_level.empty())
goto record_phases_exit;

if (trigger_info->attribute() == begin_evt_attr.id()) {
// begin/set event: save time for current entry

cali_id_t evt_attr_id = trigger_info->value().to_id();
Variant v_level = trigger_info->value(lvl_attr);
c->set(make_offset_attribute(c, evt_attr_id, v_level.to_uint()), v_usec);
} else if (trigger_info->attribute() == set_evt_attr.id()) {
// set event: get saved time for current entry and calculate duration

if (evt_attr_id == CALI_INV_ID || v_level.empty())
goto record_phases_exit;
Variant v_p_usec =
c->exchange(make_offset_attribute(c, evt_attr_id, v_level.to_uint()), v_usec);

c->set(make_offset_attribute(c, evt_attr_id, v_level.to_uint()), v_usec);
if (!v_p_usec.empty()) {
addr.immediate_attr[sizes.n_attr++] = phase_duration_attr.id();
addr.immediate_data[sizes.n_data++] = usec - v_p_usec.to_uint();
}
} else if (trigger_info->attribute() == end_evt_attr.id()) {
// end event: get saved time for current entry and calculate duration

cali_id_t evt_attr_id = trigger_info->value().to_id();
Variant v_level = trigger_info->value(lvl_attr);

if (evt_attr_id == CALI_INV_ID || v_level.empty())
goto record_phases_exit;

Attribute offs_attr =
find_offset_attribute(c, evt_attr_id, v_level.to_uint());

Expand Down Expand Up @@ -206,10 +211,12 @@ void post_init_cb(Caliper* c)
// Find begin/end event snapshot event info attributes

begin_evt_attr = c->get_attribute("cali.snapshot.event.begin");
set_evt_attr = c->get_attribute("cali.snapshot.event.set");
end_evt_attr = c->get_attribute("cali.snapshot.event.end");
lvl_attr = c->get_attribute("cali.snapshot.event.attr.level");

if (begin_evt_attr == Attribute::invalid ||
set_evt_attr == Attribute::invalid ||
end_evt_attr == Attribute::invalid ||
lvl_attr == Attribute::invalid) {
if (record_phases)
Expand Down

0 comments on commit d7565dc

Please sign in to comment.