diff --git a/include/caliper/common/Variant.h b/include/caliper/common/Variant.h index 09857e6f..7f92b21a 100644 --- a/include/caliper/common/Variant.h +++ b/include/caliper/common/Variant.h @@ -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 ::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); } diff --git a/src/caliper/Caliper.cpp b/src/caliper/Caliper.cpp index f53e11a2..33e72ad1 100644 --- a/src/caliper/Caliper.cpp +++ b/src/caliper/Caliper.cpp @@ -732,7 +732,6 @@ Attribute Caliper::create_attribute( std::lock_guard 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 @@ -755,7 +754,6 @@ Attribute Caliper::get_attribute(const std::string& name) const std::lock_guard ga(sG->attribute_lock); auto it = sG->attribute_map.find(name); - return it != sG->attribute_map.end() ? it->second : Attribute(); } @@ -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); @@ -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) @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); } diff --git a/src/caliper/MetadataTree.cpp b/src/caliper/MetadataTree.cpp index 4cdaa2c2..f8f9f26f 100644 --- a/src/caliper/MetadataTree.cpp +++ b/src/caliper/MetadataTree.cpp @@ -32,37 +32,33 @@ MetadataTree::GlobalData::GlobalData(MemoryPool& pool) Node* chunk = pool.aligned_alloc(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; } diff --git a/src/reader/Aggregator.cpp b/src/reader/Aggregator.cpp index 1824eb96..05dcab37 100644 --- a/src/reader/Aggregator.cpp +++ b/src/reader/Aggregator.cpp @@ -1083,7 +1083,6 @@ struct Aggregator::AggregatorImpl { std::vector immediates; nodes.reserve(80); - non_path_nodes.reserve(20); immediates.reserve(key_attrs.size()); for (const Entry& e : rec) { @@ -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); } diff --git a/src/reader/CaliperMetadataDB.cpp b/src/reader/CaliperMetadataDB.cpp index f64e46e2..da4dfe69 100644 --- a/src/reader/CaliperMetadataDB.cpp +++ b/src/reader/CaliperMetadataDB.cpp @@ -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) diff --git a/src/services/aggregate/Aggregate.cpp b/src/services/aggregate/Aggregate.cpp index 40c71a0d..7cdad742 100644 --- a/src/services/aggregate/Aggregate.cpp +++ b/src/services/aggregate/Aggregate.cpp @@ -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(c->get(m_tdb_attr).value().get_ptr()); + ThreadDB* tdb = static_cast(c->get_blackboard_entry(m_tdb_attr).value().get_ptr()); if (!tdb && can_alloc) { tdb = new ThreadDB(c); diff --git a/src/services/ompt/OmptService.cpp b/src/services/ompt/OmptService.cpp index 09c56a51..49178a13 100644 --- a/src/services/ompt/OmptService.cpp +++ b/src/services/ompt/OmptService.cpp @@ -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); } diff --git a/src/services/timer/Timer.cpp b/src/services/timer/Timer.cpp index cff37850..5ec14220 100644 --- a/src/services/timer/Timer.cpp +++ b/src/services/timer/Timer.cpp @@ -63,7 +63,7 @@ class TimerService TimerInfo* acquire_timerinfo(Caliper* c) { - TimerInfo* ti = static_cast(c->get(timerinfo_attr).value().get_ptr()); + TimerInfo* ti = static_cast(c->get_blackboard_entry(timerinfo_attr).value().get_ptr()); if (!ti && !c->is_signal()) { ti = new TimerInfo; diff --git a/src/services/trace/Trace.cpp b/src/services/trace/Trace.cpp index 8f68c00a..e3ac45e0 100644 --- a/src/services/trace/Trace.cpp +++ b/src/services/trace/Trace.cpp @@ -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(c->get(tbuf_attr).value().get_ptr()); + TraceBuffer* tbuf = static_cast(c->get_blackboard_entry(tbuf_attr).value().get_ptr()); if (!tbuf && can_alloc) { tbuf = new TraceBuffer(buffersize); diff --git a/src/tools/cali-query/AttributeExtract.cpp b/src/tools/cali-query/AttributeExtract.cpp index cc15b762..11e362ff 100644 --- a/src/tools/cali-query/AttributeExtract.cpp +++ b/src/tools/cali-query/AttributeExtract.cpp @@ -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()));