Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/caliper/common/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class Variant

Variant(const cali_variant_t& v) : m_v(v) {}

Variant(bool val) : m_v(cali_make_variant_from_bool(val)) {}
Variant(int val) : m_v(cali_make_variant_from_int(val)) {}
Variant(double val) : m_v(cali_make_variant_from_double(val)) {}
Variant(const char* val) : m_v(cali_make_variant_from_string(val)) {}
Variant(cali_attr_type val) : m_v(cali_make_variant_from_type(val)) {}
explicit Variant(bool val) : m_v(cali_make_variant_from_bool(val)) {}
explicit Variant(int val) : m_v(cali_make_variant_from_int(val)) {}
explicit Variant(double val) : m_v(cali_make_variant_from_double(val)) {}
explicit Variant(const char* val) : m_v(cali_make_variant_from_string(val)) {}
explicit Variant(cali_attr_type val) : m_v(cali_make_variant_from_type(val)) {}

template <typename U, typename std::enable_if<std::is_unsigned<U>::value, int>::type = 0>
Variant(U val) : m_v(cali_make_variant_from_uint(val))
explicit Variant(U val) : m_v(cali_make_variant_from_uint(val))
{}

Variant(cali_attr_type type, const void* data, std::size_t size) { m_v = cali_make_variant(type, data, size); }
Expand Down
56 changes: 33 additions & 23 deletions src/caliper/Caliper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,6 @@ Attribute Caliper::create_attribute(
std::lock_guard<std::mutex> ga(sG->attribute_lock);

auto it = sG->attribute_map.lower_bound(name);

if (it == sG->attribute_map.end() || it->first != name)
sG->attribute_map.insert(it, std::make_pair(name, Attribute::make_attribute(node)));
else
Expand All @@ -755,7 +754,6 @@ Attribute Caliper::get_attribute(const std::string& name) const
std::lock_guard<std::mutex> ga(sG->attribute_lock);

auto it = sG->attribute_map.find(name);

return it != sG->attribute_map.end() ? it->second : Attribute();
}

Expand Down Expand Up @@ -958,9 +956,12 @@ void Caliper::begin(const Attribute& attr, const Variant& data)
std::lock_guard<::siglock> g(sT->lock);

// invoke callbacks
if (run_events)
for (auto& channel : sG->active_channels)
channel.mP->events.pre_begin_evt(this, channel.body(), attr, data);
if (run_events) {
for (auto& channel : sG->active_channels) {
ChannelBody* chB = channel.body();
chB->events.pre_begin_evt(this, chB, attr, data);
}
}

if (scope == CALI_ATTR_SCOPE_THREAD)
handle_begin(attr, data, prop, sT->thread_blackboard, sT->tree);
Expand All @@ -970,9 +971,12 @@ void Caliper::begin(const Attribute& attr, const Variant& data)
}

// invoke callbacks
if (run_events)
for (auto& channel : sG->active_channels)
channel.mP->events.post_begin_evt(this, channel.body(), attr, data);
if (run_events) {
for (auto& channel : sG->active_channels) {
ChannelBody* chB = channel.body();
chB->events.post_begin_evt(this, chB, attr, data);
}
}
}

void Caliper::end(const Attribute& attr)
Expand All @@ -986,7 +990,7 @@ void Caliper::end(const Attribute& attr)
bool run_events = !(prop & CALI_ATTR_SKIP_EVENTS);

cali_id_t key = get_blackboard_key(attr.id(), prop);
BlackboardEntry current = { Entry(), Entry( ) };
BlackboardEntry current = { Entry(), Entry() };

std::lock_guard<::siglock> g(sT->lock);

Expand All @@ -1004,9 +1008,12 @@ void Caliper::end(const Attribute& attr)
}

// invoke callbacks
if (run_events)
for (auto& channel : sG->active_channels)
channel.mP->events.pre_end_evt(this, channel.body(), attr, current.entry.value());
if (run_events) {
for (auto& channel : sG->active_channels) {
ChannelBody* chB = channel.body();
chB->events.pre_end_evt(this, chB, attr, current.entry.value());
}
}

if (scope == CALI_ATTR_SCOPE_THREAD)
handle_end(attr, prop, current, key, sT->thread_blackboard, sT->tree);
Expand All @@ -1027,7 +1034,7 @@ void Caliper::end_with_value_check(const Attribute& attr, const Variant& data)
bool run_events = !(prop & CALI_ATTR_SKIP_EVENTS);

cali_id_t key = get_blackboard_key(attr.id(), prop);
BlackboardEntry current = { Entry(), Entry( ) };
BlackboardEntry current = { Entry(), Entry() };

std::lock_guard<::siglock> g(sT->lock);

Expand All @@ -1046,9 +1053,12 @@ void Caliper::end_with_value_check(const Attribute& attr, const Variant& data)
}

// invoke callbacks
if (run_events)
for (auto& channel : sG->active_channels)
channel.mP->events.pre_end_evt(this, channel.body(), attr, current.entry.value());
if (run_events) {
for (auto& channel : sG->active_channels) {
ChannelBody* chB = channel.body();
chB->events.pre_end_evt(this, chB, attr, current.entry.value());
}
}

if (scope == CALI_ATTR_SCOPE_THREAD)
handle_end(attr, prop, current, key, sT->thread_blackboard, sT->tree);
Expand All @@ -1071,9 +1081,12 @@ void Caliper::set(const Attribute& attr, const Variant& data)
std::lock_guard<::siglock> g(sT->lock);

// invoke callbacks
if (run_events)
for (auto& channel : sG->active_channels)
channel.mP->events.pre_set_evt(this, channel.body(), attr, data);
if (run_events) {
for (auto& channel : sG->active_channels) {
ChannelBody* chB = channel.body();
chB->events.pre_set_evt(this, chB, attr, data);
}
}

if (scope == CALI_ATTR_SCOPE_THREAD)
handle_set(attr, data, prop, sT->thread_blackboard, sT->tree);
Expand Down Expand Up @@ -1118,7 +1131,7 @@ void Caliper::end(ChannelBody* chB, const Attribute& attr)
bool run_events = !(prop & CALI_ATTR_SKIP_EVENTS);

cali_id_t key = get_blackboard_key(attr.id(), prop);
BlackboardEntry current = { Entry(), Entry( )};
BlackboardEntry current = { Entry(), Entry()};

std::lock_guard<::siglock> g(sT->lock);

Expand Down Expand Up @@ -1274,21 +1287,18 @@ void Caliper::make_record(size_t n, const Attribute attr[], const Variant value[
Node* Caliper::make_tree_entry(size_t n, const Node* nodelist[], Node* parent)
{
std::lock_guard<::siglock> g(sT->lock);

return sT->tree.get_path(n, nodelist, parent);
}

Node* Caliper::make_tree_entry(const Attribute& attr, const Variant& data, Node* parent)
{
std::lock_guard<::siglock> g(sT->lock);

return sT->tree.get_child(attr, data, parent);
}

Node* Caliper::make_tree_entry(const Attribute& attr, size_t n, const Variant data[], Node* parent)
{
std::lock_guard<::siglock> g(sT->lock);

return sT->tree.get_path(attr, n, data, parent);
}

Expand Down
54 changes: 25 additions & 29 deletions src/caliper/MetadataTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,33 @@ MetadataTree::GlobalData::GlobalData(MemoryPool& pool)

Node* chunk = pool.aligned_alloc<Node>(nodes_per_block);

static const struct NodeInfo {
cali_id_t id;
cali_id_t attr_id;
Variant data;
cali_id_t parent;
} bootstrap_nodes[] = { { 0, 9, { CALI_TYPE_USR }, CALI_INV_ID },
{ 1, 9, { CALI_TYPE_INT }, CALI_INV_ID },
{ 2, 9, { CALI_TYPE_UINT }, CALI_INV_ID },
{ 3, 9, { CALI_TYPE_STRING }, CALI_INV_ID },
{ 4, 9, { CALI_TYPE_ADDR }, CALI_INV_ID },
{ 5, 9, { CALI_TYPE_DOUBLE }, CALI_INV_ID },
{ 6, 9, { CALI_TYPE_BOOL }, CALI_INV_ID },
{ 7, 9, { CALI_TYPE_TYPE }, CALI_INV_ID },
{ 8, 8, { CALI_TYPE_STRING, "cali.attribute.name", 19 }, 3 },
{ 9, 8, { CALI_TYPE_STRING, "cali.attribute.type", 19 }, 7 },
{ 10, 8, { CALI_TYPE_STRING, "cali.attribute.prop", 19 }, 1 },
{ 11, 9, { CALI_TYPE_PTR }, CALI_INV_ID },
{ CALI_INV_ID, CALI_INV_ID, {}, CALI_INV_ID } };

for (const NodeInfo* info = bootstrap_nodes; info->id != CALI_INV_ID; ++info) {
Node* node = new (chunk + info->id) Node(info->id, info->attr_id, info->data);

if (info->parent != CALI_INV_ID)
chunk[info->parent].append(node);
else
root.append(node);

if (info->attr_id == 9 /* type node */)
type_nodes[info->data.to_attr_type()] = node;
// --- make the bootstrap nodes

static const struct { uint64_t id; cali_attr_type type; } bootstrap_type_nodes[] = {
{ 0, CALI_TYPE_USR },
{ 1, CALI_TYPE_INT },
{ 2, CALI_TYPE_UINT },
{ 3, CALI_TYPE_STRING },
{ 4, CALI_TYPE_ADDR },
{ 5, CALI_TYPE_DOUBLE },
{ 6, CALI_TYPE_BOOL },
{ 7, CALI_TYPE_TYPE },
{ 11, CALI_TYPE_PTR }
};

for (const auto &t : bootstrap_type_nodes) {
Node* node = new (chunk + t.id) Node (t.id, 9, cali_make_variant_from_type(t.type));
root.append(node);
type_nodes[t.type] = node;
}

Node* attr_name_node = new (chunk + 8) Node( 8, 8, Variant("cali.attribute.name"));
Node* attr_type_node = new (chunk + 9) Node( 9, 8, Variant("cali.attribute.type"));
Node* attr_prop_node = new (chunk + 10) Node(10, 8, Variant("cali.attribute.prop"));
type_nodes[CALI_TYPE_STRING]->append(attr_name_node);
type_nodes[CALI_TYPE_TYPE ]->append(attr_type_node);
type_nodes[CALI_TYPE_INT ]->append(attr_prop_node);

node_blocks[0].chunk = chunk;
node_blocks[0].index = 12;
}
Expand Down
3 changes: 1 addition & 2 deletions src/reader/Aggregator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,6 @@ struct Aggregator::AggregatorImpl {
std::vector<Entry> immediates;

nodes.reserve(80);
non_path_nodes.reserve(20);
immediates.reserve(key_attrs.size());

for (const Entry& e : rec) {
Expand All @@ -1098,7 +1097,7 @@ struct Aggregator::AggregatorImpl {
non_path_nodes.push_back(node);
}
}
} else if (e.is_immediate() && is_key(db, key_attrs, db.get_attribute(e.attribute()))) {
} else if (is_key(db, key_attrs, db.get_attribute(e.attribute()))) {
// Only include explicitly selected immediate entries in the key.
immediates.push_back(e);
}
Expand Down
62 changes: 27 additions & 35 deletions src/reader/CaliperMetadataDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,46 +70,38 @@ struct CaliperMetadataDB::CaliperMetadataDBImpl {

void setup_bootstrap_nodes()
{
// Create initial nodes

static const struct NodeInfo {
cali_id_t id;
cali_id_t attr_id;
Variant data;
cali_id_t parent;
} bootstrap_nodes[] = { { 0, 9, { CALI_TYPE_USR }, CALI_INV_ID },
{ 1, 9, { CALI_TYPE_INT }, CALI_INV_ID },
{ 2, 9, { CALI_TYPE_UINT }, CALI_INV_ID },
{ 3, 9, { CALI_TYPE_STRING }, CALI_INV_ID },
{ 4, 9, { CALI_TYPE_ADDR }, CALI_INV_ID },
{ 5, 9, { CALI_TYPE_DOUBLE }, CALI_INV_ID },
{ 6, 9, { CALI_TYPE_BOOL }, CALI_INV_ID },
{ 7, 9, { CALI_TYPE_TYPE }, CALI_INV_ID },
{ 8, 8, { CALI_TYPE_STRING, "cali.attribute.name", 19 }, 3 },
{ 9, 8, { CALI_TYPE_STRING, "cali.attribute.type", 19 }, 7 },
{ 10, 8, { CALI_TYPE_STRING, "cali.attribute.prop", 19 }, 1 },
{ 11, 9, { CALI_TYPE_PTR }, CALI_INV_ID },
{ CALI_INV_ID, CALI_INV_ID, {}, CALI_INV_ID } };

// Create nodes
// Create the bootstrap nodes

static const struct { uint64_t id; cali_attr_type type; } bootstrap_type_nodes[] = {
{ 0, CALI_TYPE_USR },
{ 1, CALI_TYPE_INT },
{ 2, CALI_TYPE_UINT },
{ 3, CALI_TYPE_STRING },
{ 4, CALI_TYPE_ADDR },
{ 5, CALI_TYPE_DOUBLE },
{ 6, CALI_TYPE_BOOL },
{ 7, CALI_TYPE_TYPE },
{ 11, CALI_TYPE_PTR }
};

m_nodes.resize(12);

for (const NodeInfo* info = bootstrap_nodes; info->id != CALI_INV_ID; ++info) {
Node* node = new Node(info->id, info->attr_id, info->data);

m_nodes[info->id] = node;
for (const auto &t : bootstrap_type_nodes) {
Node* node = new Node(t.id, 9, cali_make_variant_from_type(t.type));
m_root.append(node);
m_nodes[t.id] = node;
m_type_nodes[t.type] = node;
}

if (info->parent != CALI_INV_ID)
m_nodes[info->parent]->append(node);
else
m_root.append(node);
m_nodes[ 8] = new Node( 8, 8, Variant("cali.attribute.name"));
m_nodes[ 9] = new Node( 9, 8, Variant("cali.attribute.type"));
m_nodes[10] = new Node(10, 8, Variant("cali.attribute.prop"));

m_type_nodes[CALI_TYPE_STRING]->append(m_nodes[ 8]);
m_type_nodes[CALI_TYPE_TYPE ]->append(m_nodes[ 9]);
m_type_nodes[CALI_TYPE_INT ]->append(m_nodes[10]);

if (info->attr_id == 9 /* type node */)
m_type_nodes[info->data.to_attr_type()] = node;
else if (info->attr_id == 8 /* attribute node*/)
m_attributes.insert(make_pair(info->data.to_string(), node));
}
m_attributes.insert(std::make_pair("cali.attribute.name", m_nodes[8]));
}

Node* create_node(cali_id_t attr_id, const Variant& data, Node* parent)
Expand Down
2 changes: 1 addition & 1 deletion src/services/aggregate/Aggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Aggregate
// we store a pointer to the thread-local aggregation DB for this channel
// on the thread's blackboard

ThreadDB* tdb = static_cast<ThreadDB*>(c->get(m_tdb_attr).value().get_ptr());
ThreadDB* tdb = static_cast<ThreadDB*>(c->get_blackboard_entry(m_tdb_attr).value().get_ptr());

if (!tdb && can_alloc) {
tdb = new ThreadDB(c);
Expand Down
2 changes: 1 addition & 1 deletion src/services/ompt/OmptService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void cb_work(int wstype, ompt_scope_endpoint_t endpoint, ompt_data_t*, ompt_data
}

if (endpoint == ompt_scope_begin) {
c.begin(work_attr, name);
c.begin(work_attr, Variant(name));
} else if (endpoint == ompt_scope_end) {
c.end(work_attr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/timer/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TimerService

TimerInfo* acquire_timerinfo(Caliper* c)
{
TimerInfo* ti = static_cast<TimerInfo*>(c->get(timerinfo_attr).value().get_ptr());
TimerInfo* ti = static_cast<TimerInfo*>(c->get_blackboard_entry(timerinfo_attr).value().get_ptr());

if (!ti && !c->is_signal()) {
ti = new TimerInfo;
Expand Down
2 changes: 1 addition & 1 deletion src/services/trace/Trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class Trace
// we store a pointer to the thread-local trace buffer for this channel
// on the thread's blackboard

TraceBuffer* tbuf = static_cast<TraceBuffer*>(c->get(tbuf_attr).value().get_ptr());
TraceBuffer* tbuf = static_cast<TraceBuffer*>(c->get_blackboard_entry(tbuf_attr).value().get_ptr());

if (!tbuf && can_alloc) {
tbuf = new TraceBuffer(buffersize);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/cali-query/AttributeExtract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct AttributeExtract::AttributeExtractImpl {
if (!m_id_attr)
m_id_attr = db.create_attribute("attribute.id", CALI_TYPE_UINT, CALI_ATTR_ASVALUE);

EntryList rec { Entry(m_id_attr, node->id()) };
EntryList rec { Entry(m_id_attr, cali_make_variant_from_uint(node->id())) };

for (; node && node->id() != CALI_INV_ID; node = node->parent())
rec.push_back(Entry(db.get_attribute(node->attribute()), node->data()));
Expand Down