Skip to content

Commit 2595288

Browse files
authored
Implement annotation levels (#540)
* Implement annotation levels * Add branch filter * Update documentation
1 parent f92cceb commit 2595288

20 files changed

+264
-39
lines changed

doc/sphinx/RegionFiltering.rst

+19-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ include_regions
1111
exclude_regions
1212
Skip measurements for regions with the given pattern.
1313

14+
include_branches
15+
Only take measurements for regions inside a given branch.
16+
1417
The options take a list of region patterns. There are three pattern types:
1518

1619
match
@@ -67,11 +70,26 @@ region - `mainloop` in this case - which is why we still see measurement values
6770
for the `mainloop` region here. However, these do not represent the actual time
6871
spent in `mainloop`.
6972

73+
With the `include_branches` option, we can limit measurements to a specific
74+
branch and its sub-regions, e.g. the `mainloop` branch::
75+
76+
$ CALI_CONFIG="runtime-report,include_branches=mainloop" ./examples/apps/cxx-example
77+
Path Min time/rank Max time/rank Avg time/rank Time %
78+
main 0.000457 0.000457 0.000457 37.527884
79+
mainloop 0.000108 0.000108 0.000108 8.882529
80+
foo 0.000653 0.000653 0.000653 53.589588
81+
82+
This limits measurement to the `mainloop` region and all its sub-regions.
83+
Again, measurement values taken when entering the `mainloop` region are
84+
assigned to its enclosing region (`main` in this case), but don't necessarily
85+
reflect the actual time spent there.
86+
7087
We can use a pattern like `startswith(main)` to include `main` and `mainloop`.
71-
Be careful to wrap the option values in quotes to prevent them from being
88+
Be careful to wrap the option values in quotes to prevent them from being
7289
misinterpreted by the config parser::
7390

7491
$ CALI_CONFIG="runtime-report,include_regions=\"startswith(main)\"" ./examples/apps/cxx-example
7592
Path Min time/rank Max time/rank Avg time/rank Time %
7693
main 0.000112 0.000112 0.000112 5.177994
7794
mainloop 0.000773 0.000773 0.000773 35.737402
95+

include/caliper/cali.h

+17
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,23 @@ cali_begin_region(const char* name);
373373
void
374374
cali_end_region(const char* name);
375375

376+
/**
377+
* \brief Begin phase region \a name
378+
*
379+
* A phase marks high-level, long(er)-running code regions. While regular
380+
* regions use the "region" attribute with annotation level 0, phase regions
381+
* use the "phase" attribute with annotation level 4. Otherwise phases behave
382+
* identical to regular Caliper regions.
383+
*/
384+
void
385+
cali_begin_phase(const char* name);
386+
387+
/**
388+
* \brief End phase region \a name
389+
*/
390+
void
391+
cali_end_phase(const char* name);
392+
376393
/**
377394
* \brief Begin region where the value for \a attr is `true` on the blackboard.
378395
*/

include/caliper/cali_macros.h

+12
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ extern cali_id_t cali_annotation_attr_id;
203203
#define CALI_MARK_END(name) \
204204
cali_end_region(name)
205205

206+
/// \brief Mark begin of a phase region
207+
///
208+
/// A phase marks high-level, long(er)-running code regions. While regular
209+
/// regions use the "region" attribute with annotation level 0, phase regions
210+
/// use the "phase" attribute with annotation level 4. Otherwise phases behave
211+
/// identical to regular Caliper regions.
212+
#define CALI_MARK_PHASE_BEGIN(name) \
213+
cali_begin_phase(name)
214+
215+
/// \brief Mark end of a phase region
216+
#define CALI_MARK_PHASE_END(name) \
217+
cali_end_phase(name)
206218
/**
207219
* \} (group)
208220
*/

include/caliper/common/Attribute.h

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class Attribute
7878
bool is_global() const {
7979
return properties() & CALI_ATTR_GLOBAL;
8080
}
81+
int level() const {
82+
return (properties() & CALI_ATTR_LEVEL_MASK) >> 16;
83+
}
8184

8285
static Attribute make_attribute(Node* node);
8386

include/caliper/common/cali_types.h

+24-1
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,33 @@ typedef enum {
123123
* \a aggregate service. This flag replaces the previous
124124
* \a class.aggregatable meta-attribute.
125125
*/
126-
CALI_ATTR_AGGREGATABLE = 2048
126+
CALI_ATTR_AGGREGATABLE = 2048,
127+
128+
/**
129+
* \brief Annotation level 1
130+
*
131+
* Annotation levels can be used to describe and set the granularity of
132+
* region annotations. Level 0 is the finest level, level 7 is the
133+
* coarsest.
134+
*/
135+
CALI_ATTR_LEVEL_1 = 0x10000,
136+
/** \brief Annotation level 2 */
137+
CALI_ATTR_LEVEL_2 = 0x20000,
138+
/** \brief Annotation level 3 */
139+
CALI_ATTR_LEVEL_3 = 0x30000,
140+
/** \brief Annotation level 4 */
141+
CALI_ATTR_LEVEL_4 = 0x40000,
142+
/** \brief Annotation level 5 */
143+
CALI_ATTR_LEVEL_5 = 0x50000,
144+
/** \brief Annotation level 6 */
145+
CALI_ATTR_LEVEL_6 = 0x60000,
146+
/** \brief Annotation level 7 */
147+
CALI_ATTR_LEVEL_7 = 0x70000
127148
} cali_attr_properties;
128149

150+
#define CALI_ATTR_LEVEL_0 0x0
129151
#define CALI_ATTR_SCOPE_MASK 60
152+
#define CALI_ATTR_LEVEL_MASK 0x70000
130153

131154
/**
132155
* \brief Provides descriptive string of given attribute property flags, separated with ':'

src/caliper/api.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cali_id_t cali_subscription_event_attr_id = CALI_INV_ID;
1717

1818
cali_id_t cali_loop_attr_id = CALI_INV_ID;
1919
cali_id_t cali_region_attr_id = CALI_INV_ID;
20+
cali_id_t cali_phase_attr_id = CALI_INV_ID;
2021

2122
cali_id_t cali_alloc_fn_attr_id = CALI_INV_ID;
2223
cali_id_t cali_alloc_label_attr_id = CALI_INV_ID;
@@ -36,6 +37,7 @@ namespace cali
3637
Attribute subscription_event_attr;
3738

3839
Attribute region_attr;
40+
Attribute phase_attr;
3941
Attribute loop_attr;
4042

4143
void init_attribute_classes(Caliper* c) {
@@ -61,8 +63,11 @@ namespace cali
6163
c->create_attribute("loop", CALI_TYPE_STRING, CALI_ATTR_NESTED);
6264
region_attr =
6365
c->create_attribute("region", CALI_TYPE_STRING, CALI_ATTR_NESTED);
66+
phase_attr =
67+
c->create_attribute("phase", CALI_TYPE_STRING, CALI_ATTR_NESTED | CALI_ATTR_LEVEL_4);
6468

6569
cali_region_attr_id = region_attr.id();
70+
cali_phase_attr_id = phase_attr.id();
6671
cali_loop_attr_id = loop_attr.id();
6772
}
6873
}

src/caliper/cali.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace cali
3030
{
3131

3232
extern Attribute region_attr;
33+
extern Attribute phase_attr;
3334

3435
}
3536

@@ -385,9 +386,21 @@ void
385386
cali_end_region(const char* name)
386387
{
387388
Caliper c;
388-
Variant v_n(name);
389+
c.end_with_value_check(cali::region_attr, Variant(name));
390+
}
389391

390-
c.end_with_value_check(cali::region_attr, v_n);
392+
void
393+
cali_begin_phase(const char* name)
394+
{
395+
Caliper c;
396+
c.begin(cali::phase_attr, Variant(name));
397+
}
398+
399+
void
400+
cali_end_phase(const char* name)
401+
{
402+
Caliper c;
403+
c.end_with_value_check(cali::phase_attr, Variant(name));
391404
}
392405

393406
void

src/caliper/controllers/controllers.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ const char* builtin_option_specs = R"json(
263263
}
264264
]
265265
},
266+
{
267+
"name" : "level",
268+
"type" : "string",
269+
"description" : "Minimum region level that triggers snapshots",
270+
"category" : "event",
271+
"config" : { "CALI_EVENT_REGION_LEVEL": "{}" }
272+
},
273+
{
274+
"name" : "include_branches",
275+
"type" : "string",
276+
"description" : "Only take snapshots for branches with the given region names.",
277+
"category" : "event",
278+
"config" : { "CALI_EVENT_INCLUDE_BRANCHES": "{}" }
279+
},
266280
{
267281
"name" : "include_regions",
268282
"type" : "string",

src/caliper/test/test_attribute.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ TEST(AttributeAPITest, ValidAttribute) {
5757
std::vector<std::string> props;
5858
util::split(std::string(buf), ':', std::back_inserter(props));
5959

60-
std::vector<std::string> props_exp { "nested", "process_scope", "nomerge", "default" };
60+
std::vector<std::string> props_exp { "nested", "process_scope", "nomerge", "default", "level_0" };
6161

6262
for (auto s : props) {
6363
auto it = std::find(props_exp.begin(), props_exp.end(), s);

src/common/cali_types.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ cali_string2type(const char* str)
4545
}
4646

4747
static const struct propmap_t {
48-
const char* str; cali_attr_properties prop; int mask;
48+
const char* str; int prop; int mask;
4949
} propmap[] = {
5050
{ "default", CALI_ATTR_DEFAULT, CALI_ATTR_DEFAULT },
5151
{ "asvalue", CALI_ATTR_ASVALUE, CALI_ATTR_ASVALUE },
@@ -59,6 +59,14 @@ static const struct propmap_t {
5959
{ "global", CALI_ATTR_GLOBAL, CALI_ATTR_GLOBAL },
6060
{ "unaligned", CALI_ATTR_UNALIGNED, CALI_ATTR_UNALIGNED },
6161
{ "aggregatable", CALI_ATTR_AGGREGATABLE, CALI_ATTR_AGGREGATABLE },
62+
{ "level_0", CALI_ATTR_LEVEL_0, CALI_ATTR_LEVEL_MASK },
63+
{ "level_1", CALI_ATTR_LEVEL_1, CALI_ATTR_LEVEL_MASK },
64+
{ "level_2", CALI_ATTR_LEVEL_2, CALI_ATTR_LEVEL_MASK },
65+
{ "level_3", CALI_ATTR_LEVEL_3, CALI_ATTR_LEVEL_MASK },
66+
{ "level_4", CALI_ATTR_LEVEL_4, CALI_ATTR_LEVEL_MASK },
67+
{ "level_5", CALI_ATTR_LEVEL_5, CALI_ATTR_LEVEL_MASK },
68+
{ "level_6", CALI_ATTR_LEVEL_6, CALI_ATTR_LEVEL_MASK },
69+
{ "level_7", CALI_ATTR_LEVEL_7, CALI_ATTR_LEVEL_MASK },
6270
{ 0, CALI_ATTR_DEFAULT, CALI_ATTR_DEFAULT }
6371
};
6472

0 commit comments

Comments
 (0)