Skip to content

Commit 43be908

Browse files
authored
Use JSON specs to describe services (LLNL#436)
* Start simplifying RuntimeConfig * Implement service JSON specs * Move more services to new spec format * Small fixes * Convert CUDA services to new JSON spec * Convert roctracer service to JSON spec * Rename timestamp -> timer * Use new JSON spec in mpi service
1 parent 20db155 commit 43be908

38 files changed

+806
-555
lines changed

include/caliper/CaliperService.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ typedef void (*ServiceRegisterFn)(Caliper* c, Channel* chn);
1919
/// To register services, provide a list of CaliperService entries
2020
/// to Caliper::add_services() _before_ %Caliper is initialized.
2121
struct CaliperService {
22-
const char* name; ///< Service name (short, no spaces).
23-
ServiceRegisterFn register_fn; ///< Registration function.
22+
/// \brief Name (old style) or JSON spec (new) of the service
23+
const char* name_or_spec;
24+
/// \brief Registration function
25+
ServiceRegisterFn register_fn;
2426
};
2527

2628
} // namespace cali

include/caliper/common/RuntimeConfig.h

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace cali
2020

2121
struct ConfigSetImpl;
2222

23-
class ConfigSet
23+
class ConfigSet
2424
{
2525
std::shared_ptr<ConfigSetImpl> mP;
2626

@@ -52,17 +52,22 @@ class RuntimeConfig
5252
struct RuntimeConfigImpl;
5353

5454
std::shared_ptr<RuntimeConfigImpl> mP;
55-
55+
5656
public:
5757

58+
typedef std::vector< std::pair<std::string, std::string > > config_entry_list_t;
59+
5860
RuntimeConfig();
5961

6062
/// \brief Get config entry with given \a key from given \a set
6163
StringConverter get(const char* set, const char* key);
6264

63-
/// \brief Initialize a ConfigSet.
65+
/// \brief Initialize a ConfigSet from ConfigSet::Entry list (old method)
6466
ConfigSet init(const char* name, const ConfigSet::Entry* set);
6567

68+
/// \brief Initialize a ConfigSet
69+
ConfigSet init(const char* name, const config_entry_list_t&);
70+
6671
/// \brief Pre-set config entry \a key to \a value.
6772
///
6873
/// The value may be overwritten by configuration files or environment
@@ -77,7 +82,7 @@ class RuntimeConfig
7782

7883
/// \brief Import config values from the given the \a values map
7984
void import(const std::map<std::string, std::string>& values);
80-
85+
8186
bool allow_read_env();
8287

8388
/// \brief Enable or disable reading of configuration settings
@@ -103,7 +108,7 @@ class RuntimeConfig
103108
// --- Static API (temporary)
104109
//
105110

106-
static RuntimeConfig get_default_config();
111+
static RuntimeConfig get_default_config();
107112

108113
}; // class RuntimeConfig
109114

src/caliper/controllers/HatchetRegionProfileController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const char* controller_spec =
116116
" \"name\" : \"hatchet-region-profile\","
117117
" \"description\" : \"Record a region time profile for processing with hatchet\","
118118
" \"categories\" : [ \"adiak\", \"metric\", \"output\", \"region\", \"event\" ],"
119-
" \"services\" : [ \"aggregate\", \"event\", \"timestamp\" ],"
119+
" \"services\" : [ \"aggregate\", \"event\", \"timer\" ],"
120120
" \"config\" : "
121121
" { \"CALI_CHANNEL_FLUSH_ON_EXIT\" : \"false\","
122122
" \"CALI_EVENT_ENABLE_SNAPSHOT_INFO\" : \"false\","

src/caliper/controllers/LoopReportController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ const char* loop_report_controller_spec =
278278
" \"name\" : \"loop-report\","
279279
" \"description\" : \"Print summary and time-series information for loops\","
280280
" \"categories\" : [ \"metric\", \"output\" ],"
281-
" \"services\" : [ \"loop_monitor\", \"timestamp\", \"trace\" ],"
281+
" \"services\" : [ \"loop_monitor\", \"timer\", \"trace\" ],"
282282
" \"config\" : "
283283
" { \"CALI_CHANNEL_FLUSH_ON_EXIT\" : \"false\","
284284
" \"CALI_CHANNEL_CONFIG_CHECK\" : \"false\","

src/caliper/controllers/ROCmActivityProfileController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const char* controller_spec = R"json(
121121
"name" : "rocm-activity-profile",
122122
"description" : "Record AMD ROCm activities and a write profile",
123123
"categories" : [ "adiak", "metric", "output", "region", "event" ],
124-
"services" : [ "aggregate", "roctracer", "event", "timestamp" ],
124+
"services" : [ "aggregate", "roctracer", "event", "timer" ],
125125
"config" :
126126
{ "CALI_CHANNEL_FLUSH_ON_EXIT" : "false",
127127
"CALI_EVENT_ENABLE_SNAPSHOT_INFO" : "false",

src/caliper/controllers/ROCmActivityReportController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const char* controller_spec = R"json(
120120
"name" : "rocm-activity-report",
121121
"description" : "Record and print AMD ROCm activities (kernel executions, memcopies, etc.)",
122122
"categories" : [ "output", "region", "treeformatter", "event" ],
123-
"services" : [ "aggregate", "roctracer", "event", "timestamp" ],
123+
"services" : [ "aggregate", "roctracer", "event", "timer" ],
124124
"config" :
125125
{ "CALI_CHANNEL_FLUSH_ON_EXIT" : "false",
126126
"CALI_EVENT_ENABLE_SNAPSHOT_INFO" : "false",

src/caliper/controllers/RuntimeReportController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const char* runtime_report_spec =
119119
" \"name\" : \"runtime-report\","
120120
" \"description\" : \"Print a time profile for annotated regions\","
121121
" \"categories\" : [ \"metric\", \"output\", \"region\", \"treeformatter\", \"event\" ],"
122-
" \"services\" : [ \"aggregate\", \"event\", \"timestamp\" ],"
122+
" \"services\" : [ \"aggregate\", \"event\", \"timer\" ],"
123123
" \"config\" : "
124124
" { \"CALI_CHANNEL_FLUSH_ON_EXIT\" : \"false\","
125125
" \"CALI_EVENT_ENABLE_SNAPSHOT_INFO\" : \"false\","

src/caliper/controllers/SpotController.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ const char* spot_timeseries_spec =
214214
" \"name\" : \"spot.timeseries\","
215215
" \"description\" : \"Collect time-series information for loops\","
216216
" \"categories\" : [ \"metric\" ],"
217-
" \"services\" : [ \"loop_monitor\", \"timestamp\", \"trace\" ],"
217+
" \"services\" : [ \"loop_monitor\", \"timer\", \"trace\" ],"
218218
" \"config\" : "
219219
" { \"CALI_CHANNEL_FLUSH_ON_EXIT\" : \"false\","
220220
" \"CALI_CHANNEL_CONFIG_CHECK\" : \"false\","
@@ -545,7 +545,7 @@ const char* spot_controller_spec =
545545
" \"name\" : \"spot\","
546546
" \"description\" : \"Record a time profile for the Spot web visualization framework\","
547547
" \"categories\" : [ \"adiak\", \"metric\", \"output\", \"region\", \"event\" ],"
548-
" \"services\" : [ \"aggregate\", \"event\", \"timestamp\" ],"
548+
" \"services\" : [ \"aggregate\", \"event\", \"timer\" ],"
549549
" \"config\" : "
550550
" { \"CALI_CHANNEL_FLUSH_ON_EXIT\" : \"false\","
551551
" \"CALI_CHANNEL_CONFIG_CHECK\" : \"false\","

src/caliper/controllers/controllers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const char* event_trace_spec =
1212
"{"
1313
" \"name\" : \"event-trace\","
1414
" \"description\" : \"Record a trace of region enter/exit events in .cali format\","
15-
" \"services\" : [ \"event\", \"recorder\", \"timestamp\", \"trace\" ],"
15+
" \"services\" : [ \"event\", \"recorder\", \"timer\", \"trace\" ],"
1616
" \"categories\" : [ \"output\", \"event\" ],"
1717
" \"config\" : "
1818
" { \"CALI_CHANNEL_FLUSH_ON_EXIT\" : \"false\","
@@ -82,7 +82,7 @@ const char* roctx_spec =
8282
const char* mpireport_spec =
8383
"{"
8484
" \"name\" : \"mpi-report\","
85-
" \"services\" : [ \"aggregate\", \"event\", \"mpi\", \"mpireport\", \"timestamp\" ],"
85+
" \"services\" : [ \"aggregate\", \"event\", \"mpi\", \"mpireport\", \"timer\" ],"
8686
" \"description\" : \"Print time spent in MPI functions\","
8787
" \"categories\" : [ \"event\" ],"
8888
" \"config\" : "

src/common/RuntimeConfig.cpp

+34-38
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace
6464
// make uppercase PREFIX_NAMESPACE_KEY string
6565

6666
string str = string("CALI_") + name + string("_") + key;
67-
67+
6868
transform(str.begin(), str.end(), str.begin(), ::toupper);
6969

7070
return str;
@@ -84,46 +84,41 @@ struct ConfigSetImpl
8484
{
8585
// --- data
8686

87-
struct ConfigValue {
88-
ConfigSet::Entry entry;
89-
std::string value;
90-
};
91-
92-
unordered_map<string, ConfigValue> m_dict;
87+
std::unordered_map<string, StringConverter> m_dict;
9388

9489
// --- interface
9590

9691
StringConverter get(const char* key) const {
9792
auto it = m_dict.find(key);
98-
return (it == m_dict.end() ? StringConverter() : StringConverter(it->second.value));
93+
return (it == m_dict.end() ? StringConverter() : it->second);
9994
}
10095

101-
void init(const char* name, const ConfigSet::Entry* list, bool read_env, const ::config_profile_t& profile, const ::config_profile_t& top_profile)
96+
void init(const char* name, const RuntimeConfig::config_entry_list_t& list, bool read_env, const ::config_profile_t& profile, const ::config_profile_t& top_profile)
10297
{
103-
for (const ConfigSet::Entry* e = list; e && e->key; ++e) {
104-
ConfigValue newent { *e, string(e->value) };
105-
string varname { ::config_var_name(name, e->key) };
98+
for (const auto &e : list) {
99+
std::string varname { ::config_var_name(name, e.first) };
100+
std::string value { e.second };
106101

107102
// See if there is an entry in the top config profile
108103
auto topit = top_profile.find(varname);
109104

110105
if (topit != top_profile.end()) {
111-
newent.value = topit->second;
106+
value = topit->second;
112107
} else {
113108
// See if there is an entry in the base config profile
114109
auto it = profile.find(varname);
115110
if (it != profile.end())
116-
newent.value = it->second;
111+
value = it->second;
117112

118113
if (read_env) {
119114
// See if there is a config variable set
120-
char* val = getenv(::config_var_name(name, e->key).c_str());
115+
char* val = getenv(::config_var_name(name, e.first).c_str());
121116
if (val)
122-
newent.value = val;
117+
value = val;
123118
}
124119
}
125120

126-
m_dict.emplace(make_pair(string(e->key), newent));
121+
m_dict.emplace(make_pair(e.first, StringConverter(value)));
127122
}
128123
}
129124
};
@@ -136,7 +131,6 @@ struct ConfigSetImpl
136131
struct RuntimeConfig::RuntimeConfigImpl
137132
{
138133
// --- data
139-
static const ConfigSet::Entry s_configdata[];
140134

141135
bool m_allow_read_env = true;
142136

@@ -215,9 +209,14 @@ struct RuntimeConfig::RuntimeConfigImpl
215209
}
216210

217211
void init_config_database() {
212+
const config_entry_list_t configdata {
213+
{ "profile", "default" },
214+
{ "file", "caliper.config" }
215+
};
216+
218217
// read pre-init config set to get config file name from env var
219218
ConfigSetImpl init_config_cfg;
220-
init_config_cfg.init("config", s_configdata, m_allow_read_env, m_combined_profile, m_top_profile);
219+
init_config_cfg.init("config", configdata, m_allow_read_env, m_combined_profile, m_top_profile);
221220

222221
// read config files
223222
read_config_files(init_config_cfg.get("file").to_stringlist());
@@ -230,7 +229,7 @@ struct RuntimeConfig::RuntimeConfigImpl
230229

231230
// read "config" config again: profile may have been set in the file
232231
shared_ptr<ConfigSetImpl> config_cfg { new ConfigSetImpl };
233-
config_cfg->init("config", s_configdata, m_allow_read_env, m_combined_profile, m_top_profile);
232+
config_cfg->init("config", configdata, m_allow_read_env, m_combined_profile, m_top_profile);
234233

235234
m_database.insert(make_pair("config", config_cfg));
236235

@@ -275,7 +274,7 @@ struct RuntimeConfig::RuntimeConfigImpl
275274
m_top_profile[p.first] = p.second;
276275
}
277276

278-
shared_ptr<ConfigSetImpl> init_configset(const char* name, const ConfigSet::Entry* list) {
277+
shared_ptr<ConfigSetImpl> init_configset(const char* name, const config_entry_list_t& list) {
279278
if (m_database.empty())
280279
init_config_database();
281280

@@ -295,25 +294,11 @@ struct RuntimeConfig::RuntimeConfigImpl
295294
void print(std::ostream& os) const {
296295
for ( auto set : m_database )
297296
for ( auto entry : set.second->m_dict )
298-
os << "# " << entry.second.entry.descr
299-
<< " (" << cali_type2string(entry.second.entry.type) << ")\n"
300-
<< ::config_var_name(set.first, entry.first)
301-
<< '=' << entry.second.value << std::endl;
297+
os << ::config_var_name(set.first, entry.first)
298+
<< '=' << entry.second.to_string() << std::endl;
302299
}
303300
};
304301

305-
const ConfigSet::Entry RuntimeConfig::RuntimeConfigImpl::s_configdata[] = {
306-
{ "profile", CALI_TYPE_STRING, "default",
307-
"Configuration profile",
308-
"Configuration profile"
309-
},
310-
{ "file", CALI_TYPE_STRING, "caliper.config",
311-
"List of configuration files",
312-
"Comma-separated list of configuration files"
313-
},
314-
ConfigSet::Terminator
315-
};
316-
317302
} // namespace cali
318303

319304

@@ -329,7 +314,7 @@ StringConverter
329314
ConfigSet::get(const char* key) const
330315
{
331316
if (!mP)
332-
return std::string();
317+
return StringConverter();
333318

334319
return mP->get(key);
335320
}
@@ -351,6 +336,17 @@ RuntimeConfig::get(const char* set, const char* key)
351336

352337
ConfigSet
353338
RuntimeConfig::init(const char* name, const ConfigSet::Entry* list)
339+
{
340+
config_entry_list_t converted_list;
341+
342+
for (const ConfigSet::Entry* e = list; e && e->key; ++e)
343+
converted_list.emplace_back( std::make_pair<std::string, std::string>(e->key, e->value) );
344+
345+
return ConfigSet(mP->init_configset(name, converted_list));
346+
}
347+
348+
ConfigSet
349+
RuntimeConfig::init(const char* name, const config_entry_list_t& list)
354350
{
355351
return ConfigSet(mP->init_configset(name, list));
356352
}

src/mpi/services/mpiwrap/MpiWrap.cpp

+29-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "caliper/CaliperService.h"
55

6+
#include "../../services/Services.h"
7+
68
#include "caliper/Caliper.h"
79

810
#include "caliper/common/Log.h"
@@ -20,7 +22,7 @@ Attribute mpisize_attr { Attribute::invalid };
2022
Attribute mpicall_attr { Attribute::invalid };
2123
Attribute mpi_call_id_attr { Attribute::invalid };
2224

23-
extern void mpiwrap_init(Caliper* c, Channel* chn);
25+
extern void mpiwrap_init(Caliper* c, Channel* chn, cali::ConfigSet& cfg);
2426

2527
extern Attribute subscription_event_attr;
2628

@@ -29,6 +31,27 @@ extern Attribute subscription_event_attr;
2931
namespace
3032
{
3133

34+
const char* mpi_service_spec = R"json(
35+
{ "name": "mpi",
36+
"description": "MPI function wrapping and message tracing",
37+
"config": [
38+
{ "name": "blacklist",
39+
"description": "List of MPI functions to filter",
40+
"type": "string"
41+
},
42+
{ "name": "whitelist",
43+
"description": "List of MPI functions to instrument",
44+
"type": "string"
45+
},
46+
{ "name": "msg_tracing",
47+
"description": "List of MPI functions to instrument",
48+
"type": "bool",
49+
"value": "false"
50+
}
51+
]
52+
}
53+
)json";
54+
3255
void mpi_register(Caliper* c, Channel* chn)
3356
{
3457
Variant v_true(true);
@@ -55,7 +78,10 @@ void mpi_register(Caliper* c, Channel* chn)
5578
CALI_ATTR_SCOPE_THREAD |
5679
CALI_ATTR_ASVALUE |
5780
CALI_ATTR_SKIP_EVENTS);
58-
mpiwrap_init(c, chn);
81+
82+
ConfigSet cfg = services::init_config_from_spec(chn->config(), mpi_service_spec);
83+
84+
mpiwrap_init(c, chn, cfg);
5985

6086
Log(1).stream() << chn->name() << ": Registered MPI service" << std::endl;
6187
}
@@ -66,6 +92,6 @@ void mpi_register(Caliper* c, Channel* chn)
6692
namespace cali
6793
{
6894

69-
CaliperService mpiwrap_service = { "mpi", ::mpi_register };
95+
CaliperService mpiwrap_service = { ::mpi_service_spec, ::mpi_register };
7096

7197
} // namespace cali

0 commit comments

Comments
 (0)