Skip to content

Commit d4bcd89

Browse files
authored
Simplify handling of path attributes (LLNL#458)
* Merge function/annotation/statement attributes * Add CalQL path keyword to query spec * Replace use of prop:nested with path everywhere * Update documentation
1 parent 7cb1079 commit d4bcd89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+490
-568
lines changed

doc/sphinx/calql.rst

+11-5
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ This table contains a quick reference of all CalQL statements:
2828
<a>=scale(<b>,<S>) # computes <a> = <b>*S
2929
<a>=truncate(<b>,<S>) # computes <a> = <b> - mod(<b>, S)
3030
<a>=first(<a0>,<a1>, ...) # <a> is the first of <a0>, <a1>, ... found in the input record
31+
<a>=sum(<a0>,<a1>,...) # computes sum of <a0>, <a1>, ... in the input record
3132
... IF <condition> # apply only if input record meets condition
3233

3334
SELECT <list> # Select attributes and define aggregations (i.e., select columns)
3435
* # select all attributes
36+
path # select the nested region hierarchy
3537
<attribute> # select <attribute>
3638
count() # number of input records in grouping
3739
sum(<attribute>) # compute sum of <attribute> for grouping
@@ -45,12 +47,16 @@ This table contains a quick reference of all CalQL statements:
4547
inclusive_scale(<a>,<S>) # computes inclusive scaled sum of <a> in a nested hierarchy
4648
inclusive_percent_total(<a>) # computes inclusive percent-of-total of <a> in a nested hierarchy
4749
any(<attribute>) # pick one value for <attribute> out of all records in grouping
50+
scale_count(<S>) # count number of input records for grouping and multiplied by <S>
51+
inclusive_ratio(<a>,<b>,<S>) # computes inclusive_sum(<a>)/inclusive_sum(<b>)*<S>
52+
inclusive_min(<a>) # compute inclusive min of <a>
53+
inclusive_max(<a>) # compute inclusive max of <a>
4854
... AS <name> # use <name> as column header in tree or table formatter
4955
... UNIT <unit> # use <unit> as unit name
5056

5157
GROUP BY <list> # Define aggregation grouping (what to aggregate over, e.g. "function,mpi.rank")
5258
<attribute> # include <attribute> in grouping
53-
prop:nested # include default annotation attributes ('function', 'annotation', ...) in grouping
59+
path # include the nested region hierarchy in grouping
5460

5561
WHERE <list> # define filter (i.e., select records/rows)
5662
<attribute> # records where <attribute> exists
@@ -86,7 +92,7 @@ subsequent aggregations::
8692
LET
8793
sec=scale(time.duration,1e-6)
8894
SELECT
89-
prop:nested,sum(sec)
95+
path,sum(sec)
9096

9197
We can use the truncate() operator on an iteration counter to
9298
aggregate blocks of 10 iterations in a time-series profile::
@@ -106,7 +112,7 @@ names found in an input record. It can also be used to rename attributes::
106112
SELECT
107113
sum(time) AS Time
108114
GROUP BY
109-
prop:nested
115+
path
110116

111117
LET terms have the general form
112118

@@ -131,7 +137,7 @@ efficiency from the total and "work" time:
131137
sum(work) AS Work,
132138
ratio(work,time.duration) AS Efficiency
133139
GROUP BY
134-
prop:nested
140+
path
135141

136142
SELECT
137143
--------------------------------
@@ -175,7 +181,7 @@ A more complex example::
175181
scale(time.duration,1e-6) AS Time,
176182
inclusive_percent_total(time.duration) AS "Time %"
177183
GROUP BY
178-
prop:nested
184+
path
179185
FORMAT
180186
tree
181187

include/caliper/cali.h

-13
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,6 @@ cali_begin_string(cali_id_t attr, const char* val);
384384
void
385385
cali_end (cali_id_t attr);
386386

387-
/**
388-
* \brief Remove innermost value for attribute \a attr from the blackboard.
389-
*
390-
* Creates a mismatch warning if the current value does not match \a val.
391-
* This function is primarily used by the high-level annotation API.
392-
*
393-
* \param attr Attribute ID
394-
* \param val Expected value
395-
*/
396-
397-
void
398-
cali_safe_end_string(cali_id_t attr, const char* val);
399-
400387
/**
401388
* \brief Set value for attribute \a attr to \a val on the blackboard.
402389
*/

include/caliper/cali_macros.h

+5-11
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@
7070

7171
#endif // __cplusplus
7272

73-
extern cali_id_t cali_function_attr_id;
7473
extern cali_id_t cali_loop_attr_id;
75-
extern cali_id_t cali_statement_attr_id;
7674
extern cali_id_t cali_annotation_attr_id;
7775

7876
/// \brief Mark begin of a function.
@@ -83,17 +81,15 @@ extern cali_id_t cali_annotation_attr_id;
8381
/// \ref CALI_CXX_MARK_FUNCTION instead.
8482
/// \sa CALI_MARK_FUNCTION_END, CALI_CXX_MARK_FUNCTION
8583
#define CALI_MARK_FUNCTION_BEGIN \
86-
if (cali_function_attr_id == CALI_INV_ID) \
87-
cali_init(); \
88-
cali_begin_string(cali_function_attr_id, __func__)
84+
cali_begin_region(__func__)
8985

9086
/// \brief Mark end of a function.
9187
///
9288
/// Must be placed at \e all exit points of a function marked with
9389
/// \ref CALI_MARK_FUNCTION_BEGIN.
9490
/// \sa CALI_MARK_FUNCTION_BEGIN
9591
#define CALI_MARK_FUNCTION_END \
96-
cali_safe_end_string(cali_function_attr_id, __func__)
92+
cali_end_region(__func__)
9793

9894
/// \brief Mark a loop
9995
///
@@ -110,7 +106,7 @@ extern cali_id_t cali_annotation_attr_id;
110106
cali_init(); \
111107
cali_begin_string(cali_loop_attr_id, (name)); \
112108
cali_id_t __cali_iter_##loop_id = \
113-
cali_make_loop_iteration_attribute(name);
109+
cali_make_loop_iteration_attribute(name)
114110

115111
/// \brief Mark a loop
116112
///
@@ -175,11 +171,9 @@ extern cali_id_t cali_annotation_attr_id;
175171
/// \c break, or \c return).
176172
///
177173
#define CALI_WRAP_STATEMENT(name, statement) \
178-
if (cali_statement_attr_id == CALI_INV_ID) \
179-
cali_init(); \
180-
cali_begin_string(cali_statement_attr_id, (name)); \
174+
cali_begin_region((name)); \
181175
statement; \
182-
cali_end(cali_statement_attr_id);
176+
cali_end_region((name))
183177

184178
/// \brief Mark begin of a user-defined code region.
185179
///

include/caliper/reader/QuerySpec.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ struct QuerySpec
3333

3434
/// \brief User-defined list
3535
std::vector<T> list;
36+
37+
/// \brief Use path (main nested region hierarchy) attributes
38+
bool use_path;
3639
};
3740

3841
/// \brief Describe function signatures in query specs
@@ -124,12 +127,12 @@ struct QuerySpec
124127
typedef SelectionList<SortSpec> SortSelection;
125128

126129
/// \brief List of aggregations to be performed.
127-
AggregationSelection aggregation_ops;
130+
AggregationSelection aggregate;
128131
/// \brief List of attribute names that form the aggregation key (i.e., GROUP BY spec).
129-
AttributeSelection aggregation_key;
132+
AttributeSelection groupby;
130133

131134
/// \brief List of attributes to print in output
132-
AttributeSelection attribute_selection;
135+
AttributeSelection select;
133136

134137
/// \brief List of filter clauses (filters will be combined with AND)
135138
FilterSelection filter;

src/caliper/Annotation.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,33 @@ namespace cali
2222
{
2323

2424
extern Attribute class_iteration_attr;
25-
extern Attribute function_attr;
2625
extern Attribute loop_attr;
27-
extern Attribute annotation_attr;
26+
extern Attribute region_attr;
2827

2928
}
3029

3130
// --- Pre-defined Function annotation class
3231

3332
Function::Function(const char* name)
3433
{
35-
Caliper().begin(function_attr, Variant(name));
34+
Caliper().begin(region_attr, Variant(name));
3635
}
3736

3837
Function::~Function()
3938
{
40-
Caliper().end(function_attr);
39+
Caliper().end(region_attr);
4140
}
4241

4342
// --- Pre-defined scope annotation class
4443

4544
ScopeAnnotation::ScopeAnnotation(const char* name)
4645
{
47-
Caliper().begin(annotation_attr, Variant(name));
46+
Caliper().begin(region_attr, Variant(name));
4847
}
4948

5049
ScopeAnnotation::~ScopeAnnotation()
5150
{
52-
Caliper().end(annotation_attr);
51+
Caliper().end(region_attr);
5352
}
5453

5554
// --- Pre-defined loop annotation class

src/caliper/api.cpp

+24-66
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ cali_id_t cali_class_memoryaddress_attr_id = CALI_INV_ID;
1515
cali_id_t cali_class_iteration_attr_id = CALI_INV_ID;
1616
cali_id_t cali_subscription_event_attr_id = CALI_INV_ID;
1717

18-
cali_id_t cali_function_attr_id = CALI_INV_ID;
19-
cali_id_t cali_loop_attr_id = CALI_INV_ID;
20-
cali_id_t cali_statement_attr_id = CALI_INV_ID;
21-
cali_id_t cali_annotation_attr_id = CALI_INV_ID;
18+
cali_id_t cali_loop_attr_id = CALI_INV_ID;
19+
cali_id_t cali_region_attr_id = CALI_INV_ID;
2220

2321
cali_id_t cali_alloc_fn_attr_id = CALI_INV_ID;
2422
cali_id_t cali_alloc_label_attr_id = CALI_INV_ID;
@@ -36,75 +34,35 @@ namespace cali
3634
Attribute class_memoryaddress_attr;
3735
Attribute class_iteration_attr;
3836
Attribute subscription_event_attr;
39-
40-
Attribute function_attr;
37+
38+
Attribute region_attr;
4139
Attribute loop_attr;
42-
Attribute statement_attr;
43-
Attribute annotation_attr;
4440

4541
void init_attribute_classes(Caliper* c) {
46-
struct attr_info_t {
47-
const char* name;
48-
cali_attr_type type;
49-
int prop;
50-
Attribute* attr;
51-
cali_id_t* attr_id;
52-
} attr_info[] = {
53-
{ "class.aggregatable", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS,
54-
&class_aggregatable_attr, &cali_class_aggregatable_attr_id
55-
},
56-
{ "class.symboladdress", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS,
57-
&class_symboladdress_attr, &cali_class_symboladdress_attr_id
58-
},
59-
{ "class.memoryaddress", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS,
60-
&class_memoryaddress_attr, &cali_class_memoryaddress_attr_id
61-
},
62-
{ "class.iteration", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS,
63-
&class_iteration_attr, &cali_class_iteration_attr_id
64-
},
65-
{ "subscription_event", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS,
66-
&subscription_event_attr, &cali_subscription_event_attr_id
67-
},
68-
{ 0, CALI_TYPE_INV, CALI_ATTR_DEFAULT, 0, 0 }
69-
};
42+
class_aggregatable_attr =
43+
c->create_attribute("class.aggregatable", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS);
44+
class_symboladdress_attr =
45+
c->create_attribute("class.symboladdress", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS);
46+
class_memoryaddress_attr =
47+
c->create_attribute("class.memoryaddress", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS);
48+
class_iteration_attr =
49+
c->create_attribute("class.iteration", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS);
50+
subscription_event_attr =
51+
c->create_attribute("subscription_event", CALI_TYPE_BOOL, CALI_ATTR_SKIP_EVENTS);
7052

71-
for (attr_info_t *p = attr_info; p->name; ++p) {
72-
*(p->attr) =
73-
c->create_attribute(p->name, p->type, p->prop);
74-
*(p->attr_id) = (p->attr)->id();
75-
}
53+
cali_class_aggregatable_attr_id = class_aggregatable_attr.id();
54+
cali_class_symboladdress_attr_id = class_symboladdress_attr.id();
55+
cali_class_memoryaddress_attr_id = class_memoryaddress_attr.id();
56+
cali_class_iteration_attr_id = class_iteration_attr.id();
7657
}
7758

7859
void init_api_attributes(Caliper* c) {
79-
// --- code annotation attributes
80-
81-
struct attr_info_t {
82-
const char* name;
83-
cali_attr_type type;
84-
int prop;
85-
Attribute* attr;
86-
cali_id_t* attr_id;
87-
} attr_info[] = {
88-
{ "function", CALI_TYPE_STRING, CALI_ATTR_NESTED,
89-
&function_attr, &cali_function_attr_id
90-
},
91-
{ "loop", CALI_TYPE_STRING, CALI_ATTR_NESTED,
92-
&loop_attr, &cali_loop_attr_id
93-
},
94-
{ "statement", CALI_TYPE_STRING, CALI_ATTR_NESTED,
95-
&statement_attr, &cali_statement_attr_id
96-
},
97-
{ "annotation", CALI_TYPE_STRING, CALI_ATTR_NESTED,
98-
&annotation_attr, &cali_annotation_attr_id
99-
},
100-
{ 0, CALI_TYPE_INV, CALI_ATTR_DEFAULT, 0, 0 }
101-
};
60+
loop_attr =
61+
c->create_attribute("loop", CALI_TYPE_STRING, CALI_ATTR_NESTED);
62+
region_attr =
63+
c->create_attribute("region", CALI_TYPE_STRING, CALI_ATTR_NESTED);
10264

103-
Variant v_true(true);
104-
105-
for (attr_info_t *p = attr_info; p->name; ++p) {
106-
*(p->attr) = c->create_attribute(p->name, p->type, p->prop);
107-
*(p->attr_id) = (p->attr)->id();
108-
}
65+
cali_region_attr_id = region_attr.id();
66+
cali_loop_attr_id = loop_attr.id();
10967
}
11068
}

src/caliper/cali.cpp

+4-26
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
namespace cali
3030
{
3131

32-
extern Attribute annotation_attr;
32+
extern Attribute region_attr;
3333

3434
}
3535

@@ -362,22 +362,22 @@ void
362362
cali_begin_region(const char* name)
363363
{
364364
Caliper c;
365-
c.begin(cali::annotation_attr, Variant(name));
365+
c.begin(cali::region_attr, Variant(name));
366366
}
367367

368368
void
369369
cali_end_region(const char* name)
370370
{
371371
Caliper c;
372372
Variant v_n(name);
373-
Variant v_s = c.get(cali::annotation_attr).value();
373+
Variant v_s = c.get(cali::region_attr).value();
374374

375375
if (!(v_n == v_s))
376376
Log(0).stream() << "region nesting error: trying to end \"" << v_n
377377
<< "\" but current region is \"" << v_s << "\""
378378
<< std::endl;
379379

380-
c.end(cali::annotation_attr);
380+
c.end(cali::region_attr);
381381
}
382382

383383
void
@@ -461,28 +461,6 @@ cali_set_string(cali_id_t attr_id, const char* val)
461461
c.set(attr, Variant(CALI_TYPE_STRING, val, strlen(val)));
462462
}
463463

464-
void
465-
cali_safe_end_string(cali_id_t attr_id, const char* val)
466-
{
467-
Caliper c;
468-
Attribute attr = c.get_attribute(attr_id);
469-
Variant v = c.get(attr).value();
470-
471-
if (v.type() != CALI_TYPE_STRING)
472-
Log(1).stream() << ": Trying to end "
473-
<< attr.name() << " which is not a string" << std::endl;
474-
475-
if (0 != strncmp(static_cast<const char*>(v.data()), val, v.size()))
476-
// FIXME: Replace log output with smart error tracker
477-
Log(1).stream() << "begin/end marker mismatch: Trying to end "
478-
<< attr.name() << "=" << val
479-
<< " but current value for "
480-
<< attr.name() << " is \"" << v.to_string() << "\""
481-
<< std::endl;
482-
483-
c.end(attr);
484-
}
485-
486464
//
487465
// --- By-name annotation interface
488466
//

src/caliper/controllers/HatchetRegionProfileController.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class HatchetRegionProfileController : public cali::ChannelController
6262
config()["CALI_MPIREPORT_CONFIG" ] =
6363
opts.build_query("local", {
6464
{ "select", "*,sum(sum#time.duration) as time unit sec" },
65-
{ "group by", "prop:nested,mpi.rank" },
65+
{ "group by", "path,mpi.rank" },
6666
{ "format", format }
6767
});
6868
} else {
@@ -71,7 +71,7 @@ class HatchetRegionProfileController : public cali::ChannelController
7171
config()["CALI_REPORT_CONFIG" ] =
7272
opts.build_query("local", {
7373
{ "select", "*,sum(sum#time.duration) as time unit sec" },
74-
{ "group by", "prop:nested" },
74+
{ "group by", "path" },
7575
{ "format", format }
7676
});
7777
}

0 commit comments

Comments
 (0)