Skip to content

Commit 7ffe041

Browse files
authored
More optimizations (LLNL#484)
* Remove unused post_end and post_set callbacks * Use RegionFilter in AnnotationBinding * Make filter conditional in AnnotationBinding.cpp * Remove scope flag for snapshots * Simplify attribute check * Don't require c++14 * Fix compilation w/ Lassen XL compilers
1 parent 64c5fa8 commit 7ffe041

37 files changed

+183
-535
lines changed

include/caliper/AnnotationBinding.h

+13-14
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
#include "caliper/common/RuntimeConfig.h"
1616

1717
#include <iostream>
18+
#include <memory>
1819
#include <vector>
1920

20-
namespace cali
21+
namespace cali
2122
{
2223

23-
class Filter;
24+
class RegionFilter;
2425
class Node;
2526

2627
/// \brief Base class for bindings to third-party annotation APIs
@@ -46,15 +47,15 @@ class Node;
4647
/// class MyBinding : public cali::AnnotationBinding {
4748
/// public:
4849
///
49-
/// const char* service_tag() const {
50-
/// return "mybinding";
50+
/// const char* service_tag() const {
51+
/// return "mybinding";
5152
/// }
5253
///
5354
/// void on_begin(cali::Caliper* c, cali::Channel*, const cali::Attribute& attr, const cali::Variant& value) {
5455
/// std::string str = attr.name();
5556
/// str.append("=");
5657
/// str.append(value.to_string()); // create "<attribute name>=<value>" string
57-
///
58+
///
5859
/// mybegin(str.c_str());
5960
/// }
6061
///
@@ -69,12 +70,13 @@ class Node;
6970
/// Also see the \a nvprof and \a vtune service implementations for examples of
7071
/// using AnnotationBinding in a %Caliper service.
7172

72-
class AnnotationBinding
73+
class AnnotationBinding
7374
{
7475
ConfigSet m_config;
75-
Filter* m_filter;
7676
Attribute m_marker_attr;
7777

78+
std::unique_ptr<RegionFilter> m_filter;
79+
7880
std::vector<std::string> m_trigger_attr_names;
7981

8082
static const ConfigSet::Entry s_configdata[];
@@ -88,7 +90,7 @@ class AnnotationBinding
8890
/// These callbacks are internal Caliper mechanisms
8991
/// not meant to be touched by the code of services
9092
/// implementing an AnnotationBinding.
91-
///
93+
///
9294
/// User code should instead use on_mark_attribute(),
9395
/// on_begin(), and on_end().
9496

@@ -115,13 +117,13 @@ class AnnotationBinding
115117
/// \brief Callback for an annotation begin event
116118
/// \param c Caliper instance
117119
/// \param attr Attribute on which the %Caliper begin event was invoked.
118-
/// \param value The annotation name/value.
120+
/// \param value The annotation name/value.
119121
virtual void on_begin(Caliper* c, Channel* chn, const Attribute& attr, const Variant& value) { }
120122

121123
/// \brief Callback for an annotation end event
122124
/// \param c Caliper instance
123125
/// \param attr Attribute on which the %Caliper end event was invoked.
124-
/// \param value The annotation name/value.
126+
/// \param value The annotation name/value.
125127
virtual void on_end(Caliper* c, Channel* chn, const Attribute& attr, const Variant& value) { }
126128

127129
/// \brief Initialization callback. Invoked after the %Caliper
@@ -134,10 +136,7 @@ class AnnotationBinding
134136
public:
135137

136138
/// \brief Constructor. Usually invoked through \a make_binding().
137-
AnnotationBinding()
138-
: m_filter(nullptr),
139-
m_marker_attr(Attribute::invalid)
140-
{ }
139+
AnnotationBinding();
141140

142141
virtual ~AnnotationBinding();
143142

include/caliper/Caliper.h

+3-16
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Channel
6060
typedef util::callback<void(Caliper*,Channel*)>
6161
caliper_cbvec;
6262

63-
typedef util::callback<void(Caliper*,Channel*,int,SnapshotView,SnapshotBuilder&)>
63+
typedef util::callback<void(Caliper*,Channel*,SnapshotView,SnapshotBuilder&)>
6464
snapshot_cbvec;
6565
typedef util::callback<void(Caliper*,Channel*,SnapshotView,SnapshotView)>
6666
process_snapshot_cbvec;
@@ -87,12 +87,8 @@ class Channel
8787
update_cbvec post_begin_evt;
8888
/// \brief Invoked when value is set, \e before it has been put on the blackboard.
8989
update_cbvec pre_set_evt;
90-
/// \brief Invoked when value is set, \e after it has been put on the blackboard.
91-
update_cbvec post_set_evt;
9290
/// \brief Invoked on region end, \e before it has been removed from the blackboard.
9391
update_cbvec pre_end_evt;
94-
/// \brief Invoked on region end, \e after it has been removed from the blackboard.
95-
update_cbvec post_end_evt;
9692

9793
/// \brief Invoked when a new thread context is being created.
9894
caliper_cbvec create_thread_evt;
@@ -335,14 +331,8 @@ class Caliper : public CaliperMetadataAccessInterface
335331
///
336332
/// This function is signal safe.
337333
///
338-
/// \param channel The %Caliper channel to fetch the context from.
339-
/// \param scopes Defines which blackboard contents (thread, process,
340-
/// channel) are returned. Bitwise combination of cali_context_scope_t
341-
/// flags.
342-
/// \param trigger_info A caller-provided record that is passed to the
343-
/// snapshot callback, and added to the returned snapshot record.
344334
/// \param rec The snapshot record buffer to update.
345-
void pull_context(Channel* channel, int scopes, SnapshotBuilder& rec);
335+
void pull_context(SnapshotBuilder& rec);
346336

347337
/// \brief Trigger and return a snapshot.
348338
///
@@ -362,13 +352,10 @@ class Caliper : public CaliperMetadataAccessInterface
362352
/// This function is signal safe.
363353
///
364354
/// \param channel The %Caliper channel to fetch the snapshot from.
365-
/// \param scopes Defines which blackboard contents (thread, process,
366-
/// channel) are returned. Bitwise combination of cali_context_scope_t
367-
/// flags.
368355
/// \param trigger_info A caller-provided record that is passed to the
369356
/// snapshot callback, and added to the returned snapshot record.
370357
/// \param rec The snapshot record buffer to update.
371-
void pull_snapshot(Channel* channel, int scopes, SnapshotView trigger_info, SnapshotBuilder& rec);
358+
void pull_snapshot(Channel* channel, SnapshotView trigger_info, SnapshotBuilder& rec);
372359

373360
// --- Flush and I/O API
374361

include/caliper/cali.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ cali_attribute_properties(cali_id_t attr_id);
145145
* probably use a dedicated channel to do so.
146146
*
147147
* \param scope Indicates which scopes (process, thread, or task) the
148-
* snapshot should span
148+
* snapshot should span (deprecated, unused)
149149
* \param n Number of event info entries
150150
* \param trigger_info_attr_list Attribute IDs of event info entries
151151
* \param trigger_info_val_list Values of event info entries
@@ -164,7 +164,7 @@ cali_push_snapshot(int scope, int n,
164164
*
165165
* \param chn_id Channel to take snapshot on
166166
* \param scope Indicates which scopes (process, thread, or task) the
167-
* snapshot should span
167+
* snapshot should span (deprecated, unused)
168168
* \param n Number of event info entries
169169
* \param trigger_info_attr_list Attribute IDs of event info entries
170170
* \param trigger_info_val_list Values of event info entries
@@ -191,7 +191,7 @@ cali_channel_push_snapshot(cali_id_t chn_id,
191191
*
192192
* \param chn_id Channel to take the snapshot on
193193
* \param scope Indicates which scopes (process, thread, or task) the
194-
* snapshot should span
194+
* snapshot should span (deprecated)
195195
* \param len Length of the provided snapshot buffer.
196196
* \param buf User-provided snapshot storage buffer.
197197
* \return Actual size of the snapshot representation.

include/caliper/common/filters/DefaultFilter.h

-15
This file was deleted.

include/caliper/common/filters/Filter.h

-19
This file was deleted.

include/caliper/common/filters/RegexFilter.h

-41
This file was deleted.

src/caliper/Annotation.cpp

+14-13
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Loop::end()
120120
// --- Annotation implementation object
121121

122122
struct Annotation::Impl {
123-
std::atomic<Attribute> m_attr;
123+
std::atomic<cali::Node*> m_attr_node;
124124

125125
std::string m_name;
126126
std::vector<Attribute> m_metadata_keys;
@@ -130,26 +130,26 @@ struct Annotation::Impl {
130130
std::atomic<int> m_refcount;
131131

132132
Impl(const std::string& name, MetadataListType metadata, int opt)
133-
: m_attr(Attribute::invalid),
133+
: m_attr_node(nullptr),
134134
m_name(name),
135135
m_opt(opt),
136136
m_refcount(1)
137137
{
138138
Caliper c;
139139
Attribute attr = c.get_attribute(name);
140140

141-
if (attr == Attribute::invalid) {
141+
if (!attr) {
142142
for(auto kv : metadata) {
143143
m_metadata_keys.push_back(c.create_attribute(kv.first,kv.second.type(),0));
144144
m_metadata_values.push_back(kv.second);
145145
}
146146
} else {
147-
m_attr.store(attr);
147+
m_attr_node.store(attr.node());
148148
}
149149
}
150150

151151
Impl(const std::string& name, int opt)
152-
: m_attr(Attribute::invalid),
152+
: m_attr_node(nullptr),
153153
m_name(name),
154154
m_opt(opt),
155155
m_refcount(1)
@@ -176,26 +176,27 @@ struct Annotation::Impl {
176176

177177
void end() {
178178
Caliper c;
179-
Attribute attr = m_attr.load();
179+
Attribute attr = Attribute::make_attribute(m_attr_node.load());
180180

181181
if (attr)
182182
c.end(attr);
183183
}
184184

185185
Attribute get_attribute(Caliper& c, cali_attr_type type) {
186-
Attribute attr = m_attr.load();
186+
cali::Node* attr_node = m_attr_node.load();
187187

188-
if (!attr) {
189-
attr =
188+
if (!attr_node) {
189+
Attribute attr =
190190
c.create_attribute(m_name, type, m_opt,
191191
m_metadata_keys.size(),
192192
m_metadata_keys.data(),
193193
m_metadata_values.data());
194194

195-
m_attr.store(attr);
195+
attr_node = attr.node();
196+
m_attr_node.store(attr_node);
196197
}
197198

198-
return attr;
199+
return Attribute::make_attribute(attr_node);
199200
}
200201

201202
Impl* attach() {
@@ -263,7 +264,7 @@ Annotation& Annotation::begin()
263264

264265
Annotation& Annotation::begin(int data)
265266
{
266-
Attribute attr = pI->m_attr.load();
267+
Attribute attr = Attribute::make_attribute(pI->m_attr_node.load());
267268

268269
// special case: allow assignment of int values to 'double' or 'uint' attributes
269270
if (attr && attr.type() == CALI_TYPE_DOUBLE)
@@ -289,7 +290,7 @@ Annotation& Annotation::begin(const Variant& data)
289290

290291
Annotation& Annotation::set(int data)
291292
{
292-
Attribute attr = pI->m_attr.load();
293+
Attribute attr = Attribute::make_attribute(pI->m_attr_node.load());
293294

294295
// special case: allow assignment of int values to 'double' or 'uint' attributes
295296
if (attr && attr.type() == CALI_TYPE_DOUBLE)

0 commit comments

Comments
 (0)